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());
}
Aggregations