aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
authorPawel <pawel.kasperkiewicz@nokia.com>2019-03-27 02:31:46 -0400
committerPawel <pawel.kasperkiewicz@nokia.com>2019-03-29 03:05:46 -0400
commit3e4946f538604b1621b845c72e582f917c275275 (patch)
tree07d706ff58171811b5ef3d9f4005e0d34d3e3a34 /src/test/java
parent072b8c23fdfd43f1d2f5e7d0c4653f77fffed824 (diff)
Added stopwatch filter
Issue-ID: DMAAP-1109 Change-Id: I1738444ec9ce18768efdc9693c9669990660698f Signed-off-by: Pawel <pawel.kasperkiewicz@nokia.com>
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/onap/dmaap/dbcapi/resources/RequestTimeLogFilterTest.java78
-rw-r--r--src/test/java/org/onap/dmaap/dbcapi/service/StopWatchTest.java49
2 files changed, 78 insertions, 49 deletions
diff --git a/src/test/java/org/onap/dmaap/dbcapi/resources/RequestTimeLogFilterTest.java b/src/test/java/org/onap/dmaap/dbcapi/resources/RequestTimeLogFilterTest.java
new file mode 100644
index 0000000..0c88c0c
--- /dev/null
+++ b/src/test/java/org/onap/dmaap/dbcapi/resources/RequestTimeLogFilterTest.java
@@ -0,0 +1,78 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.onap.dmaap
+ * ================================================================================
+ * Copyright (C) 2019 Nokia 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=========================================================
+ */
+package org.onap.dmaap.dbcapi.resources;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import com.att.eelf.configuration.EELFLogger;
+import java.time.Clock;
+import java.time.Instant;
+import java.time.ZoneId;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerResponseContext;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class RequestTimeLogFilterTest {
+
+ private Clock clock ;
+ private RequestTimeLogFilter requestTimeLogFilter;
+ public static final long START = 1L;
+ @Mock
+ private ContainerRequestContext requestContext;
+ @Mock
+ private ContainerResponseContext responseContext;
+ @Mock
+ private EELFLogger logger;
+
+
+ @Before
+ public void setup() {
+ clock = Clock.fixed(Instant.parse("1970-01-01T00:00:10Z"), ZoneId.systemDefault());
+ requestTimeLogFilter = new RequestTimeLogFilter(logger, clock);
+ }
+
+ @Test
+ public void shouldHaveDefaultConstructor() {
+ assertNotNull(new RequestTimeLogFilter());
+ }
+
+ @Test
+ public void filterShouldSetStartTimestampProperty() {
+ requestTimeLogFilter.filter(requestContext);
+ verify(requestContext).setProperty("start",clock.millis());
+ }
+
+ @Test
+ public void filterShouldPrintElapsedTime() {
+ when(requestContext.getProperty("start")).thenReturn(START);
+
+ requestTimeLogFilter.filter(requestContext, responseContext);
+
+ verify(logger).info(anyString(),eq(clock.millis() - START));
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/dmaap/dbcapi/service/StopWatchTest.java b/src/test/java/org/onap/dmaap/dbcapi/service/StopWatchTest.java
deleted file mode 100644
index b4b6af2..0000000
--- a/src/test/java/org/onap/dmaap/dbcapi/service/StopWatchTest.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * org.onap.dmaap
- * ================================================================================
- * Copyright (C) 2019 Nokia 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=========================================================
- */
-package org.onap.dmaap.dbcapi.service;
-
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertEquals;
-import org.junit.Test;
-import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
-
-public class StopWatchTest extends BaseLoggingClass {
-
- private StopWatch stopWatch = new StopWatch();
-
- @Test
- public void stopWatchShouldReturnElapsedTime() throws InterruptedException {
- stopWatch.start();
- Thread.sleep(50);
- stopWatch.stop();
- assertTrue(stopWatch.getElapsedTime() > 0);
- }
-
- @Test
- public void resetShouldSetElapsedTime() {
- stopWatch.start();
- stopWatch.stop();
- stopWatch.resetElapsedTime();
- assertEquals(0,stopWatch.getElapsedTime());
-
- }
-
-} \ No newline at end of file