use of com.ctrip.framework.apollo.openapi.dto.OpenAppNamespaceDTO in project apollo by ctripcorp.
the class NamespaceControllerTest method shouldFailWhenAppNamespaceNameIsInvalid.
@Test
public void shouldFailWhenAppNamespaceNameIsInvalid() {
Assert.assertTrue(consumerPermissionValidator.hasCreateNamespacePermission(null, null));
OpenAppNamespaceDTO dto = new OpenAppNamespaceDTO();
dto.setAppId("appId");
dto.setName("invalid name");
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) {
String result = e.getResponseBodyAsString();
Assert.assertThat(result, containsString(InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE));
Assert.assertThat(result, containsString(InputValidator.INVALID_NAMESPACE_NAMESPACE_MESSAGE));
}
}
use of com.ctrip.framework.apollo.openapi.dto.OpenAppNamespaceDTO in project apollo by ctripcorp.
the class NamespaceControllerWithAuthorizationTest method testCreateAppNamespaceWithoutAuthority.
/**
* test method {@link NamespaceController#createAppNamespace(String, OpenAppNamespaceDTO)} without
* authority.
*/
@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 testCreateAppNamespaceWithoutAuthority() {
final OpenAppNamespaceDTO dto = new OpenAppNamespaceDTO();
dto.setAppId("consumer-test-app-id-1");
dto.setName("create-app-namespace-fail");
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());
fail("should throw");
} catch (HttpClientErrorException e) {
assertEquals(HttpStatus.FORBIDDEN, e.getStatusCode());
String result = e.getResponseBodyAsString();
assertTrue(result.contains("org.springframework.security.access.AccessDeniedException"));
}
// random app id
dto.setAppId(UUID.randomUUID().toString());
try {
restTemplate.exchange(this.url("/openapi/v1/apps/{appId}/appnamespaces"), HttpMethod.POST, new HttpEntity<>(dto, HTTP_HEADERS_WITH_TOKEN), OpenAppNamespaceDTO.class, dto.getAppId());
fail("should throw");
} catch (HttpClientErrorException e) {
assertEquals(HttpStatus.FORBIDDEN, e.getStatusCode());
String result = e.getResponseBodyAsString();
assertTrue(result.contains("org.springframework.security.access.AccessDeniedException"));
}
}
Aggregations