use of com.ctrip.framework.apollo.core.dto.ApolloConfig in project apollo by ctripcorp.
the class ConfigFileControllerTest method testQueryConfigAsJson.
@Test
public void testQueryConfigAsJson() throws Exception {
String someKey = "someKey";
String someValue = "someValue";
Type responseType = new TypeToken<Map<String, String>>() {
}.getType();
String someWatchKey = "someWatchKey";
Set<String> watchKeys = Sets.newHashSet(someWatchKey);
Map<String, String> configurations = ImmutableMap.of(someKey, someValue);
ApolloConfig someApolloConfig = mock(ApolloConfig.class);
when(configController.queryConfig(someAppId, someClusterName, someNamespace, someDataCenter, "-1", someClientIp, someClientLabel, null, someRequest, someResponse)).thenReturn(someApolloConfig);
when(someApolloConfig.getConfigurations()).thenReturn(configurations);
when(watchKeysUtil.assembleAllWatchKeys(someAppId, someClusterName, someNamespace, someDataCenter)).thenReturn(watchKeys);
ResponseEntity<String> response = configFileController.queryConfigAsJson(someAppId, someClusterName, someNamespace, someDataCenter, someClientIp, someClientLabel, someRequest, someResponse);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(configurations, GSON.fromJson(response.getBody(), responseType));
}
use of com.ctrip.framework.apollo.core.dto.ApolloConfig in project apollo by ctripcorp.
the class ConfigFileControllerTest method testQueryConfigAsProperties.
@Test
public void testQueryConfigAsProperties() throws Exception {
String someKey = "someKey";
String someValue = "someValue";
String anotherKey = "anotherKey";
String anotherValue = "anotherValue";
String someWatchKey = "someWatchKey";
String anotherWatchKey = "anotherWatchKey";
Set<String> watchKeys = Sets.newHashSet(someWatchKey, anotherWatchKey);
String cacheKey = configFileController.assembleCacheKey(ConfigFileController.ConfigFileOutputFormat.PROPERTIES, someAppId, someClusterName, someNamespace, someDataCenter);
Map<String, String> configurations = ImmutableMap.of(someKey, someValue, anotherKey, anotherValue);
ApolloConfig someApolloConfig = mock(ApolloConfig.class);
when(someApolloConfig.getConfigurations()).thenReturn(configurations);
when(configController.queryConfig(someAppId, someClusterName, someNamespace, someDataCenter, "-1", someClientIp, someClientLabel, null, someRequest, someResponse)).thenReturn(someApolloConfig);
when(watchKeysUtil.assembleAllWatchKeys(someAppId, someClusterName, someNamespace, someDataCenter)).thenReturn(watchKeys);
ResponseEntity<String> response = configFileController.queryConfigAsProperties(someAppId, someClusterName, someNamespace, someDataCenter, someClientIp, someClientLabel, someRequest, someResponse);
assertEquals(2, watchedKeys2CacheKey.size());
assertEquals(2, cacheKey2WatchedKeys.size());
assertTrue(watchedKeys2CacheKey.containsEntry(someWatchKey, cacheKey));
assertTrue(watchedKeys2CacheKey.containsEntry(anotherWatchKey, cacheKey));
assertTrue(cacheKey2WatchedKeys.containsEntry(cacheKey, someWatchKey));
assertTrue(cacheKey2WatchedKeys.containsEntry(cacheKey, anotherWatchKey));
assertEquals(HttpStatus.OK, response.getStatusCode());
assertTrue(response.getBody().contains(String.format("%s=%s", someKey, someValue)));
assertTrue(response.getBody().contains(String.format("%s=%s", anotherKey, anotherValue)));
ResponseEntity<String> anotherResponse = configFileController.queryConfigAsProperties(someAppId, someClusterName, someNamespace, someDataCenter, someClientIp, someClientLabel, someRequest, someResponse);
assertEquals(response, anotherResponse);
verify(configController, times(1)).queryConfig(someAppId, someClusterName, someNamespace, someDataCenter, "-1", someClientIp, someClientLabel, null, someRequest, someResponse);
}
use of com.ctrip.framework.apollo.core.dto.ApolloConfig in project apollo by ctripcorp.
the class ConfigControllerIntegrationTest method testQueryPublicConfigWithDataCenterFoundAndOverride.
@Test
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/test-release-public-dc-override.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryPublicConfigWithDataCenterFoundAndOverride() throws Exception {
ResponseEntity<ApolloConfig> response = restTemplate.getForEntity("http://{baseurl}/configs/{appId}/{clusterName}/{namespace}?dataCenter={dateCenter}", ApolloConfig.class, getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace, someDC);
ApolloConfig result = response.getBody();
assertEquals("TEST-RELEASE-KEY6" + ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR + "TEST-RELEASE-KEY4", result.getReleaseKey());
assertEquals(someAppId, result.getAppId());
assertEquals(someDC, result.getCluster());
assertEquals(somePublicNamespace, result.getNamespaceName());
assertEquals("override-someDC-v1", result.getConfigurations().get("k1"));
assertEquals("someDC-v2", result.getConfigurations().get("k2"));
}
use of com.ctrip.framework.apollo.core.dto.ApolloConfig in project apollo by ctripcorp.
the class ConfigControllerIntegrationTest method testQueryConfigForNoAppIdPlaceHolderWithPrivateNamespace.
@Test
public void testQueryConfigForNoAppIdPlaceHolderWithPrivateNamespace() throws Exception {
HttpStatusCodeException httpException = null;
try {
ResponseEntity<ApolloConfig> response = restTemplate.getForEntity("http://{baseurl}/configs/{appId}/{clusterName}/{namespace}", ApolloConfig.class, getHostUrl(), ConfigConsts.NO_APPID_PLACEHOLDER, someCluster, ConfigConsts.NAMESPACE_APPLICATION);
} catch (HttpStatusCodeException ex) {
httpException = ex;
}
assertEquals(HttpStatus.NOT_FOUND, httpException.getStatusCode());
}
use of com.ctrip.framework.apollo.core.dto.ApolloConfig in project apollo by ctripcorp.
the class ConfigControllerIntegrationTest method testQueryPublicConfigWithIncorrectCaseAndDataCenterFoundAndOverride.
@Test
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/test-release-public-dc-override.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryPublicConfigWithIncorrectCaseAndDataCenterFoundAndOverride() throws Exception {
ResponseEntity<ApolloConfig> response = restTemplate.getForEntity("http://{baseurl}/configs/{appId}/{clusterName}/{namespace}?dataCenter={dateCenter}", ApolloConfig.class, getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace.toUpperCase(), someDC);
ApolloConfig result = response.getBody();
assertEquals("TEST-RELEASE-KEY6" + ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR + "TEST-RELEASE-KEY4", result.getReleaseKey());
assertEquals("override-someDC-v1", result.getConfigurations().get("k1"));
assertEquals("someDC-v2", result.getConfigurations().get("k2"));
}
Aggregations