aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
authorSotiropoulos, Ioannis (is948x) <Ioannis.Sotiropoulos@amdocs.com>2018-06-06 10:56:36 +0100
committerSotiropoulos, Ioannis (is948x) <Ioannis.Sotiropoulos@amdocs.com>2018-06-06 11:30:41 +0100
commitc57a430c6dbd6951091978404a164000024fce20 (patch)
treecbd6a4d3ac492aa9c7cfbdeef21aa8f8aa47024e /src/test/java
parentca46bdfcfb109b856c293862f6ed77fe78eb510f (diff)
Add validation for request header
Add validation for inclusion of X-FromAppId and X-TransactionId in request header Issue-ID: AAI-1190 Change-Id: Ie1d2b64a7243c013982992196048e1d6635d5e66 Signed-off-by: Sotiropoulos, Ioannis (is948x) <Ioannis.Sotiropoulos@amdocs.com>
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/onap/crud/service/CrudRestServiceTest.java51
-rw-r--r--src/test/java/org/onap/crud/service/TestHeaders.java19
2 files changed, 60 insertions, 10 deletions
diff --git a/src/test/java/org/onap/crud/service/CrudRestServiceTest.java b/src/test/java/org/onap/crud/service/CrudRestServiceTest.java
index 029fd52..b61f234 100644
--- a/src/test/java/org/onap/crud/service/CrudRestServiceTest.java
+++ b/src/test/java/org/onap/crud/service/CrudRestServiceTest.java
@@ -20,19 +20,19 @@
*/
package org.onap.crud.service;
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
-
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
-
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
import org.onap.crud.exception.CrudException;
import org.onap.schema.RelationshipSchemaLoader;
@@ -69,6 +69,9 @@ public class CrudRestServiceTest {
private CrudRestService mockService;
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
@Before
public void init() throws Exception {
ClassLoader classLoader = getClass().getClassLoader();
@@ -141,7 +144,7 @@ public class CrudRestServiceTest {
@Test
public void testUpdateVertex() throws CrudException {
Response response;
-
+
// Test ID mismatch
response = mockService.updateVertex(putVertexPayload, "v11", "pserver", "bad-id",
"services/inventory/v11", new TestHeaders(), null, new TestRequest());
@@ -203,6 +206,42 @@ public class CrudRestServiceTest {
}
@Test
+ public void testValidRequestHeader() throws CrudException {
+ TestHeaders testHeaders = new TestHeaders();
+ mockService.validateRequestHeader(testHeaders);
+ }
+
+ @Test
+ public void testInvalidRequestHeaderXTransactionId() throws CrudException {
+ thrown.expect(CrudException.class);
+ thrown.expectMessage("Invalid request, Missing X-TransactionId header");
+
+ TestHeaders testHeaders = new TestHeaders();
+ testHeaders.clearRequestHeader("X-TransactionId");
+ mockService.validateRequestHeader(testHeaders);
+ }
+
+ @Test
+ public void testInvalidRequestHeaderXFromAppId() throws CrudException {
+ thrown.expect(CrudException.class);
+ thrown.expectMessage("Invalid request, Missing X-FromAppId header");
+
+ TestHeaders testHeaders = new TestHeaders();
+ testHeaders.clearRequestHeader("X-FromAppId");
+ mockService.validateRequestHeader(testHeaders);
+ }
+
+ @Test
+ public void testEmptyRequestHeader() throws CrudException {
+ thrown.expect(CrudException.class);
+ thrown.expectMessage("Invalid request, Missing X-FromAppId header");
+
+ TestHeaders testHeaders = new TestHeaders();
+ testHeaders.clearRequestHeader("X-TransactionId", "X-FromAppId");
+ mockService.validateRequestHeader(testHeaders);
+ }
+
+ @Test
public void testBulk() throws CrudException, IOException {
Response response;
@@ -238,4 +277,4 @@ public class CrudRestServiceTest {
}
}
-}
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/crud/service/TestHeaders.java b/src/test/java/org/onap/crud/service/TestHeaders.java
index 6e30471..835840f 100644
--- a/src/test/java/org/onap/crud/service/TestHeaders.java
+++ b/src/test/java/org/onap/crud/service/TestHeaders.java
@@ -33,6 +33,14 @@ import javax.ws.rs.core.MultivaluedMap;
public class TestHeaders implements HttpHeaders {
+ private MultivaluedMap<String, String> headers;
+
+ public TestHeaders() {
+ headers = new MultivaluedHashMap<String, String>();
+ headers.add("X-FromAppId", "test-app");
+ headers.add("X-TransactionId", "65f7e29c-57fd-45b2-bfd5-19e25c59110e");
+ }
+
@Override
public List<Locale> getAcceptableLanguages() {
return null;
@@ -82,10 +90,13 @@ public class TestHeaders implements HttpHeaders {
@Override
public MultivaluedMap<String, String> getRequestHeaders() {
- MultivaluedMap<String, String> map = new MultivaluedHashMap<String, String>();
- map.add("X-FromAppId", "test-app");
- map.add("X-TransactionId", "65f7e29c-57fd-45b2-bfd5-19e25c59110e");
- return map;
+ return headers;
+ }
+
+ public void clearRequestHeader(String... keys) {
+ for (String key : keys) {
+ headers.remove(key);
+ }
}
}