Search in sources :

Example 21 with ApolloConfig

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

the class RemoteConfigRepositoryTest method testAssembleQueryConfigUrl.

@Test
public void testAssembleQueryConfigUrl() throws Exception {
    Gson gson = new Gson();
    String someUri = "http://someServer";
    String someAppId = "someAppId";
    String someCluster = "someCluster+ &.-_someSign";
    String someReleaseKey = "20160705193346-583078ef5716c055+20160705193308-31c471ddf9087c3f";
    ApolloNotificationMessages notificationMessages = new ApolloNotificationMessages();
    String someKey = "someKey";
    long someNotificationId = 1;
    String anotherKey = "anotherKey";
    long anotherNotificationId = 2;
    notificationMessages.put(someKey, someNotificationId);
    notificationMessages.put(anotherKey, anotherNotificationId);
    RemoteConfigRepository remoteConfigRepository = new RemoteConfigRepository(someNamespace);
    ApolloConfig someApolloConfig = mock(ApolloConfig.class);
    when(someApolloConfig.getReleaseKey()).thenReturn(someReleaseKey);
    String queryConfigUrl = remoteConfigRepository.assembleQueryConfigUrl(someUri, someAppId, someCluster, someNamespace, null, notificationMessages, someApolloConfig);
    remoteConfigLongPollService.stopLongPollingRefresh();
    assertTrue(queryConfigUrl.contains("http://someServer/configs/someAppId/someCluster+%20&.-_someSign/" + someNamespace));
    assertTrue(queryConfigUrl.contains("releaseKey=20160705193346-583078ef5716c055%2B20160705193308-31c471ddf9087c3f"));
    assertTrue(queryConfigUrl.contains("messages=" + UrlEscapers.urlFormParameterEscaper().escape(gson.toJson(notificationMessages))));
}
Also used : ApolloConfig(com.ctrip.framework.apollo.core.dto.ApolloConfig) Gson(com.google.gson.Gson) ApolloNotificationMessages(com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages) Test(org.junit.Test)

Example 22 with ApolloConfig

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

the class ConfigControllerTest method testQueryConfigFile.

@Test
public void testQueryConfigFile() throws Exception {
    String someClientSideReleaseKey = "1";
    String someServerSideNewReleaseKey = "2";
    HttpServletResponse someResponse = mock(HttpServletResponse.class);
    String someNamespaceName = String.format("%s.%s", defaultClusterName, "properties");
    when(configService.loadConfig(someAppId, someClientIp, someClientLabel, someAppId, someClusterName, defaultNamespaceName, someDataCenter, someNotificationMessages)).thenReturn(someRelease);
    when(someRelease.getReleaseKey()).thenReturn(someServerSideNewReleaseKey);
    when(namespaceUtil.filterNamespaceName(someNamespaceName)).thenReturn(defaultNamespaceName);
    when(namespaceUtil.normalizeNamespace(someAppId, defaultNamespaceName)).thenReturn(defaultNamespaceName);
    ApolloConfig result = configController.queryConfig(someAppId, someClusterName, someNamespaceName, someDataCenter, someClientSideReleaseKey, someClientIp, someClientLabel, someMessagesAsString, someRequest, someResponse);
    verify(configService, times(1)).loadConfig(someAppId, someClientIp, someClientLabel, someAppId, someClusterName, defaultNamespaceName, someDataCenter, someNotificationMessages);
    assertEquals(someAppId, result.getAppId());
    assertEquals(someClusterName, result.getCluster());
    assertEquals(someNamespaceName, result.getNamespaceName());
    assertEquals(someServerSideNewReleaseKey, result.getReleaseKey());
}
Also used : ApolloConfig(com.ctrip.framework.apollo.core.dto.ApolloConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.Test)

Example 23 with ApolloConfig

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

the class ConfigControllerTest method testQueryConfigWithReleaseNotFound.

@Test
public void testQueryConfigWithReleaseNotFound() throws Exception {
    String someClientSideReleaseKey = "1";
    HttpServletResponse someResponse = mock(HttpServletResponse.class);
    when(configService.loadConfig(someAppId, someClientIp, someClientLabel, someAppId, someClusterName, defaultNamespaceName, someDataCenter, someNotificationMessages)).thenReturn(null);
    ApolloConfig result = configController.queryConfig(someAppId, someClusterName, defaultNamespaceName, someDataCenter, someClientSideReleaseKey, someClientIp, someClientLabel, someMessagesAsString, someRequest, someResponse);
    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 24 with ApolloConfig

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

the class ConfigControllerTest method testQueryConfigWithApolloConfigNotModified.

@Test
public void testQueryConfigWithApolloConfigNotModified() throws Exception {
    String someClientSideReleaseKey = "1";
    String someServerSideReleaseKey = someClientSideReleaseKey;
    HttpServletResponse someResponse = mock(HttpServletResponse.class);
    when(configService.loadConfig(someAppId, someClientIp, someClientLabel, someAppId, someClusterName, defaultNamespaceName, someDataCenter, someNotificationMessages)).thenReturn(someRelease);
    when(someRelease.getReleaseKey()).thenReturn(someServerSideReleaseKey);
    ApolloConfig result = configController.queryConfig(someAppId, someClusterName, defaultNamespaceName, someDataCenter, someClientSideReleaseKey, someClientIp, someClientLabel, someMessagesAsString, someRequest, someResponse);
    assertNull(result);
    verify(someResponse, times(1)).setStatus(HttpServletResponse.SC_NOT_MODIFIED);
}
Also used : ApolloConfig(com.ctrip.framework.apollo.core.dto.ApolloConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.Test)

Example 25 with ApolloConfig

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

the class ConfigControllerTest method testQueryConfigFileWithPublicNamespaceAndNoAppOverride.

@Test
public void testQueryConfigFileWithPublicNamespaceAndNoAppOverride() throws Exception {
    String someClientSideReleaseKey = "1";
    String someServerSideReleaseKey = "2";
    HttpServletResponse someResponse = mock(HttpServletResponse.class);
    String somePublicAppId = "somePublicAppId";
    String someNamespace = String.format("%s.%s", somePublicNamespaceName, "properties");
    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(namespaceUtil.filterNamespaceName(someNamespace)).thenReturn(somePublicNamespaceName);
    when(namespaceUtil.normalizeNamespace(someAppId, somePublicNamespaceName)).thenReturn(somePublicNamespaceName);
    when(appNamespaceService.findByAppIdAndNamespace(someAppId, somePublicNamespaceName)).thenReturn(null);
    ApolloConfig result = configController.queryConfig(someAppId, someClusterName, someNamespace, someDataCenter, someClientSideReleaseKey, someClientIp, someClientLabel, someMessagesAsString, someRequest, someResponse);
    assertEquals(someServerSideReleaseKey, result.getReleaseKey());
    assertEquals(someAppId, result.getAppId());
    assertEquals(someClusterName, result.getCluster());
    assertEquals(someNamespace, 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)

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