Search in sources :

Example 1 with RoleType

use of com.haulmont.cuba.security.entity.RoleType 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.Test)

Aggregations

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