Search in sources :

Example 51 with AppNamespace

use of com.ctrip.framework.apollo.common.entity.AppNamespace 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 52 with AppNamespace

use of com.ctrip.framework.apollo.common.entity.AppNamespace 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)

Example 53 with AppNamespace

use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.

the class AppNamespaceServiceWithCacheTest method assembleAppNamespace.

private AppNamespace assembleAppNamespace(long id, String appId, String name, boolean isPublic) {
    AppNamespace appNamespace = new AppNamespace();
    appNamespace.setId(id);
    appNamespace.setAppId(appId);
    appNamespace.setName(name);
    appNamespace.setPublic(isPublic);
    appNamespace.setDataChangeLastModifiedTime(new Date());
    return appNamespace;
}
Also used : AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Date(java.util.Date)

Example 54 with AppNamespace

use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.

the class NamespaceUtilTest method testNormalizeNamespaceWithPublicNamespace.

@Test
public void testNormalizeNamespaceWithPublicNamespace() throws Exception {
    String someAppId = "someAppId";
    String someNamespaceName = "someNamespaceName";
    String someNormalizedNamespaceName = "someNormalizedNamespaceName";
    AppNamespace someAppNamespace = mock(AppNamespace.class);
    when(someAppNamespace.getName()).thenReturn(someNormalizedNamespaceName);
    when(appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, someNamespaceName)).thenReturn(null);
    when(appNamespaceServiceWithCache.findPublicNamespaceByName(someNamespaceName)).thenReturn(someAppNamespace);
    assertEquals(someNormalizedNamespaceName, namespaceUtil.normalizeNamespace(someAppId, someNamespaceName));
    verify(appNamespaceServiceWithCache, times(1)).findByAppIdAndNamespace(someAppId, someNamespaceName);
    verify(appNamespaceServiceWithCache, times(1)).findPublicNamespaceByName(someNamespaceName);
}
Also used : AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Test(org.junit.Test)

Example 55 with AppNamespace

use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.

the class AppNamespaceControllerTest method testCreate.

@Test
@Sql(scripts = "/controller/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testCreate() {
    String appId = "6666";
    String name = "testnamespace";
    String comment = "comment";
    AppNamespaceDTO dto = new AppNamespaceDTO();
    dto.setAppId(appId);
    dto.setName(name);
    dto.setComment(comment);
    dto.setDataChangeCreatedBy("apollo");
    AppNamespaceDTO resultDto = restTemplate.postForEntity(String.format("http://localhost:%d/apps/%s/appnamespaces", port, appId), dto, AppNamespaceDTO.class).getBody();
    Assert.assertEquals(appId, resultDto.getAppId());
    Assert.assertTrue(resultDto.getId() > 0);
    AppNamespace savedAppNs = namespaceRepository.findByAppIdAndName(appId, name);
    Assert.assertNotNull(savedAppNs);
    Assert.assertNotNull(savedAppNs.getDataChangeCreatedTime());
    Assert.assertNotNull(savedAppNs.getDataChangeLastModifiedTime());
    Assert.assertNotNull(savedAppNs.getDataChangeLastModifiedBy());
    Assert.assertNotNull(savedAppNs.getDataChangeCreatedBy());
}
Also used : AppNamespaceDTO(com.ctrip.framework.apollo.common.dto.AppNamespaceDTO) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Aggregations

AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)71 Test (org.junit.Test)32 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)15 Sql (org.springframework.test.context.jdbc.Sql)13 AbstractIntegrationTest (com.ctrip.framework.apollo.portal.AbstractIntegrationTest)11 Transactional (org.springframework.transaction.annotation.Transactional)9 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)7 AbstractUnitTest (com.ctrip.framework.apollo.portal.AbstractUnitTest)7 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)6 ApolloConfig (com.ctrip.framework.apollo.core.dto.ApolloConfig)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 AppNamespaceCreationEvent (com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)3 App (com.ctrip.framework.apollo.common.entity.App)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Release (com.ctrip.framework.apollo.biz.entity.Release)2 AppNamespaceDTO (com.ctrip.framework.apollo.common.dto.AppNamespaceDTO)2 NamespaceBO (com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO)2 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)2