Search in sources :

Example 41 with Sql

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

the class NamespaceControllerWithAuthorizationTest method testCreateAppNamespaceUnauthorized.

/**
 * test method {@link NamespaceController#createAppNamespace(String, OpenAppNamespaceDTO)}.
 */
@Test
@Sql(scripts = "/sql/openapi/NamespaceControllerTest.testCreateAppNamespace.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testCreateAppNamespaceUnauthorized() {
    OpenAppNamespaceDTO dto = new OpenAppNamespaceDTO();
    dto.setAppId("consumer-test-app-id-0");
    dto.setName("namespace-0");
    dto.setFormat(ConfigFileFormat.Properties.getValue());
    dto.setDataChangeCreatedBy("apollo");
    try {
        restTemplate.postForEntity(url("/openapi/v1/apps/{appId}/appnamespaces"), dto, OpenAppNamespaceDTO.class, dto.getAppId());
        Assert.fail("should throw");
    } catch (HttpClientErrorException e) {
        assertEquals(HttpStatus.UNAUTHORIZED, e.getStatusCode());
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) OpenAppNamespaceDTO(com.ctrip.framework.apollo.openapi.dto.OpenAppNamespaceDTO) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 42 with Sql

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

the class NamespaceControllerWithAuthorizationTest method testCreateAppNamespaceInvalidNamespaceName.

/**
 * test method {@link NamespaceController#createAppNamespace(String, OpenAppNamespaceDTO)}. Just
 * for check Authorization is ok.
 */
@Test
@Sql(scripts = "/sql/openapi/NamespaceControllerTest.testCreateAppNamespace.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testCreateAppNamespaceInvalidNamespaceName() {
    OpenAppNamespaceDTO dto = new OpenAppNamespaceDTO();
    dto.setAppId("consumer-test-app-id-0");
    dto.setName("invalid name");
    dto.setFormat(ConfigFileFormat.Properties.getValue());
    dto.setDataChangeCreatedBy("apollo");
    try {
        restTemplate.exchange(this.url("/openapi/v1/apps/{appId}/appnamespaces"), HttpMethod.POST, new HttpEntity<>(dto, HTTP_HEADERS_WITH_TOKEN), OpenAppNamespaceDTO.class, dto.getAppId());
        Assert.fail("should throw");
    } catch (HttpClientErrorException e) {
        assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode());
        String result = e.getResponseBodyAsString();
        assertTrue(result.contains(InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE));
        assertTrue(result.contains(InputValidator.INVALID_NAMESPACE_NAMESPACE_MESSAGE));
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) OpenAppNamespaceDTO(com.ctrip.framework.apollo.openapi.dto.OpenAppNamespaceDTO) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 43 with Sql

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

the class RolePermissionServiceTest method testCreateRoleWithPermissions.

@Test
@Sql(scripts = "/sql/permission/insert-test-permissions.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testCreateRoleWithPermissions() throws Exception {
    String someRoleName = "someRoleName";
    Role role = assembleRole(someRoleName);
    Set<Long> permissionIds = Sets.newHashSet(990L, 991L);
    Role created = rolePermissionService.createRoleWithPermissions(role, permissionIds);
    Role createdFromDB = roleRepository.findById(created.getId()).orElse(null);
    List<RolePermission> rolePermissions = rolePermissionRepository.findByRoleIdIn(Sets.newHashSet(createdFromDB.getId()));
    Set<Long> rolePermissionIds = rolePermissions.stream().map(RolePermission::getPermissionId).collect(Collectors.toSet());
    assertEquals(someRoleName, createdFromDB.getRoleName());
    assertEquals(2, rolePermissionIds.size());
    assertTrue(rolePermissionIds.containsAll(permissionIds));
}
Also used : UserRole(com.ctrip.framework.apollo.portal.entity.po.UserRole) Role(com.ctrip.framework.apollo.portal.entity.po.Role) RolePermission(com.ctrip.framework.apollo.portal.entity.po.RolePermission) AbstractIntegrationTest(com.ctrip.framework.apollo.portal.AbstractIntegrationTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 44 with Sql

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

the class RolePermissionServiceTest method testCreatePermissionsWithPermissionsExisted.

@Test(expected = IllegalStateException.class)
@Sql(scripts = "/sql/permission/insert-test-permissions.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testCreatePermissionsWithPermissionsExisted() throws Exception {
    String someTargetId = "someTargetId";
    String anotherTargetId = "anotherTargetId";
    String somePermissionType = "somePermissionType";
    String anotherPermissionType = "anotherPermissionType";
    Permission somePermission = assemblePermission(somePermissionType, someTargetId);
    Permission anotherPermission = assemblePermission(anotherPermissionType, anotherTargetId);
    rolePermissionService.createPermissions(Sets.newHashSet(somePermission, anotherPermission));
}
Also used : RolePermission(com.ctrip.framework.apollo.portal.entity.po.RolePermission) Permission(com.ctrip.framework.apollo.portal.entity.po.Permission) AbstractIntegrationTest(com.ctrip.framework.apollo.portal.AbstractIntegrationTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 45 with Sql

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

the class RolePermissionServiceTest method testCreatePermissionWithPermissionExisted.

@Test(expected = IllegalStateException.class)
@Sql(scripts = "/sql/permission/insert-test-permissions.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testCreatePermissionWithPermissionExisted() throws Exception {
    String someTargetId = "someTargetId";
    String somePermissionType = "somePermissionType";
    Permission somePermission = assemblePermission(somePermissionType, someTargetId);
    rolePermissionService.createPermission(somePermission);
}
Also used : RolePermission(com.ctrip.framework.apollo.portal.entity.po.RolePermission) Permission(com.ctrip.framework.apollo.portal.entity.po.Permission) AbstractIntegrationTest(com.ctrip.framework.apollo.portal.AbstractIntegrationTest) 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