Search in sources :

Example 6 with GuiceConfig

use of com.peterphi.std.guice.common.serviceprops.composite.GuiceConfig in project stdlib by petergeneric.

the class ConfigRefTest method testChangingPropertyAtRuntimeAndReinjectingMembersWorks.

@Test
public void testChangingPropertyAtRuntimeAndReinjectingMembersWorks() {
    GuiceConfig configuration = new GuiceConfig();
    configuration.set("some-name", "initial value");
    final Injector injector = Guice.createInjector(new ServicePropertiesModule(configuration));
    injector.injectMembers(this);
    assertEquals("initial value", name);
    configuration.set("some-name", "changed value");
    // Re-inject the change
    injector.injectMembers(this);
    assertEquals("changed value", name);
}
Also used : GuiceConfig(com.peterphi.std.guice.common.serviceprops.composite.GuiceConfig) Injector(com.google.inject.Injector) Test(org.junit.Test)

Example 7 with GuiceConfig

use of com.peterphi.std.guice.common.serviceprops.composite.GuiceConfig in project stdlib by petergeneric.

the class JAXBResourceFactoryTest method testResourceFromClasspathReference.

/**
 * This will almost certainly be translated into a File resource
 *
 * @throws Exception
 */
@Test
public void testResourceFromClasspathReference() throws Exception {
    MyType expected = new MyType("from-disk", true);
    GuiceConfig config = new GuiceConfig();
    config.set("some.xml", "/jaxb-resource-factory/mytype.xml");
    JAXBResourceFactory factory = new JAXBResourceFactory(config, SERIALISER_FACTORY);
    assertEquals(expected, factory.get(MyType.class, "some.xml"));
}
Also used : GuiceConfig(com.peterphi.std.guice.common.serviceprops.composite.GuiceConfig) Test(org.junit.Test)

Example 8 with GuiceConfig

use of com.peterphi.std.guice.common.serviceprops.composite.GuiceConfig in project stdlib by petergeneric.

the class JAXBResourceFactoryTest method testLiteralPropertyWithInternalVariables.

/**
 * Confirm that even if we have what looks like a variable in our XML it doesn't get processed and we get the raw data we
 * expect in the xml doc
 *
 * @throws Exception
 */
@Test
public void testLiteralPropertyWithInternalVariables() throws Exception {
    MyType expected = new MyType("${some.custom.ognl}", true);
    GuiceConfig config = new GuiceConfig();
    config.set("some.xml", "<MyType name=\"${some.custom.ognl}\"/>");
    JAXBResourceFactory factory = new JAXBResourceFactory(config, SERIALISER_FACTORY);
    assertEquals(expected, factory.get(MyType.class, "some.xml"));
}
Also used : GuiceConfig(com.peterphi.std.guice.common.serviceprops.composite.GuiceConfig) Test(org.junit.Test)

Example 9 with GuiceConfig

use of com.peterphi.std.guice.common.serviceprops.composite.GuiceConfig in project stdlib by petergeneric.

the class JAXBResourceFactoryTest method testCorruptResource.

/**
 * This will almost certainly be translated into a File resource
 *
 * @throws Exception
 */
@Test(expected = JAXBRuntimeException.class)
public void testCorruptResource() throws Exception {
    GuiceConfig config = new GuiceConfig();
    config.set("some.xml", "/jaxb-resource-factory/invalid.xml");
    JAXBResourceFactory factory = new JAXBResourceFactory(config, SERIALISER_FACTORY);
    factory.get(MyType.class, "some.xml");
}
Also used : GuiceConfig(com.peterphi.std.guice.common.serviceprops.composite.GuiceConfig) Test(org.junit.Test)

Example 10 with GuiceConfig

use of com.peterphi.std.guice.common.serviceprops.composite.GuiceConfig in project stdlib by petergeneric.

the class JAXBResourceFactoryTest method testLiteralProperty.

@Test
public void testLiteralProperty() throws Exception {
    MyType expected = new MyType("test", true);
    GuiceConfig config = new GuiceConfig();
    config.set("some.xml", "<MyType name=\"test\"/>");
    JAXBResourceFactory factory = new JAXBResourceFactory(config, SERIALISER_FACTORY);
    assertEquals(expected, factory.get(MyType.class, "some.xml"));
}
Also used : GuiceConfig(com.peterphi.std.guice.common.serviceprops.composite.GuiceConfig) Test(org.junit.Test)

Aggregations

GuiceConfig (com.peterphi.std.guice.common.serviceprops.composite.GuiceConfig)11 Test (org.junit.Test)8 Provides (com.google.inject.Provides)2 Named (com.google.inject.name.Named)2 PropertyFile (com.peterphi.std.io.PropertyFile)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 AbstractModule (com.google.inject.AbstractModule)1 Injector (com.google.inject.Injector)1 Singleton (com.google.inject.Singleton)1 Matchers (com.google.inject.matcher.Matchers)1 GuiceProperties (com.peterphi.std.guice.apploader.GuiceProperties)1 GuiceRole (com.peterphi.std.guice.apploader.GuiceRole)1 GuiceSetup (com.peterphi.std.guice.apploader.GuiceSetup)1 ClassScannerFactory (com.peterphi.std.guice.common.ClassScannerFactory)1 NetworkConfig (com.peterphi.std.guice.common.serviceprops.net.NetworkConfig)1 NetworkConfigGuiceRole (com.peterphi.std.guice.common.serviceprops.net.NetworkConfigGuiceRole)1 Transactional (com.peterphi.std.guice.database.annotation.Transactional)1 HibernateConfigurationValidator (com.peterphi.std.guice.hibernate.module.ext.HibernateConfigurationValidator)1 HibernateObservingInterceptor (com.peterphi.std.guice.hibernate.module.logging.HibernateObservingInterceptor)1 DateUserType (com.peterphi.std.guice.hibernate.usertype.DateUserType)1