summaryrefslogtreecommitdiffstats
path: root/adapters
diff options
context:
space:
mode:
Diffstat (limited to 'adapters')
-rw-r--r--adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql36
-rw-r--r--adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.7.1__WorkFlowDesignerTables.sql21
-rw-r--r--adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogDBRestTest.java56
-rw-r--r--adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java27
-rw-r--r--adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterApplication.java3
-rw-r--r--adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/BPRestCallback.java144
-rw-r--r--adapters/mso-sdnc-adapter/src/test/java/org/onap/so/adapters/sdnc/sdncrest/BPRestCallbackUnitTest.java142
-rw-r--r--adapters/mso-sdnc-adapter/src/test/resources/BPRestCallbackRequest.json1
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml4
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/Sol003PackageManagementControllerExceptionHandler.java66
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/AbstractServiceProviderConfiguration.java49
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java41
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java56
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java81
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java59
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderConfiguration.java20
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java79
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementController.java19
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/EtsiCatalogManagerRequestFailureException.java43
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgConflictException.java43
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgNotFoundException.java43
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java210
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementControllerTest.java4
23 files changed, 1014 insertions, 233 deletions
diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql
index 13d736e747..9527986f52 100644
--- a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql
+++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql
@@ -25,6 +25,8 @@ INSERT INTO northbound_request_ref_lookup(MACRO_ACTION, ACTION, REQUEST_SCOPE, I
('VolumeGroup-Delete', 'deleteInstance', 'VolumeGroup', true,true, '7','7', 'DEFAULT', '*'),
('VFModule-Create', 'createInstance', 'VfModule', true,true, '7','7', 'DEFAULT', '*'),
('VFModule-Delete', 'deleteInstance', 'VfModule', true,true, '7','7', 'DEFAULT', '*'),
+('VFModule-Replace', 'replaceInstance', 'VfModule', true,true, '7','7', 'DEFAULT', '*'),
+('VFModule-Replace-Retain-Assignments', 'replaceInstanceRetainAssignments', 'VfModule', true,true, '7','7', 'DEFAULT', '*'),
('NetworkCollection-Macro-Create', 'createInstance', 'NetworkCollection', false,true, '7','7', 'DEFAULT', '*'),
('NetworkCollection-Macro-Delete', 'deleteInstance', 'NetworkCollection', false,true, '7','7', 'DEFAULT', '*'),
('VFModule-ScaleOut', 'scaleOut', 'VfModule', true, true, '7','7', 'DEFAULT', '*');
@@ -147,7 +149,35 @@ INSERT INTO orchestration_flow_reference(COMPOSITE_ACTION, SEQ_NO, FLOW_NAME, FL
('VFModule-ScaleOut', '3', 'CreateVfModuleBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-ScaleOut' and CLOUD_OWNER = 'DEFAULT')),
('VFModule-ScaleOut', '4', 'ActivateVfModuleBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-ScaleOut' and CLOUD_OWNER = 'DEFAULT')),
('VFModule-ScaleOut', '5', 'ConfigurationScaleOutBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-ScaleOut' and CLOUD_OWNER = 'DEFAULT')),
-('VFModule-ScaleOut', '6', 'GenericVnfHealthCheckBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-ScaleOut' and CLOUD_OWNER = 'DEFAULT'));
+('VFModule-ScaleOut', '6', 'GenericVnfHealthCheckBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-ScaleOut' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace', '1', 'DeactivateVfModuleBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace', '2', 'DeleteVfModuleBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace', '3', 'DeactivateVolumeGroupBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace', '4', 'DeleteVolumeGroupBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace', '5', 'UnassignVfModuleBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace', '6', 'UnassignVolumeGroupBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace', '7', 'AssignVolumeGroupBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace', '8', 'AssignVfModuleBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace', '9', 'CreateVolumeGroupBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace', '10', 'ActivateVolumeGroupBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace', '11', 'CreateVfModuleBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace', '12', 'ActivateVfModuleBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace', '13', 'ChangeModelVnfBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace', '14', 'ChangeModelServiceInstanceBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace-Retain-Assignments', '1', 'DeactivateVfModuleBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace-Retain-Assignments' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace-Retain-Assignments', '2', 'DeleteVfModuleBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace-Retain-Assignments' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace-Retain-Assignments', '3', 'DeactivateVolumeGroupBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace-Retain-Assignments' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace-Retain-Assignments', '4', 'DeleteVolumeGroupBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace-Retain-Assignments' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace-Retain-Assignments', '5', 'UnassignVolumeGroupBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace-Retain-Assignments' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace-Retain-Assignments', '6', 'AssignVolumeGroupBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace-Retain-Assignments' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace-Retain-Assignments', '7', 'ChangeModelVfModuleBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace-Retain-Assignments' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace-Retain-Assignments', '8', 'CreateVolumeGroupBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace-Retain-Assignments' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace-Retain-Assignments', '9', 'ActivateVolumeGroupBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace-Retain-Assignments' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace-Retain-Assignments', '10', 'CreateVfModuleBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace-Retain-Assignments' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace-Retain-Assignments', '11', 'ActivateVfModuleBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace-Retain-Assignments' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace-Retain-Assignments', '12', 'ChangeModelVnfBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace-Retain-Assignments' and CLOUD_OWNER = 'DEFAULT')),
+('VFModule-Replace-Retain-Assignments', '13', 'ChangeModelServiceInstanceBB', 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'VFModule-Replace-Retain-Assignments' and CLOUD_OWNER = 'DEFAULT'));
+
INSERT INTO rainy_day_handler_macro (FLOW_NAME, SERVICE_TYPE, VNF_TYPE, ERROR_CODE, WORK_STEP, POLICY)
VALUES
@@ -815,3 +845,7 @@ VALUES
UPDATE rainy_day_handler_macro SET reg_ex_error_message = '*' WHERE reg_ex_error_message IS null;
UPDATE rainy_day_handler_macro SET SERVICE_ROLE = '*' WHERE SERVICE_ROLE IS null;
+
+INSERT INTO vnf_components_recipe (VNF_TYPE, VNF_COMPONENT_TYPE, ACTION, VERSION, ORCHESTRATION_URI, RECIPE_TIMEOUT)
+VALUES
+(NULL, 'vfModule', 'replaceInstanceRetainAssignments', '1', '/mso/async/services/WorkflowActionBB', 180);
diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.7.1__WorkFlowDesignerTables.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.7.1__WorkFlowDesignerTables.sql
index e44a6b97ba..8641e51862 100644
--- a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.7.1__WorkFlowDesignerTables.sql
+++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.7.1__WorkFlowDesignerTables.sql
@@ -40,6 +40,27 @@ CREATE TABLE IF NOT EXISTS `catalogdb`.`vnf_resource_to_workflow` (
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;
+CREATE TABLE IF NOT EXISTS `catalogdb`.`pnf_resource_to_workflow` (
+ `ID` INT(11) NOT NULL AUTO_INCREMENT,
+ `PNF_RESOURCE_MODEL_UUID` VARCHAR(200) NOT NULL,
+ `WORKFLOW_ID` INT(11) NOT NULL,
+ PRIMARY KEY (`ID`),
+ UNIQUE INDEX `UK_pnf_resource_to_workflow` (`PNF_RESOURCE_MODEL_UUID` ASC, `WORKFLOW_ID` ASC),
+ INDEX `fk_pnf_resource_to_workflow__workflow1_idx` (`WORKFLOW_ID` ASC),
+ INDEX `fk_pnf_resource_to_workflow__pnf_res_mod_uuid_idx` (`PNF_RESOURCE_MODEL_UUID` ASC),
+ CONSTRAINT `fk_pnf_resource_to_workflow__pnf_resource1`
+ FOREIGN KEY (`PNF_RESOURCE_MODEL_UUID`)
+ REFERENCES `catalogdb`.`pnf_resource` (`MODEL_UUID`)
+ ON DELETE CASCADE
+ ON UPDATE CASCADE,
+ CONSTRAINT `fk_pnf_resource_to_workflow__workflow1`
+ FOREIGN KEY (`WORKFLOW_ID`)
+ REFERENCES `catalogdb`.`workflow` (`ID`)
+ ON DELETE CASCADE
+ ON UPDATE CASCADE)
+ENGINE = InnoDB
+DEFAULT CHARACTER SET = latin1;
+
CREATE TABLE IF NOT EXISTS `catalogdb`.`activity_spec` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`NAME` VARCHAR(200) NOT NULL,
diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogDBRestTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogDBRestTest.java
index 347bce5b17..69a23a0eba 100644
--- a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogDBRestTest.java
+++ b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogDBRestTest.java
@@ -21,21 +21,11 @@
package org.onap.so.adapters.catalogdb.catalogrest;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.onap.logging.ref.slf4j.ONAPLogConstants.MDCs.INVOCATION_ID;
-import static org.onap.logging.ref.slf4j.ONAPLogConstants.MDCs.LOG_TIMESTAMP;
-import static org.onap.logging.ref.slf4j.ONAPLogConstants.MDCs.PARTNER_NAME;
-import static org.onap.logging.ref.slf4j.ONAPLogConstants.MDCs.RESPONSE_CODE;
-import static org.onap.logging.ref.slf4j.ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION;
-import static org.onap.logging.ref.slf4j.ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE;
-import static org.onap.logging.ref.slf4j.ONAPLogConstants.MDCs.SERVICE_NAME;
import java.io.IOException;
-import java.util.Map;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.json.JSONException;
import org.junit.Test;
-import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest;
import org.onap.so.db.catalog.beans.ServiceRecipe;
import org.skyscreamer.jsonassert.JSONAssert;
@@ -46,7 +36,6 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.util.UriComponentsBuilder;
-import ch.qos.logback.classic.spi.ILoggingEvent;
public class CatalogDBRestTest extends CatalogDbAdapterBaseTest {
@@ -109,26 +98,6 @@ public class CatalogDBRestTest extends CatalogDbAdapterBaseTest {
restTemplate.exchange(createURLWithPort("/manage/health"), HttpMethod.GET, entity, String.class);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
- for (ILoggingEvent logEvent : TestAppender.events)
- if (logEvent.getLoggerName().equals("org.onap.so.logging.spring.interceptor.LoggingInterceptor")
- && logEvent.getMarker() != null && logEvent.getMarker().getName().equals("ENTRY")) {
- Map<String, String> mdc = logEvent.getMDCPropertyMap();
- assertNotNull(mdc.get(ONAPLogConstants.MDCs.INSTANCE_UUID));
- assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID));
- assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID));
- assertEquals("", mdc.get(ONAPLogConstants.MDCs.PARTNER_NAME));
- assertEquals("/manage/health", mdc.get(ONAPLogConstants.MDCs.SERVICE_NAME));
- assertEquals("INPROGRESS", mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
- } else if (logEvent.getLoggerName().equals("org.onap.so.logging.spring.interceptor.LoggingInterceptor")
- && logEvent.getMarker() != null && logEvent.getMarker().getName().equals("EXIT")) {
- Map<String, String> mdc = logEvent.getMDCPropertyMap();
- assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID));
- assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID));
- assertEquals("200", mdc.get(ONAPLogConstants.MDCs.RESPONSE_CODE));
- assertEquals("", mdc.get(ONAPLogConstants.MDCs.PARTNER_NAME));
- assertEquals("/manage/health", mdc.get(ONAPLogConstants.MDCs.SERVICE_NAME));
- assertEquals("COMPLETED", mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
- }
}
/* Service Resources Endpoint */
@@ -815,31 +784,6 @@ public class CatalogDBRestTest extends CatalogDbAdapterBaseTest {
assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
JSONAssert.assertEquals(badQueryParamResponse, response.getBody().toString(), false);
-
-
- for (ILoggingEvent logEvent : TestAppender.events)
- if (logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.SOAuditLogContainerFilter")
- && logEvent.getMarker().getName().equals("ENTRY")) {
- Map<String, String> mdc = logEvent.getMDCPropertyMap();
- assertNotNull(mdc.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP));
- assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID));
- assertNotNull(mdc.get(INVOCATION_ID));
- assertEquals("UNKNOWN", mdc.get(PARTNER_NAME));
- assertEquals("v2/vfModules", mdc.get(SERVICE_NAME));
- assertEquals("INPROGRESS", mdc.get(RESPONSE_STATUS_CODE));
- } else if (logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.SOAuditLogContainerFilter")
- && logEvent.getMarker().getName().equals("EXIT")) {
- Map<String, String> mdc = logEvent.getMDCPropertyMap();
- assertNotNull(mdc.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP));
- assertNotNull(mdc.get(LOG_TIMESTAMP));
- assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID));
- assertNotNull(mdc.get(INVOCATION_ID));
- assertEquals("500", mdc.get(RESPONSE_CODE));
- assertEquals("UNKNOWN", mdc.get(PARTNER_NAME));
- assertEquals("v2/vfModules", mdc.get(SERVICE_NAME));
- assertEquals("ERROR", mdc.get(RESPONSE_STATUS_CODE));
- assertNotNull(mdc.get(RESPONSE_DESCRIPTION));
- }
}
@Test
diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java
index 92d3114ebe..eacd413df6 100644
--- a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java
+++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java
@@ -23,17 +23,14 @@ package org.onap.so.adapters.requestsdb.adapters;
import static com.shazam.shazamcrest.MatcherAssert.assertThat;
import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.onap.so.adapters.requestsdb.MsoRequestsDbAdapter;
import org.onap.so.adapters.requestsdb.RequestStatusType;
import org.onap.so.adapters.requestsdb.RequestsAdapterBase;
@@ -47,7 +44,6 @@ import org.onap.so.db.request.data.repository.ResourceOperationStatusRepository;
import org.onap.so.requestsdb.RequestsDbConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.server.LocalServerPort;
-import ch.qos.logback.classic.spi.ILoggingEvent;
public class MSORequestDBImplTest extends RequestsAdapterBase {
@@ -423,28 +419,5 @@ public class MSORequestDBImplTest extends RequestsAdapterBase {
ResourceOperationStatus actualResource =
dbAdapter.getResourceOperationStatus(serviceId, operationId, "template1");
assertThat(actualResource, sameBeanAs(expectedResource));
-
- for (ILoggingEvent logEvent : TestAppender.events)
- if (logEvent.getLoggerName().equals("org.onap.so.logging.cxf.interceptor.SOAPLoggingInInterceptor")
- && logEvent.getMarker().getName().equals("ENTRY")) {
- Map<String, String> mdc = logEvent.getMDCPropertyMap();
- assertNotNull(mdc.get(ONAPLogConstants.MDCs.INSTANCE_UUID));
- assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID));
- assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID));
- assertEquals("UNKNOWN", mdc.get(ONAPLogConstants.MDCs.PARTNER_NAME));
- assertEquals("/services/RequestsDbAdapter", mdc.get(ONAPLogConstants.MDCs.SERVICE_NAME));
- assertEquals("INPROGRESS", mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
- } else if (logEvent.getLoggerName().equals("org.onap.so.logging.cxf.interceptor.SOAPLoggingOutInterceptor")
- && logEvent.getMarker().getName().equals("EXIT")) {
- Map<String, String> mdc = logEvent.getMDCPropertyMap();
- assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID));
- assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID));
- assertEquals(null, mdc.get(ONAPLogConstants.MDCs.RESPONSE_CODE));
- assertEquals("UNKNOWN", mdc.get(ONAPLogConstants.MDCs.PARTNER_NAME));
- assertEquals("/services/RequestsDbAdapter", mdc.get(ONAPLogConstants.MDCs.SERVICE_NAME));
- assertEquals("COMPLETE", mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
- }
}
-
-
}
diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterApplication.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterApplication.java
index fc6d0a6fc9..55a05436f0 100644
--- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterApplication.java
+++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/SDNCAdapterApplication.java
@@ -23,7 +23,9 @@
package org.onap.so.adapters.sdnc;
import java.util.concurrent.Executor;
+import org.onap.logging.filter.base.Constants;
import org.onap.logging.filter.spring.MDCTaskDecorator;
+import org.onap.so.utils.Components;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -52,6 +54,7 @@ public class SDNCAdapterApplication {
}
public static void main(String[] args) {
+ System.setProperty(Constants.Property.PARTNER_NAME, Components.SDNC_ADAPTER.toString());
SpringApplication.run(SDNCAdapterApplication.class, args);
System.getProperties().setProperty("server.name", "Springboot");
setLogsDir();
diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/BPRestCallback.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/BPRestCallback.java
index 8a1a7559b5..631be2f9ff 100644
--- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/BPRestCallback.java
+++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/BPRestCallback.java
@@ -24,27 +24,30 @@
package org.onap.so.adapters.sdnc.sdncrest;
+import java.net.URI;
import javax.xml.bind.DatatypeConverter;
-import org.onap.so.logger.LoggingAnchor;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.ContentType;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.util.EntityUtils;
-import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.onap.logging.filter.spring.SpringClientPayloadFilter;
import org.onap.so.adapters.sdnc.impl.Constants;
import org.onap.so.logger.ErrorCode;
+import org.onap.so.logger.LoggingAnchor;
import org.onap.so.logger.MessageEnum;
+import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter;
+import org.onap.so.utils.CryptoUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-import org.onap.so.utils.CryptoUtils;
-import org.slf4j.MDC;
import org.springframework.core.env.Environment;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.http.client.BufferingClientHttpRequestFactory;
+import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.HttpStatusCodeException;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.util.UriComponentsBuilder;
/**
* Sends asynchronous messages to the BPMN WorkflowMessage service.
@@ -95,81 +98,72 @@ public class BPRestCallback {
logger.info(LoggingAnchor.THREE, MessageEnum.RA_CALLBACK_BPEL.toString(),
message == null ? "[no content]" : message, CAMUNDA);
-
- HttpPost method = null;
- HttpResponse httpResponse = null;
-
try {
int timeout = 60 * 1000;
+ RestTemplate restTemplate = setRestTemplate(timeout);
- RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(timeout).setConnectTimeout(timeout)
- .setConnectionRequestTimeout(timeout).build();
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.APPLICATION_JSON);
- HttpClient client = HttpClientBuilder.create().build();
- method = new HttpPost(url);
- method.setConfig(requestConfig);
-
- if (message != null) {
- method.setEntity(new StringEntity(message, ContentType.APPLICATION_JSON));
- }
-
- boolean error = false;
-
- try {
- String userCredentials = CryptoUtils.decrypt(env.getProperty(Constants.BPEL_AUTH_PROP),
- env.getProperty(Constants.ENCRYPTION_KEY_PROP));
- String authorization = "Basic " + DatatypeConverter.printBase64Binary(userCredentials.getBytes());
- method.setHeader("Authorization", authorization);
- method.setHeader(ONAPLogConstants.Headers.REQUEST_ID, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID));
- method.setHeader(ONAPLogConstants.Headers.INVOCATION_ID, MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID));
- method.setHeader(ONAPLogConstants.Headers.PARTNER_NAME, "SO-SDNCAdapter");
- } catch (Exception e) {
- logger.error(LoggingAnchor.FOUR, MessageEnum.RA_SET_CALLBACK_AUTH_EXC.toString(), CAMUNDA,
- ErrorCode.BusinessProcessError.getValue(), "Unable to set authorization in callback request",
- e);
- error = true;
- }
+ boolean error = setAuthorizationHeader(headers);
+ HttpEntity<String> requestEntity = new HttpEntity<>(message, headers);
if (!error) {
- httpResponse = client.execute(method);
-
- @SuppressWarnings("unused")
- String responseContent = null;
-
- if (httpResponse.getEntity() != null) {
- responseContent = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
- }
-
- if (httpResponse.getStatusLine().getStatusCode() >= 300) {
- String msg = "Received error response to callback request: " + httpResponse.getStatusLine();
- logger.error(LoggingAnchor.FOUR, MessageEnum.RA_CALLBACK_BPEL_EXC.toString(), CAMUNDA,
- ErrorCode.BusinessProcessError.getValue(), msg);
-
- }
+ postRequest(restTemplate, url, requestEntity);
}
+ logger.info(LoggingAnchor.TWO, MessageEnum.RA_CALLBACK_BPEL_COMPLETE.toString(), CAMUNDA);
return true;
} catch (Exception e) {
logger.error(LoggingAnchor.FOUR, MessageEnum.RA_CALLBACK_BPEL_EXC.toString(), CAMUNDA,
ErrorCode.BusinessProcessError.getValue(), "Error sending callback request", e);
return false;
- } finally {
- if (httpResponse != null) {
- try {
- EntityUtils.consume(httpResponse.getEntity());
- httpResponse = null;
- } catch (Exception e) {
- logger.debug("Exception:", e);
- }
- }
+ }
+ }
- if (method != null) {
- try {
- method.reset();
- } catch (Exception e) {
- logger.debug("Exception:", e);
- }
- }
- logger.info(LoggingAnchor.TWO, MessageEnum.RA_CALLBACK_BPEL_COMPLETE.toString(), CAMUNDA);
+ protected boolean setAuthorizationHeader(HttpHeaders headers) {
+ boolean error = false;
+ try {
+ String userCredentials = CryptoUtils.decrypt(env.getProperty(Constants.BPEL_AUTH_PROP),
+ env.getProperty(Constants.ENCRYPTION_KEY_PROP));
+ String authorization = "Basic " + DatatypeConverter.printBase64Binary(userCredentials.getBytes());
+ headers.set("Authorization", authorization);
+ } catch (Exception e) {
+ logger.error(LoggingAnchor.FOUR, MessageEnum.RA_SET_CALLBACK_AUTH_EXC.toString(), CAMUNDA,
+ ErrorCode.BusinessProcessError.getValue(), "Unable to set authorization in callback request", e);
+ error = true;
+ }
+ return error;
+ }
+
+ private void postRequest(RestTemplate restTemplate, String url, HttpEntity<String> requestEntity) {
+ ResponseEntity<String> response = null;
+ try {
+ UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(url);
+ URI uri = builder.build(true).toUri();
+ response = restTemplate.postForEntity(uri, requestEntity, String.class);
+ } catch (HttpStatusCodeException e) {
+ logResponseError(e.getStatusCode());
+ }
+ if (response != null && response.getStatusCode().is3xxRedirection()) {
+ logResponseError(response.getStatusCode());
}
}
+
+ private void logResponseError(HttpStatus statusCode) {
+ String msg = "Received error response to callback request: " + statusCode;
+ logger.error(LoggingAnchor.FOUR, MessageEnum.RA_CALLBACK_BPEL_EXC.toString(), CAMUNDA,
+ ErrorCode.BusinessProcessError.getValue(), msg);
+ }
+
+ protected RestTemplate setRestTemplate(int timeout) {
+ RestTemplate restTemplate = new RestTemplate();
+ HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
+ factory.setConnectionRequestTimeout(timeout);
+ factory.setReadTimeout(timeout);
+ factory.setConnectTimeout(timeout);
+ restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(factory));
+ restTemplate.getInterceptors().add(new SOSpringClientFilter());
+ restTemplate.getInterceptors().add((new SpringClientPayloadFilter()));
+ return restTemplate;
+ }
}
diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/onap/so/adapters/sdnc/sdncrest/BPRestCallbackUnitTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/onap/so/adapters/sdnc/sdncrest/BPRestCallbackUnitTest.java
new file mode 100644
index 0000000000..09089890ab
--- /dev/null
+++ b/adapters/mso-sdnc-adapter/src/test/java/org/onap/so/adapters/sdnc/sdncrest/BPRestCallbackUnitTest.java
@@ -0,0 +1,142 @@
+package org.onap.so.adapters.sdnc.sdncrest;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.when;
+import java.io.IOException;
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.adapters.sdnc.impl.Constants;
+import org.springframework.core.env.Environment;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.HttpServerErrorException;
+import org.springframework.web.client.ResourceAccessException;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.util.UriComponentsBuilder;
+
+@RunWith(MockitoJUnitRunner.class)
+public class BPRestCallbackUnitTest {
+ @Mock
+ private Environment env;
+
+ @Mock
+ private RestTemplate restTemplate;
+
+ @Spy
+ @InjectMocks
+ private BPRestCallback bpRestCallback;
+
+ private HttpEntity<String> requestEntity;
+ private String message;
+ private HttpHeaders headers;
+ private URI uri;
+
+ @Before
+ public void setUp() throws IOException {
+ headers = new HttpHeaders();
+ headers.setContentType(MediaType.APPLICATION_JSON);
+ message = input("BPRestCallbackRequest.json");
+ requestEntity = new HttpEntity<>(message, headers);
+ UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("http://localhost:8000/sdnc");
+ uri = builder.build(true).toUri();
+ }
+
+ public String input(String JsonInput) throws IOException {
+ JsonInput = "src/test/resources/" + JsonInput;
+ return new String(Files.readAllBytes(Paths.get(JsonInput)));
+ }
+
+ @Test
+ public void sendTest() throws IOException {
+ ResponseEntity<String> postResponse = new ResponseEntity<String>("response", HttpStatus.OK);
+ doReturn(restTemplate).when(bpRestCallback).setRestTemplate(60000);
+ doReturn(false).when(bpRestCallback).setAuthorizationHeader(headers);
+ when(restTemplate.postForEntity(uri, requestEntity, String.class)).thenReturn(postResponse);
+ boolean response = bpRestCallback.send("http://localhost:8000/sdnc", message);
+ assertTrue(response);
+ }
+
+ @Test
+ public void sendNoAuthHeaderTest() throws IOException {
+ doReturn(true).when(bpRestCallback).setAuthorizationHeader(headers);
+ doReturn(restTemplate).when(bpRestCallback).setRestTemplate(60000);
+ boolean response = bpRestCallback.send("http://localhost:8000/sdnc", message);
+ assertTrue(response);
+ }
+
+ @Test
+ public void sendErrorTest() throws IOException {
+ doReturn(false).when(bpRestCallback).setAuthorizationHeader(headers);
+ doReturn(restTemplate).when(bpRestCallback).setRestTemplate(60000);
+ when(restTemplate.postForEntity(uri, requestEntity, String.class))
+ .thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, null, null, null));
+ boolean response = bpRestCallback.send("http://localhost:8000/sdnc", message);
+ assertTrue(response);
+ }
+
+ @Test
+ public void sendResponse3xxTest() throws IOException {
+ ResponseEntity<String> postResponse = new ResponseEntity<String>("response", HttpStatus.MULTIPLE_CHOICES);
+ doReturn(false).when(bpRestCallback).setAuthorizationHeader(headers);
+ doReturn(restTemplate).when(bpRestCallback).setRestTemplate(60000);
+ when(restTemplate.postForEntity(uri, requestEntity, String.class)).thenReturn(postResponse);
+ boolean response = bpRestCallback.send("http://localhost:8000/sdnc", message);
+ assertTrue(response);
+ }
+
+ @Test
+ public void sendResponseNullMessageTest() throws IOException {
+ HttpHeaders httpHeaders = new HttpHeaders();
+ httpHeaders.setContentType(MediaType.APPLICATION_JSON);
+ HttpEntity<String> requestEntityNoMessage = new HttpEntity<>(null, httpHeaders);
+ ResponseEntity<String> postResponse = new ResponseEntity<String>("response", HttpStatus.OK);
+ doReturn(false).when(bpRestCallback).setAuthorizationHeader(httpHeaders);
+ doReturn(restTemplate).when(bpRestCallback).setRestTemplate(60000);
+ when(restTemplate.postForEntity(uri, requestEntityNoMessage, String.class)).thenReturn(postResponse);
+ boolean response = bpRestCallback.send("http://localhost:8000/sdnc", null);
+ assertTrue(response);
+ }
+
+ @Test
+ public void postThrowsExceptionTest() throws IOException {
+ doReturn(false).when(bpRestCallback).setAuthorizationHeader(headers);
+ doReturn(restTemplate).when(bpRestCallback).setRestTemplate(60000);
+ when(restTemplate.postForEntity(uri, requestEntity, String.class))
+ .thenThrow(new ResourceAccessException("ResourceAccessException"));
+ boolean response = bpRestCallback.send("http://localhost:8000/sdnc", message);
+ assertFalse(response);
+ }
+
+ @Test
+ public void setAuthorizationHeaderTest() {
+ HttpHeaders authHeaders = new HttpHeaders();
+ when(env.getProperty(Constants.BPEL_AUTH_PROP))
+ .thenReturn("5E12ACACBD552A415E081E29F2C4772F9835792A51C766CCFDD7433DB5220B59969CB2798C");
+ when(env.getProperty(Constants.ENCRYPTION_KEY_PROP)).thenReturn("07a7159d3bf51a0e53be7a8f89699be7");
+ boolean result = bpRestCallback.setAuthorizationHeader(authHeaders);
+ assertFalse(result);
+ }
+
+ @Test
+ public void setAuthorizationHeaderErrorTest() {
+ HttpHeaders authHeaders = new HttpHeaders();
+ when(env.getProperty(Constants.BPEL_AUTH_PROP)).thenReturn("test");
+ when(env.getProperty(Constants.ENCRYPTION_KEY_PROP)).thenReturn("test");
+ boolean result = bpRestCallback.setAuthorizationHeader(authHeaders);
+ assertTrue(result);
+ }
+}
diff --git a/adapters/mso-sdnc-adapter/src/test/resources/BPRestCallbackRequest.json b/adapters/mso-sdnc-adapter/src/test/resources/BPRestCallbackRequest.json
new file mode 100644
index 0000000000..21f3dab7e0
--- /dev/null
+++ b/adapters/mso-sdnc-adapter/src/test/resources/BPRestCallbackRequest.json
@@ -0,0 +1 @@
+{"SDNCServiceResponse":{"sdncRequestId":"b5b763aa-0d8a-4438-b900-83af45d21d10","responseCode":"200","ackFinalIndicator":"N"}} \ No newline at end of file
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml b/adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml
index 9d9e33a524..f828a12c8b 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml
@@ -105,5 +105,9 @@
<artifactId>okio</artifactId>
<version>1.13.0</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
</dependencies>
</project>
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/Sol003PackageManagementControllerExceptionHandler.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/Sol003PackageManagementControllerExceptionHandler.java
new file mode 100644
index 0000000000..713bf01249
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/Sol003PackageManagementControllerExceptionHandler.java
@@ -0,0 +1,66 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnfmadapter;
+
+import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.ProblemDetails;
+import org.onap.so.adapters.vnfmadapter.rest.Sol003PackageManagementController;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.EtsiCatalogManagerRequestFailureException;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgConflictException;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgNotFoundException;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+
+/**
+ * Exception Handler for the Package Management Controller {@link Sol003PackageManagementController Sol003Controller}
+ *
+ * @author gareth.roper@est.tech
+ */
+@ControllerAdvice(assignableTypes = Sol003PackageManagementController.class)
+
+public class Sol003PackageManagementControllerExceptionHandler {
+
+ @ExceptionHandler(EtsiCatalogManagerRequestFailureException.class)
+ public ResponseEntity<ProblemDetails> handleEtsiCatalogManagerRequestFailureException(
+ EtsiCatalogManagerRequestFailureException etsiCatalogManagerRequestFailureException) {
+ final ProblemDetails problemDetails = new ProblemDetails();
+ problemDetails.setDetail(etsiCatalogManagerRequestFailureException.getMessage());
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(problemDetails);
+ }
+
+ @ExceptionHandler(VnfPkgConflictException.class)
+ public ResponseEntity<ProblemDetails> handleVnfPkgConflictException(
+ VnfPkgConflictException vnfPkgConflictException) {
+ final ProblemDetails problemDetails = new ProblemDetails();
+ problemDetails.setDetail(vnfPkgConflictException.getMessage());
+ return ResponseEntity.status(HttpStatus.CONFLICT).body(problemDetails);
+ }
+
+ @ExceptionHandler(VnfPkgNotFoundException.class)
+ public ResponseEntity<ProblemDetails> handleVnfPkgNotFoundException(
+ VnfPkgNotFoundException vnfPkgNotFoundException) {
+ final ProblemDetails problemDetails = new ProblemDetails();
+ problemDetails.setDetail(vnfPkgNotFoundException.getMessage());
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).body(problemDetails);
+ }
+
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/AbstractServiceProviderConfiguration.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/AbstractServiceProviderConfiguration.java
new file mode 100644
index 0000000000..8f6d853997
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/AbstractServiceProviderConfiguration.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnfmadapter.extclients;
+
+import com.google.gson.Gson;
+import java.util.Iterator;
+import org.onap.vnfmadapter.v1.JSON;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.json.GsonHttpMessageConverter;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * A base class that can be extended by classes for configuring HttpRestServiceProvider classes. Provides common methods
+ * that will be useful to some such classes.
+ *
+ * @author gareth.roper@est.tech
+ */
+public abstract class AbstractServiceProviderConfiguration {
+
+ public void setGsonMessageConverter(final RestTemplate restTemplate) {
+ final Iterator<HttpMessageConverter<?>> iterator = restTemplate.getMessageConverters().iterator();
+ while (iterator.hasNext()) {
+ if (iterator.next() instanceof MappingJackson2HttpMessageConverter) {
+ iterator.remove();
+ }
+ }
+ final Gson gson = new JSON().getGson();
+ restTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson));
+ }
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java
new file mode 100644
index 0000000000..39efc8dc23
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java
@@ -0,0 +1,41 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnfmadapter.extclients.etsicatalog;
+
+import java.util.Optional;
+
+/**
+ * Provides methods for invoking REST calls to the ETSI Catalog Manager.
+ *
+ * @author gareth.roper@est.tech
+ */
+public interface EtsiCatalogServiceProvider {
+
+ /**
+ * GET Package Content, from VNF Package.
+ *
+ * @param vnfPkgId The ID of the VNF Package from which the "package_content" will be retrieved.
+ * @return The Package Content of a VNF Package ("vnfPkgId").
+ */
+
+ Optional<byte[]> getVnfPackageContent(final String vnfPkgId);
+
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java
new file mode 100644
index 0000000000..6840dd388b
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java
@@ -0,0 +1,56 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnfmadapter.extclients.etsicatalog;
+
+import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE;
+import org.onap.so.adapters.vnfmadapter.extclients.AbstractServiceProviderConfiguration;
+import org.onap.so.configuration.rest.BasicHttpHeadersProvider;
+import org.onap.so.configuration.rest.HttpHeadersProvider;
+import org.onap.so.rest.service.HttpRestServiceProvider;
+import org.onap.so.rest.service.HttpRestServiceProviderImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * Configures the HttpRestServiceProvider to make REST calls to the ETSI Catalog Manager
+ *
+ * @author gareth.roper@est.tech
+ */
+
+@Configuration
+public class EtsiCatalogServiceProviderConfiguration extends AbstractServiceProviderConfiguration {
+
+ @Bean(name = "etsiCatalogServiceProvider")
+ public HttpRestServiceProvider httpRestServiceProvider(
+ @Qualifier(CONFIGURABLE_REST_TEMPLATE) @Autowired final RestTemplate restTemplate) {
+ return getHttpRestServiceProvider(restTemplate, new BasicHttpHeadersProvider());
+ }
+
+ private HttpRestServiceProvider getHttpRestServiceProvider(final RestTemplate restTemplate,
+ final HttpHeadersProvider httpHeadersProvider) {
+ setGsonMessageConverter(restTemplate);
+ return new HttpRestServiceProviderImpl(restTemplate, httpHeadersProvider);
+ }
+
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java
new file mode 100644
index 0000000000..9a59620993
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java
@@ -0,0 +1,81 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnfmadapter.extclients.etsicatalog;
+
+import java.util.Optional;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.EtsiCatalogManagerRequestFailureException;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgConflictException;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgNotFoundException;
+import org.onap.so.rest.exceptions.HttpResouceNotFoundException;
+import org.onap.so.rest.exceptions.RestProcessingException;
+import org.onap.so.rest.service.HttpRestServiceProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+
+/**
+ * Provides the implementations of the REST Requests to the ETSI Catalog Manager.
+ *
+ * @author gareth.roper@est.tech
+ */
+@Service
+public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvider {
+ private static final Logger logger = LoggerFactory.getLogger(EtsiCatalogServiceProviderImpl.class);
+
+ @Qualifier
+ private final HttpRestServiceProvider httpServiceProvider;
+ private final EtsiCatalogUrlProvider etsiCatalogUrlProvider;
+
+ @Autowired
+ public EtsiCatalogServiceProviderImpl(final EtsiCatalogUrlProvider etsiCatalogUrlProvider,
+ final HttpRestServiceProvider httpServiceProvider) {
+ this.etsiCatalogUrlProvider = etsiCatalogUrlProvider;
+ this.httpServiceProvider = httpServiceProvider;
+ }
+
+ @Override
+ public Optional<byte[]> getVnfPackageContent(String vnfPkgId) throws EtsiCatalogManagerRequestFailureException {
+ try {
+ ResponseEntity<byte[]> response = httpServiceProvider
+ .getHttpResponse(etsiCatalogUrlProvider.getVnfPackageContentUrl(vnfPkgId), byte[].class);
+ logger.info("getVnfPackageContent Request to ETSI Catalog Manager Status Code: {}",
+ response.getStatusCodeValue());
+ if (response.getStatusCode() == HttpStatus.OK) {
+ return Optional.ofNullable(response.getBody());
+ }
+ } catch (HttpResouceNotFoundException httpResouceNotFoundException) {
+ logger.error("Caught HttpResouceNotFoundException", httpResouceNotFoundException);
+ throw new VnfPkgNotFoundException("No Vnf Package found with vnfPkgId: " + vnfPkgId);
+ } catch (RestProcessingException restProcessingException) {
+ logger.error("Caught RestProcessingException with Status Code: {}", restProcessingException.getStatusCode(),
+ restProcessingException);
+ if (restProcessingException.getStatusCode() == HttpStatus.CONFLICT.value()) {
+ throw new VnfPkgConflictException("A conflict occurred with the state of the resource,\n"
+ + "due to the attribute: onboardingState not being set to ONBOARDED.");
+ }
+ }
+ throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred.");
+ }
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java
new file mode 100644
index 0000000000..e8188b9c7d
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java
@@ -0,0 +1,59 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnfmadapter.extclients.etsicatalog;
+
+import static org.slf4j.LoggerFactory.getLogger;
+import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+/**
+ * Provides the URLs for the REST Requests to the ETSI Catalog Manager.
+ *
+ * @author gareth.roper@est.tech
+ */
+@Service
+public class EtsiCatalogUrlProvider {
+
+ private static final Logger logger = getLogger(EtsiCatalogUrlProvider.class);
+
+ @Value("${msb.endpoint:#{\"http://msb_iag.onap:80\"}}")
+ private String msbEndpoint;
+ @Value("${msb.catalogServiceUrl:#{null}}")
+ private String catalogServiceUrl;
+ @Value("${msb.vnfpkgmServiceUrl:#{\"/api/vnfpkgm/v1\"}}")
+ private String vnfpkgmServiceUrl;
+
+ public EtsiCatalogUrlProvider() {}
+
+ /**
+ * Get the URL for retrieving the Package Content from the ETSI Catalog.".
+ *
+ * @param vnfPkgId The ID of the VNF Package
+ * @return the URL for the GET operation
+ */
+
+ public String getVnfPackageContentUrl(final String vnfPkgId) {
+ final String url = msbEndpoint + vnfpkgmServiceUrl + "/vnf_packages/" + vnfPkgId + "/package_content";
+ logger.info("getEtsiCatalogVnfPackageContentUrl: {}", url);
+ return url;
+ }
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderConfiguration.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderConfiguration.java
index ae9316cfdf..073fc93107 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderConfiguration.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderConfiguration.java
@@ -21,7 +21,6 @@
package org.onap.so.adapters.vnfmadapter.extclients.vnfm;
import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE;
-import com.google.gson.Gson;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.KeyStore;
@@ -29,7 +28,6 @@ import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
-import java.util.Iterator;
import java.util.ListIterator;
import java.util.Map;
import java.util.UUID;
@@ -43,7 +41,7 @@ import org.apache.http.ssl.SSLContextBuilder;
import org.onap.aai.domain.yang.EsrSystemInfo;
import org.onap.aai.domain.yang.EsrVnfm;
import org.onap.logging.filter.spring.SpringClientPayloadFilter;
-import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.JSON;
+import org.onap.so.adapters.vnfmadapter.extclients.AbstractServiceProviderConfiguration;
import org.onap.so.configuration.rest.BasicHttpHeadersProvider;
import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter;
import org.onap.so.rest.service.HttpRestServiceProvider;
@@ -58,9 +56,6 @@ import org.springframework.core.io.Resource;
import org.springframework.http.client.BufferingClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
-import org.springframework.http.converter.HttpMessageConverter;
-import org.springframework.http.converter.json.GsonHttpMessageConverter;
-import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails;
import org.springframework.web.client.RestTemplate;
@@ -69,7 +64,7 @@ import org.springframework.web.client.RestTemplate;
* Configures the HttpRestServiceProvider for REST call to a VNFM.
*/
@Configuration
-public class VnfmServiceProviderConfiguration {
+public class VnfmServiceProviderConfiguration extends AbstractServiceProviderConfiguration {
private static final Logger logger = LoggerFactory.getLogger(VnfmServiceProviderConfiguration.class);
private Map<String, HttpRestServiceProvider> mapOfVnfmIdToHttpRestServiceProvider = new ConcurrentHashMap<>();
@@ -135,17 +130,6 @@ public class VnfmServiceProviderConfiguration {
return new OAuth2RestTemplate(resourceDetails);
}
- private void setGsonMessageConverter(final RestTemplate restTemplate) {
- final Iterator<HttpMessageConverter<?>> iterator = restTemplate.getMessageConverters().iterator();
- while (iterator.hasNext()) {
- if (iterator.next() instanceof MappingJackson2HttpMessageConverter) {
- iterator.remove();
- }
- }
- final Gson gson = new JSON().getGson();
- restTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson));
- }
-
private void setTrustStore(final RestTemplate restTemplate) {
SSLContext sslContext;
try {
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java
index 1da1159be0..e12729a2e3 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java
@@ -24,9 +24,13 @@ import static org.onap.so.adapters.vnfmadapter.Constants.APPLICATION_ZIP;
import static org.onap.so.adapters.vnfmadapter.Constants.PACKAGE_MANAGEMENT_BASE_URL;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.List;
+import java.util.Optional;
import javax.ws.rs.core.MediaType;
+import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.EtsiCatalogServiceProvider;
+import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.ProblemDetails;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2001;
import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
@@ -45,13 +49,21 @@ import org.springframework.web.bind.annotation.RequestMapping;
@RequestMapping(value = PACKAGE_MANAGEMENT_BASE_URL, consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public class Sol003PackageManagementController {
- private static final String LOG_REQUEST_RECEIVED = "VNF Package Management Controller: {} {} {} {} {}";
+ private final EtsiCatalogServiceProvider etsiCatalogServiceProvider;
+
+ @Autowired
+ Sol003PackageManagementController(final EtsiCatalogServiceProvider etsiCatalogServiceProvider) {
+ this.etsiCatalogServiceProvider = etsiCatalogServiceProvider;
+ }
+
+
+ private static final String LOG_REQUEST_RECEIVED = "VNF PackageManagement Controller: {} {} {}";
private static final Logger logger = getLogger(Sol003PackageManagementController.class);
/**
- * GET VNF packages information. Direction: VNFM -> VNFM-Adapter. Will return zero or more VNF package
- * representations that match the attribute filter. These representations will be in a list. Section Number: 10.4.2
- *
+ * GET VNF packages information. Will return zero or more VNF package representations that match the attribute
+ * filter. These representations will be in a list. Section Number: 10.4.2
+ *
* @return A List of all VNF packages. Object: List<InlineResponse2001> Response Code: 200 OK
*/
@@ -62,9 +74,9 @@ public class Sol003PackageManagementController {
}
/**
- * GET VNF package information. Direction: VNFM -> VNFM-Adapter. Will return a specific VNF package representation
- * that match the attribute filter. Section Number: 10.4.3
- *
+ * GET VNF package information. Will return a specific VNF package representation that match the attribute filter.
+ * Section Number: 10.4.3
+ *
* @param vnfPkgId The ID of the VNF Package that you want to query.
* @return A VNF package based on vnfPkgId. Object: VnfPkgInfo Response Code: 200 OK
*/
@@ -75,44 +87,67 @@ public class Sol003PackageManagementController {
}
/**
- * GET VNFD, from VNF package. Direction: VNFM -> VNFM-Adapter. Will return a copy of the file representing the VNFD
- * or a ZIP file that contains the file/multiple files representing the VNFD specified. Section Number: 10.4.4
- *
+ * GET VNFD, from VNF package. Will return a copy of the file representing the VNFD or a ZIP file that contains the
+ * file/multiple files representing the VNFD specified. Section Number: 10.4.4
+ *
* @param vnfPkgId The ID of the VNF Package that you want to retrieve the VNFD from.
* @return The VNFD of a VNF Package as a single file or within a ZIP file. Object: byte[] Response Code: 200 OK
*/
- @GetMapping(value = "/vnf_packages/{vnfPkgId}/vnfd", produces = {MediaType.TEXT_PLAIN, APPLICATION_ZIP})
+ @GetMapping(value = "/vnf_packages/{vnfPkgId}/vnfd",
+ produces = {MediaType.TEXT_PLAIN, APPLICATION_ZIP, MediaType.APPLICATION_JSON})
public ResponseEntity<byte[]> getVnfPackageVnfd(@PathVariable("vnfPkgId") final String vnfPkgId) {
logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageVnfd: ", vnfPkgId);
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
/**
- * GET Package Content, from VNF Package. Direction: VNFM -> VNFM-Adapter. Will return a copy of the VNF package
- * file that you specified. Section Number: 10.4.5
- *
+ * GET Package Content, from VNF Package. Will return a copy of the VNF package file that you specified. Section
+ * Number: 10.4.5
+ *
* @param vnfPkgId The ID of the VNF Package that you want to retrieve the "package_content" from.
* @return The Package Content of a VNF Package. Object: byte[] Response Code: 200 OK
*/
- @GetMapping(value = "/vnf_packages/{vnfPkgId}/package_content", produces = {APPLICATION_ZIP})
- public ResponseEntity<byte[]> getVnfPackageContent(@PathVariable("vnfPkgId") final String vnfPkgId) {
- logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageContent: ", vnfPkgId);
- return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
+ @GetMapping(value = "/vnf_packages/{vnfPkgId}/package_content",
+ produces = {MediaType.APPLICATION_JSON, APPLICATION_ZIP, MediaType.APPLICATION_OCTET_STREAM})
+ public ResponseEntity getVnfPackageContent(@PathVariable("vnfPkgId") final String vnfPkgId) {
+ logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageContent Endpoint Invoked with VNF Package ID: ", vnfPkgId);
+ final Optional<byte[]> response = etsiCatalogServiceProvider.getVnfPackageContent(vnfPkgId);
+ if (response.isPresent()) {
+ logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageContent Response: ", HttpStatus.OK);
+ return new ResponseEntity(response.get(), HttpStatus.OK);
+ }
+ logger.error("Null response was received from the EtsiCatalogManager using the GET \"package_content\"");
+ return new ResponseEntity(buildProblemDetails("An error occurred, a null response was received by the\n"
+ + " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"package_content\" \n"
+ + "endpoint."), HttpStatus.INTERNAL_SERVER_ERROR);
}
/**
- * GET Artifact, from VNF Package. Direction: VNFM -> VNFM-Adapter. Will return a the content of the artifact that
- * you specified. Section Number: 10.4.6
- *
+ * GET Artifact, from VNF Package Will return a the content of the artifact that you specified. Section Number:
+ * 10.4.6
+ *
* @param vnfPkgId The ID of the VNF Package that you want to retrieve an artifact from.
* @param artifactPath The path of the artifact that you want to retrieve.
* @return An Artifact from a VNF Package. Object: byte[] Response Code: 200 OK
*/
@GetMapping(value = "/vnf_packages/{vnfPkgId}/artifacts/{artifactPath}",
- produces = {MediaType.APPLICATION_OCTET_STREAM})
+ produces = {MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON})
public ResponseEntity<byte[]> getVnfPackageArtifact(@PathVariable("vnfPkgId") final String vnfPkgId,
@PathVariable("artifactPath") final String artifactPath) {
logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageArtifact: vnfPkgId=", vnfPkgId, " artifactPath=", artifactPath);
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
+
+ /**
+ * Builds the ProblemDetails Object, using the provided error message.
+ *
+ * @param detail The error message retrieved from the exception thrown.
+ * @return ProblemDetails Object, containing error information.
+ */
+ private ProblemDetails buildProblemDetails(String detail) {
+ final ProblemDetails problemDetails = new ProblemDetails();
+ problemDetails.setDetail(detail);
+ return problemDetails;
+ }
+
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementController.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementController.java
index 6fac952aa8..16650d4a3d 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementController.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementController.java
@@ -53,9 +53,9 @@ public class Sol003SubscriptionManagementController {
private static final Logger logger = getLogger(Sol003SubscriptionManagementController.class);
/**
- * POST Subscribe request. Direction: VNFM -> VNFM Adapter. Will send request and respond with the subscription that
- * you subscribed to, if successful. Section Number: 10.4.7
- *
+ * POST Subscribe request. Will send request and respond with the subscription that you subscribed to, if
+ * successful. Section Number: 10.4.7
+ *
* @param pkgmSubscriptionRequest This includes the details of the subscription to be created.
* @return The subscription requested, if successful. Object: InlineRespone2002 Response Code: 201 Created Response
* Code: 303 Duplicate Subscription
@@ -68,9 +68,8 @@ public class Sol003SubscriptionManagementController {
}
/**
- * GET all subscriptions. Direction: VNFM -> VNFM Adapter. Will return a list of all subscriptions currently active.
- * Section Number: 10.4.7
- *
+ * GET all subscriptions. Will return a list of all subscriptions currently active. Section Number: 10.4.7
+ *
* @return All of the current active subscriptions. Object: List<InlineResponse2002> Response Code: 200 OK
*/
@GetMapping(value = "/subscriptions")
@@ -80,8 +79,8 @@ public class Sol003SubscriptionManagementController {
}
/**
- * GET a specific subscription, by subscriptionId. Direction: VNFM -> VNFM Adapter. Section Number: 10.4.8
- *
+ * GET a specific subscription, by subscriptionId. Section Number: 10.4.8
+ *
* @param subscriptionId The ID of the subscription that you wish to retrieve.
* @return A subscription based on subscriptionId. Object: InlineResponse2002 Response Code: 200 OK
*/
@@ -93,8 +92,8 @@ public class Sol003SubscriptionManagementController {
}
/**
- * DELETE a specific subscription, by subscriptionId. Direction: VNFM -> VNFM Adapter. Section Number: 10.4.7
- *
+ * DELETE a specific subscription, by subscriptionId. Section Number: 10.4.7
+ *
* @param subscriptionId The ID of the subscription that you wish to delete.
* @return Empty response if successful. Object: Void Response Code: 204 No Content
*/
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/EtsiCatalogManagerRequestFailureException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/EtsiCatalogManagerRequestFailureException.java
new file mode 100644
index 0000000000..dbdc354f4e
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/EtsiCatalogManagerRequestFailureException.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.adapters.vnfmadapter.rest.exceptions;
+
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+/**
+ * Exception for an ETSI Catalog Manager Request Failure
+ *
+ * @author gareth.roper@est.tech
+ */
+@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR)
+public class EtsiCatalogManagerRequestFailureException extends RuntimeException {
+
+ private static final long serialVersionUID = 66862444537194516L;
+
+ public EtsiCatalogManagerRequestFailureException(final String message) {
+ super(message);
+ }
+
+ @Override
+ public synchronized Throwable fillInStackTrace() {
+ return this;
+ }
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgConflictException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgConflictException.java
new file mode 100644
index 0000000000..0cc9c5bd7e
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgConflictException.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.adapters.vnfmadapter.rest.exceptions;
+
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+/**
+ * Exception for a Vnfpkg Conflict failure, due to state of resource.
+ *
+ * @author gareth.roper@est.tech
+ */
+@ResponseStatus(code = HttpStatus.CONFLICT)
+public class VnfPkgConflictException extends RuntimeException {
+
+ private static final long serialVersionUID = 26862444537198441L;
+
+ public VnfPkgConflictException(final String message) {
+ super(message);
+ }
+
+ @Override
+ public synchronized Throwable fillInStackTrace() {
+ return this;
+ }
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgNotFoundException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgNotFoundException.java
new file mode 100644
index 0000000000..0f9f214643
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgNotFoundException.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.adapters.vnfmadapter.rest.exceptions;
+
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+/**
+ * Exception for a Vnfpkg Not Found Failure
+ *
+ * @author gareth.roper@est.tech
+ */
+@ResponseStatus(code = HttpStatus.NOT_FOUND)
+public class VnfPkgNotFoundException extends RuntimeException {
+
+ private static final long serialVersionUID = 26862444537198441L;
+
+ public VnfPkgNotFoundException(final String message) {
+ super(message);
+ }
+
+ @Override
+ public synchronized Throwable fillInStackTrace() {
+ return this;
+ }
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java
index 801c468018..59dfd50b32 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java
@@ -1,74 +1,236 @@
-package org.onap.so.adapters.vnfmadapter.rest;
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.adapters.vnfmadapter.rest;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.onap.so.adapters.vnfmadapter.Constants.PACKAGE_MANAGEMENT_BASE_URL;
import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE;
-import java.net.URISyntaxException;
-import java.util.List;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
+import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
+import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
+import java.util.Random;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication;
-import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2001;
+import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.ProblemDetails;
+import org.onap.so.configuration.rest.BasicHttpHeadersProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.boot.web.server.LocalServerPort;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.web.client.RestTemplate;
+/**
+ * @author gareth.roper@est.tech
+ */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = VnfmAdapterApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
public class Sol003PackageManagementControllerTest {
- private static final String vnfPackageId = "myVnfPackageId";
- private static final String artifactPath = "myArtifactPath";
+ private static final Logger logger = LoggerFactory.getLogger(Sol003PackageManagementControllerTest.class);
+
+ @LocalServerPort
+ private int port;
@Autowired
@Qualifier(CONFIGURABLE_REST_TEMPLATE)
private RestTemplate testRestTemplate;
- private MockRestServiceServer mockRestServer;
@Autowired
private Sol003PackageManagementController controller;
+ @Autowired
+ private TestRestTemplate restTemplate;
+
+ private static final String VNF_PACKAGE_ID = "myVnfPackageId";
+ private static final String ARTIFACT_PATH = "myArtifactPath";
+ private static final String MSB_BASE_URL = "http://msb_iag.onap:80/api/vnfpkgm/v1/vnf_packages";
+ private static final String VNFPKGM_BASE_URL = PACKAGE_MANAGEMENT_BASE_URL + "/vnf_packages";
+ private static final String localhostUrl = "http://localhost:";
+
+ private MockRestServiceServer mockRestServer;
+ private BasicHttpHeadersProvider basicHttpHeadersProvider;
+
+
+ public Sol003PackageManagementControllerTest() {}
+
@Before
- public void setUp() throws Exception {
- mockRestServer = MockRestServiceServer.bindTo(testRestTemplate).build();
+ public void setUp() {
+ MockRestServiceServer.MockRestServiceServerBuilder builder = MockRestServiceServer.bindTo(testRestTemplate);
+ builder.ignoreExpectOrder(true);
+ mockRestServer = builder.build();
+ basicHttpHeadersProvider = new BasicHttpHeadersProvider();
+ }
+
+ @Test
+ public void testGetPackageContent_ValidArray_Success() {
+ byte[] responseArray = buildByteArrayWithRandomData(10);
+
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/package_content"))
+ .andExpect(method(HttpMethod.GET))
+ .andRespond(withSuccess(responseArray, MediaType.APPLICATION_OCTET_STREAM));
+
+ final String testURL = "http://localhost:" + port + PACKAGE_MANAGEMENT_BASE_URL + "/vnf_packages/"
+ + VNF_PACKAGE_ID + "/package_content";
+ final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders());
+ final ResponseEntity<byte[]> responseEntity =
+ restTemplate.withBasicAuth("test", "test").exchange(testURL, HttpMethod.GET, request, byte[].class);
+
+ assertEquals(byte[].class, responseEntity.getBody().getClass());
+ assertArrayEquals(responseEntity.getBody(), responseArray);
+ assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
}
@Test
- public void getVnfPackages() throws URISyntaxException, InterruptedException {
- final ResponseEntity<List<InlineResponse2001>> response = controller.getVnfPackages();
- assertEquals(HttpStatus.NOT_IMPLEMENTED, response.getStatusCode());
+ public void testOnGetPackageContent_Conflict_Fail() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/package_content"))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.CONFLICT));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/package_content");
+
+ assertTrue(responseEntity.getBody() instanceof ProblemDetails);
+ assertEquals(HttpStatus.CONFLICT, responseEntity.getStatusCode());
}
@Test
- public void getVnfPackage() throws URISyntaxException, InterruptedException {
- final ResponseEntity<InlineResponse2001> response = controller.getVnfPackage(vnfPackageId);
- assertEquals(HttpStatus.NOT_IMPLEMENTED, response.getStatusCode());
+ public void testOnGetPackageContent_NotFound_Fail() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/package_content"))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.NOT_FOUND));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/package_content");
+
+ assertTrue(responseEntity.getBody() instanceof ProblemDetails);
+ assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
}
@Test
- public void getVnfPackageVnfd() throws URISyntaxException, InterruptedException {
- final ResponseEntity<byte[]> response = controller.getVnfPackageVnfd(vnfPackageId);
- assertEquals(HttpStatus.NOT_IMPLEMENTED, response.getStatusCode());
+ public void testOnGetPackageContent_UnauthorizedClient_Fail() {
+ final String testURL = "http://localhost:" + port + PACKAGE_MANAGEMENT_BASE_URL + "/vnf_packages/"
+ + VNF_PACKAGE_ID + "/package_content";
+ final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders());
+ final ResponseEntity<ProblemDetails> responseEntity =
+ restTemplate.exchange(testURL, HttpMethod.GET, request, ProblemDetails.class);
+
+ assertTrue(responseEntity.getBody() instanceof ProblemDetails);
+ assertEquals(HttpStatus.UNAUTHORIZED, responseEntity.getStatusCode());
}
@Test
- public void getVnfPackageContents() throws URISyntaxException, InterruptedException {
- final ResponseEntity<byte[]> response = controller.getVnfPackageContent(vnfPackageId);
- assertEquals(HttpStatus.NOT_IMPLEMENTED, response.getStatusCode());
+ public void testOnGetPackageContent_InternalServerError_Fail() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/package_content"))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/package_content");
+
+ assertTrue(responseEntity.getBody() instanceof ProblemDetails);
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
}
@Test
- public void getVnfPackageArtifact() throws URISyntaxException, InterruptedException {
- final ResponseEntity<byte[]> response = controller.getVnfPackageArtifact(vnfPackageId, artifactPath);
- assertEquals(HttpStatus.NOT_IMPLEMENTED, response.getStatusCode());
+ public void testOnGetPackageContent_BadRequest_Fail() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/package_content"))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.BAD_REQUEST));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/package_content");
+
+ assertTrue(responseEntity.getBody() instanceof ProblemDetails);
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
}
+ @Test
+ public void testOnGetPackageContent_UnauthorizedServer_InternalError_Fail() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/package_content"))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.UNAUTHORIZED));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/package_content");
+
+ assertTrue(responseEntity.getBody() instanceof ProblemDetails);
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testGetPackageContent_SuccessResponseFromServerWithNullPackage_Fail() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/package_content"))
+ .andExpect(method(HttpMethod.GET)).andRespond(withSuccess());
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/package_content");
+
+ assertEquals(ProblemDetails.class, responseEntity.getBody().getClass());
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+ }
+
+ // The below 4 test methods are here to improve code coverage and provide a foundation for writing future tests
+ @Test
+ public void testGetVnfPackage_Not_Implemented() {
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID);
+ assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testGetVnfPackages_Not_Implemented() {
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest("");
+ assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testGetVnfd_Not_Implemented() {
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/vnfd");
+ assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testGetArtifact_Not_Implemented() {
+ final ResponseEntity<ProblemDetails> responseEntity =
+ sendHttpRequest(VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH);
+ assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode());
+ }
+
+ // Simply returns a byte array filled with random data, for use in the tests.
+ private byte[] buildByteArrayWithRandomData(int sizeInKb) {
+ final Random rnd = new Random();
+ final byte[] b = new byte[sizeInKb * 1024]; // converting kb to byte
+ rnd.nextBytes(b);
+ return b;
+ }
+
+ private ResponseEntity<ProblemDetails> sendHttpRequest(String url) {
+ final String testURL = localhostUrl + port + VNFPKGM_BASE_URL + "/" + url;
+ final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders());
+ return restTemplate.withBasicAuth("test", "test").exchange(testURL, HttpMethod.GET, request,
+ ProblemDetails.class);
+ }
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementControllerTest.java
index 999dd02f0f..8fc27c5943 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementControllerTest.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementControllerTest.java
@@ -20,6 +20,10 @@ import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.web.client.RestTemplate;
+/**
+ * @author gareth.roper@est.tech
+ */
+
@RunWith(SpringRunner.class)
@SpringBootTest(classes = VnfmAdapterApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")