Search in sources :

Example 6 with TestXmlBean

use of com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean in project apollo by ctripcorp.

the class JavaConfigPlaceholderAutoUpdateTest method testAutoUpdateWithValueAndXmlProperty.

@Test
public void testAutoUpdateWithValueAndXmlProperty() throws Exception {
    int initialTimeout = 1000;
    int initialBatch = 2000;
    int newTimeout = 1001;
    int newBatch = 2001;
    Properties properties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(initialTimeout), BATCH_PROPERTY, String.valueOf(initialBatch));
    SimpleConfig config = prepareConfig(ConfigConsts.NAMESPACE_APPLICATION, properties);
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig8.class);
    TestJavaConfigBean javaConfigBean = context.getBean(TestJavaConfigBean.class);
    TestXmlBean xmlBean = context.getBean(TestXmlBean.class);
    assertEquals(initialTimeout, javaConfigBean.getTimeout());
    assertEquals(initialBatch, javaConfigBean.getBatch());
    assertEquals(initialTimeout, xmlBean.getTimeout());
    assertEquals(initialBatch, xmlBean.getBatch());
    Properties newProperties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(newTimeout), BATCH_PROPERTY, String.valueOf(newBatch));
    config.onRepositoryChange(ConfigConsts.NAMESPACE_APPLICATION, newProperties);
    TimeUnit.MILLISECONDS.sleep(100);
    assertEquals(newTimeout, javaConfigBean.getTimeout());
    assertEquals(newBatch, javaConfigBean.getBatch());
    assertEquals(newTimeout, xmlBean.getTimeout());
    assertEquals(newBatch, xmlBean.getBatch());
}
Also used : SimpleConfig(com.ctrip.framework.apollo.internals.SimpleConfig) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) TestXmlBean(com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean) Properties(java.util.Properties) Test(org.junit.Test)

Example 7 with TestXmlBean

use of com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean in project apollo by ctripcorp.

the class JavaConfigPlaceholderAutoUpdateTest method testAutoUpdateWithYamlFileWithValueAndXmlProperty.

@Test
public void testAutoUpdateWithYamlFileWithValueAndXmlProperty() throws Exception {
    int initialTimeout = 1000;
    int initialBatch = 2000;
    int newTimeout = 1001;
    int newBatch = 2001;
    YamlConfigFile configFile = prepareYamlConfigFile("application.yaml", readYamlContentAsConfigFileProperties("case1.yaml"));
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig13.class);
    TestJavaConfigBean javaConfigBean = context.getBean(TestJavaConfigBean.class);
    TestXmlBean xmlBean = context.getBean(TestXmlBean.class);
    assertEquals(initialTimeout, javaConfigBean.getTimeout());
    assertEquals(initialBatch, javaConfigBean.getBatch());
    assertEquals(initialTimeout, xmlBean.getTimeout());
    assertEquals(initialBatch, xmlBean.getBatch());
    configFile.onRepositoryChange("application.yaml", readYamlContentAsConfigFileProperties("case1-new.yaml"));
    TimeUnit.MILLISECONDS.sleep(100);
    assertEquals(newTimeout, javaConfigBean.getTimeout());
    assertEquals(newBatch, javaConfigBean.getBatch());
    assertEquals(newTimeout, xmlBean.getTimeout());
    assertEquals(newBatch, xmlBean.getBatch());
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) TestXmlBean(com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean) YamlConfigFile(com.ctrip.framework.apollo.internals.YamlConfigFile) Test(org.junit.Test)

Example 8 with TestXmlBean

use of com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean in project apollo by ctripcorp.

the class XmlConfigPlaceholderAutoUpdateTest method testAutoUpdateWithOneNamespace.

@Test
public void testAutoUpdateWithOneNamespace() throws Exception {
    int initialTimeout = 1000;
    int initialBatch = 2000;
    int newTimeout = 1001;
    int newBatch = 2001;
    Properties properties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(initialTimeout), BATCH_PROPERTY, String.valueOf(initialBatch));
    SimpleConfig config = prepareConfig(ConfigConsts.NAMESPACE_APPLICATION, properties);
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/XmlConfigPlaceholderTest1.xml");
    TestXmlBean bean = context.getBean(TestXmlBean.class);
    assertEquals(initialTimeout, bean.getTimeout());
    assertEquals(initialBatch, bean.getBatch());
    Properties newProperties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(newTimeout), BATCH_PROPERTY, String.valueOf(newBatch));
    config.onRepositoryChange(ConfigConsts.NAMESPACE_APPLICATION, newProperties);
    TimeUnit.MILLISECONDS.sleep(100);
    assertEquals(newTimeout, bean.getTimeout());
    assertEquals(newBatch, bean.getBatch());
}
Also used : SimpleConfig(com.ctrip.framework.apollo.internals.SimpleConfig) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) TestXmlBean(com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean) Properties(java.util.Properties) Test(org.junit.Test)

Example 9 with TestXmlBean

use of com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean in project apollo by ctripcorp.

the class XmlConfigPlaceholderAutoUpdateTest method testAutoUpdateWithTypeMismatch.

@Test
public void testAutoUpdateWithTypeMismatch() throws Exception {
    int initialTimeout = 1000;
    int initialBatch = 2000;
    int newTimeout = 1001;
    String newBatch = "newBatch";
    Properties properties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(initialTimeout), BATCH_PROPERTY, String.valueOf(initialBatch));
    SimpleConfig config = prepareConfig(ConfigConsts.NAMESPACE_APPLICATION, properties);
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/XmlConfigPlaceholderTest1.xml");
    TestXmlBean bean = context.getBean(TestXmlBean.class);
    assertEquals(initialTimeout, bean.getTimeout());
    assertEquals(initialBatch, bean.getBatch());
    Properties newProperties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(newTimeout), BATCH_PROPERTY, newBatch);
    config.onRepositoryChange(ConfigConsts.NAMESPACE_APPLICATION, newProperties);
    TimeUnit.MILLISECONDS.sleep(300);
    assertEquals(newTimeout, bean.getTimeout());
    assertEquals(initialBatch, bean.getBatch());
}
Also used : SimpleConfig(com.ctrip.framework.apollo.internals.SimpleConfig) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) TestXmlBean(com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean) Properties(java.util.Properties) Test(org.junit.Test)

Example 10 with TestXmlBean

use of com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean in project apollo by ctripcorp.

the class XmlConfigPlaceholderAutoUpdateTest method testAutoUpdateWithMultipleNamespaces.

@Test
public void testAutoUpdateWithMultipleNamespaces() throws Exception {
    int initialTimeout = 1000;
    int initialBatch = 2000;
    int newTimeout = 1001;
    int newBatch = 2001;
    Properties applicationProperties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(initialTimeout));
    Properties fxApolloProperties = assembleProperties(BATCH_PROPERTY, String.valueOf(initialBatch));
    SimpleConfig applicationConfig = prepareConfig(ConfigConsts.NAMESPACE_APPLICATION, applicationProperties);
    SimpleConfig fxApolloConfig = prepareConfig(FX_APOLLO_NAMESPACE, fxApolloProperties);
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/XmlConfigPlaceholderTest3.xml");
    TestXmlBean bean = context.getBean(TestXmlBean.class);
    assertEquals(initialTimeout, bean.getTimeout());
    assertEquals(initialBatch, bean.getBatch());
    Properties newApplicationProperties = assembleProperties(TIMEOUT_PROPERTY, String.valueOf(newTimeout));
    applicationConfig.onRepositoryChange(ConfigConsts.NAMESPACE_APPLICATION, newApplicationProperties);
    TimeUnit.MILLISECONDS.sleep(100);
    assertEquals(newTimeout, bean.getTimeout());
    assertEquals(initialBatch, bean.getBatch());
    Properties newFxApolloProperties = assembleProperties(BATCH_PROPERTY, String.valueOf(newBatch));
    fxApolloConfig.onRepositoryChange(FX_APOLLO_NAMESPACE, newFxApolloProperties);
    TimeUnit.MILLISECONDS.sleep(100);
    assertEquals(newTimeout, bean.getTimeout());
    assertEquals(newBatch, bean.getBatch());
}
Also used : SimpleConfig(com.ctrip.framework.apollo.internals.SimpleConfig) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) TestXmlBean(com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

TestXmlBean (com.ctrip.framework.apollo.spring.XmlConfigPlaceholderTest.TestXmlBean)12 Test (org.junit.Test)12 SimpleConfig (com.ctrip.framework.apollo.internals.SimpleConfig)11 Properties (java.util.Properties)11 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)10 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 YamlConfigFile (com.ctrip.framework.apollo.internals.YamlConfigFile)1