Merge "Network Adapter Test Repair"
diff --git a/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/BpelRestClientTest.java b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/BpelRestClientTest.java
new file mode 100644
index 0000000..445ca54
--- /dev/null
+++ b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/BpelRestClientTest.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * 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
+ *l
+ * 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.openecomp.mso.adapters.vnf;
+
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertTrue;
+
+public class BpelRestClientTest {
+
+    @Test
+    public void testBpelRestClient() {
+
+        BpelRestClient test = new BpelRestClient();
+
+        assertEquals(test.getSocketTimeout(),5);
+        assertEquals(test.getConnectTimeout(),5);
+        assertEquals(test.getRetryCount(),5);
+        test.setRetryCount(6);
+        assertEquals(test.getRetryCount(),6);
+        assertEquals(test.getRetryInterval(),-15);
+        test.setRetryInterval(5);
+        assertEquals(test.getRetryInterval(),5);
+        test.setCredentials("credentials");
+        assertEquals(test.getCredentials(),"credentials");
+        test.setRetryList("1, 2, 3");
+        assertEquals(test.getRetryList(),"1, 2, 3");
+        assertEquals(test.getLastResponseCode(),0);
+        assertEquals(test.getLastResponse(),"");
+        assertTrue(test.bpelPost("bpelStr","url",true));
+
+    }
+}
diff --git a/asdc-controller/src/test/java/org/openecomp/mso/asdc/client/test/emulators/JsonNotificationDataTest.java b/asdc-controller/src/test/java/org/openecomp/mso/asdc/client/test/emulators/JsonNotificationDataTest.java
index c4aebf9..596b2b2 100644
--- a/asdc-controller/src/test/java/org/openecomp/mso/asdc/client/test/emulators/JsonNotificationDataTest.java
+++ b/asdc-controller/src/test/java/org/openecomp/mso/asdc/client/test/emulators/JsonNotificationDataTest.java
@@ -25,7 +25,6 @@
 
 public class JsonNotificationDataTest {
 
-
     @Test
     public void setAttributeTest()
     {
diff --git a/asdc-controller/src/test/java/org/openecomp/mso/asdc/client/test/emulators/JsonResourceInfoTest.java b/asdc-controller/src/test/java/org/openecomp/mso/asdc/client/test/emulators/JsonResourceInfoTest.java
new file mode 100644
index 0000000..ab884fe
--- /dev/null
+++ b/asdc-controller/src/test/java/org/openecomp/mso/asdc/client/test/emulators/JsonResourceInfoTest.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.openecomp.mso.asdc.client.test.emulators;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class JsonResourceInfoTest {
+
+
+    @Test
+    public void setAttributeTest()
+    {
+        JsonResourceInfo jsonResourceInfo = new JsonResourceInfo();
+        jsonResourceInfo.setAttribute("resourceInstanceName","resourceInstanceName");
+        String resourceInstanceName = jsonResourceInfo.getResourceInstanceName();
+        assertEquals(resourceInstanceName,"resourceInstanceName");
+    }
+
+    @Test
+    public void getAttributeTest()
+    {
+        JsonResourceInfo jsonResourceInfo = new JsonResourceInfo();
+        String resourceInstanceName = jsonResourceInfo.getResourceInstanceName();
+        assertEquals(resourceInstanceName,null);
+    }
+
+    @Test
+    public void getAttributeTestOthers()
+    {
+        JsonResourceInfo jsonResourceInfo = new JsonResourceInfo();
+        String resourceInvariantUUID = jsonResourceInfo.getResourceInvariantUUID();
+        jsonResourceInfo.getResourceName();
+        jsonResourceInfo.getResourceType();
+        jsonResourceInfo.getResourceUUID();
+        jsonResourceInfo.getResourceVersion();
+        jsonResourceInfo.getSubcategory();
+        jsonResourceInfo.getCategory();
+        jsonResourceInfo.getResourceCustomizationUUID();
+        jsonResourceInfo.getArtifacts();
+        assertEquals(resourceInvariantUUID,null);
+    }
+
+}
diff --git a/asdc-controller/src/test/java/org/openecomp/mso/asdc/client/test/emulators/JsonStatusDataTest.java b/asdc-controller/src/test/java/org/openecomp/mso/asdc/client/test/emulators/JsonStatusDataTest.java
new file mode 100644
index 0000000..7607832
--- /dev/null
+++ b/asdc-controller/src/test/java/org/openecomp/mso/asdc/client/test/emulators/JsonStatusDataTest.java
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.openecomp.mso.asdc.client.test.emulators;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class JsonStatusDataTest {
+
+    @Test
+    public void instantiateNotifFromJsonFileTest() {
+        JsonStatusData jsonStatusData = new JsonStatusData();
+        JsonStatusData returnedVal = null;
+        try {
+            returnedVal = jsonStatusData.instantiateNotifFromJsonFile(jsonStatusData.getArtifactURL());
+        } catch (Exception ex) {
+
+        }
+        assertEquals(returnedVal, null);
+    }
+
+    @Test
+    public void setGetAttributes()
+    {
+        JsonStatusData jsonStatusData = new JsonStatusData();
+        jsonStatusData.setAttribute("test","test");
+        jsonStatusData.getStatus();
+        jsonStatusData.getTimestamp();
+        jsonStatusData.getComponentName();
+        jsonStatusData.getConsumerID();
+        jsonStatusData.getDistributionID();
+        String errReason = jsonStatusData.getErrorReason();
+        assertEquals(errReason,"MSO FAILURE");
+
+    }
+
+
+
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/pom.xml b/mso-api-handlers/mso-api-handler-infra/pom.xml
index 93b6c8f..97bd834 100644
--- a/mso-api-handlers/mso-api-handler-infra/pom.xml
+++ b/mso-api-handlers/mso-api-handler-infra/pom.xml
@@ -225,6 +225,18 @@
             <artifactId>json</artifactId>
             <version>20160212</version>
         </dependency>
+		<dependency>
+			<groupId>org.jmockit</groupId>
+			<artifactId>jmockit</artifactId>
+			<version>1.19</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.12</version>
+			<scope>test</scope>
+		</dependency>
         <dependency>
     		<groupId>pl.pragmatists</groupId>
     		<artifactId>JUnitParams</artifactId>
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/MsoRequestTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/MsoRequestTest.java
index 7963217..7fb3bf0 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/MsoRequestTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/MsoRequestTest.java
@@ -25,18 +25,24 @@
 import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
+import java.io.PrintStream;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 
+import mockit.Expectations;
+import mockit.Mocked;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.CharEncoding;
+import org.hibernate.Session;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.runner.RunWith;
 import org.openecomp.mso.apihandler.common.ValidationException;
+import org.openecomp.mso.db.AbstractSessionFactoryManager;
+import org.openecomp.mso.properties.MsoJavaProperties;
 import org.openecomp.mso.serviceinstancebeans.ServiceInstancesRequest;
 
 import com.fasterxml.jackson.core.JsonParseException;
@@ -597,4 +603,22 @@
 		assertNotNull(msoRequest.getRequestId());
 		assertEquals(msoRequest.getReqVersion(), 6);
 	}
+
+	@Test
+	public void createRequestRecord(@Mocked AbstractSessionFactoryManager sessionFactoryManager,
+									@Mocked Session session) throws ValidationException, IOException {
+
+		new Expectations() {{
+			sessionFactoryManager.getSessionFactory().openSession(); result = session;
+		}};
+
+		this.requestJSON = inputStream("/v6AddRelationships.json");
+		this.instanceIdMapTest.put("serviceInstanceId", "ff305d54-75b4-431b-adb2-eb6b9e5ff000");
+		this.sir  = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
+		this.msoRequest = new MsoRequest ("V6RemoveRelationships");
+		msoRequest.parse(sir, instanceIdMapTest, Action.removeRelationships, "v6", originalRequestJSON);
+		msoRequest.createRequestRecord(Status.COMPLETE, Action.createInstance);
+
+	}
+
 }
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/NetworkRequestHandlerTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/NetworkRequestHandlerTest.java
index b182192..2089cf1 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/NetworkRequestHandlerTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/NetworkRequestHandlerTest.java
@@ -34,14 +34,17 @@
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
+import mockit.Expectations;
 import mockit.Mock;
 import mockit.MockUp;
 
+import mockit.Mocked;
 import org.apache.http.HttpResponse;
 import org.apache.http.ProtocolVersion;
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.entity.BasicHttpEntity;
 import org.apache.http.message.BasicHttpResponse;
+import org.hibernate.Session;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -50,6 +53,7 @@
 
 import org.openecomp.mso.apihandler.common.CamundaClient;
 import org.openecomp.mso.apihandlerinfra.networkbeans.NetworkRequest;
+import org.openecomp.mso.db.AbstractSessionFactoryManager;
 import org.openecomp.mso.db.catalog.CatalogDatabase;
 import org.openecomp.mso.db.catalog.beans.NetworkRecipe;
 import org.openecomp.mso.db.catalog.beans.VfModule;
@@ -63,7 +67,6 @@
 	private static final String REQ_XML = "<network-request xmlns=\"http://org.openecomp/mso/infra/network-request/v1\"> <request-info> <request-id>e1fc3ed3-31e5-48a8-913b-23184c1e9443</request-id><action>CREATE</action> <source>VID</source> <service-instance-id>e1fc3ed3-31e5-48a8-913b-23184c1e9443</service-instance-id></request-info> <network-inputs> <network-id>e1fc3ed3-31e5-48a8-913b-23184c1e9443</network-id> <network-name>nwInstanceName</network-name> <network-type>nwModelName</network-type><modelCustomizationId>e1fc3ed3-31e5-48a8-913b-23184c1e9443</modelCustomizationId> <aic-cloud-region>e1fc3ed3-31e5-48a8-913b-23184c1e9443</aic-cloud-region> <tenant-id>e1fc3ed3-31e5-48a8-913b-23184c1e9443</tenant-id><service-id>e1fc3ed3-31e5-48a8-913b-23184c1e9443</service-id> <backout-on-failure>false</backout-on-failure><sdncVersion>1802</sdncVersion><service-instance-id>e1fc3ed3-31e5-48a8-913b-23184c1e9443</service-instance-id></network-inputs> <network-params></network-params> </network-request>";
 
 	private static MockUp<RequestsDatabase> mockRDB;
-	private static MockUp<NetworkMsoInfraRequest> mockMsoRequest;
 	private static MockUp<CatalogDatabase> mockCDB;
 	private static MockUp<CamundaClient> mockCamundaClient;
 
@@ -107,13 +110,6 @@
 			}
 		};
 
-		mockMsoRequest = new MockUp<NetworkMsoInfraRequest>() {
-			@Mock
-			public void createRequestRecord (Status status) {
-				return;
-			}
-		};
-
 		mockCDB = new MockUp<CatalogDatabase>() {
 			@Mock
 			public NetworkRecipe getNetworkRecipe (String networkType, String action, String serviceType) {
@@ -157,50 +153,42 @@
 	@AfterClass
 	public static void tearDown() {
 		mockRDB.tearDown();
-		mockMsoRequest.tearDown();
 		mockCDB.tearDown();
 		mockCamundaClient.tearDown();
 	}
 	
 	@Test
-	public void manageVnfRequestTest(){
+	public void manageVnfRequestTest(@Mocked AbstractSessionFactoryManager sessionFactoryManager,
+                                     @Mocked Session session){
+        new Expectations() {{
+            sessionFactoryManager.getSessionFactory().openSession(); result = session;
+        }};
 		Mockito.when(uriInfo.getRequestUri()).thenReturn(URI.create("http://localhost:8080/test"));
 		Response resp = handler.manageNetworkRequest(REQ_XML, "v2");
 		assertTrue(null != resp);
 	}
 
 	@Test
-	public void manageVnfRequestTestV1(){
+	public void manageVnfRequestTestV1(@Mocked AbstractSessionFactoryManager sessionFactoryManager,
+                                       @Mocked Session session){
+        new Expectations() {{
+            sessionFactoryManager.getSessionFactory().openSession(); result = session;
+        }};
 		Mockito.when(uriInfo.getRequestUri()).thenReturn(URI.create("http://localhost:8080/test"));
 		Response resp = handler.manageNetworkRequest(REQ_XML, "v1");
 		assertTrue(null != resp);
 	}
 	
 	@Test
-	public void manageVnfRequestTestV3(){
+	public void manageVnfRequestTestV3(@Mocked AbstractSessionFactoryManager sessionFactoryManager,
+                                       @Mocked Session session){
+        new Expectations() {{
+            sessionFactoryManager.getSessionFactory().openSession(); result = session;
+        }};
 		Mockito.when(uriInfo.getRequestUri()).thenReturn(URI.create("http://localhost:8080/test"));
 		Response resp = handler.manageNetworkRequest(REQ_XML, "v3");
 		assertTrue(null != resp);
 	}
-
-	/*@Test
-	public void manageNetworkRequestTestV3Duplicate(){
-
-		MockUp<RequestsDatabase> mockDuplicate = new MockUp<RequestsDatabase>() {
-			@Mock
-			public InfraActiveRequests checkDuplicateByVnfName(String vnfName, String action, String requestType) {
-				return new InfraActiveRequests();
-			}
-		};
-
-		try {
-			Mockito.when(uriInfo.getRequestUri()).thenReturn(URI.create("http://localhost:8080/test"));
-			Response resp = handler.manageNetworkRequest(REQ_XML, "v3");
-			assertTrue(null != resp);
-		} finally {
-			mockDuplicate.tearDown();
-		}
-	}*/
 	
 	@Test
 	public void manageVnfRequestTestInvalidVersion(){
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequestsTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequestsTest.java
index be76d43..fa1cce4 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequestsTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequestsTest.java
@@ -183,7 +183,8 @@
 			Response response = null;

 			try {

 				OrchestrationRequests requests = new OrchestrationRequests();

-				response = requests.getOrchestrationRequest(new ResteasyUriInfo(new URI("")),"v5");

+				final ResteasyUriInfo ui = new ResteasyUriInfo(new URI("", "", "", "filter=service-instance-id:EQUALS:abc", ""));

+				response = requests.getOrchestrationRequest(ui,"v5");

 			} finally {

 				mockUpRDB.tearDown();

 			}

diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VnfMsoInfraRequestTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VnfMsoInfraRequestTest.java
index c8ab6b5..9a9dec3 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VnfMsoInfraRequestTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VnfMsoInfraRequestTest.java
@@ -7,9 +7,9 @@
  * 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.
@@ -20,19 +20,40 @@
 
 package org.openecomp.mso.apihandlerinfra;
 
-import static org.junit.Assert.assertTrue;
-
+import mockit.Expectations;
+import mockit.Mocked;
+import mockit.Tested;
+import mockit.integration.junit4.JMockit;
+import org.hibernate.Session;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
 import org.openecomp.mso.apihandler.common.ValidationException;
+import org.openecomp.mso.db.AbstractSessionFactoryManager;
 import org.openecomp.mso.properties.MsoJavaProperties;
 
+@RunWith(JMockit.class)
 public class VnfMsoInfraRequestTest {
-	VnfMsoInfraRequest request = new VnfMsoInfraRequest("29919020");
-	
-	@Test(expected=Exception.class)
-	public void parseTest() throws ValidationException {
-		String reqXML = "<vnf-request><request-info> <request-id>29993</request-id><request-status>COMPLETE</request-status></request-info></vnf-request>";
-		request.parse(reqXML, "v1", new MsoJavaProperties());
-	}
-	
+
+    VnfMsoInfraRequest request = new VnfMsoInfraRequest("29919020");
+    private String reqXML = "<vnf-request xmlns=\"http://org.openecomp/mso/infra/vnf-request/v1\"><request-info><request-id>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</request-id><action>CREATE_VF_MODULE</action><source>VID</source><!-- new 1610 field --><service-instance-id>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</service-instance-id></request-info><vnf-inputs><!-- not in use in 1610 --><vnf-name>vnfName</vnf-name><vnf-type>vnfType</vnf-type><vnf-id>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</vnf-id><volume-group-id>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</volume-group-id><vf-module-id>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</vf-module-id><vf-module-name>vfModuleName</vf-module-name><vf-module-model-name>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</vf-module-model-name><model-customization-id>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</model-customization-id><asdc-service-model-version>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</asdc-service-model-version><aic-cloud-region>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</aic-cloud-region><tenant-id>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</tenant-id><service-id>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</service-id><backout-on-failure>false</backout-on-failure><service-instance-id>43b34d6d-1ab2-4c7a-a3a0-5471306550c5</service-instance-id></vnf-inputs><vnf-params><vnf-parameter-name>pName</vnf-parameter-name><vnf-parameter-value>pValue</vnf-parameter-value></vnf-params></vnf-request>";
+
+    @Test
+    public void parseTest() throws ValidationException {
+        request.parse(reqXML, "v3", new MsoJavaProperties());
+    }
+
+    @Test
+    public void createRequestRecord(@Mocked AbstractSessionFactoryManager sessionFactoryManager,
+                                    @Mocked Session session) throws ValidationException {
+
+        new Expectations() {{
+            sessionFactoryManager.getSessionFactory().openSession(); result = session;
+        }};
+
+        request.parse(reqXML, "v3", new MsoJavaProperties());
+        request.createRequestRecord(Status.COMPLETE);
+
+    }
+
 }