Search in sources :

Example 31 with ApolloConfig

use of com.ctrip.framework.apollo.core.dto.ApolloConfig in project apollo by ctripcorp.

the class ConfigControllerTest method testQueryConfigForNoAppIdPlaceHolderWithPublicNamespace.

@Test
public void testQueryConfigForNoAppIdPlaceHolderWithPublicNamespace() throws Exception {
    String someClientSideReleaseKey = "1";
    String someServerSideReleaseKey = "2";
    HttpServletResponse someResponse = mock(HttpServletResponse.class);
    String somePublicAppId = "somePublicAppId";
    AppNamespace somePublicAppNamespace = assemblePublicAppNamespace(somePublicAppId, somePublicNamespaceName);
    String appId = ConfigConsts.NO_APPID_PLACEHOLDER;
    when(appNamespaceService.findPublicNamespaceByName(somePublicNamespaceName)).thenReturn(somePublicAppNamespace);
    when(configService.loadConfig(appId, someClientIp, someClientLabel, somePublicAppId, someClusterName, somePublicNamespaceName, someDataCenter, someNotificationMessages)).thenReturn(somePublicRelease);
    when(somePublicRelease.getReleaseKey()).thenReturn(someServerSideReleaseKey);
    when(namespaceUtil.normalizeNamespace(appId, somePublicNamespaceName)).thenReturn(somePublicNamespaceName);
    ApolloConfig result = configController.queryConfig(appId, someClusterName, somePublicNamespaceName, someDataCenter, someClientSideReleaseKey, someClientIp, someClientLabel, someMessagesAsString, someRequest, someResponse);
    verify(configService, never()).loadConfig(appId, someClientIp, someClientLabel, appId, someClusterName, somePublicNamespaceName, someDataCenter, someNotificationMessages);
    assertEquals(someServerSideReleaseKey, result.getReleaseKey());
    assertEquals(appId, result.getAppId());
    assertEquals(someClusterName, result.getCluster());
    assertEquals(somePublicNamespaceName, result.getNamespaceName());
    assertEquals("foo", result.getConfigurations().get("apollo.public.bar"));
}
Also used : ApolloConfig(com.ctrip.framework.apollo.core.dto.ApolloConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Test(org.junit.Test)

Example 32 with ApolloConfig

use of com.ctrip.framework.apollo.core.dto.ApolloConfig in project apollo by ctripcorp.

the class ConfigControllerTest method testQueryConfigWithPublicNamespaceAndAppOverride.

@Test
public void testQueryConfigWithPublicNamespaceAndAppOverride() throws Exception {
    String someAppSideReleaseKey = "1";
    String somePublicAppSideReleaseKey = "2";
    HttpServletResponse someResponse = mock(HttpServletResponse.class);
    String somePublicAppId = "somePublicAppId";
    AppNamespace somePublicAppNamespace = assemblePublicAppNamespace(somePublicAppId, somePublicNamespaceName);
    when(someRelease.getConfigurations()).thenReturn("{\"apollo.public.foo\": \"foo-override\"}");
    when(somePublicRelease.getConfigurations()).thenReturn("{\"apollo.public.foo\": \"foo\", \"apollo.public.bar\": \"bar\"}");
    when(configService.loadConfig(someAppId, someClientIp, someClientLabel, someAppId, someClusterName, somePublicNamespaceName, someDataCenter, someNotificationMessages)).thenReturn(someRelease);
    when(someRelease.getReleaseKey()).thenReturn(someAppSideReleaseKey);
    when(someRelease.getNamespaceName()).thenReturn(somePublicNamespaceName);
    when(appNamespaceService.findPublicNamespaceByName(somePublicNamespaceName)).thenReturn(somePublicAppNamespace);
    when(configService.loadConfig(someAppId, someClientIp, someClientLabel, somePublicAppId, someClusterName, somePublicNamespaceName, someDataCenter, someNotificationMessages)).thenReturn(somePublicRelease);
    when(somePublicRelease.getReleaseKey()).thenReturn(somePublicAppSideReleaseKey);
    when(somePublicRelease.getAppId()).thenReturn(somePublicAppId);
    when(somePublicRelease.getClusterName()).thenReturn(someDataCenter);
    when(somePublicRelease.getNamespaceName()).thenReturn(somePublicNamespaceName);
    ApolloConfig result = configController.queryConfig(someAppId, someClusterName, somePublicNamespaceName, someDataCenter, someAppSideReleaseKey, someClientIp, someClientLabel, someMessagesAsString, someRequest, someResponse);
    assertEquals(Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR).join(someAppSideReleaseKey, somePublicAppSideReleaseKey), result.getReleaseKey());
    assertEquals(someAppId, result.getAppId());
    assertEquals(someClusterName, result.getCluster());
    assertEquals(somePublicNamespaceName, result.getNamespaceName());
    assertEquals("foo-override", result.getConfigurations().get("apollo.public.foo"));
    assertEquals("bar", result.getConfigurations().get("apollo.public.bar"));
    verify(instanceConfigAuditUtil, times(1)).audit(someAppId, someClusterName, someDataCenter, someClientIp, someAppId, someClusterName, somePublicNamespaceName, someAppSideReleaseKey);
    verify(instanceConfigAuditUtil, times(1)).audit(someAppId, someClusterName, someDataCenter, someClientIp, somePublicAppId, someDataCenter, somePublicNamespaceName, somePublicAppSideReleaseKey);
}
Also used : ApolloConfig(com.ctrip.framework.apollo.core.dto.ApolloConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Test(org.junit.Test)

Example 33 with ApolloConfig

use of com.ctrip.framework.apollo.core.dto.ApolloConfig in project apollo by ctripcorp.

the class ConfigControllerTest method testQueryConfigForNoAppIdPlaceHolder.

@Test
public void testQueryConfigForNoAppIdPlaceHolder() throws Exception {
    String someClientSideReleaseKey = "1";
    HttpServletResponse someResponse = mock(HttpServletResponse.class);
    String appId = ConfigConsts.NO_APPID_PLACEHOLDER;
    ApolloConfig result = configController.queryConfig(appId, someClusterName, defaultNamespaceName, someDataCenter, someClientSideReleaseKey, someClientIp, someClientLabel, someMessagesAsString, someRequest, someResponse);
    verify(configService, never()).loadConfig(appId, someClientIp, someAppId, someClientLabel, someClusterName, defaultNamespaceName, someDataCenter, someNotificationMessages);
    verify(appNamespaceService, never()).findPublicNamespaceByName(defaultNamespaceName);
    assertNull(result);
    verify(someResponse, times(1)).sendError(eq(HttpServletResponse.SC_NOT_FOUND), anyString());
}
Also used : ApolloConfig(com.ctrip.framework.apollo.core.dto.ApolloConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.Test)

Example 34 with ApolloConfig

use of com.ctrip.framework.apollo.core.dto.ApolloConfig in project apollo by ctripcorp.

the class ConfigControllerTest method testQueryConfigFileWithPrivateNamespace.

@Test
public void testQueryConfigFileWithPrivateNamespace() throws Exception {
    String someClientSideReleaseKey = "1";
    String someServerSideNewReleaseKey = "2";
    String somePrivateNamespace = "datasource";
    HttpServletResponse someResponse = mock(HttpServletResponse.class);
    String somePrivateNamespaceName = String.format("%s.%s", somePrivateNamespace, "xml");
    AppNamespace appNamespace = mock(AppNamespace.class);
    when(configService.loadConfig(someAppId, someClientIp, someClientLabel, someAppId, someClusterName, somePrivateNamespace, someDataCenter, someNotificationMessages)).thenReturn(someRelease);
    when(someRelease.getReleaseKey()).thenReturn(someServerSideNewReleaseKey);
    when(namespaceUtil.filterNamespaceName(somePrivateNamespaceName)).thenReturn(somePrivateNamespace);
    when(namespaceUtil.normalizeNamespace(someAppId, somePrivateNamespace)).thenReturn(somePrivateNamespace);
    when(appNamespaceService.findByAppIdAndNamespace(someAppId, somePrivateNamespace)).thenReturn(appNamespace);
    ApolloConfig result = configController.queryConfig(someAppId, someClusterName, somePrivateNamespaceName, someDataCenter, someClientSideReleaseKey, someClientIp, someClientLabel, someMessagesAsString, someRequest, someResponse);
    assertEquals(someAppId, result.getAppId());
    assertEquals(someClusterName, result.getCluster());
    assertEquals(somePrivateNamespaceName, result.getNamespaceName());
    assertEquals(someServerSideNewReleaseKey, result.getReleaseKey());
}
Also used : ApolloConfig(com.ctrip.framework.apollo.core.dto.ApolloConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Test(org.junit.Test)

Example 35 with ApolloConfig

use of com.ctrip.framework.apollo.core.dto.ApolloConfig in project apollo by ctripcorp.

the class ConfigControllerTest method testQueryConfigWithPubicNamespaceAndNoAppOverride.

@Test
public void testQueryConfigWithPubicNamespaceAndNoAppOverride() throws Exception {
    String someClientSideReleaseKey = "1";
    String someServerSideReleaseKey = "2";
    HttpServletResponse someResponse = mock(HttpServletResponse.class);
    String somePublicAppId = "somePublicAppId";
    String somePublicClusterName = "somePublicClusterName";
    AppNamespace somePublicAppNamespace = assemblePublicAppNamespace(somePublicAppId, somePublicNamespaceName);
    when(configService.loadConfig(someAppId, someClientIp, someClientLabel, someAppId, someClusterName, somePublicNamespaceName, someDataCenter, someNotificationMessages)).thenReturn(null);
    when(appNamespaceService.findPublicNamespaceByName(somePublicNamespaceName)).thenReturn(somePublicAppNamespace);
    when(configService.loadConfig(someAppId, someClientIp, someClientLabel, somePublicAppId, someClusterName, somePublicNamespaceName, someDataCenter, someNotificationMessages)).thenReturn(somePublicRelease);
    when(somePublicRelease.getReleaseKey()).thenReturn(someServerSideReleaseKey);
    when(somePublicRelease.getAppId()).thenReturn(somePublicAppId);
    when(somePublicRelease.getClusterName()).thenReturn(somePublicClusterName);
    when(somePublicRelease.getNamespaceName()).thenReturn(somePublicNamespaceName);
    ApolloConfig result = configController.queryConfig(someAppId, someClusterName, somePublicNamespaceName, someDataCenter, someClientSideReleaseKey, someClientIp, someClientLabel, someMessagesAsString, someRequest, someResponse);
    assertEquals(someServerSideReleaseKey, result.getReleaseKey());
    assertEquals(someAppId, result.getAppId());
    assertEquals(someClusterName, result.getCluster());
    assertEquals(somePublicNamespaceName, result.getNamespaceName());
    assertEquals("foo", result.getConfigurations().get("apollo.public.bar"));
    verify(instanceConfigAuditUtil, times(1)).audit(someAppId, someClusterName, someDataCenter, someClientIp, somePublicAppId, somePublicClusterName, somePublicNamespaceName, someServerSideReleaseKey);
}
Also used : ApolloConfig(com.ctrip.framework.apollo.core.dto.ApolloConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Test(org.junit.Test)

Aggregations

ApolloConfig (com.ctrip.framework.apollo.core.dto.ApolloConfig)57 Test (org.junit.Test)49 Sql (org.springframework.test.context.jdbc.Sql)17 HttpServletResponse (javax.servlet.http.HttpServletResponse)11 BaseIntegrationTest (com.ctrip.framework.apollo.BaseIntegrationTest)10 Config (com.ctrip.framework.apollo.Config)10 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)10 Properties (java.util.Properties)8 OrderedProperties (com.ctrip.framework.apollo.util.OrderedProperties)7 AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 ConfigChangeListener (com.ctrip.framework.apollo.ConfigChangeListener)4 ApolloConfigNotification (com.ctrip.framework.apollo.core.dto.ApolloConfigNotification)4 ConfigChangeEvent (com.ctrip.framework.apollo.model.ConfigChangeEvent)4 Map (java.util.Map)4 ApolloNotificationMessages (com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages)3 HttpRequest (com.ctrip.framework.apollo.util.http.HttpRequest)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3