Search in sources :

Example 16 with ConfigurationWriter

use of org.infinispan.commons.configuration.io.ConfigurationWriter in project infinispan by infinispan.

the class ServerConfigurationSerializerTest method testConfigurationSerialization.

@Test
public void testConfigurationSerialization() throws IOException {
    Properties properties = new Properties();
    properties.put("infinispan.server.config.path", config.getParent().getParent().toString());
    properties.setProperty(Server.INFINISPAN_SERVER_HOME_PATH, Paths.get(System.getProperty("build.directory")).toString());
    ParserRegistry registry = new ParserRegistry(Thread.currentThread().getContextClassLoader(), false, properties);
    ConfigurationBuilderHolder holderBefore = registry.parse(config);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Map<String, Configuration> configurations = new HashMap<>();
    for (Map.Entry<String, ConfigurationBuilder> configuration : holderBefore.getNamedConfigurationBuilders().entrySet()) {
        configurations.put(configuration.getKey(), configuration.getValue().build());
    }
    try (ConfigurationWriter writer = ConfigurationWriter.to(baos).withType(type).clearTextSecrets(true).build()) {
        registry.serialize(writer, holderBefore.getGlobalConfigurationBuilder().build(), configurations);
    }
    log.debug(baos);
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ConfigurationBuilderHolder holderAfter = registry.parse(bais, null, type);
    GlobalConfiguration globalConfigurationBefore = holderBefore.getGlobalConfigurationBuilder().build();
    GlobalConfiguration globalConfigurationAfter = holderAfter.getGlobalConfigurationBuilder().build();
    ServerConfiguration serverBefore = globalConfigurationBefore.module(ServerConfiguration.class);
    ServerConfiguration serverAfter = globalConfigurationAfter.module(ServerConfiguration.class);
    compare(serverBefore.interfaces.interfaces(), serverAfter.interfaces.interfaces());
    compare(serverBefore.socketBindings, serverAfter.socketBindings);
    compare(serverBefore.dataSources, serverAfter.dataSources);
    compare(serverBefore.security.credentialStores(), serverAfter.security.credentialStores());
    compare(serverBefore.security.realms().realms(), serverAfter.security.realms().realms());
    compare(serverBefore.security.transport(), serverAfter.security.transport(), org.infinispan.server.configuration.Attribute.SECURITY_REALM.toString());
    compare(serverBefore.endpoints.endpoints(), serverAfter.endpoints.endpoints());
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) ConfigurationWriter(org.infinispan.commons.configuration.io.ConfigurationWriter) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) Configuration(org.infinispan.configuration.cache.Configuration) HashMap(java.util.HashMap) ParserRegistry(org.infinispan.configuration.parsing.ParserRegistry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties) ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

ConfigurationWriter (org.infinispan.commons.configuration.io.ConfigurationWriter)16 StringBuilderWriter (org.infinispan.commons.io.StringBuilderWriter)9 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)9 Configuration (org.infinispan.configuration.cache.Configuration)8 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)8 NettyRestResponse (org.infinispan.rest.NettyRestResponse)6 Map (java.util.Map)5 ConfigurationBuilderHolder (org.infinispan.configuration.parsing.ConfigurationBuilderHolder)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 HashMap (java.util.HashMap)4 ParserRegistry (org.infinispan.configuration.parsing.ParserRegistry)4 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)4 IOException (java.io.IOException)3 MediaType (org.infinispan.commons.dataconversion.MediaType)3 RemoteStoreConfiguration (org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration)3 MediaTypeUtils.negotiateMediaType (org.infinispan.rest.resources.MediaTypeUtils.negotiateMediaType)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 URL (java.net.URL)2