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());
}
}
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));
}
}
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));
}
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));
}
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);
}
Aggregations