diff options
author | Norm Traxler <normant@amdocs.com> | 2019-02-05 19:58:05 +0000 |
---|---|---|
committer | Norm Traxler <normant@amdocs.com> | 2019-02-05 19:58:26 +0000 |
commit | c727082e6809f7a3076809dceb218e80ce4456bf (patch) | |
tree | 2287b49dd6f714c1f8e181ea353d7e72985ae6a7 /pomba/service-decomposition/src/test | |
parent | 893e2ff0fe4f605b5ce6f709c6fab8fe65d242f5 (diff) |
Service Decomposition support for network
Issue-ID: SDNC-475
Add decompose of service-instance and vf-module "l3-network" relationships.
Some Sonar cleanup.
Change-Id: Ie944e6d8acac05ebdce1753176455d929daa2e97
Signed-off-by: Norm Traxler <normant@amdocs.com>
Diffstat (limited to 'pomba/service-decomposition/src/test')
5 files changed, 133 insertions, 404 deletions
diff --git a/pomba/service-decomposition/src/test/java/org/onap/sdnc/apps/pomba/servicedecomposition/test/AuthorizationConfigurationTest.java b/pomba/service-decomposition/src/test/java/org/onap/sdnc/apps/pomba/servicedecomposition/test/AuthorizationConfigurationTest.java index 4c7830b..319230a 100644 --- a/pomba/service-decomposition/src/test/java/org/onap/sdnc/apps/pomba/servicedecomposition/test/AuthorizationConfigurationTest.java +++ b/pomba/service-decomposition/src/test/java/org/onap/sdnc/apps/pomba/servicedecomposition/test/AuthorizationConfigurationTest.java @@ -25,10 +25,8 @@ import static org.mockito.Mockito.when; import org.junit.Test; import org.onap.sdnc.apps.pomba.servicedecomposition.AuthorizationConfiguration; -public class AuthorizationConfigurationTest -{ - AuthorizationConfiguration authorizationConfiguration = - mock(AuthorizationConfiguration.class); +public class AuthorizationConfigurationTest { + AuthorizationConfiguration authorizationConfiguration = mock(AuthorizationConfiguration.class); @Test public void testGetSdBasicAuthHeader() { diff --git a/pomba/service-decomposition/src/test/java/org/onap/sdnc/apps/pomba/servicedecomposition/test/ServiceDecompositionTest.java b/pomba/service-decomposition/src/test/java/org/onap/sdnc/apps/pomba/servicedecomposition/test/ServiceDecompositionTest.java index 37a5518..0680842 100644 --- a/pomba/service-decomposition/src/test/java/org/onap/sdnc/apps/pomba/servicedecomposition/test/ServiceDecompositionTest.java +++ b/pomba/service-decomposition/src/test/java/org/onap/sdnc/apps/pomba/servicedecomposition/test/ServiceDecompositionTest.java @@ -42,6 +42,7 @@ import org.json.JSONObject; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mockito; import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.sdnc.apps.pomba.servicedecomposition.service.rs.RestService; import org.springframework.beans.factory.annotation.Autowired; @@ -63,13 +64,15 @@ import org.springframework.test.context.web.WebAppConfiguration; "aai.servicePort=8081", "basicAuth.username=admin", "basicAuth.password=OBF:1u2a1toa1w8v1tok1u30" -}) + }) public class ServiceDecompositionTest { private static final String AUTH = "Basic " + Base64.getEncoder().encodeToString(( "admin:" + Password.deobfuscate("OBF:1u2a1toa1w8v1tok1u30")).getBytes()); + private HttpServletRequest httpRequest = Mockito.mock(HttpServletRequest.class); + // TODO missing code coverage for VNFC resources @Rule @@ -120,7 +123,6 @@ public class ServiceDecompositionTest { final String networkId1 = "HNP1d77c-1094-41ec-b7f3-94bb30951870"; final String networkId2 = "HNP1d77c-1094-41ec-b7f3-94bb30951872"; - HttpServletRequest httpRequest = new TestHttpServletRequest(); Response response = this.service.getContext(httpRequest, AUTH, "network-discovery-context-builder", null, serviceInstanceId); assertEquals(200, response.getStatus()); @@ -152,12 +154,79 @@ public class ServiceDecompositionTest { } @Test + public void testDemoFirewallServiceWithL3Networks() throws Exception { + // setup A&AI responses + addResponse( + "/aai/v13/nodes/service-instance/c6456519-6acf-4adb-997c-3c363dd4caaf", + "junit/aai-service-instance2.json"); + addResponse( + "/aai/v13/network/generic-vnfs/generic-vnf/6700c313-fbb7-4cf9-ac70-0293ec56df68?depth=2", + "junit/aai-generic-vnf1.json"); + addResponse( + "/aai/v13/network/generic-vnfs/generic-vnf/8a9ddb25-2e79-449c-a40d-5011bac0da39?depth=2", + "junit/aai-generic-vnf2.json"); + addResponse( + "/aai/v13/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/tenants/tenant" + + "/b49b830686654191bb1e952a74b014ad/vservers/vserver/b494cd6e-b9f3-45e0-afe7-e1d1a5f5d74a", + "junit/aai-vserver.json"); + addResponse( + "/aai/v13/network/l3-networks/l3-network/HNP1d77c-1094-41ec-b7f3-94bb30951870", + "junit/aai-l3-network1.json"); + addResponse( + "/aai/v13/network/l3-networks/l3-network/HNP1d77c-1094-41ec-b7f3-94bb30951872", + "junit/aai-l3-network2.json"); + + final String serviceInstanceId = "c6456519-6acf-4adb-997c-3c363dd4caaf"; + final String vnfId1 = "6700c313-fbb7-4cf9-ac70-0293ec56df68"; + final String vnfId2 = "8a9ddb25-2e79-449c-a40d-5011bac0da39"; + final String vserverId = "b494cd6e-b9f3-45e0-afe7-e1d1a5f5d74a"; + final String networkId1 = "HNP1d77c-1094-41ec-b7f3-94bb30951870"; + final String networkId2 = "HNP1d77c-1094-41ec-b7f3-94bb30951872"; + + Response response = this.service.getContext(httpRequest, AUTH, "network-discovery-context-builder", null, + serviceInstanceId); + assertEquals(200, response.getStatus()); + + JSONObject serviceInstance = new JSONObject((String)response.getEntity()); + + // verify two generic-vnfs added to service instance data + verifyResource(serviceInstance, "generic-vnfs", "vnf-id", vnfId1); + verifyResource(serviceInstance, "generic-vnfs", "vnf-id", vnfId2); + verifyResource(serviceInstance, "l3-networks", "network-id", networkId1); + + JSONArray vnfs = serviceInstance.getJSONArray("generic-vnfs"); + for (int i = 0; i < vnfs.length(); i++) { + JSONObject vnf = vnfs.getJSONObject(i); + String vnfId = vnf.getString("vnf-id"); + switch (vnfId) { + case vnfId1: + // verify vserver resource + verifyResource(vnf, "vservers", "vserver-id", vserverId); + break; + case vnfId2: + // verify network resources + verifyResource(vnf, "l3-networks", "network-id", networkId1); + verifyResource(vnf, "l3-networks", "network-id", networkId2); + JSONObject vfmodules = vnf.getJSONObject("vf-modules"); + JSONArray vfmoduleList = vfmodules.getJSONArray("vf-module"); + for (int j = 0; j < vfmoduleList.length(); j++) { + JSONObject vfmodule = vfmoduleList.getJSONObject(j); + verifyResource(vfmodule, "l3-networks", "network-id", networkId1); + } + break; + default: + fail("Unexpected generic-vnf " + vnfId); + } + } + } + + @Test public void testNoAuthHeader() throws Exception { String fromAppId = "junit"; String transactionId = null; String serviceInstanceId = "aServiceInstanceId"; // no Authorization header - Response response = this.service.getContext(new TestHttpServletRequest(), null, fromAppId, transactionId, + Response response = this.service.getContext(httpRequest, null, fromAppId, transactionId, serviceInstanceId); assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus()); // should get WWW-Authenticate header in response @@ -172,7 +241,7 @@ public class ServiceDecompositionTest { String transactionId = null; String serviceInstanceId = "aServiceInstanceId"; - Response response = this.service.getContext(new TestHttpServletRequest(), authorization, fromAppId, + Response response = this.service.getContext(httpRequest, authorization, fromAppId, transactionId, serviceInstanceId); assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus()); // should not get WWW-Authenticate header in response @@ -186,7 +255,7 @@ public class ServiceDecompositionTest { String transactionId = null; String serviceInstanceId = "someValue"; - Response response = this.service.getContext(new TestHttpServletRequest(), AUTH, fromAppId, transactionId, + Response response = this.service.getContext(httpRequest, AUTH, fromAppId, transactionId, serviceInstanceId); assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); assertTrue(((String)response.getEntity()).contains(ONAPLogConstants.Headers.PARTNER_NAME)); @@ -199,7 +268,7 @@ public class ServiceDecompositionTest { String transactionId = null; String serviceInstanceId = null; - Response response = this.service.getContext(new TestHttpServletRequest(), AUTH, fromAppId, transactionId, + Response response = this.service.getContext(httpRequest, AUTH, fromAppId, transactionId, serviceInstanceId); assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); assertTrue(((String)response.getEntity()).contains("service-instance-id")); @@ -211,7 +280,7 @@ public class ServiceDecompositionTest { aai.stubFor(get("/aai/v13/nodes/service-instance/noSuchServiceId").willReturn(notFound())); Response response = - this.service.getContext(new TestHttpServletRequest(), AUTH, "junit", null, "noSuchServiceId"); + this.service.getContext(httpRequest, AUTH, "junit", null, "noSuchServiceId"); assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); } diff --git a/pomba/service-decomposition/src/test/java/org/onap/sdnc/apps/pomba/servicedecomposition/test/TestHttpServletRequest.java b/pomba/service-decomposition/src/test/java/org/onap/sdnc/apps/pomba/servicedecomposition/test/TestHttpServletRequest.java deleted file mode 100644 index fc00a61..0000000 --- a/pomba/service-decomposition/src/test/java/org/onap/sdnc/apps/pomba/servicedecomposition/test/TestHttpServletRequest.java +++ /dev/null @@ -1,392 +0,0 @@ -/* - * ============LICENSE_START=================================================== - * Copyright (c) 2018 Amdocs - * ============================================================================ - * 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.sdnc.apps.pomba.servicedecomposition.test; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.security.Principal; -import java.util.Collection; -import java.util.Enumeration; -import java.util.Locale; -import java.util.Map; -import javax.servlet.AsyncContext; -import javax.servlet.DispatcherType; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletInputStream; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import javax.servlet.http.HttpUpgradeHandler; -import javax.servlet.http.Part; - -public class TestHttpServletRequest implements HttpServletRequest { - @Override - public String getHeader(String name) { - return null; - } - - @Override - public String getRemoteAddr() { - return "localhost"; - } - - @Override - public String getServerName() { - return "localhost"; - } - - @Override - public String getRequestURI() { - return "/test"; - } - - - @Override - public Object getAttribute(String name) { - throw new UnsupportedOperationException("getAttribute"); - } - - @Override - public Enumeration<String> getAttributeNames() { - throw new UnsupportedOperationException("getAttributeNames"); - } - - @Override - public String getCharacterEncoding() { - throw new UnsupportedOperationException("getCharacterEncoding"); - } - - @Override - public void setCharacterEncoding(String env) throws UnsupportedEncodingException { - throw new UnsupportedOperationException("setCharacterEncoding"); - } - - @Override - public int getContentLength() { - throw new UnsupportedOperationException("getContentLength"); - } - - @Override - public long getContentLengthLong() { - throw new UnsupportedOperationException("getContentLengthLong"); - } - - @Override - public String getContentType() { - throw new UnsupportedOperationException("getContentType"); - } - - @Override - public ServletInputStream getInputStream() throws IOException { - throw new UnsupportedOperationException("getInputStream"); - } - - @Override - public String getParameter(String name) { - throw new UnsupportedOperationException("getParameter"); - } - - @Override - public Enumeration<String> getParameterNames() { - throw new UnsupportedOperationException("getParameterNames"); - } - - @Override - public String[] getParameterValues(String name) { - throw new UnsupportedOperationException("getParameterValues"); - } - - @Override - public Map<String, String[]> getParameterMap() { - throw new UnsupportedOperationException("getParameterMap"); - } - - @Override - public String getProtocol() { - throw new UnsupportedOperationException("getProtocol"); - } - - @Override - public String getScheme() { - throw new UnsupportedOperationException("getScheme"); - } - - @Override - public int getServerPort() { - throw new UnsupportedOperationException("getServerPort"); - } - - @Override - public BufferedReader getReader() throws IOException { - throw new UnsupportedOperationException("getReader"); - } - - @Override - public String getRemoteHost() { - throw new UnsupportedOperationException("getRemoteHost"); - } - - @Override - public void setAttribute(String name, Object obj) { - throw new UnsupportedOperationException("setAttribute"); - } - - @Override - public void removeAttribute(String name) { - throw new UnsupportedOperationException("removeAttribute"); - } - - @Override - public Locale getLocale() { - throw new UnsupportedOperationException("getLocale"); - } - - @Override - public Enumeration<Locale> getLocales() { - throw new UnsupportedOperationException("getLocales"); - } - - @Override - public boolean isSecure() { - throw new UnsupportedOperationException("isSecure"); - } - - @Override - public RequestDispatcher getRequestDispatcher(String path) { - throw new UnsupportedOperationException("getRequestDispatcher"); - } - - @Override - public String getRealPath(String path) { - throw new UnsupportedOperationException("getRealPath"); - } - - @Override - public int getRemotePort() { - throw new UnsupportedOperationException("getRemotePort"); - } - - @Override - public String getLocalName() { - throw new UnsupportedOperationException("getLocalName"); - } - - @Override - public String getLocalAddr() { - throw new UnsupportedOperationException("getLocalAddr"); - } - - @Override - public int getLocalPort() { - throw new UnsupportedOperationException("getLocalPort"); - } - - @Override - public ServletContext getServletContext() { - throw new UnsupportedOperationException("getServletContext"); - } - - @Override - public AsyncContext startAsync() throws IllegalStateException { - throw new UnsupportedOperationException("startAsync"); - } - - @Override - public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) - throws IllegalStateException { - throw new UnsupportedOperationException("startAsync"); - } - - @Override - public boolean isAsyncStarted() { - throw new UnsupportedOperationException("isAsyncStarted"); - } - - @Override - public boolean isAsyncSupported() { - throw new UnsupportedOperationException("isAsyncSupported"); - } - - @Override - public AsyncContext getAsyncContext() { - throw new UnsupportedOperationException("getAsyncContext"); - } - - @Override - public DispatcherType getDispatcherType() { - throw new UnsupportedOperationException("getDispatcherType"); - } - - @Override - public String getAuthType() { - throw new UnsupportedOperationException("getAuthType"); - } - - @Override - public Cookie[] getCookies() { - throw new UnsupportedOperationException("getCookies"); - } - - @Override - public long getDateHeader(String name) { - throw new UnsupportedOperationException("getDateHeader"); - } - - @Override - public Enumeration<String> getHeaders(String name) { - throw new UnsupportedOperationException("getHeaders"); - } - - @Override - public Enumeration<String> getHeaderNames() { - throw new UnsupportedOperationException("getHeaderNames"); - } - - @Override - public int getIntHeader(String name) { - throw new UnsupportedOperationException("getIntHeader"); - } - - @Override - public String getMethod() { - throw new UnsupportedOperationException("getMethod"); - } - - @Override - public String getPathInfo() { - throw new UnsupportedOperationException("getPathInfo"); - } - - @Override - public String getPathTranslated() { - throw new UnsupportedOperationException("getPathTranslated"); - } - - @Override - public String getContextPath() { - throw new UnsupportedOperationException("getContextPath"); - } - - @Override - public String getQueryString() { - throw new UnsupportedOperationException("getQueryString"); - } - - @Override - public String getRemoteUser() { - throw new UnsupportedOperationException("getRemoteUser"); - } - - @Override - public boolean isUserInRole(String role) { - throw new UnsupportedOperationException("isUserInRole"); - } - - @Override - public Principal getUserPrincipal() { - throw new UnsupportedOperationException("getUserPrincipal"); - } - - @Override - public String getRequestedSessionId() { - throw new UnsupportedOperationException("getRequestedSessionId"); - } - - @Override - public StringBuffer getRequestURL() { - throw new UnsupportedOperationException("getRequestURL"); - } - - @Override - public String getServletPath() { - throw new UnsupportedOperationException("getServletPath"); - } - - @Override - public HttpSession getSession(boolean create) { - throw new UnsupportedOperationException("getSession"); - } - - @Override - public HttpSession getSession() { - throw new UnsupportedOperationException("getSession"); - } - - @Override - public String changeSessionId() { - throw new UnsupportedOperationException("changeSessionId"); - } - - @Override - public boolean isRequestedSessionIdValid() { - throw new UnsupportedOperationException("isRequestedSessionIdValid"); - } - - @Override - public boolean isRequestedSessionIdFromCookie() { - throw new UnsupportedOperationException("isRequestedSessionIdFromCookie"); - } - - @Override - public boolean isRequestedSessionIdFromURL() { - throw new UnsupportedOperationException("isRequestedSessionIdFromURL"); - } - - @Override - public boolean isRequestedSessionIdFromUrl() { - throw new UnsupportedOperationException("isRequestedSessionIdFromUrl"); - } - - @Override - public boolean authenticate(HttpServletResponse response) throws IOException, ServletException { - throw new UnsupportedOperationException("authenticate"); - } - - @Override - public void login(String username, String password) throws ServletException { - throw new UnsupportedOperationException("login"); - } - - @Override - public void logout() throws ServletException { - throw new UnsupportedOperationException("logout"); - } - - @Override - public Collection<Part> getParts() throws IOException, ServletException { - throw new UnsupportedOperationException("getParts"); - } - - @Override - public Part getPart(String name) throws IOException, ServletException { - throw new UnsupportedOperationException("getPart"); - } - - @Override - public <T extends HttpUpgradeHandler> T upgrade(Class<T> httpUpgradeHandlerClass) - throws IOException, ServletException { - throw new UnsupportedOperationException("upgrade"); - } -} diff --git a/pomba/service-decomposition/src/test/resources/junit/aai-generic-vnf2.json b/pomba/service-decomposition/src/test/resources/junit/aai-generic-vnf2.json index f96431e..8ea03bf 100644 --- a/pomba/service-decomposition/src/test/resources/junit/aai-generic-vnf2.json +++ b/pomba/service-decomposition/src/test/resources/junit/aai-generic-vnf2.json @@ -89,7 +89,14 @@ "model-invariant-id": "74bc1518-282d-4148-860f-8892b6369456", "model-version-id": "4e3d28cf-d654-41af-a47b-04b4bd0ac58e", "model-customization-id": "cc51ab7d-9b03-4bd6-9104-09df0c7c7907", - "module-index": 0 + "module-index": 0, + "relationship-list": { + "relationship": [ + { + "related-to": "l3-network", + "related-link": "/aai/v13/network/l3-networks/l3-network/HNP1d77c-1094-41ec-b7f3-94bb30951870" + }] + } } ] } diff --git a/pomba/service-decomposition/src/test/resources/junit/aai-service-instance2.json b/pomba/service-decomposition/src/test/resources/junit/aai-service-instance2.json new file mode 100644 index 0000000..2d3acc8 --- /dev/null +++ b/pomba/service-decomposition/src/test/resources/junit/aai-service-instance2.json @@ -0,0 +1,47 @@ +{ + "service-instance-id": "c6456519-6acf-4adb-997c-3c363dd4caaf", + "service-instance-name": "Firewall1", + "model-invariant-id": "0c5a20de-87ad-442c-9190-f38ab0a6bb7f", + "model-version-id": "d3d6cf83-d03a-43cc-99ff-206d40bb9a72", + "resource-version": "1527637758480", + "relationship-list": { + "relationship": [ + { + "related-to": "l3-network", + "related-link": "/aai/v13/network/l3-networks/l3-network/HNP1d77c-1094-41ec-b7f3-94bb30951870" + }, + { + "related-to": "generic-vnf", + "related-link": "/aai/v13/network/generic-vnfs/generic-vnf/6700c313-fbb7-4cf9-ac70-0293ec56df68", + "relationship-data": [ + { + "relationship-key": "generic-vnf.vnf-id", + "relationship-value": "6700c313-fbb7-4cf9-ac70-0293ec56df68" + } + ], + "related-to-property": [ + { + "property-key": "generic-vnf.vnf-name", + "property-value": "PacketGenerator-1" + } + ] + }, + { + "related-to": "generic-vnf", + "related-link": "/aai/v13/network/generic-vnfs/generic-vnf/8a9ddb25-2e79-449c-a40d-5011bac0da39", + "relationship-data": [ + { + "relationship-key": "generic-vnf.vnf-id", + "relationship-value": "8a9ddb25-2e79-449c-a40d-5011bac0da39" + } + ], + "related-to-property": [ + { + "property-key": "generic-vnf.vnf-name", + "property-value": "Firewall-1" + } + ] + } + ] + } +} |