From 2b8e432c7207a59b8d539bd365ed3899de8565f6 Mon Sep 17 00:00:00 2001 From: Seshu-Kumar-M Date: Fri, 6 Oct 2017 20:51:13 +0800 Subject: UT for MSOinfra SO-171 Change-Id: Id3af1d70eb603b1f4fd54226a0f602e9fde78b6a Signed-off-by: Seshu-Kumar-M --- .../apihandlerinfra/NetworkRequestHandlerTest.java | 68 ++++++++++ .../apihandlerinfra/VnfMsoInfraRequestTest.java | 38 ++++++ .../mso/apihandlerinfra/VnfRequestHandlerTest.java | 93 +++++++++++++- .../apihandlerinfra/VolumeRequestHandlerTest.java | 139 ++++++++++++++++++++- 4 files changed, 335 insertions(+), 3 deletions(-) create mode 100644 mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VnfMsoInfraRequestTest.java (limited to 'mso-api-handlers') 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 3feb168f51..3c5c89fc92 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 @@ -24,6 +24,9 @@ import static org.junit.Assert.assertTrue; import java.lang.reflect.Field; import java.net.URI; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; @@ -35,7 +38,9 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; import org.openecomp.mso.apihandlerinfra.networkbeans.NetworkRequest; +import org.openecomp.mso.requestsdb.InfraActiveRequests; import org.openecomp.mso.requestsdb.InfraRequests; +import org.openecomp.mso.requestsdb.RequestsDatabase; public class NetworkRequestHandlerTest { @@ -61,6 +66,23 @@ UriInfo uriInfo = null; Response resp = handler.manageNetworkRequest("Test", "v2"); assertTrue(null != resp); } + @Test + public void manageVnfRequestTestV1(){ + Response resp = handler.manageNetworkRequest("Test", "v1"); + assertTrue(null != resp); + } + + @Test + public void manageVnfRequestTestV3(){ + Response resp = handler.manageNetworkRequest("Test", "v3"); + assertTrue(null != resp); + } + + @Test + public void manageVnfRequestTestInvalidVersion(){ + Response resp = handler.manageNetworkRequest("Test", "v249"); + assertTrue(null != resp); + } @Test public void manageVnfRequest2Test(){ @@ -150,4 +172,50 @@ UriInfo uriInfo = null; assertTrue(param.equals("test")); } + @Test + public void queryFiltersTest(){ + new MockUp() { + @Mock + public List getRequestListFromInfraActive (String queryAttributeName, + String queryValue, + String requestType) { + List list = new ArrayList(); + InfraActiveRequests req = new InfraActiveRequests(); + req.setAaiServiceId("299392"); + req.setAction("CREATE"); + req.setRequestStatus("COMPLETE"); + req.setProgress(10001l); + req.setSource("test"); + req.setStartTime(new Timestamp(10020100)); + req.setEndTime(new Timestamp(20020100)); + req.setStatusMessage("message"); + list.add(req); + return list; + } + }; + Response resp = handler.queryFilters("networkType", "serviceType", "aicNodeClli", "tenantId", "v1"); + assertTrue(resp.getEntity().toString() != null); + } + + @Test + public void getRequestTest(){ + new MockUp() { + @Mock + public InfraActiveRequests getRequestFromInfraActive (String requestId, String requestType) { + InfraActiveRequests req = new InfraActiveRequests(); + req.setAaiServiceId("299392"); + req.setAction("CREATE"); + req.setRequestStatus("COMPLETE"); + req.setProgress(10001l); + req.setSource("test"); + req.setStartTime(new Timestamp(10020100)); + req.setEndTime(new Timestamp(20020100)); + req.setStatusMessage("message"); + return req; + } + }; + Response resp = handler.getRequest("388293", "v1"); + assertTrue(resp.getEntity().toString() != null); + } + } 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 new file mode 100644 index 0000000000..c8ab6b5612 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VnfMsoInfraRequestTest.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T 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.apihandlerinfra; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openecomp.mso.apihandler.common.ValidationException; +import org.openecomp.mso.properties.MsoJavaProperties; + +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()); + } + +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VnfRequestHandlerTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VnfRequestHandlerTest.java index 8d06b40074..2d3a2a47a5 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VnfRequestHandlerTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VnfRequestHandlerTest.java @@ -24,6 +24,9 @@ import static org.junit.Assert.assertTrue; import java.lang.reflect.Field; import java.net.URI; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; import mockit.Mock; import mockit.MockUp; @@ -32,7 +35,9 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; import org.openecomp.mso.apihandlerinfra.vnfbeans.VnfRequest; +import org.openecomp.mso.requestsdb.InfraActiveRequests; import org.openecomp.mso.requestsdb.InfraRequests; +import org.openecomp.mso.requestsdb.RequestsDatabase; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; @@ -55,10 +60,25 @@ public class VnfRequestHandlerTest { } @Test - public void manageVnfRequestTest(){ + public void manageVnfRequestTestV2(){ Response resp = handler.manageVnfRequest("Test", "v2"); assertTrue(null != resp); } + @Test + public void manageVnfRequestTestv1(){ + Response resp = handler.manageVnfRequest("Test", "v1"); + assertTrue(null != resp); + } + @Test + public void manageVnfRequestTestv3(){ + Response resp = handler.manageVnfRequest("Test", "v3"); + assertTrue(null != resp); + } + @Test + public void manageVnfRequestTestInvalidVersion(){ + Response resp = handler.manageVnfRequest("Test", "v30"); + assertTrue(null != resp); + } @Test public void manageVnfRequest2Test(){ @@ -149,5 +169,76 @@ public class VnfRequestHandlerTest { String param = (String)qr.getVnfParams(); assertTrue(param.equals("test")); } + + @Test + public void queryFiltersTest(){ + new MockUp() { + @Mock + public List getRequestListFromInfraActive (String queryAttributeName, + String queryValue, + String requestType) { + List list = new ArrayList(); + InfraActiveRequests req = new InfraActiveRequests(); + req.setAaiServiceId("299392"); + req.setAction("CREATE"); + req.setRequestStatus("COMPLETE"); + req.setProgress(10001l); + req.setSource("test"); + req.setStartTime(new Timestamp(10020100)); + req.setEndTime(new Timestamp(20020100)); + req.setStatusMessage("message"); + list.add(req); + return list; + } + }; + Response resp = handler.queryFilters("vnfType", "serviceType", "aicNodeClli", "tenantId", "volumeGroupId", "volumeGroupName", "vnfName", "v1"); + assertTrue(resp.getEntity().toString() != null); + } + + @Test + public void queryFiltersTestNullVnfType(){ + new MockUp() { + @Mock + public List getRequestListFromInfraActive (String queryAttributeName, + String queryValue, + String requestType) { + List list = new ArrayList(); + InfraActiveRequests req = new InfraActiveRequests(); + req.setAaiServiceId("299392"); + req.setAction("CREATE"); + req.setRequestStatus("COMPLETE"); + req.setProgress(10001l); + req.setSource("test"); + req.setStartTime(new Timestamp(10020100)); + req.setEndTime(new Timestamp(20020100)); + req.setStatusMessage("message"); + list.add(req); + return list; + } + }; + Response resp = handler.queryFilters(null, null, null, null, null, null, null, "v1"); + assertTrue(resp.getEntity().toString() != null); + } + + @Test + public void getRequestTest(){ + new MockUp() { + @Mock + public InfraActiveRequests getRequestFromInfraActive (String requestId, String requestType) { + InfraActiveRequests req = new InfraActiveRequests(); + req.setAaiServiceId("299392"); + req.setAction("CREATE"); + req.setRequestStatus("COMPLETE"); + req.setProgress(10001l); + req.setSource("test"); + req.setStartTime(new Timestamp(10020100)); + req.setEndTime(new Timestamp(20020100)); + req.setStatusMessage("message"); + return req; + } + }; + Response resp = handler.getRequest("388293", "v1"); + assertTrue(resp.getEntity().toString() != null); + } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VolumeRequestHandlerTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VolumeRequestHandlerTest.java index be41944b31..bf4d7c4d98 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VolumeRequestHandlerTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/VolumeRequestHandlerTest.java @@ -24,6 +24,9 @@ import static org.junit.Assert.assertTrue; import java.lang.reflect.Field; import java.net.URI; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; @@ -34,6 +37,10 @@ import mockit.MockUp; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; +import org.openecomp.mso.apihandler.common.ValidationException; +import org.openecomp.mso.properties.MsoJavaProperties; +import org.openecomp.mso.requestsdb.InfraActiveRequests; +import org.openecomp.mso.requestsdb.RequestsDatabase; public class VolumeRequestHandlerTest { VolumeRequestHandler handler = null; @@ -60,7 +67,7 @@ public class VolumeRequestHandlerTest { } @Test - public void manageVnfRequest2Test(){ + public void manageVnfRequest2TestV1InvalidRequestData(){ Mockito.when(uriInfo.getRequestUri()) .thenReturn(URI.create("http://localhost:8080/test")); @@ -70,7 +77,135 @@ public class VolumeRequestHandlerTest { return false; } }; - Response resp = handler.manageVolumeRequest("Test", "v2"); + String request = "{\"result\":\"success\"}"; + Response resp = handler.manageVolumeRequest(request, "v1"); + assertTrue(null != resp); + } + + @Test + public void manageVnfRequest2TestV1(){ + Mockito.when(uriInfo.getRequestUri()) + .thenReturn(URI.create("http://localhost:8080/test")); + + new MockUp() { + @Mock + public synchronized final boolean getNoPropertiesState() { + return false; + } + }; + String request = "CREATECOMPLETEmessage100011970-01-01 02:47:00.11970-01-01 05:33:40.1test299392"; + Response resp = handler.manageVolumeRequest(request, "v1"); + assertTrue(null != resp); + } + + @Test + public void manageVnfRequest2TestV2(){ + Mockito.when(uriInfo.getRequestUri()) + .thenReturn(URI.create("http://localhost:8080/test")); + + new MockUp() { + @Mock + public synchronized final boolean getNoPropertiesState() { + return false; + } + }; + String request = "CREATECOMPLETEmessage100011970-01-01 02:47:00.11970-01-01 05:33:40.1test299392"; + Response resp = handler.manageVolumeRequest(request, "v2"); assertTrue(null != resp); } + @Test + public void manageVnfRequest2TestV3(){ + Mockito.when(uriInfo.getRequestUri()) + .thenReturn(URI.create("http://localhost:8080/test")); + + new MockUp() { + @Mock + public synchronized final boolean getNoPropertiesState() { + return false; + } + }; + String request = "CREATECOMPLETEmessage100011970-01-01 02:47:00.11970-01-01 05:33:40.1test299392"; + Response resp = handler.manageVolumeRequest(request, "v3"); + assertTrue(null != resp); + } + @Test + public void manageVnfRequest2TestInvalidVersion(){ + Mockito.when(uriInfo.getRequestUri()) + .thenReturn(URI.create("http://localhost:8080/test")); + + new MockUp() { + @Mock + public synchronized final boolean getNoPropertiesState() { + return false; + } + }; + String request = "CREATECOMPLETEmessage100011970-01-01 02:47:00.11970-01-01 05:33:40.1test299392"; + Response resp = handler.manageVolumeRequest(request, "v33"); + assertTrue(null != resp); + } + + @Test + public void queryFiltersTest(){ + new MockUp() { + @Mock + public List getRequestListFromInfraActive (String queryAttributeName, + String queryValue, + String requestType) { + List list = new ArrayList(); + InfraActiveRequests req = new InfraActiveRequests(); + req.setAaiServiceId("299392"); + req.setAction("CREATE"); + req.setRequestStatus("COMPLETE"); + req.setProgress(10001l); + req.setSource("test"); + req.setStartTime(new Timestamp(10020100)); + req.setEndTime(new Timestamp(20020100)); + req.setStatusMessage("message"); + list.add(req); + return list; + } + }; + Response resp = handler.queryFilters("vnfType", "serviceType", "aic", "19929293", "288393923", "test", "v1"); + assertTrue(resp.getEntity().toString() != null); + } + @Test + public void getRequestTestV3(){ + new MockUp() { + @Mock + public InfraActiveRequests getRequestFromInfraActive (String requestId, String requestType) { + InfraActiveRequests req = new InfraActiveRequests(); + req.setAaiServiceId("299392"); + req.setAction("CREATE"); + req.setRequestStatus("COMPLETE"); + req.setProgress(10001l); + req.setSource("test"); + req.setStartTime(new Timestamp(10020100)); + req.setEndTime(new Timestamp(20020100)); + req.setStatusMessage("message"); + return req; + } + }; + Response resp = handler.getRequest("399293", "v3"); + assertTrue(resp.getEntity().toString() != null); + } + @Test + public void getRequestTestV2(){ + new MockUp() { + @Mock + public InfraActiveRequests getRequestFromInfraActive (String requestId, String requestType) { + InfraActiveRequests req = new InfraActiveRequests(); + req.setAaiServiceId("299392"); + req.setAction("CREATE"); + req.setRequestStatus("COMPLETE"); + req.setProgress(10001l); + req.setSource("test"); + req.setStartTime(new Timestamp(10020100)); + req.setEndTime(new Timestamp(20020100)); + req.setStatusMessage("message"); + return req; + } + }; + Response resp = handler.getRequest("399293", "v2"); + assertTrue(resp.getEntity().toString() != null); + } } -- cgit 1.2.3-korg