use of org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl in project incubator-servicecomb-java-chassis by apache.
the class ApolloClientTest method refreshApolloConfig.
@Test
public void refreshApolloConfig() {
ApolloConfig apolloConfig = ApolloConfig.INSTANCE;
RestTemplate rest = Mockito.mock(RestTemplate.class);
ResponseEntity<String> responseEntity = new ResponseEntity<>("{\"apollo\":\"mocked\", \"configurations\":{\"timeout\":1000}}", HttpStatus.OK);
Mockito.when(rest.exchange(Matchers.anyString(), Matchers.any(HttpMethod.class), Matchers.<HttpEntity<String>>any(), Matchers.<Class<String>>any())).thenReturn(responseEntity);
ApolloConfigurationSourceImpl impl = new ApolloConfigurationSourceImpl();
UpdateHandler updateHandler = impl.new UpdateHandler();
ApolloClient apolloClient = new ApolloClient(updateHandler);
Deencapsulation.setField(apolloClient, "rest", rest);
ConfigRefresh cr = apolloClient.new ConfigRefresh(apolloConfig.getServerUri());
cr.run();
Map<String, Object> originMap = Deencapsulation.getField(apolloClient, "originalConfigMap");
Assert.assertEquals(1, originMap.size());
}
use of org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl in project incubator-servicecomb-java-chassis by apache.
the class ApolloClientTest method testCompareChangedConfig.
@Test
public void testCompareChangedConfig() {
boolean status = true;
Map<String, Object> before = new HashMap<>();
Map<String, Object> after = new HashMap<>();
ApolloConfigurationSourceImpl impl = new ApolloConfigurationSourceImpl();
UpdateHandler updateHandler = impl.new UpdateHandler();
ApolloClient apolloClient = new ApolloClient(updateHandler);
ConfigRefresh cr = apolloClient.new ConfigRefresh("");
try {
Deencapsulation.invoke(cr, "compareChangedConfig", before, after);
} catch (Exception e) {
status = false;
}
Assert.assertTrue(status);
status = true;
before.put("test", "testValue");
try {
Deencapsulation.invoke(cr, "compareChangedConfig", before, after);
} catch (Exception e) {
status = false;
}
Assert.assertTrue(status);
status = true;
after.put("test", "testValue2");
try {
Deencapsulation.invoke(cr, "compareChangedConfig", before, after);
} catch (Exception e) {
status = false;
}
Assert.assertTrue(status);
status = true;
try {
Deencapsulation.invoke(cr, "compareChangedConfig", before, after);
} catch (Exception e) {
status = false;
}
Assert.assertTrue(status);
}
use of org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl in project java-chassis by ServiceComb.
the class ApolloClientTest method testCompareChangedConfig.
@Test
public void testCompareChangedConfig() {
boolean status = true;
Map<String, Object> before = new HashMap<>();
Map<String, Object> after = new HashMap<>();
ApolloConfigurationSourceImpl impl = new ApolloConfigurationSourceImpl();
UpdateHandler updateHandler = impl.new UpdateHandler();
ApolloClient apolloClient = new ApolloClient(updateHandler);
ConfigRefresh cr = apolloClient.new ConfigRefresh("");
try {
Deencapsulation.invoke(cr, "compareChangedConfig", before, after);
} catch (Exception e) {
status = false;
}
Assert.assertTrue(status);
status = true;
before.put("test", "testValue");
try {
Deencapsulation.invoke(cr, "compareChangedConfig", before, after);
} catch (Exception e) {
status = false;
}
Assert.assertTrue(status);
status = true;
after.put("test", "testValue2");
try {
Deencapsulation.invoke(cr, "compareChangedConfig", before, after);
} catch (Exception e) {
status = false;
}
Assert.assertTrue(status);
status = true;
try {
Deencapsulation.invoke(cr, "compareChangedConfig", before, after);
} catch (Exception e) {
status = false;
}
Assert.assertTrue(status);
}
use of org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl in project java-chassis by ServiceComb.
the class ApolloClientTest method refreshApolloConfig.
@Test
public void refreshApolloConfig() {
ApolloConfig apolloConfig = ApolloConfig.INSTANCE;
RestTemplate rest = Mockito.mock(RestTemplate.class);
ResponseEntity<String> responseEntity = new ResponseEntity<>("{\"apollo\":\"mocked\", \"configurations\":{\"timeout\":1000}}", HttpStatus.OK);
Mockito.when(rest.exchange(Matchers.anyString(), Matchers.any(HttpMethod.class), Matchers.<HttpEntity<String>>any(), Matchers.<Class<String>>any())).thenReturn(responseEntity);
ApolloConfigurationSourceImpl impl = new ApolloConfigurationSourceImpl();
UpdateHandler updateHandler = impl.new UpdateHandler();
ApolloClient apolloClient = new ApolloClient(updateHandler);
Deencapsulation.setField(apolloClient, "rest", rest);
ConfigRefresh cr = apolloClient.new ConfigRefresh(apolloConfig.getServerUri());
cr.run();
Map<String, Object> originMap = Deencapsulation.getField(apolloClient, "originalConfigMap");
Assert.assertEquals(1, originMap.size());
}
Aggregations