Merge "vnr vrf fk issue"
authorSteve Smokowski <ss835w@att.com>
Mon, 15 Apr 2019 12:43:36 +0000 (12:43 +0000)
committerGerrit Code Review <gerrit@onap.org>
Mon, 15 Apr 2019 12:43:36 +0000 (12:43 +0000)
adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/factory/MsoCloudClientFactoryImplTest.java [new file with mode: 0644]
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java
mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/BaseTest.java
mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java
mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/ConfigurationResourceCustomizationRepository.java

diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/factory/MsoCloudClientFactoryImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/factory/MsoCloudClientFactoryImplTest.java
new file mode 100644 (file)
index 0000000..701ed65
--- /dev/null
@@ -0,0 +1,71 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 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.heatbridge.factory;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.so.heatbridge.HeatBridgeException;
+import org.onap.so.heatbridge.openstack.api.OpenstackAccess;
+import org.onap.so.heatbridge.openstack.factory.OpenstackClientFactory;
+import org.onap.so.utils.CryptoUtils;
+
+public class MsoCloudClientFactoryImplTest {
+
+    private static final String URL_V2 = "http://localhost:8080/v2.0";
+    private static final String URL_V3 = "http://localhost:8080/v3";
+    private static final String URL_WITH_UNSUPPORTED_VERSION = "http://localhost:8080/v4";
+
+    private static final String MSO_ID = "testMsoId";
+    private static final String ENCRYPTED_PASSWORD = CryptoUtils.encryptCloudConfigPassword("testPassword");
+    private static final String CLOUD_REGION_ID = "testCloudRegionId";
+    private static final String TENANT_ID = "testTenantId";
+
+    private MsoCloudClientFactoryImpl testedObject;
+    private OpenstackClientFactory openstackClientFactoryMock;
+
+    @Before
+    public void setup() {
+        openstackClientFactoryMock = mock(OpenstackClientFactory.class);
+        testedObject = new MsoCloudClientFactoryImpl(openstackClientFactoryMock);
+    }
+
+    @Test
+    public void getOpenstackClientWithVersion2() throws Exception {
+        testedObject.getOpenstackClient(URL_V2, MSO_ID, ENCRYPTED_PASSWORD, CLOUD_REGION_ID, TENANT_ID);
+        verify(openstackClientFactoryMock).createOpenstackV2Client(any(OpenstackAccess.class));
+    }
+
+    @Test
+    public void getOpenstackClientWithVersion3() throws Exception {
+        testedObject.getOpenstackClient(URL_V3, MSO_ID, ENCRYPTED_PASSWORD, CLOUD_REGION_ID, TENANT_ID);
+        verify(openstackClientFactoryMock).createOpenstackV3Client(any(OpenstackAccess.class));
+    }
+
+    @Test(expected = HeatBridgeException.class)
+    public void getOpenstackClient_unsupportedVersion() throws Exception {
+        testedObject.getOpenstackClient(URL_WITH_UNSUPPORTED_VERSION, MSO_ID, ENCRYPTED_PASSWORD, CLOUD_REGION_ID,
+                TENANT_ID);
+    }
+
+}
index 2903798..2f898b6 100644 (file)
@@ -531,7 +531,7 @@ public class SniroHomingV2 {
             si.setServiceInstanceId(identifierValue);
             si.setOrchestrationStatus(OrchestrationStatus.CREATED);
             cloud.setLcpCloudRegionId(assignmentsMap.get("cloudRegionId"));
-            if (assignmentsMap.containsKey("vnfHostName")) {
+            if (assignmentsMap.containsKey("vnfHostName") && !assignmentsMap.get("vnfHostName").isEmpty()) {
                 logger.debug("Resources has been homed to a vnf");
                 GenericVnf vnf = setVnf(assignmentsMap);
                 vnf.setCloudRegion(cloud);
index da37be9..5da16f4 100644 (file)
@@ -28,10 +28,12 @@ import javax.transaction.Transactional;
 import org.junit.After;
 import org.junit.BeforeClass;
 import org.junit.runner.RunWith;
+import org.onap.so.db.request.client.RequestsDbClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.mock.mockito.SpyBean;
 import org.springframework.boot.test.web.client.TestRestTemplate;
 import org.springframework.boot.web.server.LocalServerPort;
 import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
@@ -52,6 +54,9 @@ public abstract class BaseTest {
     protected Logger logger = LoggerFactory.getLogger(BaseTest.class);
     protected TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
 
+    @SpyBean
+    protected RequestsDbClient requestsDbClient;
+
     @Autowired
     protected Environment env;
 
index 1bb3932..db6273d 100644 (file)
@@ -55,6 +55,7 @@ import javax.ws.rs.core.Response;
 import org.apache.http.HttpStatus;
 import org.junit.Before;
 import org.junit.Test;
+import org.mockito.Mockito;
 import org.onap.logging.ref.slf4j.ONAPLogConstants;
 import org.onap.so.db.catalog.beans.Service;
 import org.onap.so.db.catalog.beans.ServiceRecipe;
@@ -124,6 +125,7 @@ public class ServiceInstancesTest extends BaseTest {
         }
         wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests.*")).willReturn(aResponse()
                 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_OK)));
+        Mockito.doReturn(null).when(requestsDbClient).getInfraActiveRequestbyRequestId(Mockito.any());
     }
 
     public String inputStream(String JsonInput) throws IOException {
index 4310498..74c4c8c 100644 (file)
@@ -26,6 +26,6 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource;
 @RepositoryRestResource(collectionResourceRel = "configurationResourceCustomization",
         path = "configurationResourceCustomization")
 public interface ConfigurationResourceCustomizationRepository
-        extends JpaRepository<ConfigurationResourceCustomization, String> {
+        extends JpaRepository<ConfigurationResourceCustomization, Integer> {
 
 }