Search in sources :

Example 1 with JsonBean

use of com.ctrip.framework.apollo.spring.JavaConfigPlaceholderTest.JsonBean in project apollo by ctripcorp.

the class JavaConfigPlaceholderAutoUpdateTest method testAutoUpdateJsonValueWithInvalidValue.

@Test
public void testAutoUpdateJsonValueWithInvalidValue() throws Exception {
    String someValidValue = "{\"a\":\"someString\", \"b\":10}";
    String someInvalidValue = "someInvalidValue";
    Properties properties = assembleProperties("jsonProperty", someValidValue);
    SimpleConfig config = prepareConfig(ConfigConsts.NAMESPACE_APPLICATION, properties);
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig10.class);
    TestApolloJsonValue bean = context.getBean(TestApolloJsonValue.class);
    JsonBean jsonBean = bean.getJsonBean();
    assertEquals("someString", jsonBean.getA());
    assertEquals(10, jsonBean.getB());
    Properties newProperties = assembleProperties("jsonProperty", someInvalidValue);
    config.onRepositoryChange(ConfigConsts.NAMESPACE_APPLICATION, newProperties);
    TimeUnit.MILLISECONDS.sleep(300);
    // should not change anything
    assertTrue(jsonBean == bean.getJsonBean());
}
Also used : SimpleConfig(com.ctrip.framework.apollo.internals.SimpleConfig) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) JsonBean(com.ctrip.framework.apollo.spring.JavaConfigPlaceholderTest.JsonBean) Properties(java.util.Properties) Test(org.junit.Test)

Example 2 with JsonBean

use of com.ctrip.framework.apollo.spring.JavaConfigPlaceholderTest.JsonBean in project apollo by ctripcorp.

the class JavaConfigPlaceholderAutoUpdateTest method testAutoUpdateJsonValueWithNoValueAndDefaultValue.

@Test
public void testAutoUpdateJsonValueWithNoValueAndDefaultValue() throws Exception {
    String someValidValue = "{\"a\":\"someString\", \"b\":10}";
    Properties properties = assembleProperties("jsonProperty", someValidValue);
    SimpleConfig config = prepareConfig(ConfigConsts.NAMESPACE_APPLICATION, properties);
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig11.class);
    TestApolloJsonValueWithDefaultValue bean = context.getBean(TestApolloJsonValueWithDefaultValue.class);
    JsonBean jsonBean = bean.getJsonBean();
    assertEquals("someString", jsonBean.getA());
    assertEquals(10, jsonBean.getB());
    Properties newProperties = new Properties();
    config.onRepositoryChange(ConfigConsts.NAMESPACE_APPLICATION, newProperties);
    TimeUnit.MILLISECONDS.sleep(100);
    JsonBean newJsonBean = bean.getJsonBean();
    assertEquals("defaultString", newJsonBean.getA());
    assertEquals(1, newJsonBean.getB());
}
Also used : SimpleConfig(com.ctrip.framework.apollo.internals.SimpleConfig) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) JsonBean(com.ctrip.framework.apollo.spring.JavaConfigPlaceholderTest.JsonBean) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with JsonBean

use of com.ctrip.framework.apollo.spring.JavaConfigPlaceholderTest.JsonBean in project apollo by ctripcorp.

the class JavaConfigPlaceholderAutoUpdateTest method testAutoUpdateJsonValueWithNoValueAndNoDefaultValue.

@Test
public void testAutoUpdateJsonValueWithNoValueAndNoDefaultValue() throws Exception {
    String someValidValue = "{\"a\":\"someString\", \"b\":10}";
    Properties properties = assembleProperties("jsonProperty", someValidValue);
    SimpleConfig config = prepareConfig(ConfigConsts.NAMESPACE_APPLICATION, properties);
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig10.class);
    TestApolloJsonValue bean = context.getBean(TestApolloJsonValue.class);
    JsonBean jsonBean = bean.getJsonBean();
    assertEquals("someString", jsonBean.getA());
    assertEquals(10, jsonBean.getB());
    Properties newProperties = new Properties();
    config.onRepositoryChange(ConfigConsts.NAMESPACE_APPLICATION, newProperties);
    TimeUnit.MILLISECONDS.sleep(300);
    // should not change anything
    assertTrue(jsonBean == bean.getJsonBean());
}
Also used : SimpleConfig(com.ctrip.framework.apollo.internals.SimpleConfig) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) JsonBean(com.ctrip.framework.apollo.spring.JavaConfigPlaceholderTest.JsonBean) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

SimpleConfig (com.ctrip.framework.apollo.internals.SimpleConfig)3 JsonBean (com.ctrip.framework.apollo.spring.JavaConfigPlaceholderTest.JsonBean)3 Properties (java.util.Properties)3 Test (org.junit.Test)3 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)3