Merge "remove multiline strings with A&AI client"
authorRob Daugherty <rd472p@att.com>
Mon, 10 Dec 2018 13:57:21 +0000 (13:57 +0000)
committerGerrit Code Review <gerrit@onap.org>
Mon, 10 Dec 2018 13:57:21 +0000 (13:57 +0000)
22 files changed:
adapters/mso-catalog-db-adapter/src/main/resources/application.yaml
adapters/mso-openstack-adapters/src/main/java/db/migration/R__CloudConfigMigration.java
adapters/mso-openstack-adapters/src/main/resources/application.yaml
adapters/mso-requests-db-adapter/src/main/resources/application.yaml
bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtil.groovy
bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtilFactory.groovy [new file with mode: 0644]
bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java
bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtilTest.groovy [new file with mode: 0644]
bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java
bpmn/mso-infrastructure-bpmn/pom.xml
bpmn/pom.xml
bpmn/so-bpmn-building-blocks/pom.xml
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/Create3rdONAPE2EServiceInstance.groovy
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/Delete3rdONAPE2EServiceInstance.groovy
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/SdnCommonTasks.java
bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java
bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdn/common/SdnCommonTasksTest.java
bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java
common/src/main/java/org/onap/so/client/HttpClientFactory.java [new file with mode: 0644]
pom.xml

index ff6f237..749a319 100644 (file)
@@ -14,7 +14,6 @@ mso:
     max-pool-size: 50
     queue-capacity: 500
     
-# CatalogDB
 spring:
   datasource:
     jdbc-url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/catalogdb
@@ -34,7 +33,7 @@ spring:
       fail-on-empty-beans: false
 flyway:
   baseline-on-migrate: false
-  jdbc-url:  jdbc:mariadb://${DB_HOST}:${DB_PORT}/catalogdb
+  url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/catalogdb
   user: ${DB_ADMIN_USERNAME}
   password: ${DB_ADMIN_PASSWORD}
   outOfOrder: true
index 6339616..257ad3c 100644 (file)
@@ -67,7 +67,7 @@ public class R__CloudConfigMigration implements JdbcMigration , MigrationInfoPro
         CloudConfig cloudConfig = null;
 
         // Try the override file
-        String configLocation = System.getProperty("spring.config.location");
+        String configLocation = System.getProperty("spring.config.additional-location");
         if (configLocation != null) {
             try (InputStream stream = new FileInputStream(Paths.get(configLocation).normalize().toString())) {
                 cloudConfig = loadCloudConfig(stream);
index 88099be..bc3bfba 100644 (file)
@@ -13,8 +13,7 @@ mso:
     core-pool-size: 50
     max-pool-size: 50
     queue-capacity: 500
-    
-# CatalogDB
+
 spring:
   datasource:
     jdbc-url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/catalogdb
index 4d200d2..af99a86 100644 (file)
@@ -46,7 +46,7 @@ spring:
       role: ACTUATOR
 flyway:
   baseline-on-migrate: false
-  jdbc-url:  jdbc:mariadb://${DB_HOST}:${DB_PORT}/requestdb
+  url:  jdbc:mariadb://${DB_HOST}:${DB_PORT}/requestdb
   user: ${DB_ADMIN_USERNAME}
   password: ${DB_ADMIN_PASSWORD}
 
index 5c935e9..250cdda 100644 (file)
  */
 
 package org.onap.so.bpmn.common.scripts
-import org.camunda.bpm.engine.delegate.BpmnError
+
+
 import org.camunda.bpm.engine.delegate.DelegateExecution
-import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor;
+import org.onap.logging.ref.slf4j.ONAPLogConstants
 import org.onap.so.client.HttpClient
+import org.onap.so.client.HttpClientFactory
 import org.onap.so.logger.MsoLogger
-import org.apache.commons.lang3.StringEscapeUtils
-import java.util.regex.Matcher
-import java.util.regex.Pattern
+import org.onap.so.utils.TargetEntity
 
 import javax.ws.rs.core.MediaType
 import javax.ws.rs.core.Response
-import org.onap.so.utils.TargetEntity
+import java.util.regex.Matcher
+import java.util.regex.Pattern
 
 class ExternalAPIUtil {
 
        String Prefix="EXTAPI_"
 
-       public MsoUtils utils = new MsoUtils()
-
-       ExceptionUtil exceptionUtil = new ExceptionUtil()
-
        private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, ExternalAPIUtil.class)
 
+       private final HttpClientFactory httpClientFactory;
+       private final MsoUtils utils;
+       private final ExceptionUtil exceptionUtil;
+
        public static final String PostServiceOrderRequestsTemplate =
        "{\n" +
        "\t\"externalId\": <externalId>,\n" +
@@ -85,7 +86,10 @@ class ExternalAPIUtil {
     "\t} \n" +
     "}"
 
-       public ExternalAPIUtil() {
+       ExternalAPIUtil(HttpClientFactory httpClientFactory, MsoUtils utils, ExceptionUtil exceptionUtil) {
+               this.httpClientFactory = httpClientFactory
+               this.utils = utils
+               this.exceptionUtil = exceptionUtil
        }
 
 //     public String getUri(DelegateExecution execution, resourceName) {
@@ -137,8 +141,7 @@ class ExternalAPIUtil {
                        msoLogger.debug( "Generated uuid is: " + uuid)
                        msoLogger.debug( "URL to be used is: " + url)
 
-                       URL Url = new URL(url)
-                       HttpClient client = new HttpClient(Url, MediaType.APPLICATION_JSON, TargetEntity.EXTERNAL)
+                       HttpClient client = httpClientFactory.create(new URL(url), MediaType.APPLICATION_JSON, TargetEntity.EXTERNAL)
                        client.addBasicAuthHeader(execution.getVariable("URN_externalapi_auth"), execution.getVariable("URN_mso_msoKey"))
                        client.addAdditionalHeader("X-FromAppId", "MSO")
                        client.addAdditionalHeader(ONAPLogConstants.Headers.REQUEST_ID, uuid)
@@ -166,17 +169,15 @@ class ExternalAPIUtil {
         * @return Response
         *
         */
-       public Response executeExternalAPIPostCall(DelegateExecution execution, String urlString, String payload){
+       public Response executeExternalAPIPostCall(DelegateExecution execution, String url, String payload){
                msoLogger.debug( " ======== Started Execute ExternalAPI Post Process ======== ")
                Response apiResponse = null
                try{
                        String uuid = utils.getRequestID()
                        msoLogger.debug( "Generated uuid is: " + uuid)
-                       msoLogger.debug( "URL to be used is: " + urlString)
-
-                       URL url = new URL(urlString);
+                       msoLogger.debug( "URL to be used is: " + url)
 
-                       HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.AAI)
+                       HttpClient httpClient = httpClientFactory.create(new URL(url), MediaType.APPLICATION_JSON, TargetEntity.AAI)
                        httpClient.addBasicAuthHeader(execution.getVariable("URN_externalapi_auth"), execution.getVariable("URN_mso_msoKey"))
                        httpClient.addAdditionalHeader("X-FromAppId", "MSO")
                        httpClient.addAdditionalHeader("X-TransactionId", uuid)
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtilFactory.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtilFactory.groovy
new file mode 100644 (file)
index 0000000..e7f4646
--- /dev/null
@@ -0,0 +1,29 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 Nokia.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.bpmn.common.scripts
+
+import org.onap.so.client.HttpClientFactory
+
+class ExternalAPIUtilFactory {
+
+    ExternalAPIUtil create() {
+        return new ExternalAPIUtil(new HttpClientFactory(), new MsoUtils(), new ExceptionUtil())
+    }
+}
index c0f1c48..b1e5d0d 100644 (file)
@@ -115,7 +115,7 @@ public class BBInputSetup implements JavaDelegate {
        private BBInputSetupMapperLayer mapperLayer;
        
        @Autowired
-       private CloudInfoFromAAI bbInputSetupHelper;
+       private CloudInfoFromAAI cloudInfoFromAAI;
 
        @Autowired
        private ExceptionBuilder exceptionUtil;
@@ -125,6 +125,10 @@ public class BBInputSetup implements JavaDelegate {
        public BBInputSetupUtils getBbInputSetupUtils() {
                return bbInputSetupUtils;
        }
+       
+       public void setCloudInfoFromAAI(CloudInfoFromAAI cloudInfoFromAAI) {
+               this.cloudInfoFromAAI = cloudInfoFromAAI;
+       }
 
        public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) {
                this.bbInputSetupUtils = bbInputSetupUtils;
@@ -987,7 +991,7 @@ public class BBInputSetup implements JavaDelegate {
                ServiceInstance serviceInstance = gBB.getServiceInstance();
                CloudRegion cloudRegion = null;
                if(cloudConfiguration == null) {
-                       Optional<CloudRegion> cloudRegionOp = bbInputSetupHelper.getCloudInfoFromAAI(serviceInstance);
+                       Optional<CloudRegion> cloudRegionOp = cloudInfoFromAAI.getCloudInfoFromAAI(serviceInstance);
                        if(cloudRegionOp.isPresent()) {
                                cloudRegion = cloudRegionOp.get();
                        }
@@ -1040,9 +1044,9 @@ public class BBInputSetup implements JavaDelegate {
                                                vnfModelInfo.setModelCustomizationUuid(vnfModelCustomizationUUID);
                                                this.mapCatalogVnf(vnf, vnfModelInfo, service);
                                                lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, vnf.getVnfId());
-                                               if (cloudConfiguration != null) {
-                                                       String volumeGroupCustomizationUUID = this.bbInputSetupUtils.getAAIVolumeGroup(cloudConfiguration.getCloudOwner(),
-                                                                       cloudConfiguration.getLcpCloudRegionId(), volumeGroup.getVolumeGroupId())
+                                               if (cloudRegion != null) {
+                                                       String volumeGroupCustomizationUUID = this.bbInputSetupUtils.getAAIVolumeGroup(cloudRegion.getCloudOwner(),
+                                                                       cloudRegion.getLcpCloudRegionId(), volumeGroup.getVolumeGroupId())
                                                                        .getModelCustomizationId();
                                                        ModelInfo volumeGroupModelInfo = new ModelInfo();
                                                        volumeGroupModelInfo.setModelCustomizationId(volumeGroupCustomizationUUID);
diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtilTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/ExternalAPIUtilTest.groovy
new file mode 100644 (file)
index 0000000..5f428f1
--- /dev/null
@@ -0,0 +1,199 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 Nokia.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.bpmn.common.scripts
+
+import org.assertj.core.api.AbstractAssert
+import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.junit.Test
+import org.onap.logging.ref.slf4j.ONAPLogConstants
+import org.onap.so.client.HttpClient
+import org.onap.so.client.HttpClientFactory
+import org.onap.so.utils.TargetEntity
+import org.springframework.http.HttpStatus
+
+import javax.ws.rs.core.MediaType
+import javax.ws.rs.core.Response
+
+import static org.assertj.core.api.Assertions.assertThat
+import static org.assertj.core.api.Assertions.catchThrowableOfType
+import static org.mockito.BDDMockito.given
+import static org.mockito.BDDMockito.then
+import static org.mockito.BDDMockito.willThrow
+import static org.mockito.Mockito.mock
+import static org.mockito.Mockito.times
+
+class ExternalAPIUtilTest {
+
+    private static final String URL = "http://someUrl"
+    private static final String UUID_STR = UUID.nameUUIDFromBytes("deterministic_uuid".getBytes())
+    private static final String BODY_PAYLOAD = "payload"
+
+    @Test
+    void executeExternalAPIGetCall_shouldPerformRestGetCall_withAuthorizationHeaderSet() {
+        // GIVEN
+        Response expectedResponse = createExpectedResponse(HttpStatus.ACCEPTED, BODY_PAYLOAD)
+        HttpClient httpClient = mock(HttpClient.class)
+        given(httpClient.get()).willReturn(expectedResponse)
+        HttpClientFactory httpClientFactory = mock(HttpClientFactory.class)
+        given(httpClientFactory.create(new URL(URL), MediaType.APPLICATION_JSON, TargetEntity.EXTERNAL)).willReturn(httpClient)
+
+        // WHEN
+        ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil(httpClientFactory, new DummyMsoUtils(UUID_STR), new ExceptionUtil())
+        Response apiResponse = externalAPIUtil.executeExternalAPIGetCall(createDelegateExecution(), URL)
+
+        // THEN
+        then(httpClient).should(times(1)).addBasicAuthHeader("value_externalapi_auth", "value_mso_msoKey")
+        then(httpClient).should(times(1)).addAdditionalHeader("X-FromAppId", "MSO")
+        then(httpClient).should(times(1)).addAdditionalHeader(ONAPLogConstants.Headers.REQUEST_ID, UUID_STR)
+        then(httpClient).should(times(1)).addAdditionalHeader("Accept", MediaType.APPLICATION_JSON)
+        ResponseAssert.assertThat(apiResponse)
+                .hasStatusCode(HttpStatus.ACCEPTED)
+                .hasBody(BODY_PAYLOAD)
+    }
+
+    @Test
+    void executeExternalAPIGetCall_shouldHandleExceptionsThrownByGetCall_andRethrowAsBpmnError() {
+        // GIVEN
+        HttpClient httpClient = mock(HttpClient.class)
+        willThrow(new RuntimeException("error occurred")).given(httpClient).get()
+        HttpClientFactory httpClientFactory = mock(HttpClientFactory.class)
+        given(httpClientFactory.create(new URL(URL), MediaType.APPLICATION_JSON, TargetEntity.EXTERNAL)).willReturn(httpClient)
+        DelegateExecution delegateExecution = createDelegateExecution()
+        DummyExceptionUtil exceptionUtil = new DummyExceptionUtil()
+
+        // WHEN
+        ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil(httpClientFactory, new DummyMsoUtils(UUID_STR), exceptionUtil)
+        BpmnError bpmnError = catchThrowableOfType({ -> externalAPIUtil.executeExternalAPIGetCall(delegateExecution, URL)
+        }, BpmnError.class)
+
+        // THEN
+        assertThat(exceptionUtil.getDelegateExecution()).isSameAs(delegateExecution)
+        assertThat(bpmnError.getMessage()).isEqualTo("error occurred")
+        assertThat(bpmnError.getErrorCode()).isEqualTo("9999")
+    }
+
+    @Test
+    void executeExternalAPIPostCall_shouldHandleExceptionsThrownByPostCall_andRethrowAsBpmnError() {
+        // GIVEN
+        HttpClient httpClient = mock(HttpClient.class)
+        willThrow(new RuntimeException("error occurred")).given(httpClient).post(BODY_PAYLOAD)
+        HttpClientFactory httpClientFactory = mock(HttpClientFactory.class)
+        given(httpClientFactory.create(new URL(URL), MediaType.APPLICATION_JSON, TargetEntity.AAI)).willReturn(httpClient)
+        DelegateExecution delegateExecution = createDelegateExecution()
+        DummyExceptionUtil exceptionUtil = new DummyExceptionUtil()
+
+        // WHEN
+        ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil(httpClientFactory, new DummyMsoUtils(UUID_STR), exceptionUtil)
+        BpmnError bpmnError = catchThrowableOfType({ ->
+            externalAPIUtil.executeExternalAPIPostCall(delegateExecution, URL, BODY_PAYLOAD)
+        }, BpmnError.class)
+
+        // THEN
+        assertThat(exceptionUtil.getDelegateExecution()).isSameAs(delegateExecution)
+        assertThat(bpmnError.getMessage()).isEqualTo("error occurred")
+        assertThat(bpmnError.getErrorCode()).isEqualTo("9999")
+    }
+
+    @Test
+    void executeExternalAPIPostCall_shouldPerformRestPostCall_withPayloadAndAuthorizationHeaderSet() {
+        // GIVEN
+        Response expectedResponse = createExpectedResponse(HttpStatus.ACCEPTED, BODY_PAYLOAD)
+        HttpClient httpClient = mock(HttpClient.class)
+        given(httpClient.post(BODY_PAYLOAD)).willReturn(expectedResponse)
+        HttpClientFactory httpClientFactory = mock(HttpClientFactory.class)
+        given(httpClientFactory.create(new URL(URL), MediaType.APPLICATION_JSON, TargetEntity.AAI)).willReturn(httpClient)
+
+        // WHEN
+        ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil(httpClientFactory, new DummyMsoUtils(UUID_STR), new ExceptionUtil())
+        Response apiResponse = externalAPIUtil.executeExternalAPIPostCall(createDelegateExecution(), URL, BODY_PAYLOAD)
+
+        // THEN
+        then(httpClient).should(times(1)).addBasicAuthHeader("value_externalapi_auth", "value_mso_msoKey")
+        then(httpClient).should(times(1)).addAdditionalHeader("X-FromAppId", "MSO")
+        then(httpClient).should(times(1)).addAdditionalHeader("X-TransactionId", UUID_STR)
+        ResponseAssert.assertThat(apiResponse)
+                .hasStatusCode(HttpStatus.ACCEPTED)
+                .hasBody(BODY_PAYLOAD)
+    }
+
+    private Response createExpectedResponse(HttpStatus httpStatus, String body) {
+        Response expectedResponse = mock(Response.class)
+        given(expectedResponse.getStatus()).willReturn(httpStatus.value())
+        given(expectedResponse.getEntity()).willReturn(body)
+        return expectedResponse
+    }
+
+    private DelegateExecution createDelegateExecution() {
+        DelegateExecution delegateExecution = mock(DelegateExecution.class)
+        given(delegateExecution.getVariable("URN_externalapi_auth")).willReturn("value_externalapi_auth")
+        given(delegateExecution.getVariable("URN_mso_msoKey")).willReturn("value_mso_msoKey")
+        return delegateExecution
+    }
+
+    private static class ResponseAssert extends AbstractAssert<ResponseAssert, Response> {
+
+        ResponseAssert(Response response) {
+            super(response, ResponseAssert.class)
+        }
+
+        static ResponseAssert assertThat(Response response) {
+            return new ResponseAssert(response)
+        }
+
+        ResponseAssert hasStatusCode(HttpStatus httpStatus) {
+            assertThat(actual.getStatus()).isEqualTo(httpStatus.value())
+            return this
+        }
+
+        ResponseAssert hasBody(String responseBody) {
+            assertThat(actual.getEntity()).isEqualTo(responseBody)
+            return this
+        }
+    }
+
+    private static class DummyMsoUtils extends MsoUtils {
+
+        private final String uuid
+
+        DummyMsoUtils(String uuid) {
+            this.uuid = uuid
+        }
+
+        String getRequestID() {
+            return uuid
+        }
+    }
+
+    private static class DummyExceptionUtil extends ExceptionUtil {
+
+        private DelegateExecution delegateExecution
+
+        @Override
+        void buildAndThrowWorkflowException(DelegateExecution delegateExecution, int errorCode, String errorMessage) {
+            this.delegateExecution = delegateExecution
+            throw new BpmnError(String.valueOf(errorCode), errorMessage)
+        }
+
+        DelegateExecution getDelegateExecution() {
+            return delegateExecution
+        }
+    }
+}
\ No newline at end of file
index 8399fe1..1654aa0 100644 (file)
@@ -40,6 +40,7 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 
 import org.camunda.bpm.engine.delegate.DelegateExecution;
 import org.junit.Before;
@@ -130,6 +131,9 @@ public class BBInputSetupTest {
        @Mock
        private BBInputSetupUtils SPY_bbInputSetupUtils;
        
+       @Mock
+       private CloudInfoFromAAI SPY_cloudInfoFromAAI;
+       
        @Spy
        private BBInputSetupMapperLayer bbInputSetupMapperLayer; 
        
@@ -137,6 +141,7 @@ public class BBInputSetupTest {
        public void setup(){
                SPY_bbInputSetup.setBbInputSetupUtils(SPY_bbInputSetupUtils);
                SPY_bbInputSetup.setMapperLayer(bbInputSetupMapperLayer);
+               SPY_bbInputSetup.setCloudInfoFromAAI(SPY_cloudInfoFromAAI);
        }
        
        @Test
@@ -2270,19 +2275,22 @@ public class BBInputSetupTest {
                verify(SPY_bbInputSetup, times(1)).mapCatalogVfModule(any(VfModule.class), any(ModelInfo.class),
                                any(Service.class), any(String.class));
 
-               org.onap.aai.domain.yang.CloudRegion aaiCloudRegion = Mockito.mock(org.onap.aai.domain.yang.CloudRegion.class);
+               CloudRegion cloudRegion = new CloudRegion();
+               cloudRegion.setLcpCloudRegionId("cloudRegionId");
+               cloudRegion.setCloudOwner("CloudOwner");
+               doReturn(Optional.of(cloudRegion)).when(SPY_cloudInfoFromAAI).getCloudInfoFromAAI(gBB.getServiceInstance());
                VolumeGroup volumeGroup = new VolumeGroup();
                volumeGroup.setVolumeGroupId("volumeGroupId");
                gBB.getServiceInstance().getVnfs().get(0).getVolumeGroups().add(volumeGroup);
                org.onap.aai.domain.yang.VolumeGroup aaiVolumeGroup = new org.onap.aai.domain.yang.VolumeGroup();
                aaiVolumeGroup.setModelCustomizationId("modelCustId");
-               doReturn(aaiVolumeGroup).when(SPY_bbInputSetupUtils).getAAIVolumeGroup(Defaults.CLOUD_OWNER.toString(),
-                               cloudConfiguration.getLcpCloudRegionId(), volumeGroup.getVolumeGroupId());
+               doReturn(aaiVolumeGroup).when(SPY_bbInputSetupUtils).getAAIVolumeGroup(cloudRegion.getCloudOwner(),
+                               cloudRegion.getLcpCloudRegionId(), volumeGroup.getVolumeGroupId());
 
                executeBB.getBuildingBlock().setBpmnFlowName("UnassignVolumeGroupBB");
                executeBB.getBuildingBlock().setKey("72d9d1cd-f46d-447a-abdb-451d6fb05fa8");
                SPY_bbInputSetup.getGBBMacroExistingService(executeBB, lookupKeyMap,
-                               executeBB.getBuildingBlock().getBpmnFlowName(), gBB, service, requestAction, cloudConfiguration);
+                               executeBB.getBuildingBlock().getBpmnFlowName(), gBB, service, requestAction, null);
                verify(SPY_bbInputSetup, times(3)).mapCatalogVnf(any(GenericVnf.class), any(ModelInfo.class),
                                any(Service.class));
                verify(SPY_bbInputSetup, times(1)).mapCatalogVolumeGroup(isA(VolumeGroup.class), isA(ModelInfo.class),
index e22125b..fb5d010 100644 (file)
                        <artifactId>camunda-bpm-assert</artifactId>
                        <version>2.0-alpha2</version>
                        <scope>test</scope>
-               </dependency>   
+               </dependency>
                <dependency>
-            <groupId>org.assertj</groupId>
-            <artifactId>assertj-core</artifactId>
-            <version>1.7.0</version>
-            <scope>test</scope>
-        </dependency>  
+                       <groupId>org.assertj</groupId>
+                       <artifactId>assertj-core</artifactId>
+                       <version>1.7.0</version>
+                       <scope>test</scope>
+               </dependency>
        </dependencies>
 </project>
index a7b49bc..c66178b 100644 (file)
@@ -64,7 +64,7 @@
                        <dependency>
                                <groupId>org.assertj</groupId>
                                <artifactId>assertj-core</artifactId>
-                               <version>1.7.0</version>
+                               <version>3.11.1</version>
                                <scope>test</scope>
                        </dependency>
                </dependencies>
index 8f1f2bf..4fe02ee 100644 (file)
                        <version>2.0-alpha2</version>
                        <scope>test</scope>
                </dependency>
+               <dependency>
+                       <groupId>org.assertj</groupId>
+                       <artifactId>assertj-core</artifactId>
+                       <version>1.7.0</version>
+                       <scope>test</scope>
+               </dependency>
                <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-test</artifactId>
index 2ae7686..05fd517 100644 (file)
@@ -23,6 +23,7 @@ package org.onap.so.bpmn.infrastructure.scripts
 import org.json.JSONArray
 import org.json.JSONObject
 import org.json.XML
+import org.onap.so.bpmn.common.scripts.ExternalAPIUtilFactory
 
 import static org.apache.commons.lang3.StringUtils.*
 import groovy.xml.XmlUtil
@@ -381,7 +382,7 @@ public class Create3rdONAPE2EServiceInstance extends AbstractServiceTaskProcesso
                valueMap.put("serviceName", '"' + serviceName + '"')
                valueMap.put("serviceUuId", '"' + serviceUuId + '"')
 
-               ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil()
+               ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
 
                // insert CallSource='ExternalAPI' to uuiRequest
                Map<String, String> requestInputsMap = new HashMap<>()
@@ -426,7 +427,7 @@ public class Create3rdONAPE2EServiceInstance extends AbstractServiceTaskProcesso
                msoLogger.debug("doCreateE2ESIin3rdONAP externalAPIURL is: " + extAPIPath)
                msoLogger.debug("doCreateE2ESIin3rdONAP payload is: " + payload)
 
-               ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil()
+               ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
                execution.setVariable("ServiceOrderId", "")
 
                Response response = externalAPIUtil.executeExternalAPIPostCall(execution, extAPIPath, payload)
@@ -471,7 +472,7 @@ public class Create3rdONAPE2EServiceInstance extends AbstractServiceTaskProcesso
                extAPIPath += "/" + execution.getVariable("ServiceOrderId")
                msoLogger.debug("getE2ESIProgressin3rdONAP create externalAPIURL is: " + extAPIPath)
 
-               ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil()
+               ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
 
                Response response = externalAPIUtil.executeExternalAPIGetCall(execution, extAPIPath)
 
index 078d68b..b718e4a 100644 (file)
@@ -20,6 +20,8 @@
 
 package org.onap.so.bpmn.infrastructure.scripts
 
+import org.onap.so.bpmn.common.scripts.ExternalAPIUtilFactory
+
 import javax.ws.rs.NotFoundException
 import javax.ws.rs.core.Response
 
@@ -249,7 +251,7 @@ public class Delete3rdONAPE2EServiceInstance extends AbstractServiceTaskProcesso
                valueMap.put("serviceName", "null")
                valueMap.put("serviceUuId", '"' + serviceSpecificationId + '"')
 
-               ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil()
+               ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
 
                valueMap.put("_requestInputs_",  "")
 
@@ -271,7 +273,7 @@ public class Delete3rdONAPE2EServiceInstance extends AbstractServiceTaskProcesso
                String extAPIPath = sppartnerUrl + "/service?relatedParty.id=" + globalSubscriberId
                msoLogger.debug("queryServicefrom3rdONAP externalAPIURL is: " + extAPIPath)
 
-               ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil()
+               ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
 
                Response response = externalAPIUtil.executeExternalAPIGetCall(execution, extAPIPath)
 
@@ -317,7 +319,7 @@ public class Delete3rdONAPE2EServiceInstance extends AbstractServiceTaskProcesso
                msoLogger.debug("doDeleteE2ESIin3rdONAP externalAPIURL is: " + extAPIPath)
                msoLogger.debug("doDeleteE2ESIin3rdONAP payload is: " + payload)
 
-               ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil()
+               ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
                execution.setVariable("ServiceOrderId", "")
 
                Response response = externalAPIUtil.executeExternalAPIPostCall(execution, extAPIPath, payload)
@@ -361,7 +363,7 @@ public class Delete3rdONAPE2EServiceInstance extends AbstractServiceTaskProcesso
                extAPIPath += "/" + execution.getVariable("ServiceOrderId")
                msoLogger.debug("getE2ESIProgressin3rdONAP delete externalAPIURL is: " + extAPIPath)
 
-               ExternalAPIUtil externalAPIUtil = new ExternalAPIUtil()
+               ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
 
                Response response = externalAPIUtil.executeExternalAPIGetCall(execution, extAPIPath)
 
index fedec4f..58c6db1 100644 (file)
@@ -32,6 +32,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import com.jayway.jsonpath.JsonPath;
+import com.jayway.jsonpath.PathNotFoundException;
  
 @Component
 public class SDNCRequestTasks {
@@ -61,6 +62,9 @@ public class SDNCRequestTasks {
                        String response = sdncClient.post(request.getSDNCPayload(),request.getTopology());
                        String finalMessageIndicator = JsonPath.read(response, "$.output.ack-final-indicator");         
                        execution.setVariable("isSDNCCompleted", convertIndicatorToBoolean(finalMessageIndicator));
+               } catch(PathNotFoundException e) {
+                       logger.error("Error Parsing SDNC Response", e);
+                       exceptionBuilder.buildAndThrowWorkflowException(execution, 7000,"Error Parsing SDNC Response");
                } catch (MapperException e) {
                        logger.error("Error Parsing SDNC Response", e);
                        exceptionBuilder.buildAndThrowWorkflowException(execution, 7000,"Error Parsing SDNC Response");
index 66e2694..7670e02 100644 (file)
@@ -311,8 +311,14 @@ public class WorkflowActionBBTasks {
                        InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
                        String errorMsg = null;
                        String rollbackErrorMsg = null;
-                       boolean rollbackCompleted = (boolean) execution.getVariable("isRollbackComplete");
-                       boolean isRollbackFailure = (boolean) execution.getVariable("isRollback");
+                       Boolean rollbackCompleted = (Boolean) execution.getVariable("isRollbackComplete");
+                       Boolean isRollbackFailure = (Boolean) execution.getVariable("isRollback");
+                       
+                       if(rollbackCompleted==null)
+                               rollbackCompleted = false;
+                       
+                       if(isRollbackFailure==null)
+                               isRollbackFailure = false;
                        
                        if(rollbackCompleted){
                                rollbackErrorMsg = "Rollback has been completed successfully.";
index 37e13fb..13ba107 100644 (file)
@@ -105,12 +105,20 @@ public class SdnCommonTasks {
                responseCode = (String) embeddedResponse.get(RESPONSE_CODE);
             responseMessage = (String) embeddedResponse.get(RESPONSE_MESSAGE);
         }
-        
+        ObjectMapper objMapper = new ObjectMapper();
+        String jsonResponse;
+               try {
+                       jsonResponse = objMapper.writeValueAsString(output);
+                       msoLogger.debug(jsonResponse);
+               } catch (JsonProcessingException e) {
+                       msoLogger.warnSimple("Could not convert SDNC Response to String", e);
+                       jsonResponse = "";
+               }
                msoLogger.info("ResponseCode: " + responseCode + " ResponseMessage: " + responseMessage);
                int code = StringUtils.isNotEmpty(responseCode) ? Integer.parseInt(responseCode) : 0;
                if (isHttpCodeSuccess(code)) {
                        msoLogger.info("Successful Response from SDNC");
-                       return responseMessage;
+                       return jsonResponse;
                } else {
                        String errorMessage = String.format(SDNC_CODE_NOT_0_OR_IN_200_299, responseMessage);
                        msoLogger.error(MessageEnum.RA_RESPONSE_FROM_SDNC, errorMessage, "BPMN", MsoLogger.getServiceName(),
index fc269cd..0ef764a 100644 (file)
@@ -39,8 +39,10 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
+import org.mockito.Mockito;
 import org.mockito.Spy;
 import org.onap.so.bpmn.BaseTaskTest;
+import org.onap.so.bpmn.core.WorkflowException;
 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
 import org.onap.so.db.request.beans.InfraActiveRequests;
@@ -54,6 +56,9 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest {
        @Spy
        protected WorkflowActionBBTasks workflowActionBBTasks;
        
+       @Mock
+       InfraActiveRequests reqMock;
+       
        private DelegateExecution execution;
        
        @Rule
@@ -284,4 +289,23 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest {
                workflowActionBBTasks.checkRetryStatus(execution);
                assertEquals(0,execution.getVariable("retryCount"));
        }
+       
+       
+       @Test
+       public void updateRequestStatusToFailed_Null_Rollback(){
+               String reqId = "reqId123";
+               execution.setVariable("mso-request-id", reqId);
+               execution.setVariable("retryCount", 3);
+               execution.setVariable("handlingCode","Success");
+               execution.setVariable("gCurrentSequence",1);
+               WorkflowException we = new WorkflowException("WorkflowAction",1231,"Error Case");
+               execution.setVariable("WorkflowException",we);
+               
+               doReturn(reqMock).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
+               workflowActionBBTasks.updateRequestStatusToFailed(execution);
+               Mockito.verify( reqMock, Mockito.times(1)).setStatusMessage("Error Case");
+               Mockito.verify( reqMock, Mockito.times(1)).setRequestStatus("FAILED");
+               Mockito.verify( reqMock, Mockito.times(1)).setProgress(Long.valueOf(100));
+               Mockito.verify( reqMock, Mockito.times(1)).setLastModifiedBy("CamundaBPMN");
+       }
 }
index e30fe66..2636aec 100644 (file)
@@ -60,12 +60,13 @@ public class SdnCommonTasksTest{
 
     @Test
     public void validateSDNResponseTest() throws BadResponseException {
+       String jsonResponse = "{\"output\":{\"response-code\":\"0\",\"response-message\":\"success\"}}";
         LinkedHashMap<String, Object> responseMap = new LinkedHashMap<>();
         LinkedHashMap<String, Object> output = new LinkedHashMap<>();
         output.put("response-code", "0");
         output.put("response-message", "success");
         responseMap.put("output", output);
-        assertEquals("success", sdnCommonTasks.validateSDNResponse(responseMap));
+        assertEquals(jsonResponse, sdnCommonTasks.validateSDNResponse(responseMap));
     }
 
     @Test
index cc1c5c5..9117b8e 100644 (file)
@@ -77,6 +77,6 @@ public class SDNCClientIT extends BaseIntegrationTest {
                         .withHeader("Content-Type", "application/json").withBody(responseJson)));
        
         String response = SPY_sdncClient.post("", SDNCTopology.NETWORK);
-        JSONAssert.assertEquals("", response, false);
+        JSONAssert.assertEquals(responseJson, response, true);
     }
 }
diff --git a/common/src/main/java/org/onap/so/client/HttpClientFactory.java b/common/src/main/java/org/onap/so/client/HttpClientFactory.java
new file mode 100644 (file)
index 0000000..9705d7d
--- /dev/null
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 Nokia.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.client;
+
+import java.net.URL;
+import org.onap.so.utils.TargetEntity;
+
+public class HttpClientFactory {
+
+    public HttpClient create(URL host, String contentType, TargetEntity targetEntity) {
+        return new HttpClient(host, contentType, targetEntity);
+    }
+}
diff --git a/pom.xml b/pom.xml
index e88d67f..1be848a 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                <dependency>
                        <groupId>org.assertj</groupId>
                        <artifactId>assertj-core</artifactId>
+                       <version>3.11.1</version>
                        <scope>test</scope>
                </dependency>
                <dependency>