use of org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl.UpdateHandler 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.UpdateHandler in project incubator-servicecomb-java-chassis by apache.
the class ApolloConfigurationSourceImplTest method testUpdate.
@Test
public void testUpdate() throws Exception {
ApolloConfigurationSourceImpl apolloConfigurationSource = new ApolloConfigurationSourceImpl();
apolloConfigurationSource.addUpdateListener(result -> Assert.assertTrue(!result.getChanged().isEmpty()));
UpdateHandler udateHandler = Deencapsulation.getField(apolloConfigurationSource, UpdateHandler.class);
Map<String, Object> updateItems = new HashMap<>();
updateItems.put("testKey", "testValue");
udateHandler.handle(SET, updateItems);
}
use of org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl.UpdateHandler in project incubator-servicecomb-java-chassis by apache.
the class ApolloConfigurationSourceImplTest method testDelete.
@Test
public void testDelete() throws Exception {
ApolloConfigurationSourceImpl apolloConfigurationSource = new ApolloConfigurationSourceImpl();
apolloConfigurationSource.addUpdateListener(result -> Assert.assertTrue(!result.getDeleted().isEmpty()));
UpdateHandler udateHandler = Deencapsulation.getField(apolloConfigurationSource, UpdateHandler.class);
Map<String, Object> deleteItems = new HashMap<>();
deleteItems.put("testKey", "testValue");
apolloConfigurationSource.getCurrentData().put("testKey", "testValue");
udateHandler.handle(DELETE, deleteItems);
Assert.assertTrue(apolloConfigurationSource.getCurrentData().isEmpty());
}
use of org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl.UpdateHandler 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());
}
use of org.apache.servicecomb.config.archaius.sources.ApolloConfigurationSourceImpl.UpdateHandler in project java-chassis by ServiceComb.
the class ApolloConfigurationSourceImplTest method testDelete.
@Test
public void testDelete() throws Exception {
ApolloConfigurationSourceImpl apolloConfigurationSource = new ApolloConfigurationSourceImpl();
apolloConfigurationSource.addUpdateListener(result -> Assert.assertTrue(!result.getDeleted().isEmpty()));
UpdateHandler udateHandler = Deencapsulation.getField(apolloConfigurationSource, UpdateHandler.class);
Map<String, Object> deleteItems = new HashMap<>();
deleteItems.put("testKey", "testValue");
apolloConfigurationSource.getCurrentData().put("testKey", "testValue");
udateHandler.handle(DELETE, deleteItems);
Assert.assertTrue(apolloConfigurationSource.getCurrentData().isEmpty());
}
Aggregations