aboutsummaryrefslogtreecommitdiffstats
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/main/resources/db/migration/V8.2__AddScopeAndActionColumnsInOrchestrationFlowReference.sql5
-rw-r--r--adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogDBRestTest.java56
-rw-r--r--adapters/mso-openstack-adapters/src/test/resources/schema.sql2
-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-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/MessageConverterConfiguration.java10
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/Sol003PackageManagementControllerExceptionHandler.java14
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter.java180
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java17
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java91
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java25
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java40
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgBadRequestException.java43
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java253
19 files changed, 911 insertions, 199 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/main/resources/db/migration/V8.2__AddScopeAndActionColumnsInOrchestrationFlowReference.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V8.2__AddScopeAndActionColumnsInOrchestrationFlowReference.sql
new file mode 100644
index 0000000000..19bfb0f1e1
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V8.2__AddScopeAndActionColumnsInOrchestrationFlowReference.sql
@@ -0,0 +1,5 @@
+use catalogdb;
+
+ALTER TABLE orchestration_flow_reference
+ADD SCOPE VARCHAR (200) DEFAULT NULL,
+ADD ACTION VARCHAR (200) DEFAULT NULL; \ No newline at end of file
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-openstack-adapters/src/test/resources/schema.sql b/adapters/mso-openstack-adapters/src/test/resources/schema.sql
index b96d58f419..6b791e789c 100644
--- a/adapters/mso-openstack-adapters/src/test/resources/schema.sql
+++ b/adapters/mso-openstack-adapters/src/test/resources/schema.sql
@@ -735,6 +735,8 @@ CREATE TABLE `orchestration_flow_reference` (
`SEQ_NO` int(11) NOT NULL,
`FLOW_NAME` varchar(200) NOT NULL,
`FLOW_VERSION` double NOT NULL,
+ `SCOPE` varchar(200) DEFAULT NULL,
+ `ACTION` varchar(200) DEFAULT NULL,
`NB_REQ_REF_LOOKUP_ID` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UK_orchestration_flow_reference` (`COMPOSITE_ACTION`,`FLOW_NAME`,`SEQ_NO`,`NB_REQ_REF_LOOKUP_ID`),
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-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/MessageConverterConfiguration.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/MessageConverterConfiguration.java
index 32c22356b3..84282e0c7f 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/MessageConverterConfiguration.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/MessageConverterConfiguration.java
@@ -23,10 +23,13 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.ArrayList;
import java.util.Collection;
+import org.onap.so.adapters.vnfmadapter.converters.Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter;
import org.onap.so.adapters.vnfmadapter.oauth.OAuth2AccessTokenAdapter;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.core.convert.ConversionService;
+import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.GsonHttpMessageConverter;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
@@ -38,6 +41,13 @@ import org.springframework.security.oauth2.common.OAuth2AccessToken;
public class MessageConverterConfiguration {
@Bean
+ public ConversionService conversionService() {
+ final DefaultConversionService service = new DefaultConversionService();
+ service.addConverter(new Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter());
+ return service;
+ }
+
+ @Bean
public HttpMessageConverters customConverters() {
final Collection<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
final Gson gson = new GsonBuilder()
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
index 713bf01249..2a97bb47e4 100644
--- 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
@@ -23,6 +23,7 @@ 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.VnfPkgBadRequestException;
import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgConflictException;
import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgNotFoundException;
import org.springframework.http.HttpStatus;
@@ -41,7 +42,7 @@ public class Sol003PackageManagementControllerExceptionHandler {
@ExceptionHandler(EtsiCatalogManagerRequestFailureException.class)
public ResponseEntity<ProblemDetails> handleEtsiCatalogManagerRequestFailureException(
- EtsiCatalogManagerRequestFailureException etsiCatalogManagerRequestFailureException) {
+ final EtsiCatalogManagerRequestFailureException etsiCatalogManagerRequestFailureException) {
final ProblemDetails problemDetails = new ProblemDetails();
problemDetails.setDetail(etsiCatalogManagerRequestFailureException.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(problemDetails);
@@ -49,7 +50,7 @@ public class Sol003PackageManagementControllerExceptionHandler {
@ExceptionHandler(VnfPkgConflictException.class)
public ResponseEntity<ProblemDetails> handleVnfPkgConflictException(
- VnfPkgConflictException vnfPkgConflictException) {
+ final VnfPkgConflictException vnfPkgConflictException) {
final ProblemDetails problemDetails = new ProblemDetails();
problemDetails.setDetail(vnfPkgConflictException.getMessage());
return ResponseEntity.status(HttpStatus.CONFLICT).body(problemDetails);
@@ -57,10 +58,17 @@ public class Sol003PackageManagementControllerExceptionHandler {
@ExceptionHandler(VnfPkgNotFoundException.class)
public ResponseEntity<ProblemDetails> handleVnfPkgNotFoundException(
- VnfPkgNotFoundException vnfPkgNotFoundException) {
+ final VnfPkgNotFoundException vnfPkgNotFoundException) {
final ProblemDetails problemDetails = new ProblemDetails();
problemDetails.setDetail(vnfPkgNotFoundException.getMessage());
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(problemDetails);
}
+ @ExceptionHandler(VnfPkgBadRequestException.class)
+ public ResponseEntity<ProblemDetails> handleVnfPkgBadRequestException(
+ final VnfPkgBadRequestException vnfPkgBadRequestException) {
+ final ProblemDetails problemDetails = new ProblemDetails();
+ problemDetails.setDetail(vnfPkgBadRequestException.getMessage());
+ return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(problemDetails);
+ }
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter.java
new file mode 100644
index 0000000000..de18ecc43e
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter.java
@@ -0,0 +1,180 @@
+/*-
+ * ============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.converters;
+
+import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.*;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.stereotype.Service;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Converter to convert from an Etsi Catalog Model {@link VnfPkgInfo} Object to a PackageManagement Model
+ * {@link InlineResponse2001} Object
+ *
+ * @author andrew.a.lamb@est.tech
+ */
+@Service
+public class Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter
+ implements Converter<VnfPkgInfo, InlineResponse2001> {
+ private static final Logger logger =
+ LoggerFactory.getLogger(Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter.class);
+
+ /**
+ * Convert a {@link VnfPkgInfo} Object to an {@link InlineResponse2001} Object
+ *
+ * @param vnfPkgInfo The VnfPkgInfo Object to Convert
+ * @return The Converted InlineResponse2001 Object
+ */
+ @Override
+ public InlineResponse2001 convert(final VnfPkgInfo vnfPkgInfo) {
+ if (vnfPkgInfo == null) {
+ logger.info("No VnfPkgInfo Object Provided for Conversion. (Null object received, returning Null)");
+ return null;
+ }
+ final InlineResponse2001 response = new InlineResponse2001();
+ response.setId(vnfPkgInfo.getId());
+ response.setVnfdId(vnfPkgInfo.getVnfdId());
+ response.setVnfProvider(vnfPkgInfo.getVnfProvider());
+ response.setVnfProductName(vnfPkgInfo.getVnfProductName());
+ response.setVnfSoftwareVersion(vnfPkgInfo.getVnfSoftwareVersion());
+ response.setVnfdVersion(vnfPkgInfo.getVnfdVersion());
+ response.setChecksum(convertChecksumToVnfPackagesChecksum(vnfPkgInfo.getChecksum()));
+ response.setSoftwareImages(
+ convertVnfPackageSoftwareImageInfoListToVnfPackagesSoftwareImagesList(vnfPkgInfo.getSoftwareImages()));
+ response.setAdditionalArtifacts(convertVnfPackageArtifactInfoListToVnfPackagesAdditionalArtifactsList(
+ vnfPkgInfo.getAdditionalArtifacts()));
+
+ if (vnfPkgInfo.getOnboardingState() != null) {
+ response.setOnboardingState(
+ InlineResponse2001.OnboardingStateEnum.fromValue(vnfPkgInfo.getOnboardingState().getValue()));
+ }
+
+ if (vnfPkgInfo.getOperationalState() != null) {
+ response.setOperationalState(
+ InlineResponse2001.OperationalStateEnum.fromValue(vnfPkgInfo.getOperationalState().getValue()));
+ }
+
+ response.setUserDefinedData((vnfPkgInfo.getUserDefinedData()));
+
+ if (vnfPkgInfo.getLinks() != null) {
+ response.setLinks(convertVNFPKGMLinkSerializerToVnfPackagesLinks(vnfPkgInfo.getLinks()));
+ }
+
+ return response;
+ }
+
+ private VnfPackagesChecksum convertChecksumToVnfPackagesChecksum(final Checksum checksum) {
+ final VnfPackagesChecksum vnfPackagesChecksum = new VnfPackagesChecksum();
+ if (checksum != null) {
+ vnfPackagesChecksum.setAlgorithm(checksum.getAlgorithm());
+ vnfPackagesChecksum.setHash(checksum.getHash());
+ }
+ return vnfPackagesChecksum;
+ }
+
+ private List<VnfPackagesSoftwareImages> convertVnfPackageSoftwareImageInfoListToVnfPackagesSoftwareImagesList(
+ final List<VnfPackageSoftwareImageInfo> vnfPackageSoftwareImageInfoList) {
+ final List<VnfPackagesSoftwareImages> vnfPackagesSoftwareImages = new ArrayList<>();
+ if (vnfPackageSoftwareImageInfoList != null) {
+ for (final VnfPackageSoftwareImageInfo vnfPackageSoftwareImageInfo : vnfPackageSoftwareImageInfoList) {
+ final VnfPackagesSoftwareImages softwareImage =
+ convertVnfPackageSoftwareImageInfoToVnfPackagesSoftwareImages(vnfPackageSoftwareImageInfo);
+ vnfPackagesSoftwareImages.add(softwareImage);
+ }
+ }
+ return vnfPackagesSoftwareImages;
+ }
+
+ private VnfPackagesSoftwareImages convertVnfPackageSoftwareImageInfoToVnfPackagesSoftwareImages(
+ final VnfPackageSoftwareImageInfo vnfPackageSoftwareImageInfo) {
+ final VnfPackagesSoftwareImages vnfPackagesSoftwareImages = new VnfPackagesSoftwareImages();
+ vnfPackagesSoftwareImages.setId(vnfPackageSoftwareImageInfo.getId());
+ vnfPackagesSoftwareImages.setName(vnfPackageSoftwareImageInfo.getName());
+ vnfPackagesSoftwareImages.setProvider(vnfPackageSoftwareImageInfo.getProvider());
+ vnfPackagesSoftwareImages.setVersion(vnfPackageSoftwareImageInfo.getVersion());
+ vnfPackagesSoftwareImages
+ .setChecksum(convertChecksumToVnfPackagesChecksum(vnfPackageSoftwareImageInfo.getChecksum()));
+ if (vnfPackageSoftwareImageInfo.getContainerFormat() != null) {
+ vnfPackagesSoftwareImages.setContainerFormat(VnfPackagesSoftwareImages.ContainerFormatEnum
+ .fromValue(vnfPackageSoftwareImageInfo.getContainerFormat().getValue()));
+ }
+
+ if (vnfPackageSoftwareImageInfo.getDiskFormat() != null) {
+ vnfPackagesSoftwareImages.setDiskFormat(VnfPackagesSoftwareImages.DiskFormatEnum
+ .fromValue(vnfPackageSoftwareImageInfo.getDiskFormat().getValue()));
+ }
+
+ vnfPackagesSoftwareImages.setCreatedAt(vnfPackageSoftwareImageInfo.getCreatedAt());
+ vnfPackagesSoftwareImages.setMinDisk(vnfPackageSoftwareImageInfo.getMinDisk());
+ vnfPackagesSoftwareImages.setMinRam(vnfPackageSoftwareImageInfo.getMinRam());
+ vnfPackagesSoftwareImages.setSize(vnfPackageSoftwareImageInfo.getSize());
+ vnfPackagesSoftwareImages.setUserMetadata(vnfPackageSoftwareImageInfo.getUserMetadata());
+ vnfPackagesSoftwareImages.setImagePath(vnfPackageSoftwareImageInfo.getImagePath());
+ return vnfPackagesSoftwareImages;
+ }
+
+ private List<VnfPackagesAdditionalArtifacts> convertVnfPackageArtifactInfoListToVnfPackagesAdditionalArtifactsList(
+ final List<VnfPackageArtifactInfo> vnfPackageArtifactInfoList) {
+ if (vnfPackageArtifactInfoList != null) {
+ final List<VnfPackagesAdditionalArtifacts> additionalArtifacts = new ArrayList<>();
+ for (final VnfPackageArtifactInfo artifactInfo : vnfPackageArtifactInfoList) {
+ final VnfPackagesAdditionalArtifacts artifact =
+ convertVnfPackageArtifactInfoToVnfPackagesAdditionalArtifacts(artifactInfo);
+ additionalArtifacts.add(artifact);
+ }
+ return additionalArtifacts;
+ }
+ return null;
+ }
+
+ private VnfPackagesAdditionalArtifacts convertVnfPackageArtifactInfoToVnfPackagesAdditionalArtifacts(
+ final VnfPackageArtifactInfo vnfPackageArtifactInfo) {
+ final VnfPackagesAdditionalArtifacts vnfPackagesAdditionalArtifacts = new VnfPackagesAdditionalArtifacts();
+ vnfPackagesAdditionalArtifacts.setArtifactPath(vnfPackageArtifactInfo.getArtifactPath());
+ vnfPackagesAdditionalArtifacts
+ .setChecksum(convertChecksumToVnfPackagesChecksum(vnfPackageArtifactInfo.getChecksum()));
+ vnfPackagesAdditionalArtifacts.setMetadata(vnfPackageArtifactInfo.getMetadata());
+ return vnfPackagesAdditionalArtifacts;
+ }
+
+ private VnfPackagesLinks convertVNFPKGMLinkSerializerToVnfPackagesLinks(
+ final VNFPKGMLinkSerializer vnfpkgmLinkSerializer) {
+ final VnfPackagesLinks vnfPackagesLinks = new VnfPackagesLinks();
+ vnfPackagesLinks.setSelf(convertUriLinkToVnfPackagesLinksSelf(vnfpkgmLinkSerializer.getSelf()));
+ vnfPackagesLinks.setVnfd(convertUriLinkToVnfPackagesLinksSelf(vnfpkgmLinkSerializer.getVnfd()));
+ vnfPackagesLinks
+ .setPackageContent(convertUriLinkToVnfPackagesLinksSelf(vnfpkgmLinkSerializer.getPackageContent()));
+ return vnfPackagesLinks;
+ }
+
+ private VnfPackagesLinksSelf convertUriLinkToVnfPackagesLinksSelf(final UriLink uriLink) {
+ final VnfPackagesLinksSelf vnfPackagesLinksSelf = new VnfPackagesLinksSelf();
+ if (uriLink != null) {
+ vnfPackagesLinksSelf.setHref(uriLink.getHref());
+ }
+ return vnfPackagesLinksSelf;
+ }
+
+}
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
index 39efc8dc23..a73958e544 100644
--- 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
@@ -20,6 +20,7 @@
package org.onap.so.adapters.vnfmadapter.extclients.etsicatalog;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2001;
import java.util.Optional;
/**
@@ -35,7 +36,21 @@ public interface EtsiCatalogServiceProvider {
* @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);
+ /**
+ * GET VNF packages information from ETSI Catalog. Will return zero or more VNF package representations.
+ *
+ * @return An Array of all VNF packages retrieved from the ETSI Catalog.
+ */
+ Optional<InlineResponse2001[]> getVnfPackages();
+
+ /**
+ * GET specific VNF package information from ETSI Catalog.
+ *
+ * @param vnfPkgId The ID of the VNF Package that you want to query.
+ * @return The VNF package retrieved from the ETSI Catalog
+ */
+ Optional<InlineResponse2001> getVnfPackage(final String vnfPkgId);
+
}
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
index 9a59620993..96b01f04e4 100644
--- 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
@@ -21,16 +21,21 @@
package org.onap.so.adapters.vnfmadapter.extclients.etsicatalog;
import java.util.Optional;
+import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VnfPkgInfo;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2001;
import org.onap.so.adapters.vnfmadapter.rest.exceptions.EtsiCatalogManagerRequestFailureException;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgBadRequestException;
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.InvalidRestRequestException;
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.core.convert.ConversionService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
@@ -44,31 +49,34 @@ import org.springframework.stereotype.Service;
public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvider {
private static final Logger logger = LoggerFactory.getLogger(EtsiCatalogServiceProviderImpl.class);
- @Qualifier
+ @Qualifier("etsiCatalogServiceProvider")
private final HttpRestServiceProvider httpServiceProvider;
private final EtsiCatalogUrlProvider etsiCatalogUrlProvider;
+ private final ConversionService conversionService;
@Autowired
public EtsiCatalogServiceProviderImpl(final EtsiCatalogUrlProvider etsiCatalogUrlProvider,
- final HttpRestServiceProvider httpServiceProvider) {
+ final HttpRestServiceProvider httpServiceProvider, final ConversionService conversionService) {
this.etsiCatalogUrlProvider = etsiCatalogUrlProvider;
this.httpServiceProvider = httpServiceProvider;
+ this.conversionService = conversionService;
}
@Override
- public Optional<byte[]> getVnfPackageContent(String vnfPkgId) throws EtsiCatalogManagerRequestFailureException {
+ public Optional<byte[]> getVnfPackageContent(final String vnfPkgId)
+ throws EtsiCatalogManagerRequestFailureException {
try {
- ResponseEntity<byte[]> response = httpServiceProvider
+ final 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) {
+ } catch (final HttpResouceNotFoundException httpResouceNotFoundException) {
logger.error("Caught HttpResouceNotFoundException", httpResouceNotFoundException);
throw new VnfPkgNotFoundException("No Vnf Package found with vnfPkgId: " + vnfPkgId);
- } catch (RestProcessingException restProcessingException) {
+ } catch (final RestProcessingException restProcessingException) {
logger.error("Caught RestProcessingException with Status Code: {}", restProcessingException.getStatusCode(),
restProcessingException);
if (restProcessingException.getStatusCode() == HttpStatus.CONFLICT.value()) {
@@ -78,4 +86,75 @@ public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvide
}
throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred.");
}
+
+ @Override
+ public Optional<InlineResponse2001[]> getVnfPackages() {
+ try {
+ final ResponseEntity<VnfPkgInfo[]> response =
+ httpServiceProvider.getHttpResponse(etsiCatalogUrlProvider.getVnfPackagesUrl(), VnfPkgInfo[].class);
+ logger.info("getVnfPackages Request to ETSI Catalog Manager Status Code: {}",
+ response.getStatusCodeValue());
+ if (response.getStatusCode() == HttpStatus.OK) {
+ if (response.hasBody()) {
+ final VnfPkgInfo[] vnfPackages = response.getBody();
+ final InlineResponse2001[] responses = new InlineResponse2001[vnfPackages.length];
+ for (int index = 0; index < vnfPackages.length; index++) {
+ if (conversionService.canConvert(vnfPackages[index].getClass(), InlineResponse2001.class)) {
+ final InlineResponse2001 inlineResponse2001 =
+ conversionService.convert(vnfPackages[index], InlineResponse2001.class);
+ if (inlineResponse2001 != null) {
+ responses[index] = inlineResponse2001;
+ }
+ }
+ logger.error("Unable to find Converter for response class: {}", vnfPackages[index].getClass());
+ }
+ return Optional.ofNullable(responses);
+ }
+ logger.error("Received response without body ...");
+ }
+ logger.error("Unexpected status code received {}", response.getStatusCode());
+ return Optional.empty();
+ } catch (final InvalidRestRequestException invalidRestRequestException) {
+ logger.error("Caught InvalidRestRequestException", invalidRestRequestException);
+ throw new VnfPkgBadRequestException("Error: Bad Request Received");
+ } catch (final HttpResouceNotFoundException httpResouceNotFoundException) {
+ logger.error("Caught HttpResouceNotFoundException", httpResouceNotFoundException);
+ throw new VnfPkgNotFoundException("No Vnf Packages found");
+ } catch (final RestProcessingException restProcessingException) {
+ logger.error("Caught RestProcessingException with Status Code: {}", restProcessingException.getStatusCode(),
+ restProcessingException);
+ throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred.");
+ }
+ }
+
+ @Override
+ public Optional<InlineResponse2001> getVnfPackage(final String vnfPkgId) {
+ try {
+ final ResponseEntity<VnfPkgInfo> response = httpServiceProvider
+ .getHttpResponse(etsiCatalogUrlProvider.getVnfPackageUrl(vnfPkgId), VnfPkgInfo.class);
+ logger.info("getVnfPackage Request for vnfPkgId {} to ETSI Catalog Manager Status Code: {}", vnfPkgId,
+ response.getStatusCodeValue());
+ if (response.getStatusCode() == HttpStatus.OK) {
+ if (response.hasBody()) {
+ final VnfPkgInfo vnfPkgInfo = response.getBody();
+ if (conversionService.canConvert(vnfPkgInfo.getClass(), InlineResponse2001.class)) {
+ return Optional.ofNullable(conversionService.convert(vnfPkgInfo, InlineResponse2001.class));
+ }
+ logger.error("Unable to find Converter for response class: {}", vnfPkgInfo.getClass());
+ }
+ logger.error("Received response without body ....");
+ }
+ return Optional.empty();
+ } catch (final InvalidRestRequestException invalidRestRequestException) {
+ logger.error("Caught InvalidRestRequestException", invalidRestRequestException);
+ throw new VnfPkgBadRequestException("Error: Bad Request Received");
+ } catch (final HttpResouceNotFoundException httpResouceNotFoundException) {
+ logger.error("Caught HttpResouceNotFoundException", httpResouceNotFoundException);
+ throw new VnfPkgNotFoundException("No Vnf Package found with vnfPkgId: " + vnfPkgId);
+ } catch (final RestProcessingException restProcessingException) {
+ logger.error("Caught RestProcessingException with Status Code: {}", restProcessingException.getStatusCode(),
+ restProcessingException);
+ 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
index e8188b9c7d..d233c3f0fd 100644
--- 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
@@ -50,10 +50,33 @@ public class EtsiCatalogUrlProvider {
* @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;
}
+
+ /**
+ * Get the URL for retrieving VNF packages information from ETSI Catalog.".
+ *
+ * @return the URL for the GET operation
+ */
+ public String getVnfPackagesUrl() {
+ final String url = msbEndpoint + vnfpkgmServiceUrl + "/vnf_packages";
+ logger.info("getEtsiCatalogVnfPackagesEndpoint: {}", url);
+ return url;
+ }
+
+ /**
+ * Get the URL for retrieving specific VNF package information from the ETSI Catalog.".
+ *
+ * @param vnfPkgId The ID of the VNF Package
+ * @return the URL for the GET operation
+ */
+ public String getVnfPackageUrl(final String vnfPkgId) {
+ final String url = msbEndpoint + vnfpkgmServiceUrl + "/vnf_packages/" + vnfPkgId;
+ logger.info("getEtsiCatalogVnfPackageEndpoint: {}", url);
+ return url;
+ }
+
}
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 e12729a2e3..76ec492bd4 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
@@ -23,7 +23,6 @@ package org.onap.so.adapters.vnfmadapter.rest;
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;
@@ -50,40 +49,55 @@ import org.springframework.web.bind.annotation.RequestMapping;
public class Sol003PackageManagementController {
private final EtsiCatalogServiceProvider etsiCatalogServiceProvider;
+ private static final String LOG_REQUEST_RECEIVED = "VNF PackageManagement Controller: {} {} {}";
+ private static final Logger logger = getLogger(Sol003PackageManagementController.class);
@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. 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
+ * @return An Array of all VNF packages. Object: InlineResponse2001[] Response Code: 200 OK
*/
-
@GetMapping(value = "/vnf_packages", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
- public ResponseEntity<List<InlineResponse2001>> getVnfPackages() {
+ public ResponseEntity getVnfPackages() {
logger.info(LOG_REQUEST_RECEIVED, "getVnfPackages.");
- return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
+ final Optional<InlineResponse2001[]> response = etsiCatalogServiceProvider.getVnfPackages();
+ if (response.isPresent()) {
+ logger.info(LOG_REQUEST_RECEIVED, "getVnfPackages Response: ", HttpStatus.OK);
+ return new ResponseEntity(response.get(), HttpStatus.OK);
+ }
+ final String errorMessage = "An error occurred, a null response was received by the\n"
+ + " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"vnf_packages\" \n"
+ + "endpoint.";
+ logger.error(errorMessage);
+ return new ResponseEntity(buildProblemDetails(errorMessage), HttpStatus.INTERNAL_SERVER_ERROR);
}
/**
* 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
*/
@GetMapping(value = "/vnf_packages/{vnfPkgId}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
- public ResponseEntity<InlineResponse2001> getVnfPackage(@PathVariable("vnfPkgId") final String vnfPkgId) {
+ public ResponseEntity getVnfPackage(@PathVariable("vnfPkgId") final String vnfPkgId) {
logger.info(LOG_REQUEST_RECEIVED, "getVnfPackage: ", vnfPkgId);
- return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
+ final Optional<InlineResponse2001> response = etsiCatalogServiceProvider.getVnfPackage(vnfPkgId);
+ if (response.isPresent()) {
+ logger.info(LOG_REQUEST_RECEIVED, "getVnfPackage Response: ", HttpStatus.OK);
+ return new ResponseEntity(response.get(), HttpStatus.OK);
+ }
+ final String errorMessage = "An error occurred, a null response was received by the\n"
+ + " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"vnf_packages\" by vnfPkgId: \""
+ + vnfPkgId + "\" \n" + "endpoint.";
+ logger.error(errorMessage);
+ return new ResponseEntity(buildProblemDetails(errorMessage), HttpStatus.INTERNAL_SERVER_ERROR);
}
/**
@@ -144,7 +158,7 @@ public class Sol003PackageManagementController {
* @param detail The error message retrieved from the exception thrown.
* @return ProblemDetails Object, containing error information.
*/
- private ProblemDetails buildProblemDetails(String detail) {
+ private ProblemDetails buildProblemDetails(final 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/exceptions/VnfPkgBadRequestException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgBadRequestException.java
new file mode 100644
index 0000000000..211131c2a4
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgBadRequestException.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 Bad Request failure, due to state of resource.
+ *
+ * @author andrew.a.lamb@est.tech
+ */
+@ResponseStatus(code = HttpStatus.BAD_REQUEST)
+public class VnfPkgBadRequestException extends RuntimeException {
+
+ private static final long serialVersionUID = 3301317418914258411L;
+
+ public VnfPkgBadRequestException(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 59dfd50b32..857bd7dc3e 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
@@ -20,21 +20,22 @@
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.junit.Assert.*;
import static org.onap.so.adapters.vnfmadapter.Constants.PACKAGE_MANAGEMENT_BASE_URL;
import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE;
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.ArrayList;
+import java.util.List;
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.etsicatalog.model.ProblemDetails;
+import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.*;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2001;
import org.onap.so.configuration.rest.BasicHttpHeadersProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -52,6 +53,7 @@ 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;
+import com.google.gson.Gson;
/**
* @author gareth.roper@est.tech
@@ -81,16 +83,27 @@ public class Sol003PackageManagementControllerTest {
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 static final String GET_VNF_PACKAGES_URL = "";
+ private static final String GET_VNF_PACKAGE_BY_ID_URL = "/" + VNF_PACKAGE_ID;
+ private static final String VNFD_ID = "vnfdId";
+ private static final String VNF_PROVIDER = "vnfProvider";
+ private static final String VNF_PRODUCT_NAME = "vnfProductName";
+ private static final String VNF_SOFTWARE_VERSION = "vnfSoftwareVersion";
+ private static final String VNFD_VERSION = "vnfdVersion";
+ private static final String ALGORITHM = "algorithm";
+ private static final String HASH = "hash";
+ private static final String URI_HREF = "uriHref";
private MockRestServiceServer mockRestServer;
private BasicHttpHeadersProvider basicHttpHeadersProvider;
-
+ private final Gson gson = new Gson();
public Sol003PackageManagementControllerTest() {}
@Before
public void setUp() {
- MockRestServiceServer.MockRestServiceServerBuilder builder = MockRestServiceServer.bindTo(testRestTemplate);
+ final MockRestServiceServer.MockRestServiceServerBuilder builder =
+ MockRestServiceServer.bindTo(testRestTemplate);
builder.ignoreExpectOrder(true);
mockRestServer = builder.build();
basicHttpHeadersProvider = new BasicHttpHeadersProvider();
@@ -98,7 +111,7 @@ public class Sol003PackageManagementControllerTest {
@Test
public void testGetPackageContent_ValidArray_Success() {
- byte[] responseArray = buildByteArrayWithRandomData(10);
+ final byte[] responseArray = buildByteArrayWithRandomData(10);
mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/package_content"))
.andExpect(method(HttpMethod.GET))
@@ -193,20 +206,171 @@ public class Sol003PackageManagementControllerTest {
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());
+ public void testVnfPackagesReceivedAsInlineResponse2001ListIfGetVnfPackagesSuccessful() {
+ final VnfPkgInfo[] responses = createVnfPkgArray();
+
+ mockRestServer.expect(requestTo(MSB_BASE_URL)).andExpect(method(HttpMethod.GET))
+ .andRespond(withSuccess(gson.toJson(responses), MediaType.APPLICATION_JSON));
+
+ final String testURL = localhostUrl + port + VNFPKGM_BASE_URL;
+ final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders());
+
+ final ResponseEntity<InlineResponse2001[]> responseEntity = restTemplate.withBasicAuth("test", "test")
+ .exchange(testURL, HttpMethod.GET, request, InlineResponse2001[].class);
+
+ assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
+ assertNotNull(responseEntity.getBody());
+ final InlineResponse2001[] inlineResponse2001array = responseEntity.getBody();
+ final InlineResponse2001 inlineResponse2001 = inlineResponse2001array[0];
+ assertEquals(VNF_PACKAGE_ID, inlineResponse2001.getId());
+ assertEquals(VNFD_ID, inlineResponse2001.getVnfdId());
+ assertEquals(VNFD_ID, inlineResponse2001.getSoftwareImages().get(0).getId());
+ assertEquals(VNF_PRODUCT_NAME, inlineResponse2001.getSoftwareImages().get(0).getName());
+ assertEquals(ALGORITHM, inlineResponse2001.getChecksum().getAlgorithm());
+ assertEquals(HASH, inlineResponse2001.getChecksum().getHash());
+ assertEquals(ARTIFACT_PATH, inlineResponse2001.getAdditionalArtifacts().get(0).getArtifactPath());
+ assertEquals(ALGORITHM, inlineResponse2001.getAdditionalArtifacts().get(0).getChecksum().getAlgorithm());
+ assertEquals(HASH, inlineResponse2001.getAdditionalArtifacts().get(0).getChecksum().getHash());
+ assertEquals(URI_HREF, inlineResponse2001.getLinks().getSelf().getHref());
}
@Test
- public void testGetVnfPackages_Not_Implemented() {
- final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest("");
- assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode());
+ public void test400BadRequestInfoReceivedAsProblemDetailsIfGetVnfPackagesIs400BadRequest() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL)).andExpect(method(HttpMethod.GET))
+ .andRespond(withStatus(HttpStatus.BAD_REQUEST));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGES_URL);
+ assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
+
+ assertNotNull(responseEntity.getBody());
+ final ProblemDetails problemDetails = responseEntity.getBody();
+ assertEquals("Error: Bad Request Received", problemDetails.getDetail());
+ }
+
+ @Test
+ public void test404NotFoundInfoReceivedAsProblemDetailsIfGetVnfPackagesIs404NotFound() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL)).andExpect(method(HttpMethod.GET))
+ .andRespond(withStatus(HttpStatus.NOT_FOUND));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGES_URL);
+ assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
+
+ assertNotNull(responseEntity.getBody());
+ final ProblemDetails problemDetails = responseEntity.getBody();
+ assertEquals("No Vnf Packages found", problemDetails.getDetail());
+ }
+
+ @Test
+ public void test500InternalServerErrorProblemDetailsReceivedIfGetVnfPackagesReturns500InternalServerError() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL)).andExpect(method(HttpMethod.GET))
+ .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGES_URL);
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+
+ assertNotNull(responseEntity.getBody());
+ final ProblemDetails problemDetails = responseEntity.getBody();
+ assertEquals("Internal Server Error Occurred.", problemDetails.getDetail());
+ }
+
+ @Test
+ public void test500InternalServerErrorProblemDetailsReceivedIfGetVnfPackagesReturnsANullPackage() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL)).andExpect(method(HttpMethod.GET)).andRespond(withSuccess());
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGES_URL);
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+
+ assertNotNull(responseEntity.getBody());
+ final ProblemDetails problemDetails = responseEntity.getBody();
+ assertEquals("An error occurred, a null response was received by the\n"
+ + " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"vnf_packages\" \n"
+ + "endpoint.", problemDetails.getDetail());
+ }
+
+ @Test
+ public void testVnfPackageReceivedAsInlineResponse2001IfGetVnfPackageByIdSuccessful() {
+ final VnfPkgInfo response = createVnfPkgInfo(VNF_PACKAGE_ID);
+
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID)).andExpect(method(HttpMethod.GET))
+ .andRespond(withSuccess(gson.toJson(response), MediaType.APPLICATION_JSON));
+
+ final String testURL = localhostUrl + port + VNFPKGM_BASE_URL + "/" + VNF_PACKAGE_ID;
+ final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders());
+ final ResponseEntity<InlineResponse2001> responseEntity = restTemplate.withBasicAuth("test", "test")
+ .exchange(testURL, HttpMethod.GET, request, InlineResponse2001.class);
+
+ assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
+ assertNotNull(responseEntity.getBody());
+ final InlineResponse2001 inlineResponse2001 = responseEntity.getBody();
+ assertEquals(VNF_PACKAGE_ID, inlineResponse2001.getId());
+ assertEquals(VNFD_ID, inlineResponse2001.getVnfdId());
+ assertEquals(VNFD_ID, inlineResponse2001.getSoftwareImages().get(0).getId());
+ assertEquals(VNF_PRODUCT_NAME, inlineResponse2001.getSoftwareImages().get(0).getName());
+ assertEquals(ALGORITHM, inlineResponse2001.getChecksum().getAlgorithm());
+ assertEquals(HASH, inlineResponse2001.getChecksum().getHash());
+ assertEquals(ARTIFACT_PATH, inlineResponse2001.getAdditionalArtifacts().get(0).getArtifactPath());
+ assertEquals(ALGORITHM, inlineResponse2001.getAdditionalArtifacts().get(0).getChecksum().getAlgorithm());
+ assertEquals(HASH, inlineResponse2001.getAdditionalArtifacts().get(0).getChecksum().getHash());
+ assertEquals(URI_HREF, inlineResponse2001.getLinks().getSelf().getHref());
+ }
+
+ @Test
+ public void test400BadRequestInfoReceivedAsProblemDetailsIfGetVnfPackageByIdIs400BadRequest() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID)).andExpect(method(HttpMethod.GET))
+ .andRespond(withStatus(HttpStatus.BAD_REQUEST));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGE_BY_ID_URL);
+
+ assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
+ assertNotNull(responseEntity.getBody());
+ final ProblemDetails problemDetails = responseEntity.getBody();
+ assertEquals("Error: Bad Request Received", problemDetails.getDetail());
+ }
+
+ @Test
+ public void test404NotFoundInfoReceivedAsProblemDetailsIfGetVnfPackageByIdIs404NotFound() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID)).andExpect(method(HttpMethod.GET))
+ .andRespond(withStatus(HttpStatus.NOT_FOUND));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGE_BY_ID_URL);
+
+ assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
+ assertNotNull(responseEntity.getBody());
+ final ProblemDetails problemDetails = responseEntity.getBody();
+ assertEquals("No Vnf Package found with vnfPkgId: " + VNF_PACKAGE_ID, problemDetails.getDetail());
+ }
+
+ @Test
+ public void test500InternalServerErrorProblemDetailsReceivedIfGetVnfPackageByIdReturns500InternalServerError() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID)).andExpect(method(HttpMethod.GET))
+ .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGE_BY_ID_URL);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+ assertNotNull(responseEntity.getBody());
+ final ProblemDetails problemDetails = responseEntity.getBody();
+ assertEquals("Internal Server Error Occurred.", problemDetails.getDetail());
}
@Test
+ public void test500InternalServerErrorProblemDetailsReceivedIfGetVnfPackageByIdReturnsANullPackage() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID)).andExpect(method(HttpMethod.GET))
+ .andRespond(withSuccess());
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGE_BY_ID_URL);
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+
+ assertNotNull(responseEntity.getBody());
+ final ProblemDetails problemDetails = responseEntity.getBody();
+ assertEquals("An error occurred, a null response was received by the\n"
+ + " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"vnf_packages\" by vnfPkgId: \""
+ + VNF_PACKAGE_ID + "\" \n" + "endpoint.", problemDetails.getDetail());
+ }
+
+ // The below 2 test methods are here to improve code coverage and provide a foundation for writing future tests
+ @Test
public void testGetVnfd_Not_Implemented() {
final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/vnfd");
assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode());
@@ -220,17 +384,74 @@ public class Sol003PackageManagementControllerTest {
}
// Simply returns a byte array filled with random data, for use in the tests.
- private byte[] buildByteArrayWithRandomData(int sizeInKb) {
+ private byte[] buildByteArrayWithRandomData(final 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) {
+ private ResponseEntity<ProblemDetails> sendHttpRequest(final 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);
}
+
+ private VnfPkgInfo[] createVnfPkgArray() {
+ final VnfPkgInfo[] vnfPkgInfoArray = new VnfPkgInfo[1];
+ final VnfPkgInfo vnfPkgInfo = createVnfPkgInfo(VNF_PACKAGE_ID);
+ vnfPkgInfoArray[0] = vnfPkgInfo;
+ return vnfPkgInfoArray;
+ }
+
+ private VnfPkgInfo createVnfPkgInfo(final String vnfPackageId) {
+ final VnfPkgInfo vnfPkgInfo = new VnfPkgInfo();
+ vnfPkgInfo.setId(vnfPackageId);
+ vnfPkgInfo.setVnfdId(VNFD_ID);
+ vnfPkgInfo.setVnfProvider(VNF_PROVIDER);
+ vnfPkgInfo.setVnfProductName(VNF_PRODUCT_NAME);
+ vnfPkgInfo.setVnfSoftwareVersion(VNF_SOFTWARE_VERSION);
+ vnfPkgInfo.setVnfdVersion(VNFD_VERSION);
+ vnfPkgInfo.setChecksum(createVnfPkgChecksum());
+ vnfPkgInfo.setSoftwareImages(createSoftwareImages());
+ vnfPkgInfo.setAdditionalArtifacts(createAdditionalArtifacts());
+ vnfPkgInfo.setLinks(createVNFPKGMLinkSerializerLinks());
+ return vnfPkgInfo;
+ }
+
+ private Checksum createVnfPkgChecksum() {
+ final Checksum checksum = new Checksum();
+ checksum.setAlgorithm(ALGORITHM);
+ checksum.setHash(HASH);
+ return checksum;
+ }
+
+ private List<VnfPackageSoftwareImageInfo> createSoftwareImages() {
+ final List<VnfPackageSoftwareImageInfo> softwareImages = new ArrayList<>();
+ final VnfPackageSoftwareImageInfo vnfPackageSoftwareImageInfo = new VnfPackageSoftwareImageInfo();
+ vnfPackageSoftwareImageInfo.setId(VNFD_ID);
+ vnfPackageSoftwareImageInfo.setName(VNF_PRODUCT_NAME);
+ vnfPackageSoftwareImageInfo.setProvider("");
+ vnfPackageSoftwareImageInfo.setVersion("");
+ vnfPackageSoftwareImageInfo.setChecksum(createVnfPkgChecksum());
+ vnfPackageSoftwareImageInfo
+ .setContainerFormat(VnfPackageSoftwareImageInfo.ContainerFormatEnum.fromValue("AKI"));
+ softwareImages.add(vnfPackageSoftwareImageInfo);
+ return softwareImages;
+ }
+
+ private List<VnfPackageArtifactInfo> createAdditionalArtifacts() {
+ final List<VnfPackageArtifactInfo> vnfPackageArtifactInfos = new ArrayList<>();
+ final VnfPackageArtifactInfo vnfPackageArtifactInfo =
+ new VnfPackageArtifactInfo().artifactPath(ARTIFACT_PATH).checksum(createVnfPkgChecksum());
+ vnfPackageArtifactInfos.add(vnfPackageArtifactInfo);
+ return vnfPackageArtifactInfos;
+ }
+
+ private VNFPKGMLinkSerializer createVNFPKGMLinkSerializerLinks() {
+ final UriLink uriLink = new UriLink().href(URI_HREF);
+ final VNFPKGMLinkSerializer vnfpkgmLinkSerializer = new VNFPKGMLinkSerializer().self(uriLink);
+ return vnfpkgmLinkSerializer;
+ }
}