Search in sources :

Example 1 with TestConfig

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);
}
Also used : TestConfig(com.haulmont.cuba.core.config.TestConfig) User(com.haulmont.cuba.security.entity.User) Configuration(com.haulmont.cuba.core.global.Configuration) RoleType(com.haulmont.cuba.security.entity.RoleType) Date(java.util.Date) ParseException(java.text.ParseException) UUID(java.util.UUID) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.jupiter.api.Test)

Example 2 with TestConfig

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
    }
}
Also used : TestConfig(com.haulmont.cuba.core.config.TestConfig) Configuration(com.haulmont.cuba.core.global.Configuration) ParseException(java.text.ParseException) Test(org.junit.jupiter.api.Test)

Example 3 with TestConfig

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);
}
Also used : TestConfig(com.haulmont.cuba.core.config.TestConfig) Configuration(com.haulmont.cuba.core.global.Configuration) Test(org.junit.jupiter.api.Test)

Example 4 with TestConfig

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);
}
Also used : TestConfig(com.haulmont.cuba.core.config.TestConfig) Configuration(com.haulmont.cuba.core.global.Configuration) Test(org.junit.jupiter.api.Test)

Example 5 with TestConfig

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());
}
Also used : TestConfig(com.haulmont.cuba.core.config.TestConfig) TestBeanToInjectConfig(com.haulmont.cuba.core.config.TestBeanToInjectConfig) Test(org.junit.jupiter.api.Test)

Aggregations

TestConfig (com.haulmont.cuba.core.config.TestConfig)6 Test (org.junit.jupiter.api.Test)6 Configuration (com.haulmont.cuba.core.global.Configuration)4 TestBeanToInjectConfig (com.haulmont.cuba.core.config.TestBeanToInjectConfig)2 ParseException (java.text.ParseException)2 RoleType (com.haulmont.cuba.security.entity.RoleType)1 User (com.haulmont.cuba.security.entity.User)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 UUID (java.util.UUID)1