aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorPrudence Au <prudence.au@amdocs.com>2018-08-30 13:24:55 -0400
committerPrudence Au <prudence.au@amdocs.com>2018-08-30 14:07:15 -0400
commit45e403d89794720689be5c8ee71f4c7174c022c3 (patch)
tree5ef6860e221d465a343b83b41547dafd36b583a3 /src/test
parent9047e48a607fda3796b131f9c95b03efc73b538c (diff)
Add support for using the "old" headers
Change-Id: Ie4b302ca4325ee3b04fee0319efbc1a770d6c1ab Signed-off-by: Prudence Au <prudence.au@amdocs.com> Issue-ID: LOG-401
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/unittest/service/NetworkDiscoveryContextBuilderTest.java124
1 files changed, 81 insertions, 43 deletions
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
index 77e37ca..5485535 100644
--- 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
@@ -1,19 +1,15 @@
/*
- * ============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
+ * ============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
+ * 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=====================================================
+ * 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;
@@ -25,10 +21,6 @@ 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.client.WireMock;
-import com.github.tomakehurst.wiremock.junit.WireMockRule;
-import com.github.tomakehurst.wiremock.matching.UrlPattern;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -47,11 +39,11 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.onap.pomba.common.datatypes.DataQuality;
import org.onap.pomba.contextbuilder.networkdiscovery.model.NetworkDiscoveryRspInfo;
import org.onap.pomba.contextbuilder.networkdiscovery.service.SpringServiceImpl;
import org.onap.pomba.contextbuilder.networkdiscovery.service.rs.RestService;
import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.Attribute;
-import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.DataQuality;
import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.NetworkDiscoveryNotification;
import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.Resource;
import org.springframework.beans.factory.annotation.Autowired;
@@ -63,18 +55,23 @@ 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;
+import com.github.jknack.handlebars.internal.Files;
+import com.github.tomakehurst.wiremock.client.WireMock;
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+import com.github.tomakehurst.wiremock.matching.UrlPattern;
+
@RunWith(SpringJUnit4ClassRunner.class)
-@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class })
+@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
@WebAppConfiguration
@SpringBootTest
-@TestPropertySource(properties = { "serviceDecomposition.host=localhost", "serviceDecomposition.port=3333",
+@TestPropertySource(properties = {"serviceDecomposition.host=localhost", "serviceDecomposition.port=3333",
"networkDiscoveryMicroService.host=localhost", "networkDiscoveryMicroService.port=9808",
- "networkDiscoveryMicroService.responseTimeOutInMilliseconds=1000" })
+ "networkDiscoveryMicroService.responseTimeOutInMilliseconds=1000"})
public class NetworkDiscoveryContextBuilderTest {
- private String authorization = "Basic "
- + Base64.getEncoder().encodeToString(("admin" + ":" + "admin").getBytes(StandardCharsets.UTF_8));
+ 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";
@@ -97,35 +94,33 @@ public class NetworkDiscoveryContextBuilderTest {
public WireMockRule networkDiscoveryMicroServiceRule = new WireMockRule(wireMockConfig().port(9808));
@Before
- public void setUp() throws Exception {
- }
+ public void setUp() throws Exception {}
@After
- public void tearDown() throws Exception {
- }
+ public void tearDown() throws Exception {}
@Test
public void testVerifyNoAuthoriztion() throws Exception {
- Response response = this.restService.getContext(httpServletRequest, null, partnerName, transactionId,
- serviceInstanceId, null, null);
+ Response response = this.restService.getContext(httpServletRequest, null, partnerName, transactionId, null,
+ null, serviceInstanceId, null, null);
assertTrue(response.getEntity().toString().contains("Missing Authorization: "));
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
}
@Test
public void testVerifyBadAuthoriztion() throws Exception {
- String authorization = "Basic "
- + Base64.getEncoder().encodeToString(("Test" + ":" + "Fake").getBytes(StandardCharsets.UTF_8));
+ String authorization =
+ "Basic " + Base64.getEncoder().encodeToString(("Test" + ":" + "Fake").getBytes(StandardCharsets.UTF_8));
Response response = this.restService.getContext(httpServletRequest, authorization, partnerName, transactionId,
- serviceInstanceId, null, null);
+ null, null, serviceInstanceId, null, null);
assertEquals("Authorization Failed", response.getEntity().toString());
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
}
@Test
public void testVerifyPartnerName() throws Exception {
- Response response = this.restService.getContext(httpServletRequest, authorization, null, transactionId,
- serviceInstanceId, null, null);
+ Response response = this.restService.getContext(httpServletRequest, authorization, null, transactionId, null,
+ null, serviceInstanceId, null, null);
assertTrue(response.getEntity().toString().contains("X-ONAP-PartnerName"));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
@@ -133,7 +128,7 @@ public class NetworkDiscoveryContextBuilderTest {
@Test
public void testVerifyServiceInstanceId() throws Exception {
Response response = this.restService.getContext(httpServletRequest, authorization, partnerName, transactionId,
- null, null, null);
+ null, null, null, null, null);
assertTrue(response.getEntity().toString().contains("serviceInstanceId"));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
@@ -149,7 +144,7 @@ public class NetworkDiscoveryContextBuilderTest {
this.serviceDecompositionRule.stubFor(get(urlStr).willReturn(okJson(sdResonse)));
addResponse_any("junit/networkDiscoveryResponse-1.json", networkDiscoveryMicroServiceRule);
Response response = this.restService.getContext(httpServletRequest, authorization, partnerName, transactionId,
- serviceInstanceId, null, null);
+ null, null, serviceInstanceId, null, null);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
@@ -161,7 +156,7 @@ public class NetworkDiscoveryContextBuilderTest {
addResponse_any("junit/networkDiscoveryResponse-1.json", networkDiscoveryMicroServiceRule);
Response response = this.restService.getContext(httpServletRequest, authorization, partnerName, transactionId,
- serviceInstanceId, null, null);
+ null, null, serviceInstanceId, null, null);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
@@ -171,10 +166,10 @@ public class NetworkDiscoveryContextBuilderTest {
String networkDiscoveryCallBackUrl = "/network-discovery/service/networkDiscoveryNotification";
addResponse(networkDiscoveryCallBackUrl, "junit/networkDiscovery-1.json", networkDiscoveryMicroServiceRule);
- String badAuthorization = "Basic "
- + Base64.getEncoder().encodeToString(("Test" + ":" + "Fake").getBytes(StandardCharsets.UTF_8));
- Response response = this.restService.networkDiscoveryNotification(networkDiscoveryNotification,
- badAuthorization);
+ String badAuthorization =
+ "Basic " + Base64.getEncoder().encodeToString(("Test" + ":" + "Fake").getBytes(StandardCharsets.UTF_8));
+ Response response =
+ this.restService.networkDiscoveryNotification(networkDiscoveryNotification, badAuthorization);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
}
@@ -192,6 +187,50 @@ public class NetworkDiscoveryContextBuilderTest {
assertEquals(rsp.getNetworkDiscoveryNotificationList().size(), 1);
}
+ @Test
+ public void testVerifyNoPartnerNameWithFromAppId() throws Exception {
+ String serviceDecompUrl = "/service-decomposition/service/context?serviceInstanceId=" + serviceInstanceId;
+ addResponse(serviceDecompUrl, "junit/serviceDecomposition-1.json", serviceDecompositionRule);
+ addResponse_any("junit/networkDiscoveryResponse-1.json", networkDiscoveryMicroServiceRule);
+
+ Response response = this.restService.getContext(httpServletRequest, authorization, null, transactionId,
+ partnerName, null, serviceInstanceId, null, null);
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ }
+
+ @Test
+ public void testVerifyNoRequestIdNoTransactionId() throws Exception {
+ String serviceDecompUrl = "/service-decomposition/service/context?serviceInstanceId=" + serviceInstanceId;
+ addResponse(serviceDecompUrl, "junit/serviceDecomposition-1.json", serviceDecompositionRule);
+ addResponse_any("junit/networkDiscoveryResponse-1.json", networkDiscoveryMicroServiceRule);
+
+ Response response = this.restService.getContext(httpServletRequest, authorization, partnerName, null, null,
+ null, serviceInstanceId, null, null);
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ }
+
+ @Test
+ public void testVerifyNoPartnerNameNoFromAppId() throws Exception {
+ String serviceDecompUrl = "/service-decomposition/service/context?serviceInstanceId=" + serviceInstanceId;
+ addResponse(serviceDecompUrl, "junit/serviceDecomposition-1.json", serviceDecompositionRule);
+ addResponse_any("junit/networkDiscoveryResponse-1.json", networkDiscoveryMicroServiceRule);
+
+ Response response = this.restService.getContext(httpServletRequest, authorization, null, transactionId, null,
+ null, serviceInstanceId, null, null);
+ assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
+ }
+
+ @Test
+ public void testVerifyNoRequestIdWithTransactionId() throws Exception {
+ String serviceDecompUrl = "/service-decomposition/service/context?serviceInstanceId=" + serviceInstanceId;
+ addResponse(serviceDecompUrl, "junit/serviceDecomposition-1.json", serviceDecompositionRule);
+ addResponse_any("junit/networkDiscoveryResponse-1.json", networkDiscoveryMicroServiceRule);
+
+ Response response = this.restService.getContext(httpServletRequest, authorization, partnerName, null, null,
+ transactionId, serviceInstanceId, null, null);
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ }
+
private void addResponse(String path, String classpathResource, WireMockRule thisMock) throws IOException {
String payload = readFully(ClassLoader.getSystemResourceAsStream(classpathResource));
thisMock.stubFor(get(path).willReturn(okJson(payload)));
@@ -223,8 +262,7 @@ public class NetworkDiscoveryContextBuilderTest {
DataQuality dataQuality = new DataQuality();
dataQuality.setStatus(DataQuality.Status.ok);
myResource.setDataQuality(dataQuality);
- List<Attribute> attributeList = new ArrayList<>();
- ;
+ List<Attribute> attributeList = new ArrayList<>();;
Attribute attribute = new Attribute();
attribute.setName("vserver-id");
attribute.setValue("25fb07ab-0478-465e-a021-6384ac299671");