use of com.haulmont.cuba.core.config.TestConfig in project cuba by cuba-platform.
the class ConfigProviderTest method testAppProperties.
@Test
public void testAppProperties() {
TestConfig config = AppBeans.get(Configuration.class).getConfig(TestConfig.class);
// String property
String stringProp = config.getStringProp();
assertNull(stringProp);
String stringPropDef = config.getStringPropDef();
assertEquals("def_value", stringPropDef);
config.setStringProp("test_value");
stringProp = config.getStringProp();
assertEquals("test_value", stringProp);
// Integer property
Integer integerProp = config.getIntegerProp();
assertNull(integerProp);
Integer integerPropDef = config.getIntegerPropDef();
assertEquals(Integer.valueOf(100), integerPropDef);
Integer integerPropDefRuntime = config.getIntegerPropDefRuntime(200);
assertEquals(Integer.valueOf(200), integerPropDefRuntime);
config.setIntegerProp(10);
integerProp = config.getIntegerProp();
assertEquals(Integer.valueOf(10), integerProp);
// primitive int
int intPropDef = config.getIntPropDef();
assertEquals(0, intPropDef);
config.setIntPropDef(1);
intPropDef = config.getIntPropDef();
assertEquals(1, intPropDef);
int intPropDefRuntime = config.getIntPropDefRuntime(11);
assertEquals(11, intPropDefRuntime);
config.setIntPropDefRuntime(12);
intPropDefRuntime = config.getIntPropDefRuntime(11);
assertEquals(12, intPropDefRuntime);
// Boolean property
Boolean booleanProp = config.getBooleanProp();
assertNull(booleanProp);
config.setBooleanProp(true);
booleanProp = config.getBooleanProp();
assertTrue(booleanProp);
Boolean booleanPropDef = config.getBooleanPropDef();
assertTrue(booleanPropDef);
// primitive boolean
boolean boolProp = config.getBoolProp();
assertFalse(boolProp);
config.setBoolProp(true);
boolProp = config.getBoolProp();
assertTrue(boolProp);
// UUID property
UUID uuidProp = config.getUuidProp();
assertNull(uuidProp);
UUID uuid = UUID.randomUUID();
config.setUuidProp(uuid);
uuidProp = config.getUuidProp();
assertEquals(uuid, uuidProp);
// Entity property
User adminUser = config.getAdminUser();
assertNotNull(adminUser);
assertEquals("admin", adminUser.getLogin());
// Enum property
RoleType roleType = config.getRoleTypeProp();
assertTrue(roleType == RoleType.STANDARD);
// Date property
Date date = config.getDateProp();
try {
assertEquals(new SimpleDateFormat("yyyy-MM-dd").parse("2013-12-12"), date);
} catch (ParseException e) {
throw new RuntimeException(e);
}
// List of Integer
List<Integer> integerList = config.getIntegerListProp();
assertEquals(Arrays.asList(1, 2, 3), integerList);
// List of String
List<String> stringList = config.getStringListProp();
assertEquals(Arrays.asList("aaa", "bbb", "ccc"), stringList);
}
use of com.haulmont.cuba.core.config.TestConfig in project cuba by cuba-platform.
the class ConfigProviderTest method testNotFoundGetterForProperty.
@Test
public void testNotFoundGetterForProperty() {
try {
TestConfig config = AppBeans.get(Configuration.class).getConfig(TestConfig.class);
config.setStringNotFoundGetProp("problem");
fail("Exception is not thrown for property without getter");
} catch (Exception e) {
// it's OK
}
}
use of com.haulmont.cuba.core.config.TestConfig in project cuba by cuba-platform.
the class ConfigProviderTest method testSystemPropOverridesAppProp.
@Test
public void testSystemPropOverridesAppProp() throws Exception {
TestConfig config = AppBeans.get(Configuration.class).getConfig(TestConfig.class);
String value = config.getStringPropDef();
assertEquals("def_value", value);
System.setProperty("cuba.test.stringPropDef", "new_value");
AppContext.Internals.getAppProperties().initSystemProperties();
value = config.getStringPropDef();
assertEquals("new_value", value);
}
use of com.haulmont.cuba.core.config.TestConfig in project cuba by cuba-platform.
the class ConfigProviderTest method testDatabaseProperties.
@Test
public void testDatabaseProperties() throws Exception {
TestConfig config = AppBeans.get(Configuration.class).getConfig(TestConfig.class);
String dbProp = config.getDatabaseProp();
assertNull(dbProp);
config.setDatabaseProp("test_value");
dbProp = config.getDatabaseProp();
assertEquals("test_value", dbProp);
config.setDatabaseProp("test_value_1");
dbProp = config.getDatabaseProp();
assertEquals("test_value_1", dbProp);
AppContext.setProperty("cuba.test.databaseProp", "overridden_value");
dbProp = config.getDatabaseProp();
assertEquals("overridden_value", dbProp);
AppContext.setProperty("cuba.test.databaseProp", "");
dbProp = config.getDatabaseProp();
assertEquals("test_value_1", dbProp);
}
use of com.haulmont.cuba.core.config.TestConfig in project cuba by cuba-platform.
the class ConfigProviderTest method testInjectedConfigBySetter.
@Test
public void testInjectedConfigBySetter() throws Exception {
TestBeanToInjectConfig bean = AppBeans.get(TestBeanToInjectConfig.class);
TestConfig config = bean.getConfig2();
assertNotNull(config);
assertTrue(config.getBooleanPropDef());
}
Aggregations