diff options
author | Tait,Trevor(rt0435) <rtait@amdocs.com> | 2018-07-23 16:49:03 -0400 |
---|---|---|
committer | Tait,Trevor(rt0435) <rtait@amdocs.com> | 2018-08-08 14:14:22 -0400 |
commit | 6dcf97a8e2160f9d54a3a155a36f4c4fa7e35f0d (patch) | |
tree | 9d640649b9dd671375a415994dba8dc6538a6c3d /src/test/java/org | |
parent | a5ca3ae3f9729fa628042e17ea78dde99706be76 (diff) |
Initial Network Discovery Context Builder code
Issue-ID: LOG-401
Change-Id: Id7211386f5eb7f9de2706037fbaf336c636e906c
Signed-off-by: Tait,Trevor(rt0435) <rtait@amdocs.com>
Diffstat (limited to 'src/test/java/org')
4 files changed, 307 insertions, 0 deletions
diff --git a/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/test/JerseyConfigurationTest.java b/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/test/JerseyConfigurationTest.java new file mode 100644 index 0000000..92de24d --- /dev/null +++ b/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/test/JerseyConfigurationTest.java @@ -0,0 +1,37 @@ +/*
+ * ============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.networkdiscovery.test;
+
+import static junit.framework.TestCase.assertEquals;
+
+import javax.ws.rs.client.Client;
+import org.junit.Test;
+import org.onap.pomba.contextbuilder.networkdiscovery.JerseyConfiguration;
+
+
+public class JerseyConfigurationTest {
+
+ @Test
+ public void runTest() {
+ 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/networkdiscovery/test/NdctxbConfigurationTest.java b/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/test/NdctxbConfigurationTest.java new file mode 100644 index 0000000..cdcad8b --- /dev/null +++ b/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/test/NdctxbConfigurationTest.java @@ -0,0 +1,53 @@ +/*
+ * ============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.networkdiscovery.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.junit.Test;
+import org.onap.pomba.contextbuilder.networkdiscovery.NdctxbConfiguration;
+
+public class NdctxbConfigurationTest {
+
+ NdctxbConfiguration configuration = mock(NdctxbConfiguration.class);
+
+ @Test
+ public void testGetUrl() {
+ String url = "www.google.com";
+ when(configuration.getURL()).thenReturn(url);
+ assertEquals(url, configuration.getURL());
+ }
+
+ @Test
+ public void testGetNdBasicAuth() {
+ String msg = "Basic YWRtaW46YWRtaW4=";
+ when(configuration.getNdBasicAuth()).thenReturn(msg);
+ assertEquals(msg, configuration.getNdBasicAuth());
+ }
+
+ @Test
+ public void testGetSdBasicAuth() {
+ String msg = "Basic YWRtaW46YWRtaW4=";
+ when(configuration.getSdBasicAuth()).thenReturn(msg);
+ assertEquals(msg, configuration.getSdBasicAuth());
+ }
+
+}
diff --git a/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/test/WebConfigurationTest.java b/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/test/WebConfigurationTest.java new file mode 100644 index 0000000..1c97aa8 --- /dev/null +++ b/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/test/WebConfigurationTest.java @@ -0,0 +1,40 @@ +/*
+ * ============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.networkdiscovery.test;
+
+import static junit.framework.TestCase.assertEquals;
+import static org.mockito.Mockito.mock;
+
+import org.junit.Test;
+import org.onap.pomba.contextbuilder.networkdiscovery.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 webMvcConfigurerAdapter = webConfiguration.forwardToIndex();
+ ViewResolverRegistry registry = mock(ViewResolverRegistry.class);
+ webMvcConfigurerAdapter.configureViewResolvers(registry);
+ assertEquals(false, registry.hasRegistrations());
+ }
+
+}
diff --git a/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/unittest/service/NetworkDiscoveryContextBuilderTest.java b/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/unittest/service/NetworkDiscoveryContextBuilderTest.java new file mode 100644 index 0000000..16b327b --- /dev/null +++ b/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/unittest/service/NetworkDiscoveryContextBuilderTest.java @@ -0,0 +1,177 @@ +/* + * ============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.networkdiscovery.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 com.github.jknack.handlebars.internal.Files; +import com.github.tomakehurst.wiremock.junit.WireMockRule; +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.UUID; +import javax.servlet.http.HttpServletRequest; +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.networkdiscovery.service.rs.RestService; +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.core.env.Environment; +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 = { + "serviceDecomposition.host=localhost", + "serviceDecomposition.port=3333", + "serviceDecomposition.serviceInstancePath=/service-decomposition/service/context" + }) +public class NetworkDiscoveryContextBuilderTest { + + private String authorization = "Basic " + + Base64.getEncoder() + .encodeToString(("admin" + ":" + "admin") + .getBytes(StandardCharsets.UTF_8)); + private String partnerName = "POMBA"; + private String transactionId = UUID.randomUUID().toString(); + private String serviceInstanceId = "c6456519-6acf-4adb-997c-3c363dd4caaf"; + + HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); + + @Autowired + Environment environment; + + @Autowired + RestService restService; + + @Rule + public WireMockRule serviceDecompositionRule = new WireMockRule(wireMockConfig().port(3333)); + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testVerifyNoAuthoriztion() throws Exception { + Response response = this + .restService + .getContext(httpServletRequest, + null, + partnerName, + transactionId, + serviceInstanceId, + null, + null); + assertTrue(response.getEntity().toString().contains("Missing Authorization: ")); + assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); + } + + @Test + public void testVerifyBadAuthoriztion() throws Exception { + String authorization = "Basic " + + Base64.getEncoder() + .encodeToString(("Test" + ":" + "Fake") + .getBytes(StandardCharsets.UTF_8)); + Response response = this + .restService + .getContext(httpServletRequest, + authorization, + partnerName, + transactionId, + serviceInstanceId, + null, + null); + assertEquals("Authorization Failed", response.getEntity().toString()); + assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); + } + + + @Test + public void testVerifyPartnerName() throws Exception { + Response response = this + .restService + .getContext(httpServletRequest, + authorization, + null, + transactionId, + serviceInstanceId, + null, + null); + assertTrue(response.getEntity().toString().contains("X-ONAP-PartnerName")); + assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); + } + + @Test + public void testVerifyServiceInstanceId() throws Exception { + Response response = this + .restService + .getContext(httpServletRequest, + authorization, + partnerName, + transactionId, + null, + null, + null); + assertTrue(response.getEntity().toString().contains("serviceInstanceId")); + assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); + } + + @Test + public void testVerifyServiceDecomposition() throws Exception { + + String urlStr = "/service-decomposition/service/context?serviceInstanceId=" + serviceInstanceId; + + File file = new File(ClassLoader.getSystemResource("SD_response.json").getFile()); + String sdResonse = new String(Files.read(file)); + + this.serviceDecompositionRule.stubFor(get(urlStr).willReturn(okJson(sdResonse))); + Response response = this + .restService + .getContext(httpServletRequest, + authorization, + partnerName, + transactionId, + serviceInstanceId, + null, + null); + assertEquals(Status.OK.getStatusCode(), response.getStatus()); + } + +} |