Skip to content

Commit

Permalink
Provide listDeployedServices service for ISV
Browse files Browse the repository at this point in the history
  • Loading branch information
WangLiNaruto committed Nov 10, 2023
1 parent f2f35b2 commit 31d685f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public CredentialsConfigApi(CredentialCenter credentialCenter) {
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
@Operation(description = "List the credential types supported by the cloud service provider.")
public List<CredentialType> getUserCloudCredentialTypes(
public List<CredentialType> getCredentialTypes(
@Parameter(name = "cspName", description = "The cloud service provider.")
@RequestParam(name = "cspName", required = false) Csp csp) {
if (Objects.isNull(csp)) {
Expand All @@ -88,7 +88,7 @@ public List<CredentialType> getUserCloudCredentialTypes(
@ResponseStatus(HttpStatus.OK)
@Operation(description =
"List the credential capabilities defined by the cloud service provider.")
public List<AbstractCredentialInfo> getUserCloudCredentialCapabilities(
public List<AbstractCredentialInfo> getCredentialCapabilities(
@Parameter(name = "cspName", description = "name of the cloud service provider.")
@RequestParam(name = "cspName") Csp csp,
@Parameter(name = "type", description = "The type of credential.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*/
@Slf4j
@RestController
@RequestMapping("/xpanse")
@RequestMapping("/xpanse/user")
@CrossOrigin
@Secured({ROLE_ADMIN, ROLE_USER})
public class UserCloudCredentialsApi {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void testCredentialCapabilityNotFound() throws Exception {
when(credentialCenter.listCredentials(any(), any(), anyString()))
.thenThrow(new CredentialCapabilityNotFound("test error"));
when(identityProviderManager.getCurrentLoginUserId()).thenReturn(Optional.of(userId));
this.mockMvc.perform(get("/xpanse/credentials"))
this.mockMvc.perform(get("/xpanse/user/credentials"))
.andExpect(status().is(400))
.andExpect(jsonPath("$.resultType").value("Credential Capability Not Found"))
.andExpect(jsonPath("$.details[0]").value("test error"));
Expand All @@ -74,7 +74,7 @@ void testCredentialsNotFoundException() throws Exception {
when(credentialCenter.listCredentials(any(), any(), anyString()))
.thenThrow(new CredentialsNotFoundException("test error"));
when(identityProviderManager.getCurrentLoginUserId()).thenReturn(Optional.of(userId));
this.mockMvc.perform(get("/xpanse/credentials"))
this.mockMvc.perform(get("/xpanse/user/credentials"))
.andExpect(status().is(400))
.andExpect(jsonPath("$.resultType").value("Credentials Not Found"))
.andExpect(jsonPath("$.details[0]").value("test error"));
Expand All @@ -85,7 +85,7 @@ void testCredentialVariablesNotComplete() throws Exception {
when(credentialCenter.listCredentials(any(), any(), anyString()))
.thenThrow(new CredentialVariablesNotComplete(Set.of("test error")));
when(identityProviderManager.getCurrentLoginUserId()).thenReturn(Optional.of(userId));
this.mockMvc.perform(get("/xpanse/credentials"))
this.mockMvc.perform(get("/xpanse/user/credentials"))
.andExpect(status().is(400))
.andExpect(jsonPath("$.resultType").value("Credential Variables Not Complete"))
.andExpect(jsonPath("$.details[0]").value("test error"));
Expand All @@ -96,7 +96,7 @@ void testNoCredentialDefinitionAvailable() throws Exception {
when(credentialCenter.listCredentials(any(), any(), anyString()))
.thenThrow(new NoCredentialDefinitionAvailable("test error"));
when(identityProviderManager.getCurrentLoginUserId()).thenReturn(Optional.of(userId));
this.mockMvc.perform(get("/xpanse/credentials"))
this.mockMvc.perform(get("/xpanse/user/credentials"))
.andExpect(status().is(400))
.andExpect(jsonPath("$.resultType").value("No Credential Definition Available"))
.andExpect(jsonPath("$.details[0]").value("test error"));
Expand All @@ -107,7 +107,7 @@ void testNoCredentialDefinitionAvailable() throws Exception {
void testHandleUserNoLoginException() throws Exception {
when(credentialCenter.listCredentials(any(), any(), anyString()))
.thenThrow(new NoCredentialDefinitionAvailable("test error"));
this.mockMvc.perform(get("/xpanse/credentials"))
this.mockMvc.perform(get("/xpanse/user/credentials"))
.andExpect(status().is(401))
.andExpect(jsonPath("$.resultType").value("Current Login User No Found"))
.andExpect(jsonPath("$.details[0]").value("Unable to get current login information"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void testServiceDeployer() throws Exception {
boolean deploySuccess = deploySuccess(taskId);

testGetServiceDetails();
testListDeployedServices();
testListDeployedServices(deploySuccess);

testDestroy(deploySuccess);

Expand Down Expand Up @@ -213,21 +213,21 @@ void registerServiceTemplate() throws Exception {
Thread.sleep(1000);
}

void testListDeployedServices() throws Exception {
void testListDeployedServices(boolean deploySuccess) throws Exception {
// Set up
ServiceVo serviceVo = new ServiceVo();
BeanUtils.copyProperties(serviceDetailVo, serviceVo);
String result = objectMapper.writeValueAsString(List.of(serviceVo));

String state = deploySuccess ? ServiceDeploymentState.DEPLOY_FAILED.toValue():
ServiceDeploymentState.DEPLOY_FAILED.toValue();
// Run the test
final MockHttpServletResponse listResponse = mockMvc.perform(
get("/xpanse/services")
.param("categoryName", "middleware")
.param("cspName", "huawei")
.param("serviceName", "kafka-cluster")
.param("serviceVersion", "v3.3.2")
.param("serviceState",
ServiceDeploymentState.DEPLOY_SUCCESS.toValue())
.param("serviceState", state)
.accept(MediaType.APPLICATION_JSON))
.andReturn().getResponse();
// Verify the results
Expand Down Expand Up @@ -402,8 +402,8 @@ void testDestroy(boolean deploySuccess) throws Exception {
Response errorResponse = Response.errorResponse(ResultType.SERVICE_STATE_INVALID,
Collections.singletonList(errorMsg));
String errorResult = objectMapper.writeValueAsString(errorResponse);
Assertions.assertEquals(HttpStatus.BAD_REQUEST.value(), destroyResponse.getStatus());
Assertions.assertEquals(errorResult, destroyResponse.getContentAsString());
Assertions.assertEquals(HttpStatus.ACCEPTED.value(), destroyResponse.getStatus());
Assertions.assertEquals(result, destroyResponse.getContentAsString());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void testListCredentials_CredentialCenterReturnsNoItems() throws Exception {
String result = "[]";
// Run the test
final MockHttpServletResponse response =
mockMvc.perform(get("/xpanse/credentials")
mockMvc.perform(get("/xpanse/user/credentials")
.accept(MediaType.APPLICATION_JSON))
.andReturn().getResponse();

Expand Down Expand Up @@ -220,13 +220,13 @@ void testAddCredentialWithSensitiveIsFalse() throws Exception {
String queryResult = objectMapper.writeValueAsString(List.of(credentialVariables1));
// Run the test
final MockHttpServletResponse addResponse =
mockMvc.perform(post("/xpanse/credentials")
mockMvc.perform(post("/xpanse/user/credentials")
.content(requestBody).contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andReturn().getResponse();

final MockHttpServletResponse queryResponse =
mockMvc.perform(get("/xpanse/credentials")
mockMvc.perform(get("/xpanse/user/credentials")
.accept(MediaType.APPLICATION_JSON))
.andReturn().getResponse();

Expand Down Expand Up @@ -266,13 +266,13 @@ void testAddCredentialWithSensitiveIsTrue() throws Exception {
String queryResult = objectMapper.writeValueAsString(List.of(credentialVariables1));
// Run the test
final MockHttpServletResponse addResponse =
mockMvc.perform(post("/xpanse/credentials")
mockMvc.perform(post("/xpanse/user/credentials")
.content(requestBody).contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andReturn().getResponse();

final MockHttpServletResponse queryResponse =
mockMvc.perform(get("/xpanse/credentials")
mockMvc.perform(get("/xpanse/user/credentials")
.accept(MediaType.APPLICATION_JSON))
.andReturn().getResponse();

Expand All @@ -294,7 +294,7 @@ void testGetCredentials_CredentialCenterReturnsNoItems() throws Exception {

// Run the test
final MockHttpServletResponse response =
mockMvc.perform(get("/xpanse/credentials")
mockMvc.perform(get("/xpanse/user/credentials")
.param("cspName", "huawei")
.param("type", "VARIABLES")
.accept(MediaType.APPLICATION_JSON))
Expand Down Expand Up @@ -357,13 +357,13 @@ void testUpdateCredential() throws Exception {

// Run the test
final MockHttpServletResponse updateResponse =
mockMvc.perform(put("/xpanse/credentials")
mockMvc.perform(put("/xpanse/user/credentials")
.content(requestBody).contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andReturn().getResponse();

final MockHttpServletResponse queryResponse =
mockMvc.perform(get("/xpanse/credentials")
mockMvc.perform(get("/xpanse/user/credentials")
.accept(MediaType.APPLICATION_JSON))
.andReturn().getResponse();

Expand All @@ -386,15 +386,15 @@ void testDeleteCredential() throws Exception {

// Run the test
final MockHttpServletResponse deleteResponse =
mockMvc.perform(delete("/xpanse/credentials")
mockMvc.perform(delete("/xpanse/user/credentials")
.param("cspName", "huawei")
.param("type", "VARIABLES")
.param("name", "AK_SK")
.accept(MediaType.APPLICATION_JSON))
.andReturn().getResponse();

final MockHttpServletResponse queryResponse =
mockMvc.perform(get("/xpanse/credentials", Csp.HUAWEI)
mockMvc.perform(get("/xpanse/user/credentials", Csp.HUAWEI)
.param("type", "VARIABLES")
.param("name", "AK_SK")
.accept(MediaType.APPLICATION_JSON))
Expand Down

0 comments on commit 31d685f

Please sign in to comment.