summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/pomba/contextbuilder/sdnc/test/JerseyConfigurationTest.java35
-rw-r--r--src/test/java/org/onap/pomba/contextbuilder/sdnc/test/WebConfigurationTest.java39
-rw-r--r--src/test/java/org/onap/pomba/contextbuilder/sdnc/unittest/service/SdncContextBuilderTest.java155
-rw-r--r--src/test/resources/sdncResponse.json1
4 files changed, 230 insertions, 0 deletions
diff --git a/src/test/java/org/onap/pomba/contextbuilder/sdnc/test/JerseyConfigurationTest.java b/src/test/java/org/onap/pomba/contextbuilder/sdnc/test/JerseyConfigurationTest.java
new file mode 100644
index 0000000..df58cd1
--- /dev/null
+++ b/src/test/java/org/onap/pomba/contextbuilder/sdnc/test/JerseyConfigurationTest.java
@@ -0,0 +1,35 @@
+/*
+ * ============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.pomba.contextbuilder.sdnc.test;
+
+import static org.junit.Assert.assertEquals;
+
+import javax.ws.rs.client.Client;
+import org.junit.Test;
+import org.onap.pomba.contextbuilder.sdnc.JerseyConfiguration;
+
+public class JerseyConfigurationTest {
+ @Test
+ public void testJerseyConfiguration() {
+ JerseyConfiguration jerseyConfiguration = new JerseyConfiguration();
+ Client client = jerseyConfiguration.jerseyClient();
+ String protocol = client.getSslContext().getProtocol();
+ assertEquals("TLS", protocol);
+ }
+}
diff --git a/src/test/java/org/onap/pomba/contextbuilder/sdnc/test/WebConfigurationTest.java b/src/test/java/org/onap/pomba/contextbuilder/sdnc/test/WebConfigurationTest.java
new file mode 100644
index 0000000..17f3f8c
--- /dev/null
+++ b/src/test/java/org/onap/pomba/contextbuilder/sdnc/test/WebConfigurationTest.java
@@ -0,0 +1,39 @@
+/*
+ * ============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.pomba.contextbuilder.sdnc.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+
+import org.junit.Test;
+import org.onap.pomba.contextbuilder.sdnc.WebConfiguration;
+import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+
+public class WebConfigurationTest {
+ @Test
+ public void runTest() {
+ WebConfiguration webConfiguration = new WebConfiguration();
+ WebMvcConfigurerAdapter webMvConfigurationAdapter = webConfiguration.forwardToIndex();
+ ViewResolverRegistry registry = mock(ViewResolverRegistry.class);
+ webMvConfigurationAdapter.configureViewResolvers(registry);
+ assertEquals(false, registry.hasRegistrations());
+ }
+
+}
diff --git a/src/test/java/org/onap/pomba/contextbuilder/sdnc/unittest/service/SdncContextBuilderTest.java b/src/test/java/org/onap/pomba/contextbuilder/sdnc/unittest/service/SdncContextBuilderTest.java
new file mode 100644
index 0000000..91ab1cf
--- /dev/null
+++ b/src/test/java/org/onap/pomba/contextbuilder/sdnc/unittest/service/SdncContextBuilderTest.java
@@ -0,0 +1,155 @@
+/*
+ * ============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.pomba.contextbuilder.sdnc.unittest.service;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.okJson;
+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.github.jknack.handlebars.internal.Files;
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+import java.io.File;
+import java.util.Collections;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.pomba.contextbuilder.sdnc.service.rs.RestService;
+import org.onap.pomba.contextbuilder.sdnc.util.RestUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
+@WebAppConfiguration
+@SpringBootTest
+@TestPropertySource(properties = {"sdnc.host=localhost", "sdnc.port=30202"})
+public class SdncContextBuilderTest {
+
+ private String serviceInstanceId = "c6456519-6acf-4adb-997c-3c363dd4caaf";
+ private String testRestHeaders = "testRestHeaders";
+ @Autowired
+ RestService service;
+ @Autowired
+ private String sdncCtxBuilderBasicAuthorization;
+
+ @Rule
+ public WireMockRule sdncRule = new WireMockRule(wireMockConfig().port(30202));
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testRestHeaders() throws Exception {
+ HttpHeaders mockHttpHeaders = mock( HttpHeaders.class);
+
+ // Test with No Partner Name
+ final MultivaluedMap<String, String> multivaluedMapImpl = buildHeaders(
+ null, testRestHeaders, sdncCtxBuilderBasicAuthorization);
+
+ when(mockHttpHeaders.getRequestHeaders()).thenReturn(multivaluedMapImpl);
+ Response response = service.getContext(mockHttpHeaders, serviceInstanceId);
+ assertTrue(response.getEntity().toString().contains("Missing header parameter: " + RestUtil.FROM_APP_ID));
+
+ // Test with no Authorization
+ final MultivaluedMap<String, String> multivaluedMapImpl1 = buildHeaders(
+ "test2", testRestHeaders, null);
+
+ when(mockHttpHeaders.getRequestHeaders()).thenReturn(multivaluedMapImpl1);
+ response = service.getContext(mockHttpHeaders, serviceInstanceId);
+ assertTrue(response.getEntity().toString().contains("Missing header parameter: " + RestUtil.AUTHORIZATION));
+
+ // Test with garbage Authorization
+ final MultivaluedMap<String, String> multivaluedMapImpl2 = buildHeaders(
+ "test2", testRestHeaders, "garbage");
+
+ when(mockHttpHeaders.getRequestHeaders()).thenReturn(multivaluedMapImpl2);
+ response = service.getContext(mockHttpHeaders, serviceInstanceId);
+ assertTrue(response.getEntity().toString().contains("Failed Basic " + RestUtil.AUTHORIZATION));
+ }
+
+ @Test
+ public void testRestParameterServiceInstanceId() throws Exception {
+ HttpHeaders mockHttpHeaders = mock( HttpHeaders.class);
+ final MultivaluedMap<String, String> multivaluedMapImpl = buildHeaders(
+ "testRestParameterServiceInstanceId", "test1", sdncCtxBuilderBasicAuthorization);
+
+ when(mockHttpHeaders.getRequestHeaders()).thenReturn(multivaluedMapImpl);
+ Response response = service.getContext(mockHttpHeaders, null);
+ assertTrue(response.getEntity().toString().contains("Invalid request URL, missing parameter: serviceInstanceId"));
+ }
+
+ @Test
+ public void testVerifySdncContextBuilder() throws Exception {
+
+ String urlStr = "/restconf/config/GENERIC-RESOURCE-API:services/service/" + serviceInstanceId;
+ File file = new File(ClassLoader.getSystemResource("sdncResponse.json").getFile());
+ String sdResonse = Files.read(file);
+ this.sdncRule.stubFor(get(urlStr).willReturn(okJson(sdResonse)));
+
+ HttpHeaders mockHttpHeaders = mock( HttpHeaders.class);
+ final MultivaluedMap<String, String> multivaluedMapImpl = buildHeaders(
+ "testVerifyServiceDecomposition", "test1", sdncCtxBuilderBasicAuthorization);
+
+ when(mockHttpHeaders.getRequestHeaders()).thenReturn(multivaluedMapImpl);
+ Response response = this.service.getContext(mockHttpHeaders, serviceInstanceId);
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+
+ // Try again with no transcactionId
+ final MultivaluedMap<String, String> multivaluedMapImpl1 = buildHeaders(
+ "testVerifyServiceDecomposition", null, sdncCtxBuilderBasicAuthorization);
+
+ when(mockHttpHeaders.getRequestHeaders()).thenReturn(multivaluedMapImpl1);
+ response = this.service.getContext(mockHttpHeaders, serviceInstanceId);
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ }
+
+ private static MultivaluedMap<String, String> buildHeaders(
+ String partnerName, String transactionId, String authorization) {
+
+ MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
+ headers.put(RestUtil.FROM_APP_ID, Collections.singletonList(partnerName));
+ headers.put(RestUtil.TRANSACTION_ID, Collections.singletonList(transactionId));
+ if (null != authorization) {
+ headers.put(RestUtil.AUTHORIZATION, Collections.singletonList(authorization));
+ }
+ return headers;
+ }
+}
diff --git a/src/test/resources/sdncResponse.json b/src/test/resources/sdncResponse.json
new file mode 100644
index 0000000..25499c9
--- /dev/null
+++ b/src/test/resources/sdncResponse.json
@@ -0,0 +1 @@
+{"service":[{"service-instance-id":"7d518257-49bd-40ac-8d17-017a726ec12a","service-status":{"final-indicator":"Y","rpc-action":"assign","rpc-name":"vf-module-topology-operation","response-code":"200","response-timestamp":"2018-08-27T01:58:25.652Z","action":"CreateVfModuleInstance","response-message":"","request-status":"synccomplete"},"service-data":{"service-request-input":{"service-instance-name":"vcpe_svc_vcpesvc_rescust_0822a_201808262153","service-input-parameters":{"param":[{"name":"BRG_WAN_MAC_Address","value":"fa:16:3e:79:24:0e"},{"name":"customerLongitude","value":"-97.040443"},{"name":"customerLatitude","value":"32.897480"},{"name":"Homing_Solution","value":"sniro"},{"name":"customerName","value":"some_company"}]}},"service-information":{"service-id":"a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb","onap-model-information":{"model-invariant-uuid":"3a4e6986-5c5e-434e-b0be-8d718107fa83","model-name":"vcpesvc_rescust_0822a","model-version":"1.0","model-uuid":"209efacc-54d4-4f12-9064-099d47c36a29"},"service-instance-id":"7d518257-49bd-40ac-8d17-017a726ec12a","global-customer-id":"SDN-ETHERNET-INTERNET","subscription-service-type":"vCPE"},"service-topology":{"service-topology-identifier":{"service-instance-id":"7d518257-49bd-40ac-8d17-017a726ec12a","service-instance-name":"vcpe_svc_vcpesvc_rescust_0822a_201808262153","global-customer-id":"SDN-ETHERNET-INTERNET","service-type":"vCPE"},"onap-model-information":{"model-invariant-uuid":"3a4e6986-5c5e-434e-b0be-8d718107fa83","model-name":"vcpesvc_rescust_0822a","model-version":"1.0","model-uuid":"209efacc-54d4-4f12-9064-099d47c36a29"}},"sdnc-request-header":{"svc-action":"assign","svc-request-id":"dd3dffc8-6a15-4f7f-9787-d835ee247283","svc-notification-url":"http://c1.vm1.mso.simpledemo.openecomp.org:8080/adapters/rest/SDNCNotify"},"request-information":{"request-id":"2a950a5c-21bf-4496-a592-b51f45719603","request-action":"CreateServiceInstance","source":"MSO"},"vnfs":{"vnf":[{"vnf-id":"bf2a200d-744f-4900-afc4-d5ef44638467","vnf-data":{"vf-modules":{"vf-module":[{"vf-module-id":"815e8636-5c2a-41ad-b24d-17c824106bd2","vf-module-data":{"service-information":{"service-id":"null","onap-model-information":{"model-invariant-uuid":"3a4e6986-5c5e-434e-b0be-8d718107fa83","model-name":"vcpesvc_rescust_0822a","model-version":"1.0","model-uuid":"209efacc-54d4-4f12-9064-099d47c36a29"},"service-instance-id":"7d518257-49bd-40ac-8d17-017a726ec12a","global-customer-id":"SDN-ETHERNET-INTERNET","subscription-service-type":"null"},"vf-module-topology":{"onap-model-information":{"model-invariant-uuid":"7e91451d-e320-4755-a1a8-fcf140b86779","model-name":"VcpevspVgw0822a..base_vcpe_vgw..module-0","model-version":"1","model-customization-uuid":"7fbb59b7-a7ac-4fa6-b0bc-42f47339010a","model-uuid":"1908874e-cfae-4ee1-93b9-f4ba46b460ff"},"vf-module-parameters":{"param":[{"name":"mux_ip_addr","value":"10.5.0.21"},{"name":"mux_gw_private_net_id","value":"vcpe_net_mux_gw_201808231522"},{"name":"vg_vgmux_tunnel_vni","value":"107"},{"name":"repo_url_artifacts","value":"https://nexus.onap.org/content/groups/staging"},{"name":"cpe_public_net_id","value":"vcpe_net_cpe_public_201808231522"},{"name":"key_name","value":"vgw_key"},{"name":"onap_private_subnet_id","value":"oam_onap_1MdY"},{"name":"cpe_public_net_cidr","value":"10.2.0.0/24"},{"name":"mux_gw_private_net_cidr","value":"10.5.0.0/24"},{"name":"cloud_env","value":"openstack"},{"name":"cpe_public_subnet_id","value":"vcpe_net_cpe_public_subnet_201808231522"},{"name":"mux_gw_private_subnet_id","value":"vcpe_net_mux_gw_subnet_201808231522"},{"name":"onap_private_net_id","value":"oam_onap_1MdY"},{"name":"repo_url_blob","value":"https://nexus.onap.org/content/sites/raw"},{"name":"install_script_version","value":"1.1.1"},{"name":"demo_artifacts_version","value":"1.1.1"},{"name":"vgw_name_0","value":"zdcpe1cpe01gw01_201808261550"},{"name":"vgw_private_ip_1","value":"10.0.101.99"},{"name":"vgw_private_ip_0","value":"10.5.0.107"},{"name":"public_net_id","value":"971040b2-7059-49dc-b220-4fab50cb2ad4"},{"name":"vgw_private_ip_2","value":"10.2.0.6"},{"name":"onap_private_net_cidr","value":"10.0.0.0/16"},{"name":"pub_key","value":"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDKXDgoo3+WOqcUG8/5uUbk81+yczgwC4Y8ywTmuQqbNxlY1oQ0YxdMUqUnhitSXs5S/yRuAVOYHwGg2mCs20oAINrP+mxBI544AMIb9itPjCtgqtE2EWo6MmnFGbHB4Sx3XioE7F4VPsh7japsIwzOjbrQe+Mua1TGQ5d4nfEOQaaglXLLPFfuc7WbhbJbK6Q7rHqZfRcOwAMXgDoBqlyqKeiKwnumddo2RyNT8ljYmvB6buz7KnMinzo7qB0uktVT05FH9Rg0CTWH5norlG5qXgP2aukL0gk1ph8iAt7uYLf1ktp+LJI2gaF6L0/qli9EmVCSLr1uJ38Q8CBflhkh"}]},"tenant":"7fad299815104c0a8f90a8df80343f03","aic-clli":"clli1","aic-cloud-region":"RegionOne","vf-module-topology-identifier":{"vf-module-id":"815e8636-5c2a-41ad-b24d-17c824106bd2","vf-module-name":"zRegionOne06_base_vcpe_vgw_0","vf-module-type":"VcpevspVgw0822a..base_vcpe_vgw..module-0"},"vf-module-assignments":{"vms":{"vm":[{"vm-type":"vgw","vm-count":1,"vm-type-tag":"vgw","vm-names":{"vm-name":["zRegionOne06001"]}}]}}},"vf-module-request-input":{"vf-module-name":"zRegionOne06_base_vcpe_vgw_0","tenant":"7fad299815104c0a8f90a8df80343f03","aic-cloud-region":"RegionOne"},"vf-module-information":{"onap-model-information":{"model-invariant-uuid":"7e91451d-e320-4755-a1a8-fcf140b86779","model-name":"VcpevspVgw0822a..base_vcpe_vgw..module-0","model-version":"1","model-customization-uuid":"7fbb59b7-a7ac-4fa6-b0bc-42f47339010a","model-uuid":"1908874e-cfae-4ee1-93b9-f4ba46b460ff"},"vf-module-id":"815e8636-5c2a-41ad-b24d-17c824106bd2","vf-module-type":"VcpevspVgw0822a..base_vcpe_vgw..module-0"},"sdnc-request-header":{"svc-action":"assign","svc-request-id":"2a950a5c-21bf-4496-a592-b51f45719603-1535335110722","svc-notification-url":"http://c1.vm1.mso.simpledemo.openecomp.org:8080/adapters/rest/SDNCNotify"},"vnf-information":{"vnf-id":"bf2a200d-744f-4900-afc4-d5ef44638467","vnf-type":"vcpesvc_rescust_0822a/vcpevsp_vgw_0822a 0","onap-model-information":{"model-invariant-uuid":"71370375-e1b4-4ad2-9832-1b7877428c81","model-name":"vcpevsp_vgw_0822a","model-version":"1.0","model-customization-uuid":"d4484d8e-09c8-4e1e-89f7-b556bf7c57ba","model-uuid":"7dd31559-9fc6-4b0d-bbe3-7ba641bf8a9b"}},"request-information":{"request-id":"2a950a5c-21bf-4496-a592-b51f45719603","request-action":"CreateVfModuleInstance","source":"VID"},"vf-module-level-oper-status":{"order-status":"PendingCreate","last-rpc-action":"assign"}}}]},"vnf-level-oper-status":{"last-rpc-action":"activate","order-status":"Created","last-action":"CreateVnfInstance"},"service-information":{"service-id":"a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb","onap-model-information":{"model-invariant-uuid":"3a4e6986-5c5e-434e-b0be-8d718107fa83","model-name":"vcpesvc_rescust_0822a","model-version":"1.0","model-uuid":"209efacc-54d4-4f12-9064-099d47c36a29"},"service-instance-id":"7d518257-49bd-40ac-8d17-017a726ec12a","global-customer-id":"SDN-ETHERNET-INTERNET","subscription-service-type":"a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb"},"sdnc-request-header":{"svc-action":"activate","svc-request-id":"2a950a5c-21bf-4496-a592-b51f45719603-1535335104196","svc-notification-url":"http://c1.vm1.mso.simpledemo.openecomp.org:8080/adapters/rest/SDNCNotify"},"vnf-information":{"vnf-id":"bf2a200d-744f-4900-afc4-d5ef44638467","vnf-type":"vcpesvc_rescust_0822a/vcpevsp_vgw_0822a 0","onap-model-information":{"model-invariant-uuid":"71370375-e1b4-4ad2-9832-1b7877428c81","model-name":"vcpevsp_vgw_0822a","model-version":"1.0","model-customization-uuid":"d4484d8e-09c8-4e1e-89f7-b556bf7c57ba","model-uuid":"7dd31559-9fc6-4b0d-bbe3-7ba641bf8a9b"}},"request-information":{"request-id":"2a950a5c-21bf-4496-a592-b51f45719603","request-action":"CreateVnfInstance","source":"VID"},"vnf-request-input":{"vnf-name":"zRegionOne06","tenant":"7fad299815104c0a8f90a8df80343f03","aic-cloud-region":"RegionOne"},"vnf-topology":{"onap-model-information":{"model-invariant-uuid":"71370375-e1b4-4ad2-9832-1b7877428c81","model-name":"vcpevsp_vgw_0822a","model-version":"1.0","model-customization-uuid":"d4484d8e-09c8-4e1e-89f7-b556bf7c57ba","model-uuid":"7dd31559-9fc6-4b0d-bbe3-7ba641bf8a9b"},"tenant":"7fad299815104c0a8f90a8df80343f03","aic-clli":"clli1","aic-cloud-region":"RegionOne","vnf-topology-identifier-structure":{"vnf-id":"bf2a200d-744f-4900-afc4-d5ef44638467","vnf-type":"vcpesvc_rescust_0822a/vcpevsp_vgw_0822a 0","vnf-name":"zRegionOne06"},"vnf-resource-assignments":{"availability-zones":{"availability-zone":["nova"],"max-count":1}}}}}]},"service-level-oper-status":{"last-rpc-action":"assign","order-status":"Created","last-action":"CreateServiceInstance"}}}]}