aboutsummaryrefslogtreecommitdiffstats
path: root/datarouter-node
diff options
context:
space:
mode:
Diffstat (limited to 'datarouter-node')
-rwxr-xr-xdatarouter-node/pom.xml29
-rwxr-xr-xdatarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigTest.java254
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServletTest.java297
3 files changed, 580 insertions, 0 deletions
diff --git a/datarouter-node/pom.xml b/datarouter-node/pom.xml
index 6cc396a1..61e95400 100755
--- a/datarouter-node/pom.xml
+++ b/datarouter-node/pom.xml
@@ -186,6 +186,35 @@
<version>1.2.17</version>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.10</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.10.19</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>1.6.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>1.6.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.0</version>
+ </dependency>
</dependencies>
<profiles>
<profile>
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigTest.java
new file mode 100755
index 00000000..6350e640
--- /dev/null
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigTest.java
@@ -0,0 +1,254 @@
+/*******************************************************************************
+ * ============LICENSE_START==================================================
+ * * org.onap.dmaap
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package org.onap.dmaap.datarouter.node;
+
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+
+@RunWith(PowerMockRunner.class)
+public class NodeConfigTest {
+
+ private static NodeConfig nodeConfig;
+
+ @BeforeClass
+ public static void setUp() throws IOException{
+ ProvData provData = setUpProvData();
+ nodeConfig = new NodeConfig(provData, "Name", "spool/dir", 80, "Key");
+ }
+
+ @Test
+ public void Given_Feed_Does_Not_Exist_Then_Is_Publish_Permitted_Returns_Not_Null() {
+ String permitted = nodeConfig.isPublishPermitted("2", "user", "0.0.0.0");
+ Assert.assertEquals("Feed does not exist", permitted);
+ }
+
+ @Test
+ public void Given_Feed_But_User_Not_Permitted_Then_Is_Publish_Permitted_Returns_Not_Null() {
+ String permitted = nodeConfig.isPublishPermitted("1", "user", "0.0.0.0");
+ Assert.assertEquals("Publisher not permitted for this feed", permitted);
+ }
+
+ @Test
+ public void Given_Feed_But_Ip_Does_Not_Match_Then_Is_Publish_Permitted_Returns_Not_Null() {
+ String permitted = nodeConfig.isPublishPermitted("1", "Basic dXNlcjE6cGFzc3dvcmQx", "0.0.0.0");
+ Assert.assertEquals("Publisher not permitted for this feed", permitted);
+ }
+
+ @Test
+ public void Given_Feed_Then_Is_Publish_Permitted_Returns_Null() {
+ String permitted = nodeConfig.isPublishPermitted("1", "Basic dXNlcjE6cGFzc3dvcmQx", "172.0.0.1");
+ Assert.assertNull(permitted);
+ }
+
+ @Test
+ public void Given_SubId_Then_Get_Feed_Id_Returns_Correct_Id() {
+ String feedId = nodeConfig.getFeedId("1");
+ Assert.assertEquals("1", feedId);
+ }
+
+ @Test
+ public void Given_Incorrect_SubId_Then_Get_Feed_Id_Returns_Null() {
+ String feedId = nodeConfig.getFeedId("2");
+ Assert.assertNull(feedId);
+ }
+
+ @Test
+ public void Given_SubId_Then_Get_Spool_Dir_Returns_Correct_Id() {
+ String spoolDir = nodeConfig.getSpoolDir("1");
+ Assert.assertEquals("spool/dir/s/0/1", spoolDir);
+ }
+
+ @Test
+ public void Given_Incorrect_SubId_Then_Get_Spool_Dir_Returns_Null() {
+ String spoolDir = nodeConfig.getSpoolDir("2");
+ Assert.assertNull(spoolDir);
+ }
+
+ @Test
+ public void Given_Feed_And_Incorrect_Credentials_Then_Get_Auth_User_Returns_Null() {
+ String authUser = nodeConfig.getAuthUser("1", "incorrect");
+ Assert.assertNull(authUser);
+ }
+
+ @Test
+ public void Given_Feed_And_Correct_Credentials_Then_Get_Auth_User_Returns_User() {
+ String authUser = nodeConfig.getAuthUser("1", "Basic dXNlcjE6cGFzc3dvcmQx");
+ Assert.assertEquals("user1", authUser);
+ }
+
+ @Test
+ public void Given_Correct_Feed_Then_Get_Ingress_Node_Returns_Node() {
+ String node = nodeConfig.getIngressNode("1", "user1", "172.0.0.1");
+ Assert.assertEquals("172.0.0.4", node);
+ }
+
+ @Test
+ public void Given_Correct_Feed_Then_Get_Targets_Returns_Correct_Dest_Info() {
+ Target[] targets = nodeConfig.getTargets("1");
+ Assert.assertEquals("1", targets[0].getDestInfo().getSubId());
+ Assert.assertEquals("spool/dir/s/0/1", targets[0].getDestInfo().getSpool());
+ }
+
+ @Test(expected = ArrayIndexOutOfBoundsException.class)
+ public void Given_Null_Feed_Then_Get_Targets_Returns_Empty_Array() {
+ Target[] targets = nodeConfig.getTargets(null);
+ targets[0].getDestInfo();
+ }
+
+ @Test(expected = ArrayIndexOutOfBoundsException.class)
+ public void Given_Incorrect_Feed_Then_Get_Targets_Returns_Empty_Array() {
+ Target[] targets = nodeConfig.getTargets("2");
+ targets[0].getDestInfo();
+ }
+
+ @Test
+ public void Given_Same_Ip_Then_Is_Another_Node_Returns_False() {
+ Boolean isAnotherNode = nodeConfig.isAnotherNode("Basic MTcyLjAuMC40OmtCTmhkWVFvbzhXNUphZ2g4T1N4Zmp6Mzl1ND0=", "172.0.0.1");
+ Assert.assertFalse(isAnotherNode);
+ }
+
+ @Test
+ public void Given_Different_Ip_Then_Is_Another_Node_Returns_True() {
+ Boolean isAnotherNode = nodeConfig.isAnotherNode("Basic MTcyLjAuMC40OmtCTmhkWVFvbzhXNUphZ2g4T1N4Zmp6Mzl1ND0=", "172.0.0.4");
+ Assert.assertTrue(isAnotherNode);
+ }
+
+ @Test
+ public void Given_Param_Name_Then_Get_Prov_Param_Returns_Parameter() {
+ String paramValue = nodeConfig.getProvParam("DELIVERY_MAX_AGE");
+ Assert.assertEquals("86400", paramValue);
+ }
+
+ @Test
+ public void Validate_Get_All_Dests_Returns_Dest_Info() {
+ DestInfo[] destInfo = nodeConfig.getAllDests();
+ Assert.assertEquals("n:172.0.0.4", destInfo[0].getName());
+ }
+
+ @Test
+ public void Validate_Get_MyAuth_Returns_Correct_Auth() {
+ String auth = nodeConfig.getMyAuth();
+ Assert.assertEquals("Basic TmFtZTp6Z04wMFkyS3gybFppbXltNy94ZDhuMkdEYjA9", auth);
+ }
+
+ private static ProvData setUpProvData() throws IOException {
+ JSONObject provData = new JSONObject();
+ createValidFeed(provData);
+ createValidSubscription(provData);
+ createValidParameters(provData);
+ createValidIngressValues(provData);
+ createValidEgressValues(provData);
+ createValidRoutingValues(provData);
+ Reader reader = new StringReader(provData.toString());
+ return new ProvData(reader);
+ }
+
+ private static void createValidFeed(JSONObject provData) {
+ JSONArray feeds = new JSONArray();
+ JSONObject feed = new JSONObject();
+ JSONObject auth = new JSONObject();
+ JSONArray endpointIds = new JSONArray();
+ JSONArray endpointAddrs = new JSONArray();
+ JSONObject endpointId = new JSONObject();
+ feed.put("feedid", "1");
+ feed.put("name", "Feed1");
+ feed.put("version", "m1.0");
+ feed.put("suspend", false);
+ feed.put("deleted", false);
+ endpointId.put("id", "user1");
+ endpointId.put("password", "password1");
+ endpointIds.put(endpointId);
+ auth.put("endpoint_ids", endpointIds);
+ endpointAddrs.put("172.0.0.1");
+ auth.put("endpoint_addrs", endpointAddrs);
+ feed.put("authorization", auth);
+ feeds.put(feed);
+ provData.put("feeds", feeds);
+ }
+
+ private static void createValidSubscription(JSONObject provData) {
+ JSONArray subscriptions = new JSONArray();
+ JSONObject subscription = new JSONObject();
+ JSONObject delivery = new JSONObject();
+ subscription.put("subid", "1");
+ subscription.put("feedid", "1");
+ subscription.put("suspend", false);
+ subscription.put("metadataOnly", false);
+ delivery.put("url", "https://172.0.0.2");
+ delivery.put("user", "user1");
+ delivery.put("password", "password1");
+ delivery.put("use100", true);
+ subscription.put("delivery", delivery);
+ subscriptions.put(subscription);
+ provData.put("subscriptions", subscriptions);
+ }
+
+ private static void createValidParameters(JSONObject provData) {
+ JSONObject parameters = new JSONObject();
+ JSONArray nodes = new JSONArray();
+ parameters.put("PROV_NAME", "prov.datarouternew.com");
+ parameters.put("DELIVERY_INIT_RETRY_INTERVAL", "10");
+ parameters.put("DELIVERY_MAX_AGE", "86400");
+ parameters.put("PROV_DOMAIN", "");
+ nodes.put("172.0.0.4");
+ parameters.put("NODES", nodes);
+ provData.put("parameters", parameters);
+ }
+
+ private static void createValidIngressValues(JSONObject provData) {
+ JSONArray ingresses = new JSONArray();
+ JSONObject ingress = new JSONObject();
+ ingress.put("feedid", "1");
+ ingress.put("subnet", "");
+ ingress.put("user", "");
+ ingress.put("node", "172.0.0.4");
+ ingresses.put(ingress);
+ provData.put("ingress", ingresses);
+ }
+
+ private static void createValidEgressValues(JSONObject provData) {
+ JSONObject egress = new JSONObject();
+ egress.put("subid", "1");
+ egress.put("nodeid", "172.0.0.4");
+ provData.put("egress", egress);
+ }
+
+ private static void createValidRoutingValues(JSONObject provData) {
+ JSONArray routings = new JSONArray();
+ JSONObject routing = new JSONObject();
+ routing.put("from", "prov.datarouternew.com");
+ routing.put("to", "172.0.0.4");
+ routing.put("via", "172.100.0.1");
+ routings.put(routing);
+ provData.put("routing", routings);
+ }
+}
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServletTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServletTest.java
new file mode 100644
index 00000000..048c44fa
--- /dev/null
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServletTest.java
@@ -0,0 +1,297 @@
+/*******************************************************************************
+ * ============LICENSE_START==================================================
+ * * org.onap.dmaap
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package org.onap.dmaap.datarouter.node;
+
+import org.apache.commons.lang3.reflect.FieldUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import java.util.*;
+
+import static org.hamcrest.Matchers.notNullValue;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.*;
+
+@RunWith(PowerMockRunner.class)
+@SuppressStaticInitializationFor("org.onap.dmaap.datarouter.node.NodeConfigManager")
+public class NodeServletTest {
+
+ private NodeServlet nodeServlet;
+
+ @Mock
+ private HttpServletRequest request;
+
+ @Mock
+ private HttpServletResponse response;
+
+ @Before
+ public void setUp() throws Exception{
+ nodeServlet = new NodeServlet();
+ setBehalfHeader("Stub_Value");
+ when(request.getPathInfo()).thenReturn("2");
+ when(request.isSecure()).thenReturn(true);
+ setUpConfig();
+ setUpNodeMainDelivery();
+ when(request.getHeader("Authorization")).thenReturn("User1");
+ when(request.getHeader("X-ATT-DR-PUBLISH-ID")).thenReturn("User1");
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_GET_And_Config_Is_Down_Then_Service_Unavailable_Response_Is_Generated() throws Exception {
+ setNodeConfigManagerIsConfiguredToReturnFalse();
+ nodeServlet.doGet(request, response);
+ verify(response).sendError(eq(HttpServletResponse.SC_SERVICE_UNAVAILABLE));
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_GET_And_Endpoint_Is_Internal_FetchProv_Then_No_Content_Response_Is_Generated() throws Exception {
+ when(request.getPathInfo()).thenReturn("/internal/fetchProv");
+ nodeServlet.doGet(request, response);
+ verify(response).setStatus(eq(HttpServletResponse.SC_NO_CONTENT));
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_GET_And_Endpoint_Is_ResetSubscription_Then_No_Content_Response_Is_Generated() throws Exception {
+ when(request.getPathInfo()).thenReturn("/internal/resetSubscription/1");
+ nodeServlet.doGet(request, response);
+ verify(response).setStatus(eq(HttpServletResponse.SC_NO_CONTENT));
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_GET_And_Endpoint_Is_Internal_Logs_And_File_Does_Not_Exist_Then_Not_Found_Response_Is_Generated() throws Exception {
+ when(request.getPathInfo()).thenReturn("/internal/logs/fileName");
+ when(request.getRemoteAddr()).thenReturn("135.207.136.128");
+ nodeServlet.doGet(request, response);
+ verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND));
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_GET_And_Endpoint_Is_Internal_Rtt_And_Error_Connecting_To_Socket_Occurs_Then_Ok_Response_Is_Generated() throws Exception {
+ when(request.getPathInfo()).thenReturn("/internal/rtt/0.0.0.0");
+ when(request.getRemoteAddr()).thenReturn("135.207.136.128");
+ ServletOutputStream outStream = mock(ServletOutputStream.class);
+ when(response.getOutputStream()).thenReturn(outStream);
+ nodeServlet.doGet(request, response);
+ verify(response).setStatus(eq(200));
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_GET_To_Invalid_Endpoint_Then_Not_Found_Response_Is_Generated() throws Exception {
+ when(request.getPathInfo()).thenReturn("/incorrect");
+ nodeServlet.doGet(request, response);
+ verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND));
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_PUT_And_Config_Is_Down_Then_Service_Unavailable_Response_Is_Generated() throws Exception {
+ setNodeConfigManagerIsConfiguredToReturnFalse();
+ nodeServlet.doPut(request, response);
+ verify(response).sendError(eq(HttpServletResponse.SC_SERVICE_UNAVAILABLE));
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_PUT_And_Endpoint_Is_Incorrect_Then_Not_Found_Response_Is_Generated() throws Exception {
+ when(request.getPathInfo()).thenReturn("/incorrect/");
+ nodeServlet.doPut(request, response);
+ verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), argThat(notNullValue(String.class)));
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_PUT_And_Request_Is_Not_Secure_Then_Forbidden_Response_Is_Generated() throws Exception {
+ when(request.isSecure()).thenReturn(false);
+ nodeServlet.doPut(request, response);
+ verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_PUT_And_File_Id_Is_Null_Then_Not_Found_Response_Is_Generated() throws Exception {
+ when(request.getPathInfo()).thenReturn(null);
+ nodeServlet.doPut(request, response);
+ verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), argThat(notNullValue(String.class)));
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_PUT_And_Authorization_Is_Null_Then_Forbidden_Response_Is_Generated() throws Exception {
+ when(request.getHeader("Authorization")).thenReturn(null);
+ nodeServlet.doPut(request, response);
+ verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_PUT_And_Publish_Does_Not_Include_File_Id_Then_Not_Found_Response_Is_Generated() throws Exception {
+ when(request.getPathInfo()).thenReturn("/publish/");
+ nodeServlet.doPut(request, response);
+ verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), argThat(notNullValue(String.class)));
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_PUT_And_Publish_Not_Permitted_Then_Forbidden_Response_Is_Generated() throws Exception {
+ when(request.getPathInfo()).thenReturn("/publish/1/fileName");
+ setNodeConfigManagerIsPublishPermittedToReturnAReason();
+ nodeServlet.doPut(request, response);
+ verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_PUT_And_Internal_Publish_On_Same_Node_Then_Forbidden_Response_Is_Generated() throws Exception {
+ when(request.getPathInfo()).thenReturn("/internal/publish/1/fileName");
+ setNodeConfigManagerIsPublishPermittedToReturnAReason();
+ nodeServlet.doPut(request, response);
+ verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN));
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_PUT_And_Internal_Publish_But_Invalid_File_Id_Then_Not_Found_Response_Is_Generated() throws Exception {
+ when(request.getPathInfo()).thenReturn("/internal/publish/1/");
+ nodeServlet.doPut(request, response);
+ verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), argThat(notNullValue(String.class)));
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_PUT_On_Publish_And_Ingress_Node_Is_Provided_Then_Request_Is_Redirected() throws Exception {
+ when(request.getPathInfo()).thenReturn("/publish/1/fileName");
+ setNodeConfigManagerToAllowRedirectOnIngressNode();
+ nodeServlet.doPut(request, response);
+ verify(response).sendRedirect(anyString());
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_PUT_On_Publish_With_Meta_Data_Too_Long_Then_Bad_Request_Response_Is_Generated() throws Exception {
+ when(request.getPathInfo()).thenReturn("/publish/1/fileName");
+ setHeadersForValidRequest(true);
+ nodeServlet.doPut(request, response);
+ verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_PUT_On_Publish_With_Meta_Data_Malformed_Then_Bad_Request_Response_Is_Generated() throws Exception {
+ when(request.getPathInfo()).thenReturn("/publish/1/fileName");
+ setHeadersForValidRequest(false);
+ nodeServlet.doPut(request, response);
+ verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_DELETE_On_Publish_With_Meta_Data_Malformed_Then_Bad_Request_Response_Is_Generated() throws Exception {
+ when(request.getPathInfo()).thenReturn("/publish/1/fileName");
+ setHeadersForValidRequest(false);
+ nodeServlet.doDelete(request, response);
+ verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
+ }
+
+
+ private void setBehalfHeader(String headerValue) {
+ when(request.getHeader("X-ATT-DR-ON-BEHALF-OF")).thenReturn(headerValue);
+ }
+
+ private void setUpConfig() throws IllegalAccessException{
+ NodeConfigManager config = mock(NodeConfigManager.class);
+ PowerMockito.mockStatic(NodeConfigManager.class);
+ when(config.isShutdown()).thenReturn(false);
+ when(config.isConfigured()).thenReturn(true);
+ when(config.getSpoolDir()).thenReturn("spool/dir");
+ when(config.getLogDir()).thenReturn("log/dir");
+ when(config.getPublishId()).thenReturn("User1");
+ when(config.isAnotherNode(anyString(), anyString())).thenReturn(true);
+ when(config.getEventLogInterval()).thenReturn("40");
+ FieldUtils.writeDeclaredStaticField(NodeServlet.class, "config", config, true);
+ FieldUtils.writeDeclaredStaticField(NodeMain.class, "nodeConfigManager", config, true);
+ PowerMockito.when(NodeConfigManager.getInstance()).thenReturn(config);
+ }
+
+
+ private void setUpNodeMainDelivery() throws IllegalAccessException{
+ Delivery delivery = mock(Delivery.class);
+ doNothing().when(delivery).resetQueue(anyObject());
+ FieldUtils.writeDeclaredStaticField(NodeMain.class, "delivery", delivery, true);
+ }
+
+ private void setNodeConfigManagerIsConfiguredToReturnFalse() throws IllegalAccessException{
+ NodeConfigManager config = mock(NodeConfigManager.class);
+ when(config.isConfigured()).thenReturn(false);
+ FieldUtils.writeDeclaredStaticField(NodeServlet.class, "config", config, true);
+ }
+
+ private void setNodeConfigManagerIsPublishPermittedToReturnAReason() throws IllegalAccessException{
+ NodeConfigManager config = mock(NodeConfigManager.class);
+ when(config.isShutdown()).thenReturn(false);
+ when(config.isConfigured()).thenReturn(true);
+ when(config.getSpoolDir()).thenReturn("spool/dir");
+ when(config.getLogDir()).thenReturn("log/dir");
+ when(config.isPublishPermitted(anyString(), anyString(), anyString())).thenReturn("Not Permitted");
+ when(config.isAnotherNode(anyString(), anyString())).thenReturn(false);
+ FieldUtils.writeDeclaredStaticField(NodeServlet.class, "config", config, true);
+ }
+
+ private void setNodeConfigManagerToAllowRedirectOnIngressNode() throws IllegalAccessException{
+ NodeConfigManager config = mock(NodeConfigManager.class);
+ when(config.isShutdown()).thenReturn(false);
+ when(config.isConfigured()).thenReturn(true);
+ when(config.getSpoolDir()).thenReturn("spool/dir");
+ when(config.getLogDir()).thenReturn("log/dir");
+ when(config.getPublishId()).thenReturn("User1");
+ when(config.isAnotherNode(anyString(), anyString())).thenReturn(true);
+ when(config.getAuthUser(anyString(), anyString())).thenReturn("User1");
+ when(config.getIngressNode(anyString(), anyString(), anyString())).thenReturn("NewNode");
+ when(config.getExtHttpsPort()).thenReturn(8080);
+ FieldUtils.writeDeclaredStaticField(NodeServlet.class, "config", config, true);
+ }
+
+ private String createLargeMetaDataString() {
+ StringBuilder myString = new StringBuilder("meta");
+ for (int i = 0; i <= 4098; ++i) {
+ myString.append('x');
+ }
+ return myString.toString();
+ }
+
+ private void setHeadersForValidRequest(boolean isMetaTooLong) {
+ String metaDataString;
+ if (isMetaTooLong) {
+ metaDataString = createLargeMetaDataString();
+ } else {
+ metaDataString = "?#@><";
+ }
+ List<String> headers = new ArrayList<>();
+ headers.add("Content-Type");
+ headers.add("X-ATT-DR-ON-BEHALF-OF");
+ headers.add("X-ATT-DR-META");
+ Enumeration<String> headerNames = Collections.enumeration(headers);
+ when(request.getHeaderNames()).thenReturn(headerNames);
+ Enumeration<String> contentTypeHeader = Collections.enumeration(Arrays.asList("text/plain"));
+ Enumeration<String> behalfHeader = Collections.enumeration(Arrays.asList("User1"));
+ Enumeration<String> metaDataHeader = Collections.enumeration(Arrays.asList(metaDataString));
+ when(request.getHeaders("Content-Type")).thenReturn(contentTypeHeader);
+ when(request.getHeaders("X-ATT-DR-ON-BEHALF-OF")).thenReturn(behalfHeader);
+ when(request.getHeaders("X-ATT-DR-META")).thenReturn(metaDataHeader);
+ }
+}