Search in sources :

Example 21 with Sql

use of org.springframework.test.context.jdbc.Sql in project apollo by ctripcorp.

the class NotificationControllerV2IntegrationTest method testPollNotificationWithDefaultNamespaceWithNotificationIdOutDated.

@Test(timeout = 5000L)
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/test-release-message.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWithDefaultNamespaceWithNotificationIdOutDated() throws Exception {
    long someOutDatedNotificationId = 1;
    ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange("http://{baseurl}/notifications/v2?appId={appId}&cluster={clusterName}&notifications={notifications}", HttpMethod.GET, null, typeReference, getHostUrl(), someAppId, someCluster, transformApolloConfigNotificationsToString(defaultNamespace, someOutDatedNotificationId));
    long newNotificationId = 10;
    List<ApolloConfigNotification> notifications = result.getBody();
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals(1, notifications.size());
    assertEquals(defaultNamespace, notifications.get(0).getNamespaceName());
    assertEquals(newNotificationId, notifications.get(0).getNotificationId());
    String key = assembleKey(someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, ConfigConsts.NAMESPACE_APPLICATION);
    ApolloNotificationMessages messages = result.getBody().get(0).getMessages();
    assertEquals(1, messages.getDetails().size());
    assertTrue(messages.has(key));
    assertEquals(newNotificationId, messages.get(key).longValue());
}
Also used : ApolloNotificationMessages(com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages) List(java.util.List) ApolloConfigNotification(com.ctrip.framework.apollo.core.dto.ApolloConfigNotification) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 22 with Sql

use of org.springframework.test.context.jdbc.Sql in project apollo by ctripcorp.

the class NotificationControllerV2IntegrationTest method testPollNotificationWithMultipleNamespacesAndNotificationIdsOutDatedAndIncorrectCase.

@Test(timeout = 5000L)
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/test-release-message.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWithMultipleNamespacesAndNotificationIdsOutDatedAndIncorrectCase() throws Exception {
    String publicAppId = "somePublicAppId";
    long someOutDatedNotificationId = 1;
    long newDefaultNamespaceNotificationId = 10;
    long newPublicNamespaceNotification = 20;
    String someDefaultNamespaceWithIncorrectCase = defaultNamespace.toUpperCase();
    String somePublicNamespaceWithIncorrectCase = somePublicNamespace.toUpperCase();
    ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange("http://{baseurl}/notifications/v2?appId={appId}&cluster={clusterName}&notifications={notifications}", HttpMethod.GET, null, typeReference, getHostUrl(), someAppId, someCluster, transformApolloConfigNotificationsToString(somePublicNamespaceWithIncorrectCase, someOutDatedNotificationId, someDefaultNamespaceWithIncorrectCase, someOutDatedNotificationId));
    List<ApolloConfigNotification> notifications = result.getBody();
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals(2, notifications.size());
    Set<String> outDatedNamespaces = Sets.newHashSet(notifications.get(0).getNamespaceName(), notifications.get(1).getNamespaceName());
    assertEquals(Sets.newHashSet(someDefaultNamespaceWithIncorrectCase, somePublicNamespaceWithIncorrectCase), outDatedNamespaces);
    Set<Long> newNotificationIds = Sets.newHashSet(notifications.get(0).getNotificationId(), notifications.get(1).getNotificationId());
    assertEquals(Sets.newHashSet(newDefaultNamespaceNotificationId, newPublicNamespaceNotification), newNotificationIds);
    String defaultNamespaceKey = assembleKey(someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, ConfigConsts.NAMESPACE_APPLICATION);
    String publicNamespaceKey = assembleKey(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace);
    ApolloNotificationMessages firstMessages = notifications.get(0).getMessages();
    ApolloNotificationMessages secondMessages = notifications.get(1).getMessages();
    assertEquals(1, firstMessages.getDetails().size());
    assertEquals(1, secondMessages.getDetails().size());
    assertTrue((firstMessages.has(defaultNamespaceKey) && firstMessages.get(defaultNamespaceKey).equals(newDefaultNamespaceNotificationId)) || (firstMessages.has(publicNamespaceKey) && firstMessages.get(publicNamespaceKey).equals(newPublicNamespaceNotification)));
    assertTrue((secondMessages.has(defaultNamespaceKey) && secondMessages.get(defaultNamespaceKey).equals(newDefaultNamespaceNotificationId)) || (secondMessages.has(publicNamespaceKey) && secondMessages.get(publicNamespaceKey).equals(newPublicNamespaceNotification)));
}
Also used : ApolloNotificationMessages(com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages) List(java.util.List) ApolloConfigNotification(com.ctrip.framework.apollo.core.dto.ApolloConfigNotification) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 23 with Sql

use of org.springframework.test.context.jdbc.Sql in project apollo by ctripcorp.

the class NotificationControllerV2IntegrationTest method testPollNotificationWithDefaultNamespaceAsFile.

@Test(timeout = 5000L)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWithDefaultNamespaceAsFile() throws Exception {
    AtomicBoolean stop = new AtomicBoolean();
    String key = assembleKey(someAppId, someCluster, defaultNamespace);
    periodicSendMessage(executorService, key, stop);
    ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange("http://{baseurl}/notifications/v2?appId={appId}&cluster={clusterName}&notifications={notifications}", HttpMethod.GET, null, typeReference, getHostUrl(), someAppId, someCluster, transformApolloConfigNotificationsToString(defaultNamespace + ".properties", ConfigConsts.NOTIFICATION_ID_PLACEHOLDER));
    stop.set(true);
    List<ApolloConfigNotification> notifications = result.getBody();
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals(1, notifications.size());
    assertEquals(defaultNamespace, notifications.get(0).getNamespaceName());
    assertNotEquals(0, notifications.get(0).getNotificationId());
    ApolloNotificationMessages messages = result.getBody().get(0).getMessages();
    assertEquals(1, messages.getDetails().size());
    assertTrue(messages.has(key));
    assertNotEquals(ConfigConsts.NOTIFICATION_ID_PLACEHOLDER, messages.get(key).longValue());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ApolloNotificationMessages(com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages) List(java.util.List) ApolloConfigNotification(com.ctrip.framework.apollo.core.dto.ApolloConfigNotification) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 24 with Sql

use of org.springframework.test.context.jdbc.Sql in project apollo by ctripcorp.

the class NotificationControllerV2IntegrationTest method testPollNotificationWithMultipleNamespaces.

@Test
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWithMultipleNamespaces() throws Exception {
    AtomicBoolean stop = new AtomicBoolean();
    String key = assembleKey(someAppId, someCluster, somePublicNamespace);
    periodicSendMessage(executorService, key, stop);
    ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange("http://{baseurl}/notifications/v2?appId={appId}&cluster={clusterName}&notifications={notifications}", HttpMethod.GET, null, typeReference, getHostUrl(), someAppId, someCluster, transformApolloConfigNotificationsToString(defaultNamespace + ".properties", ConfigConsts.NOTIFICATION_ID_PLACEHOLDER, defaultNamespace, ConfigConsts.NOTIFICATION_ID_PLACEHOLDER, somePublicNamespace, ConfigConsts.NOTIFICATION_ID_PLACEHOLDER));
    stop.set(true);
    List<ApolloConfigNotification> notifications = result.getBody();
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals(1, notifications.size());
    assertEquals(somePublicNamespace, notifications.get(0).getNamespaceName());
    assertNotEquals(0, notifications.get(0).getNotificationId());
    ApolloNotificationMessages messages = result.getBody().get(0).getMessages();
    assertEquals(1, messages.getDetails().size());
    assertTrue(messages.has(key));
    assertNotEquals(ConfigConsts.NOTIFICATION_ID_PLACEHOLDER, messages.get(key).longValue());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ApolloNotificationMessages(com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages) List(java.util.List) ApolloConfigNotification(com.ctrip.framework.apollo.core.dto.ApolloConfigNotification) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 25 with Sql

use of org.springframework.test.context.jdbc.Sql in project apollo by ctripcorp.

the class NotificationControllerV2IntegrationTest method testPollNotificationWthPublicNamespaceAndNoDataCenter.

@Test(timeout = 5000L)
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWthPublicNamespaceAndNoDataCenter() throws Exception {
    String publicAppId = "somePublicAppId";
    AtomicBoolean stop = new AtomicBoolean();
    String key = assembleKey(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace);
    periodicSendMessage(executorService, key, stop);
    ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange("http://{baseurl}/notifications/v2?appId={appId}&cluster={clusterName}&notifications={notifications}", HttpMethod.GET, null, typeReference, getHostUrl(), someAppId, someCluster, transformApolloConfigNotificationsToString(somePublicNamespace, ConfigConsts.NOTIFICATION_ID_PLACEHOLDER));
    stop.set(true);
    List<ApolloConfigNotification> notifications = result.getBody();
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals(1, notifications.size());
    assertEquals(somePublicNamespace, notifications.get(0).getNamespaceName());
    assertNotEquals(0, notifications.get(0).getNotificationId());
    ApolloNotificationMessages messages = result.getBody().get(0).getMessages();
    assertEquals(1, messages.getDetails().size());
    assertTrue(messages.has(key));
    assertNotEquals(ConfigConsts.NOTIFICATION_ID_PLACEHOLDER, messages.get(key).longValue());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ApolloNotificationMessages(com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages) List(java.util.List) ApolloConfigNotification(com.ctrip.framework.apollo.core.dto.ApolloConfigNotification) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Aggregations

Sql (org.springframework.test.context.jdbc.Sql)122 Test (org.junit.Test)111 ApolloConfigNotification (com.ctrip.framework.apollo.core.dto.ApolloConfigNotification)26 AbstractIntegrationTest (com.ctrip.framework.apollo.portal.AbstractIntegrationTest)26 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)23 AppDTO (com.ctrip.framework.apollo.common.dto.AppDTO)17 ApolloConfig (com.ctrip.framework.apollo.core.dto.ApolloConfig)17 ApolloNotificationMessages (com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages)17 List (java.util.List)17 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)16 AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)13 ReleaseHistory (com.ctrip.framework.apollo.biz.entity.ReleaseHistory)11 GrayReleaseRule (com.ctrip.framework.apollo.biz.entity.GrayReleaseRule)10 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 Release (com.ctrip.framework.apollo.biz.entity.Release)8 AbstractControllerTest (com.ctrip.framework.apollo.adminservice.controller.AbstractControllerTest)6 Favorite (com.ctrip.framework.apollo.portal.entity.po.Favorite)6 CustomerData (io.codekvast.common.customer.CustomerData)6 HttpHeaders (org.springframework.http.HttpHeaders)6