summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test
diff options
context:
space:
mode:
authorvempo <vitaliy.emporopulo@amdocs.com>2018-08-06 16:21:01 +0300
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-08-06 16:09:04 +0000
commit44651d903d83f9256c324ec2a3c8886e91e1e433 (patch)
tree0e1961ce6c69dcb8eb18cf8b4e8af1e5eed6e3b4 /openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test
parent1ecdbf74427467327de0b1e11cd0a839d6dc05bd (diff)
Minor improvements to logging for servlets
Fixed import order, more resilient statuses for Spring, cleaner code and tests, more convenient APIs. Change-Id: I6493c81d9c3c1c543c354562e074876268794438 Issue-ID: SDC-1580 Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test')
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/servlet/CombinedTrackerTest.java59
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/servlet/ContextTrackerTest.java4
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/servlet/HttpHeaderTest.java12
3 files changed, 67 insertions, 8 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/servlet/CombinedTrackerTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/servlet/CombinedTrackerTest.java
new file mode 100644
index 0000000000..4454493c01
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/servlet/CombinedTrackerTest.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * 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.
+ */
+
+package org.openecomp.sdc.logging.servlet;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import javax.servlet.http.HttpServletRequest;
+import org.junit.Test;
+
+/**
+ * Test the construction and invocation of combined tracker.
+ *
+ * @author evitaliy
+ * @since 01 Aug 2018
+ */
+public class CombinedTrackerTest {
+
+ @Test(expected = NullPointerException.class)
+ public void throwExceptionWhenTrackersNull() {
+ new CombinedTracker((Tracker[]) null);
+ }
+
+ @Test
+ public void trackersCalledWhenPreRequest() {
+ Tracker firstTracker = mock(Tracker.class);
+ Tracker secondTracker = mock(Tracker.class);
+ CombinedTracker tracker = new CombinedTracker(firstTracker, secondTracker);
+ tracker.preRequest(mock(HttpServletRequest.class));
+ verify(firstTracker, times(1)).preRequest(any(HttpServletRequest.class));
+ verify(secondTracker, times(1)).preRequest(any(HttpServletRequest.class));
+ }
+
+ @Test
+ public void trackersCalledWhenPostRequest() {
+ Tracker firstTracker = mock(Tracker.class);
+ Tracker secondTracker = mock(Tracker.class);
+ CombinedTracker tracker = new CombinedTracker(firstTracker, secondTracker);
+ tracker.postRequest(mock(RequestProcessingResult.class));
+ verify(firstTracker, times(1)).postRequest(any(RequestProcessingResult.class));
+ verify(secondTracker, times(1)).postRequest(any(RequestProcessingResult.class));
+ }
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/servlet/ContextTrackerTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/servlet/ContextTrackerTest.java
index a247d119c8..59c690d763 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/servlet/ContextTrackerTest.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/servlet/ContextTrackerTest.java
@@ -45,10 +45,10 @@ import org.powermock.modules.junit4.PowerMockRunner;
public class ContextTrackerTest {
private static final String X_REQUEST_ID = "X-REQUEST-ID";
- private static final HttpHeader REQUEST_ID_HEADER = new HttpHeader(new String[] {X_REQUEST_ID});
+ private static final HttpHeader REQUEST_ID_HEADER = new HttpHeader(X_REQUEST_ID);
private static final String X_PARTNER_NAME = "X-PARTNER-NAME";
- private static final HttpHeader PARTNER_NAME_HEADER = new HttpHeader(new String[] {X_PARTNER_NAME});
+ private static final HttpHeader PARTNER_NAME_HEADER = new HttpHeader(X_PARTNER_NAME);
@Test(expected = NullPointerException.class)
public void throwExceptionWhenPartnerNamesNull() {
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/servlet/HttpHeaderTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/servlet/HttpHeaderTest.java
index 5cbd0c0d76..2effa9fab1 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/servlet/HttpHeaderTest.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/servlet/HttpHeaderTest.java
@@ -49,7 +49,7 @@ public class HttpHeaderTest {
@Test(expected = IllegalArgumentException.class)
public void throwExceptionWhenInputArrayEmpty() {
- new HttpHeader(new String[0]);
+ new HttpHeader();
}
@Test(expected = IllegalArgumentException.class)
@@ -59,7 +59,7 @@ public class HttpHeaderTest {
@Test
public void valueNotReturnedWhenNameInArrayNotRequested() {
- HttpHeader header = new HttpHeader(new String[] {"A"});
+ HttpHeader header = new HttpHeader("A");
assertFalse(header.getAny(NULL_WHEN_NAME_NOT_B).isPresent());
}
@@ -71,7 +71,7 @@ public class HttpHeaderTest {
@Test
public void valueReturnedWhenSinglePossibleHeaderInArrayMatches() {
- HttpHeader header = new HttpHeader(new String[] {"B"});
+ HttpHeader header = new HttpHeader("B");
assertTrue(header.getAny(NULL_WHEN_NAME_NOT_B).isPresent());
}
@@ -83,7 +83,7 @@ public class HttpHeaderTest {
@Test
public void valueReturnedWhenLastHeaderInArrayMatches() throws Throwable {
- HttpHeader header = new HttpHeader(new String[] {"A", "B"});
+ HttpHeader header = new HttpHeader("A", "B");
header.getAny(NULL_WHEN_NAME_NOT_B).orElseThrow(VALUE_EXPECTED);
}
@@ -95,7 +95,7 @@ public class HttpHeaderTest {
@Test
public void valueReturnedWhenFirstHeaderInArrayMatches() throws Throwable {
- HttpHeader header = new HttpHeader(new String[] {"B", "A"});
+ HttpHeader header = new HttpHeader("B", "A");
header.getAny(NULL_WHEN_NAME_NOT_B).orElseThrow(VALUE_EXPECTED);
}
@@ -107,7 +107,7 @@ public class HttpHeaderTest {
@Test
public void valueReturnedWhenMiddleHeaderInArrayMatches() throws Throwable {
- HttpHeader header = new HttpHeader(new String[] {"A", "B", "C"});
+ HttpHeader header = new HttpHeader("A", "B", "C");
header.getAny(NULL_WHEN_NAME_NOT_B).orElseThrow(VALUE_EXPECTED);
}