Skip to content

Commit

Permalink
Add integration testing for APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
baixinsui committed Mar 26, 2024
1 parent f7958c0 commit 8d1bdb9
Show file tree
Hide file tree
Showing 67 changed files with 4,707 additions and 1,928 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@


import static org.eclipse.xpanse.modules.security.common.RoleConstants.ROLE_ADMIN;
import static org.eclipse.xpanse.modules.security.common.RoleConstants.ROLE_CSP;
import static org.eclipse.xpanse.modules.security.common.RoleConstants.ROLE_ISV;
import static org.eclipse.xpanse.modules.security.common.RoleConstants.ROLE_USER;

import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -134,7 +136,7 @@ public List<DeployedService> listDeployedServices(
@RequestParam(name = "serviceVersion", required = false) String serviceVersion,
@Parameter(name = "serviceState", description = "deployment state of the service")
@RequestParam(name = "serviceState", required = false)
ServiceDeploymentState serviceState) {
ServiceDeploymentState serviceState) {
return this.serviceDetailsViewManager.listDeployedServices(
category, csp, serviceName, serviceVersion, serviceState);
}
Expand All @@ -160,7 +162,7 @@ public List<DeployedService> listDeployedServicesDetails(
@RequestParam(name = "serviceVersion", required = false) String serviceVersion,
@Parameter(name = "serviceState", description = "deployment state of the service")
@RequestParam(name = "serviceState", required = false)
ServiceDeploymentState serviceState) {
ServiceDeploymentState serviceState) {
// return type is DeployedService but actually returns one of the child types
// VendorHostedDeployedServiceDetails or DeployedServiceDetails
return this.serviceDetailsViewManager.listDeployedServicesDetails(
Expand Down Expand Up @@ -259,11 +261,13 @@ public Response purge(@PathVariable("id") String id) {
@GetMapping(value = "/csp/region/azs",
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
@Secured({ROLE_ADMIN, ROLE_CSP, ROLE_ISV, ROLE_USER})
public List<String> getAvailabilityZones(
@Parameter(name = "cspName", description = "name of the cloud service provider")
@RequestParam(name = "cspName") Csp csp,
@Parameter(name = "regionName", description = "name of the region")
@RequestParam(name = "regionName") String regionName) {

Optional<String> userIdOptional = identityProviderManager.getCurrentLoginUserId();
if (userIdOptional.isPresent()) {
OrchestratorPlugin orchestratorPlugin = pluginManager.getOrchestratorPlugin(csp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import lombok.extern.slf4j.Slf4j;
import org.eclipse.xpanse.modules.deployment.deployers.terraform.exceptions.TerraformBootRequestFailedException;
import org.eclipse.xpanse.modules.deployment.deployers.terraform.exceptions.TerraformExecutorException;
import org.eclipse.xpanse.modules.deployment.deployers.terraform.exceptions.TerraformProviderNotFoundException;
import org.eclipse.xpanse.modules.models.response.Response;
import org.eclipse.xpanse.modules.models.response.ResultType;
import org.eclipse.xpanse.modules.models.service.deploy.exceptions.ActivitiTaskNotFoundException;
Expand Down Expand Up @@ -85,18 +84,6 @@ public Response handleDeployerNotFoundException(
Collections.singletonList(ex.getMessage()));
}

/**
* Exception handler for handleTerraformProviderNotFoundException.
*/
@ExceptionHandler({TerraformProviderNotFoundException.class})
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public Response handleTerraformProviderNotFoundException(
TerraformProviderNotFoundException ex) {
return Response.errorResponse(ResultType.TERRAFORM_PROVIDER_NOT_FOUND,
Collections.singletonList(ex.getMessage()));
}

/**
* Exception handler for InvalidServiceStateException.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import lombok.extern.slf4j.Slf4j;
import org.eclipse.xpanse.modules.models.response.Response;
import org.eclipse.xpanse.modules.models.response.ResultType;
import org.eclipse.xpanse.modules.models.service.deploy.exceptions.ServiceMigrationNotFoundException;
import org.eclipse.xpanse.modules.models.workflow.migrate.exceptions.ServiceMigrationFailedException;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
Expand All @@ -34,9 +35,17 @@ public class ServiceMigrationExceptionHandler {
@ExceptionHandler({ServiceMigrationFailedException.class})
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public Response handleServiceNotMigrationException(
ServiceMigrationFailedException ex) {
public Response handleServiceNotMigrationException(ServiceMigrationFailedException ex) {
return Response.errorResponse(ResultType.SERVICE_MIGRATION_FAILED_EXCEPTION,
Collections.singletonList(ex.getMessage()));
}


@ExceptionHandler({ServiceMigrationNotFoundException.class})
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public Response handleServiceNotMigrationException(ServiceMigrationNotFoundException ex) {
return Response.errorResponse(ResultType.SERVICE_MIGRATION_NOT_FOUND,
Collections.singletonList(ex.getMessage()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.eclipse.xpanse.modules.deployment.DeployerKindManager;
import org.eclipse.xpanse.modules.deployment.ServiceDetailsViewManager;
import org.eclipse.xpanse.modules.deployment.deployers.terraform.exceptions.TerraformExecutorException;
import org.eclipse.xpanse.modules.deployment.deployers.terraform.exceptions.TerraformProviderNotFoundException;
import org.eclipse.xpanse.modules.models.service.deploy.exceptions.DeployerNotFoundException;
import org.eclipse.xpanse.modules.models.service.deploy.exceptions.FlavorInvalidException;
import org.eclipse.xpanse.modules.models.service.deploy.exceptions.InvalidDeploymentVariableException;
Expand Down Expand Up @@ -115,16 +114,6 @@ void testDeployerNotFoundException() throws Exception {
.andExpect(jsonPath("$.details[0]").value("test error"));
}

@Test
void testTerraformProviderNotFoundException() throws Exception {
when(serviceDetailsViewManager.listDeployedServices(any(), any(), any(), any(),
any())).thenThrow(new TerraformProviderNotFoundException("test error"));

this.mockMvc.perform(get("/xpanse/services")).andExpect(status().is(400))
.andExpect(jsonPath("$.resultType").value("Terraform Provider Not Found"))
.andExpect(jsonPath("$.details[0]").value("test error"));
}

@Test
void testInvalidServiceStateException() throws Exception {
when(serviceDetailsViewManager.listDeployedServices(any(), any(), any(), any(),
Expand Down
36 changes: 28 additions & 8 deletions modules/api/src/test/resources/ocl_terraform_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name: terraform-test
# The version of the service, the end-user can select the version they want to deploy.
serviceVersion: v1.0.0
# For the users may have more than one service, the @namespace can be used to separate the clusters.
description: This is an ehanced compute services by ISV-A.
description: terraform test with local script.
namespace: ISV-A
# Icon for the service.
icon: |
Expand Down Expand Up @@ -36,6 +36,9 @@ flavors:
# Properties for the service, which can be used by the deployment.
properties:
flavor_id: s6.large.2
modificationImpact:
isDataLost: true
isServiceInterrupted: true
- name: 2vCPUs-8GB-normal
# The fixed price during the period (the price applied one shot whatever is the service use)
fixedPrice: 30
Expand All @@ -50,6 +53,11 @@ serviceProviderContactDetails:
deployment:
# kind, Supported values are terraform, opentofu.
kind: terraform
serviceAvailability:
- displayName: Availability Zone
varName: availability_zone
mandatory: false
description: The availability zone to deploy the service instance. If the value is empty, the service instance will be deployed in a random availability zone.
# Context for deployment: the context including some kind of parameters for the deployment, such as fix_env, fix_variable, env, variable, env_env, env_variable.
# - fix_env: Values for variable of this type are defined by the managed service provider in the OCL template. Runtime will inject it to deployer as environment variables. This variable is not visible to the end user.
# - fix_variable: Values for variable of this type are defined by the managed service provider in the OCL template. Runtime will inject it to deployer as usual variables. This variable is not visible to the end user.
Expand Down Expand Up @@ -102,11 +110,21 @@ deployment:
isDataLost: true
isServiceInterrupted: true
deployer: |
variable "region" {
type = string
description = "The region to deploy the service instance."
}
variable "flavor_id" {
type = string
default = "s6.large.2"
description = "The flavor id of the service instance."
}
variable "availability_zone" {
type = string
default = ""
description = "The availability zone of the service instance."
}
variable "admin_passwd" {
type = string
Expand All @@ -131,12 +149,6 @@ deployment:
default = "secgroup-default"
description = "The security group name of the service instance."
}
variable "region" {
type = string
default = "cn-southwest-2"
description = "The region to deploy the service instance."
}
locals {
admin_passwd = var.admin_passwd == "" ? random_password.password.result : var.admin_passwd
Expand All @@ -155,6 +167,14 @@ deployment:
output "flavor_id" {
value = var.flavor_id
}
output "region" {
value = var.region
}
output "availability_zone" {
value = var.availability_zone == "" ? "" : var.availability_zone
}
output "vpc_name" {
value = var.vpc_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class ServicePolicyEntity extends CreateModifiedTime {
* The registered service template we belonged to.
*/
@ManyToOne
@JoinColumn(name = "SERVICE_TEMPLATE_ID")
@JoinColumn(name = "SERVICE_TEMPLATE_ID", nullable = false)
@JsonIgnoreProperties({"servicePolicyEntity"})
private ServiceTemplateEntity serviceTemplate;

Expand Down
41 changes: 32 additions & 9 deletions modules/database/src/test/resources/ocl_terraform_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name: terraform-test
# The version of the service, the end-user can select the version they want to deploy.
serviceVersion: v1.0.0
# For the users may have more than one service, the @namespace can be used to separate the clusters.
description: This is an ehanced compute services by ISV-A.
description: terraform test with local script.
namespace: ISV-A
# Icon for the service.
icon: |
Expand Down Expand Up @@ -36,17 +36,28 @@ flavors:
# Properties for the service, which can be used by the deployment.
properties:
flavor_id: s6.large.2
modificationImpact:
isDataLost: true
isServiceInterrupted: true
- name: 2vCPUs-8GB-normal
# The fixed price during the period (the price applied one shot whatever is the service use)
fixedPrice: 30
# Properties for the service, which can be used by the deployment.
properties:
flavor_id: s6.large.4
modificationImpact:
isDataLost: true
isServiceInterrupted: true
serviceProviderContactDetails:
email: [ "test@test.com" ]
deployment:
# kind, Supported values are terraform, opentofu.
kind: terraform
serviceAvailability:
- displayName: Availability Zone
varName: availability_zone
mandatory: false
description: The availability zone to deploy the service instance. If the value is empty, the service instance will be deployed in a random availability zone.
# Context for deployment: the context including some kind of parameters for the deployment, such as fix_env, fix_variable, env, variable, env_env, env_variable.
# - fix_env: Values for variable of this type are defined by the managed service provider in the OCL template. Runtime will inject it to deployer as environment variables. This variable is not visible to the end user.
# - fix_variable: Values for variable of this type are defined by the managed service provider in the OCL template. Runtime will inject it to deployer as usual variables. This variable is not visible to the end user.
Expand Down Expand Up @@ -99,11 +110,21 @@ deployment:
isDataLost: true
isServiceInterrupted: true
deployer: |
variable "region" {
type = string
description = "The region to deploy the service instance."
}
variable "flavor_id" {
type = string
default = "s6.large.2"
description = "The flavor id of the service instance."
}
variable "availability_zone" {
type = string
default = ""
description = "The availability zone of the service instance."
}
variable "admin_passwd" {
type = string
Expand All @@ -128,13 +149,7 @@ deployment:
default = "secgroup-default"
description = "The security group name of the service instance."
}
variable "region" {
type = string
default = "cn-southwest-2"
description = "The region to deploy the service instance."
}
locals {
admin_passwd = var.admin_passwd == "" ? random_password.password.result : var.admin_passwd
}
Expand All @@ -152,6 +167,14 @@ deployment:
output "flavor_id" {
value = var.flavor_id
}
output "region" {
value = var.region
}
output "availability_zone" {
value = var.availability_zone == "" ? "" : var.availability_zone
}
output "vpc_name" {
value = var.vpc_name
Expand Down

0 comments on commit 8d1bdb9

Please sign in to comment.