From b454a280561c0f5e040db9a63088e536710b31cd Mon Sep 17 00:00:00 2001 From: Abhishek Shekhar Date: Wed, 28 Mar 2018 19:46:15 +0530 Subject: UT Coverage for API Handler 1. VnfMsoInfraRequest 2. MsoRequest 3. NetworkRequestHandler 4. OrchestrationRequests Change-Id: Id85e5bd157bb491287ffb229f7b87c501554ca0f Issue-ID: SO-369 Signed-off-by: Abhishek Shekhar --- .../mso/apihandlerinfra/MsoRequestTest.java | 24 +++++++++++ .../apihandlerinfra/NetworkRequestHandlerTest.java | 50 ++++++++-------------- .../apihandlerinfra/OrchestrationRequestsTest.java | 3 +- .../apihandlerinfra/VnfMsoInfraRequestTest.java | 45 +++++++++++++------ 4 files changed, 78 insertions(+), 44 deletions(-) (limited to 'mso-api-handlers/mso-api-handler-infra/src/test/java') 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 7963217721..7fb3bf00b0 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.assertNotNull; 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 @@ public class MsoRequestTest { 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 b182192257..2089cf1d32 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 java.util.List; 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.mockito.Mockito; 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 @@ public class NetworkRequestHandlerTest { private static final String REQ_XML = " e1fc3ed3-31e5-48a8-913b-23184c1e9443CREATE VID e1fc3ed3-31e5-48a8-913b-23184c1e9443 e1fc3ed3-31e5-48a8-913b-23184c1e9443 nwInstanceName nwModelNamee1fc3ed3-31e5-48a8-913b-23184c1e9443 e1fc3ed3-31e5-48a8-913b-23184c1e9443 e1fc3ed3-31e5-48a8-913b-23184c1e9443e1fc3ed3-31e5-48a8-913b-23184c1e9443 false1802e1fc3ed3-31e5-48a8-913b-23184c1e9443 "; private static MockUp mockRDB; - private static MockUp mockMsoRequest; private static MockUp mockCDB; private static MockUp mockCamundaClient; @@ -107,13 +110,6 @@ public class NetworkRequestHandlerTest { } }; - mockMsoRequest = new MockUp() { - @Mock - public void createRequestRecord (Status status) { - return; - } - }; - mockCDB = new MockUp() { @Mock public NetworkRecipe getNetworkRecipe (String networkType, String action, String serviceType) { @@ -157,50 +153,42 @@ public class NetworkRequestHandlerTest { @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 mockDuplicate = new MockUp() { - @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 be76d433aa..fa1cce462f 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 @@ public class OrchestrationRequestsTest { 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 c8ab6b5612..9a9dec3c27 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 = " 29993COMPLETE"; - request.parse(reqXML, "v1", new MsoJavaProperties()); - } - + + VnfMsoInfraRequest request = new VnfMsoInfraRequest("29919020"); + private String reqXML = "43b34d6d-1ab2-4c7a-a3a0-5471306550c5CREATE_VF_MODULEVID43b34d6d-1ab2-4c7a-a3a0-5471306550c5vnfNamevnfType43b34d6d-1ab2-4c7a-a3a0-5471306550c543b34d6d-1ab2-4c7a-a3a0-5471306550c543b34d6d-1ab2-4c7a-a3a0-5471306550c5vfModuleName43b34d6d-1ab2-4c7a-a3a0-5471306550c543b34d6d-1ab2-4c7a-a3a0-5471306550c543b34d6d-1ab2-4c7a-a3a0-5471306550c543b34d6d-1ab2-4c7a-a3a0-5471306550c543b34d6d-1ab2-4c7a-a3a0-5471306550c543b34d6d-1ab2-4c7a-a3a0-5471306550c5false43b34d6d-1ab2-4c7a-a3a0-5471306550c5pNamepValue"; + + @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); + + } + } -- cgit 1.2.3-korg