summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpriyanshu <pagarwal@amdocs.com>2019-04-09 09:24:51 +0530
committerAvi Gaffa <avi.gaffa@amdocs.com>2019-04-10 06:01:38 +0000
commit163c4dfc0480a128f3243f8c466dccba41011e96 (patch)
treea4b1c30b41e92e61546091efd39c92e6e6877be6
parentef6ec63b05fb93adef0edb392b0a33de97203876 (diff)
Internal API for interface artifact upload
Internal API for interface artifact upload Change-Id: I9934a6d6aa11680b883f51ba8f231aeb866f2487 Issue-ID: SDC-2226 Signed-off-by: priyanshu <pagarwal@amdocs.com>
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArtifactServlet.java52
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/api/Urls.java1
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/artifacts/ArtifactServletTest.java147
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/interfaceoperation/InterfaceOperationsTest.java66
4 files changed, 214 insertions, 52 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArtifactServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArtifactServlet.java
index ddb1af4888..b69fa0b840 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArtifactServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArtifactServlet.java
@@ -33,6 +33,7 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.ArtifactUiDownloadData;
import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
@@ -476,6 +477,57 @@ public class ArtifactServlet extends BeGenericServlet {
}
+ @POST
+ @Path("/{assetType}/{uuid}/interfaces/{interfaceUUID}/operations/{operationUUID}/artifacts/{artifactUUID}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "uploads of artifact to component operation workflow", httpMethod = "POST", notes = "uploads of artifact to component operation workflow")
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "Artifact uploaded", response = ArtifactDefinition.class),
+ @ApiResponse(code = 404, message = "Specified resource is not found - SVC4063"),
+ @ApiResponse(code = 400, message = "Invalid artifactType was defined as input - SVC4122"),
+ @ApiResponse(code = 400, message = "Artifact type (mandatory field) is missing in request - SVC4124"),
+ @ApiResponse(code = 400, message = "Artifact name given in input already exists in the context of the asset - SVC4125"),
+ @ApiResponse(code = 400, message = "Artifact name is missing in input - SVC4128"),
+ @ApiResponse(code = 400, message = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
+ @ApiResponse(code = 400, message = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
+ @ApiImplicitParams({@ApiImplicitParam(required = true, dataType = "org.openecomp.sdc.be.model.ArtifactDefinition", paramType = "body", value = "json describe the artifact")})
+ public Response uploadInterfaceOperationArtifact(
+ @ApiParam(value = "Asset type") @PathParam("assetType") String assetType,
+ @ApiParam(value = "The uuid of the asset as published in the metadata", required = true)@PathParam("uuid") final String uuid,
+ @ApiParam(value = "The uuid of the interface", required = true)@PathParam("interfaceUUID") final String interfaceUUID,
+ @ApiParam(value = "The uuid of the operation", required = true)@PathParam("operationUUID") final String operationUUID,
+ @ApiParam(value = "The uuid of the artifact", required = true)@PathParam("artifactUUID") final String artifactUUID,
+ @ApiParam( hidden = true) String data,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}" , url);
+
+ try {
+ ServletContext context = request.getSession().getServletContext();
+ ArtifactsBusinessLogic artifactsLogic = getArtifactBL(context);
+ Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither =
+ artifactsLogic.updateArtifactOnInterfaceOperationByResourceUUID(data, request,
+ ComponentTypeEnum.findByParamName(assetType), uuid, interfaceUUID, operationUUID, artifactUUID,
+ new ResourceCommonInfo(assetType), artifactsLogic.new ArtifactOperationInfo(true,
+ false, ArtifactOperationEnum.UPDATE));
+ if (uploadArtifactEither.isRight()) {
+ log.debug("failed to update artifact");
+ return buildErrorResponse(uploadArtifactEither.right().value());
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), uploadArtifactEither.left().value());
+ }
+ catch (Exception e) {
+ final String message = "failed to update artifact on a resource or service";
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
+ log.debug(message, e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
// ////////// API END ///////////////////////////
// ************ private *********************
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/api/Urls.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/api/Urls.java
index 1f1c90764b..ad699d07ae 100644
--- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/api/Urls.java
+++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/api/Urls.java
@@ -408,6 +408,7 @@ public interface Urls {
final String UPDATE_INTERFACE_OPERATIONS = SDC_HTTP_METHOD + "://%s:%s/sdc2/rest/v1/catalog/%s/%s/interfaceOperations";
final String GET_INTERFACE_OPERATIONS = SDC_HTTP_METHOD + "://%s:%s/sdc2/rest/v1/catalog/%s/%s/interfaces/%s/operations/%s";
final String DELETE_INTERFACE_OPERATIONS = SDC_HTTP_METHOD + "://%s:%s/sdc2/rest/v1/catalog/%s/%s/interfaces/%s/operations/%s";
+ final String UPLOAD_INTERFACE_OPERATION_ARTIFACT = SDC_HTTP_METHOD + "://%s:%s/sdc2/rest/v1/catalog/%s/%s/interfaces/%s/operations/%s/artifacts/%s";
//Requirements
String CREATE_REQUIREMENT = SDC_HTTP_METHOD + "://%s:%s/sdc2/rest/v1/catalog/%s/%s/requirements";
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/artifacts/ArtifactServletTest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/artifacts/ArtifactServletTest.java
index c735169e77..81a165afc9 100644
--- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/artifacts/ArtifactServletTest.java
+++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/artifacts/ArtifactServletTest.java
@@ -42,6 +42,7 @@ import org.json.simple.parser.ParseException;
import org.junit.Rule;
import org.junit.rules.TestName;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
@@ -54,6 +55,7 @@ import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum;
import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
+import org.openecomp.sdc.ci.tests.execute.interfaceoperation.InterfaceOperationsTest;
import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
import org.openecomp.sdc.ci.tests.utils.rest.*;
@@ -73,6 +75,10 @@ import java.util.Map;
public class ArtifactServletTest extends ComponentBaseTest {
+ private static final String ARTIFACT_NAME_STR = "artifactName";
+ private static final String ARTIFACT_TYPE_STR = "artifactType";
+ private static final String ARTIFACT_DESCRIPTION_STR = "description";
+ private static final String ARTIFACT_PAYLOAD_DATA_STR = "payloadData";
private static Logger log = LoggerFactory.getLogger(ArtifactServletTest.class.getName());
protected static final String UPLOAD_ARTIFACT_PAYLOAD = "UHVUVFktVXNlci1LZXktRmlsZS0yOiBzc2gtcnNhDQpFbmNyeXB0aW9uOiBhZXMyNTYtY2JjDQpDb21tZW5wOA0K";
protected static final String UPLOAD_ARTIFACT_NAME = "TLV_prv.ppk";
@@ -84,6 +90,8 @@ public class ArtifactServletTest extends ComponentBaseTest {
protected String serviceVersion;
protected Resource resourceDetailsVFCcomp;
protected Service defaultService1;
+ protected Resource resource;
+ protected Resource pnfResource;
protected User sdncUserDetails;
@@ -106,6 +114,14 @@ public class ArtifactServletTest extends ComponentBaseTest {
Either<Service, RestResponse> defaultService1e = AtomicOperationUtils
.createDefaultService(UserRoleEnum.DESIGNER, true);
defaultService1 = defaultService1e.left().value();
+
+ Either<Resource, RestResponse> createDefaultResourceEither =
+ AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true);
+ resource = createDefaultResourceEither.left().value();
+
+ Either<Resource, RestResponse> createDefaultPNFResourceEither =
+ AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true);
+ pnfResource = createDefaultPNFResourceEither.left().value();
}
@Test
@@ -161,12 +177,12 @@ public class ArtifactServletTest extends ComponentBaseTest {
String artifactId = getLifecycleArtifactUid(response);
Map<String, Object> jsonBody = new HashMap<String, Object>();
- jsonBody.put("artifactName", "TLV_prv.ppk");
+ jsonBody.put(ARTIFACT_NAME_STR, "TLV_prv.ppk");
jsonBody.put("artifactDisplayName", "configure");
- jsonBody.put("artifactType", "SHELL");
+ jsonBody.put(ARTIFACT_TYPE_STR, "SHELL");
jsonBody.put("mandatory", "false");
String newDescription = "new something";
- jsonBody.put("description", newDescription);
+ jsonBody.put(ARTIFACT_DESCRIPTION_STR, newDescription);
jsonBody.put("artifactLabel", "configure");
userBodyJson = gson.toJson(jsonBody);
@@ -193,7 +209,7 @@ public class ArtifactServletTest extends ComponentBaseTest {
responseMap = (JSONObject) responseMap.get("operations");
responseMap = (JSONObject) responseMap.get(operationName.toLowerCase());
responseMap = (JSONObject) responseMap.get("implementation");
- String description = (String) responseMap.get("description");
+ String description = (String) responseMap.get(ARTIFACT_DESCRIPTION_STR);
AssertJUnit.assertEquals("the new description value was not set", newDescription, description);
@@ -214,12 +230,12 @@ public class ArtifactServletTest extends ComponentBaseTest {
protected String createUploadArtifactBodyJson() {
Map<String, Object> jsonBody = new HashMap<String, Object>();
- jsonBody.put("artifactName", UPLOAD_ARTIFACT_NAME);
+ jsonBody.put(ARTIFACT_NAME_STR, UPLOAD_ARTIFACT_NAME);
jsonBody.put("artifactDisplayName", "configure");
- jsonBody.put("artifactType", "SHELL");
+ jsonBody.put(ARTIFACT_TYPE_STR, "SHELL");
jsonBody.put("mandatory", "false");
- jsonBody.put("description", "ff");
- jsonBody.put("payloadData", UPLOAD_ARTIFACT_PAYLOAD);
+ jsonBody.put(ARTIFACT_DESCRIPTION_STR, "ff");
+ jsonBody.put(ARTIFACT_PAYLOAD_DATA_STR, UPLOAD_ARTIFACT_PAYLOAD);
jsonBody.put("artifactLabel", "configure");
return gson.toJson(jsonBody);
}
@@ -310,10 +326,10 @@ public class ArtifactServletTest extends ComponentBaseTest {
protected String createLoadArtifactBody() {
Map<String, Object> json = new HashMap<String, Object>();
- json.put("artifactName", "install_apache2.sh");
- json.put("artifactType", "SHELL");
- json.put("description", "ddd");
- json.put("payloadData", "UEsDBAoAAAAIAAeLb0bDQz");
+ json.put(ARTIFACT_NAME_STR, "install_apache2.sh");
+ json.put(ARTIFACT_TYPE_STR, "SHELL");
+ json.put(ARTIFACT_DESCRIPTION_STR, "ddd");
+ json.put(ARTIFACT_PAYLOAD_DATA_STR, "UEsDBAoAAAAIAAeLb0bDQz");
json.put("artifactLabel", "name123");
String jsonStr = gson.toJson(json);
@@ -442,8 +458,8 @@ public class ArtifactServletTest extends ComponentBaseTest {
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
Map<String, Object> json = new HashMap<String, Object>();
- json.put("description", "desc");
- json.put("payloadData", "UEsDBAoAAAAIAAeLb0bDQz");
+ json.put(ARTIFACT_DESCRIPTION_STR, "desc");
+ json.put(ARTIFACT_PAYLOAD_DATA_STR, "UEsDBAoAAAAIAAeLb0bDQz");
json.put("Content-MD5", "YTg2Mjg4MWJhNmI5NzBiNzdDFkMWI=");
String jsonBody = gson.toJson(json);
@@ -466,10 +482,10 @@ public class ArtifactServletTest extends ComponentBaseTest {
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
HashMap<String, Object> json = new HashMap<String, Object>();
- json.put("artifactName", "install_apache.sh");
- json.put("artifactType", "SHELL");
- json.put("description", "kjglkh");
- json.put("payloadData", "UEsDBYTEIWUYIFHWFMABCNAoAAAAIAAeLb0bDQz");
+ json.put(ARTIFACT_NAME_STR, "install_apache.sh");
+ json.put(ARTIFACT_TYPE_STR, "SHELL");
+ json.put(ARTIFACT_DESCRIPTION_STR, "kjglkh");
+ json.put(ARTIFACT_PAYLOAD_DATA_STR, "UEsDBYTEIWUYIFHWFMABCNAoAAAAIAAeLb0bDQz");
json.put("artifactLabel", "name123");
String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE, config.getCatalogBeHost(),
config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId());
@@ -575,10 +591,10 @@ public class ArtifactServletTest extends ComponentBaseTest {
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
Map<String, Object> json = new HashMap<String, Object>();
- json.put("artifactName", "install_apache.sh");
- json.put("artifactType", "SHELL11");
- json.put("description", "fff");
- json.put("payloadData", "UEsDBAoAAAAIAAeLb0bDQz");
+ json.put(ARTIFACT_NAME_STR, "install_apache.sh");
+ json.put(ARTIFACT_TYPE_STR, "SHELL11");
+ json.put(ARTIFACT_DESCRIPTION_STR, "fff");
+ json.put(ARTIFACT_PAYLOAD_DATA_STR, "UEsDBAoAAAAIAAeLb0bDQz");
json.put("artifactLabel", "name123");
String jsonStr = gson.toJson(json);
@@ -643,4 +659,91 @@ public class ArtifactServletTest extends ComponentBaseTest {
}
AssertJUnit.assertTrue(isExist);
}
+
+ @Test
+ public void addInterfaceOperationArtifactOnResource() throws Exception {
+ try (CloseableHttpClient httpclient = HttpClients.createDefault()){
+ Map<String, Object> artifactData = new HashMap<>();
+ artifactData.put(ARTIFACT_NAME_STR, "TestWF-1_0.bpmn");
+ artifactData.put(ARTIFACT_TYPE_STR, "WORKFLOW");
+ artifactData.put(ARTIFACT_DESCRIPTION_STR, "Resource Workflow Artifact Description");
+ artifactData.put(ARTIFACT_PAYLOAD_DATA_STR, "Test Data of Resource");
+
+ String jsonStr = gson.toJson(artifactData);
+ RestResponse restResponse = InterfaceOperationsRestUtils.addInterfaceOperations(resource,
+ new InterfaceOperationsTest().buildInterfaceDefinitionForResource(resource,
+ null, null),
+ ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ String interfaceDefStr = ResponseParser.getListFromJson(restResponse, "interfaces").get(0).toString();
+ InterfaceDefinition interfaceDefinition = ResponseParser.convertInterfaceDefinitionResponseToJavaObject(interfaceDefStr);
+ String interfaceUUID = interfaceDefinition.getUniqueId();
+ String operationUUID = interfaceDefinition.getOperationsMap().keySet().stream().findFirst().orElse(null);
+ String artifactUUID = interfaceDefinition.getOperationsMap().values().stream().findFirst().get().getImplementation().getArtifactUUID();
+
+ String url = String.format(Urls.UPLOAD_INTERFACE_OPERATION_ARTIFACT, config.getCatalogBeHost(),
+ config.getCatalogBePort(), ComponentTypeEnum.findParamByType(resource.getComponentType()),
+ resource.getUUID(), interfaceUUID, operationUUID, artifactUUID);
+ CloseableHttpResponse result = httpclient.execute(createPostAddArtifactRequeast(jsonStr, url, true));
+ int status = result.getStatusLine().getStatusCode();
+ AssertJUnit.assertEquals("add informational artifact request returned status: " + status, 200, status);
+ }
+ }
+
+ @Test
+ public void addInterfaceOperationArtifactOnPNFResource() throws Exception {
+ try (CloseableHttpClient httpclient = HttpClients.createDefault()){
+ Map<String, Object> artifactData = new HashMap<>();
+ artifactData.put(ARTIFACT_NAME_STR, "TestWF-1_0.bpmn");
+ artifactData.put(ARTIFACT_TYPE_STR, "WORKFLOW");
+ artifactData.put(ARTIFACT_DESCRIPTION_STR, "PNF Resource Workflow Artifact Description");
+ artifactData.put(ARTIFACT_PAYLOAD_DATA_STR, "Test Data of PNF Resource");
+
+ String jsonStr = gson.toJson(artifactData);
+ RestResponse restResponse = InterfaceOperationsRestUtils.addInterfaceOperations(pnfResource,
+ new InterfaceOperationsTest().buildInterfaceDefinitionForResource(pnfResource,
+ null, null),
+ ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ String interfaceDefStr = ResponseParser.getListFromJson(restResponse, "interfaces").get(0).toString();
+ InterfaceDefinition interfaceDefinition = ResponseParser.convertInterfaceDefinitionResponseToJavaObject(interfaceDefStr);
+ String interfaceUUID = interfaceDefinition.getUniqueId();
+ String operationUUID = interfaceDefinition.getOperationsMap().keySet().stream().findFirst().orElse(null);
+ String artifactUUID = interfaceDefinition.getOperationsMap().values().stream().findFirst().get().getImplementation().getArtifactUUID();
+
+ String url = String.format(Urls.UPLOAD_INTERFACE_OPERATION_ARTIFACT, config.getCatalogBeHost(),
+ config.getCatalogBePort(), ComponentTypeEnum.findParamByType(pnfResource.getComponentType()),
+ pnfResource.getUUID(), interfaceUUID, operationUUID, artifactUUID);
+ CloseableHttpResponse result = httpclient.execute(createPostAddArtifactRequeast(jsonStr, url, true));
+ int status = result.getStatusLine().getStatusCode();
+ AssertJUnit.assertEquals("add informational artifact request returned status: " + status, 200, status);
+ }
+ }
+
+ @Test
+ public void addInterfaceOperationArtifactOnService() throws Exception {
+ try (CloseableHttpClient httpclient = HttpClients.createDefault()){
+ Map<String, Object> artifactData = new HashMap<>();
+ artifactData.put(ARTIFACT_NAME_STR, "TestWF-1_0.bpmn");
+ artifactData.put(ARTIFACT_TYPE_STR, "WORKFLOW");
+ artifactData.put(ARTIFACT_DESCRIPTION_STR, "Service Workflow Artifact Description");
+ artifactData.put(ARTIFACT_PAYLOAD_DATA_STR, "Test Data of Service");
+
+ String jsonStr = gson.toJson(artifactData);
+ RestResponse restResponse = InterfaceOperationsRestUtils.addInterfaceOperations(defaultService1,
+ new InterfaceOperationsTest().buildInterfaceDefinitionForService(),
+ ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
+ String interfaceDefinitionStr = ResponseParser.getListFromJson(restResponse, "interfaces").get(0).toString();
+ InterfaceDefinition interfaceDefinition = ResponseParser.convertInterfaceDefinitionResponseToJavaObject(interfaceDefinitionStr);
+ String interfaceUUID = interfaceDefinition.getUniqueId();
+ String operationUUID = interfaceDefinition.getOperationsMap().keySet().stream().findFirst().orElse(null);
+ String artifactUUID = interfaceDefinition.getOperationsMap().values().stream().findFirst().get().getImplementation().getArtifactUUID();
+
+ String url = String.format(Urls.UPLOAD_INTERFACE_OPERATION_ARTIFACT, config.getCatalogBeHost(),
+ config.getCatalogBePort(), ComponentTypeEnum.findParamByType(defaultService1.getComponentType()),
+ defaultService1.getUUID(), interfaceUUID, operationUUID, artifactUUID);
+ CloseableHttpResponse result = httpclient.execute(createPostAddArtifactRequeast(jsonStr, url, true));
+ int status = result.getStatusLine().getStatusCode();
+ AssertJUnit.assertEquals("add informational artifact request returned status: " + status, 200, status);
+ }
+ }
+
}
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/interfaceoperation/InterfaceOperationsTest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/interfaceoperation/InterfaceOperationsTest.java
index f26f175f9d..d0513b5ad3 100644
--- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/interfaceoperation/InterfaceOperationsTest.java
+++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/interfaceoperation/InterfaceOperationsTest.java
@@ -9,6 +9,7 @@ import java.util.HashMap;
import java.util.Map;
import fj.data.Either;
+import org.apache.commons.collections4.CollectionUtils;
import org.junit.Rule;
import org.junit.rules.TestName;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
@@ -41,6 +42,9 @@ public class InterfaceOperationsTest extends ComponentBaseTest {
private static final String INTERFACES = "interfaces";
private static final String TOSCA_PRESENTATION = "toscaPresentation";
private static final User user = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
+ private static final String WORKFLOW_ID_STR = "WorkflowId";
+ private static final String WORKFLOW_VERSION_ID_STR = "workflowVersionId";
+ private static final String WORKFLOW_ASSOCIATION_TYPE_NONE_STR = "NONE";
private static Service service;
private static Resource resource;
@@ -76,26 +80,29 @@ public class InterfaceOperationsTest extends ComponentBaseTest {
// Create default PNF resource
Either<Resource, RestResponse> createDefaultPNFResourceEither =
- AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true);
+ AtomicOperationUtils.createResourceByType(ResourceTypeEnum.PNF, UserRoleEnum.DESIGNER, true);
if (createDefaultPNFResourceEither.isRight()) {
fail("Error creating default pnf resource");
}
pnfResource = createDefaultPNFResourceEither.left().value();
}
- private Map<String, Object> buildInterfaceDefinitionForResource(String resourceInterfaceUniqueId,
+ public Map<String, Object> buildInterfaceDefinitionForResource(Resource resource,
+ String resourceInterfaceUniqueId,
String resourceOperationUniqueId) {
Operation operation = new Operation();
operation.setName("TestOperationOnResource");
- operation.setWorkflowId("WorkflowId");
- operation.setWorkflowVersionId("workflowVersionId");
- operation.setWorkflowAssociationType("NONE");
- PropertyDefinition property =
- resource.getInputs().stream().filter(a -> a.getName().equalsIgnoreCase("nf_naming")).findFirst()
- .orElse(new InputDefinition());
- ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>();
- operationInputDefinitionList.add(createOperationInputDefinition("TestInput1", property.getUniqueId()));
- operation.setInputs(operationInputDefinitionList);
+ operation.setWorkflowId(WORKFLOW_ID_STR);
+ operation.setWorkflowVersionId(WORKFLOW_VERSION_ID_STR);
+ operation.setWorkflowAssociationType(WORKFLOW_ASSOCIATION_TYPE_NONE_STR);
+ if(CollectionUtils.isNotEmpty(resource.getInputs())){
+ PropertyDefinition property =
+ resource.getInputs().stream().filter(a -> a.getName().equalsIgnoreCase("nf_naming")).findFirst()
+ .orElse(new InputDefinition());
+ ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>();
+ operationInputDefinitionList.add(createOperationInputDefinition("TestInput1", property.getUniqueId()));
+ operation.setInputs(operationInputDefinitionList);
+ }
ListDataDefinition<OperationOutputDefinition> operationOutputDefinitionList = new ListDataDefinition<>();
operationOutputDefinitionList.add(createOperationOutputDefinition("TestOutput1"));
operation.setOutputs(operationOutputDefinitionList);
@@ -106,15 +113,17 @@ public class InterfaceOperationsTest extends ComponentBaseTest {
private Map<String, Object> buildInterfaceDefinitionOfGlobalTypeForResource(Resource resource) {
Operation operation = new Operation();
operation.setName("create");
- operation.setWorkflowId("WorkflowId");
- operation.setWorkflowVersionId("workflowVersionId");
+ operation.setWorkflowId(WORKFLOW_ID_STR);
+ operation.setWorkflowVersionId(WORKFLOW_VERSION_ID_STR);
operation.setWorkflowAssociationType("NONE");
- PropertyDefinition property =
- resource.getInputs().stream().filter(a -> a.getName().equalsIgnoreCase("nf_naming")).findFirst()
- .orElse(new InputDefinition());
- ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>();
- operationInputDefinitionList.add(createOperationInputDefinition("TestInput1", property.getUniqueId()));
- operation.setInputs(operationInputDefinitionList);
+ if(CollectionUtils.isNotEmpty(resource.getInputs())){
+ PropertyDefinition property =
+ resource.getInputs().stream().filter(a -> a.getName().equalsIgnoreCase("nf_naming")).findFirst()
+ .orElse(new InputDefinition());
+ ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>();
+ operationInputDefinitionList.add(createOperationInputDefinition("TestInput1", property.getUniqueId()));
+ operation.setInputs(operationInputDefinitionList);
+ }
ListDataDefinition<OperationOutputDefinition> operationOutputDefinitionList = new ListDataDefinition<>();
operationOutputDefinitionList.add(createOperationOutputDefinition("TestOutput1"));
operation.setOutputs(operationOutputDefinitionList);
@@ -175,11 +184,11 @@ public class InterfaceOperationsTest extends ComponentBaseTest {
return objectAsMap;
}
- private Map<String, Object> buildInterfaceDefinitionForService() {
+ public Map<String, Object> buildInterfaceDefinitionForService() {
Operation operation = new Operation();
operation.setName("TestOperationOnService");
- operation.setWorkflowId("WorkflowId");
- operation.setWorkflowVersionId("workflowVersionId");
+ operation.setWorkflowId(WORKFLOW_ID_STR);
+ operation.setWorkflowVersionId(WORKFLOW_VERSION_ID_STR);
operation.setWorkflowAssociationType("NONE");
return buildInterfaceDefinitionMap(operation, "TestInterface", serviceInterfaceUniqueId,
serviceOperationUniqueId);
@@ -189,8 +198,8 @@ public class InterfaceOperationsTest extends ComponentBaseTest {
public void addInterfaceOperationsOnResource() throws Exception {
RestResponse restResponse = InterfaceOperationsRestUtils
.addInterfaceOperations(resource,
- buildInterfaceDefinitionForResource(resourceInterfaceUniqueId, resourceOperationUniqueId),
- user);
+ buildInterfaceDefinitionForResource(resource, resourceInterfaceUniqueId,
+ resourceOperationUniqueId), user);
logger.info("addInterfaceOperationsOnResource Response Code:" + restResponse.getErrorCode());
Assert.assertEquals((int) restResponse.getErrorCode(), BaseRestUtils.STATUS_CODE_SUCCESS);
String interfaceDefinitionStr = ResponseParser.getListFromJson(restResponse, INTERFACES).get(0).toString();
@@ -213,7 +222,7 @@ public class InterfaceOperationsTest extends ComponentBaseTest {
public void updateInterfaceOperationsOnResource() throws Exception {
RestResponse restResponse = InterfaceOperationsRestUtils
.updateInterfaceOperations(resource,
- buildInterfaceDefinitionForResource(resourceInterfaceUniqueId, resourceOperationUniqueId),
+ buildInterfaceDefinitionForResource(resource, resourceInterfaceUniqueId, resourceOperationUniqueId),
user);
logger.info("updateInterfaceOperationsOnResource Response Code:" + restResponse.getErrorCode());
Assert.assertEquals((int) restResponse.getErrorCode(), BaseRestUtils.STATUS_CODE_SUCCESS);
@@ -231,7 +240,7 @@ public class InterfaceOperationsTest extends ComponentBaseTest {
@Test
public void addInterfaceOperationsOnPNFResource() throws Exception {
RestResponse restResponse = InterfaceOperationsRestUtils
- .addInterfaceOperations(pnfResource, buildInterfaceDefinitionForResource(pnfResourceInterfaceUniqueId,
+ .addInterfaceOperations(pnfResource, buildInterfaceDefinitionForResource(pnfResource, pnfResourceInterfaceUniqueId,
pnfResourceOperationUniqueId), user);
logger.info("addInterfaceOperationsOnPNFResource Response Code:" + restResponse.getErrorCode());
Assert.assertEquals((int) restResponse.getErrorCode(), BaseRestUtils.STATUS_CODE_SUCCESS);
@@ -256,7 +265,7 @@ public class InterfaceOperationsTest extends ComponentBaseTest {
public void updateInterfaceOperationsOnPNFResource() throws Exception {
RestResponse restResponse = InterfaceOperationsRestUtils
.updateInterfaceOperations(pnfResource,
- buildInterfaceDefinitionForResource(pnfResourceInterfaceUniqueId,
+ buildInterfaceDefinitionForResource(pnfResource, pnfResourceInterfaceUniqueId,
pnfResourceOperationUniqueId), user);
logger.info("updateInterfaceOperationsOnPNFResource Response Code:" + restResponse.getErrorCode());
Assert.assertEquals((int) restResponse.getErrorCode(), BaseRestUtils.STATUS_CODE_SUCCESS);
@@ -320,9 +329,6 @@ public class InterfaceOperationsTest extends ComponentBaseTest {
logger.info("addInterfaceOperationsOnResource Response Code:" + restResponse.getErrorCode());
Assert.assertEquals((int) restResponse.getErrorCode(), BaseRestUtils.STATUS_CODE_SUCCESS);
- String interfaceDefinitionStr = ResponseParser.getListFromJson(restResponse, INTERFACES).get(0).toString();
- InterfaceDefinition interfaceDefinition =
- ResponseParser.convertInterfaceDefinitionResponseToJavaObject(interfaceDefinitionStr);
}
@Test