+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.dmaap\r
+ * ================================================================================\r
+ * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+package org.onap.dmaap.dbcapi.resources;\r
+\r
+import static org.junit.Assert.assertNotNull;\r
+import static org.mockito.Matchers.anyString;\r
+import static org.mockito.Matchers.eq;\r
+import static org.mockito.Mockito.verify;\r
+import static org.mockito.Mockito.when;\r
+import com.att.eelf.configuration.EELFLogger;\r
+import java.time.Clock;\r
+import java.time.Instant;\r
+import java.time.ZoneId;\r
+import javax.ws.rs.container.ContainerRequestContext;\r
+import javax.ws.rs.container.ContainerResponseContext;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.Mock;\r
+import org.mockito.runners.MockitoJUnitRunner;\r
+\r
+@RunWith(MockitoJUnitRunner.class)\r
+public class RequestTimeLogFilterTest {\r
+\r
+ private Clock clock ;\r
+ private RequestTimeLogFilter requestTimeLogFilter;\r
+ public static final long START = 1L;\r
+ @Mock\r
+ private ContainerRequestContext requestContext;\r
+ @Mock\r
+ private ContainerResponseContext responseContext;\r
+ @Mock\r
+ private EELFLogger logger;\r
+\r
+\r
+ @Before\r
+ public void setup() {\r
+ clock = Clock.fixed(Instant.parse("1970-01-01T00:00:10Z"), ZoneId.systemDefault());\r
+ requestTimeLogFilter = new RequestTimeLogFilter(logger, clock);\r
+ }\r
+\r
+ @Test\r
+ public void shouldHaveDefaultConstructor() {\r
+ assertNotNull(new RequestTimeLogFilter());\r
+ }\r
+\r
+ @Test\r
+ public void filterShouldSetStartTimestampProperty() {\r
+ requestTimeLogFilter.filter(requestContext);\r
+ verify(requestContext).setProperty("start",clock.millis());\r
+ }\r
+\r
+ @Test\r
+ public void filterShouldPrintElapsedTime() {\r
+ when(requestContext.getProperty("start")).thenReturn(START);\r
+\r
+ requestTimeLogFilter.filter(requestContext, responseContext);\r
+\r
+ verify(logger).info(anyString(),eq(clock.millis() - START));\r
+ }\r
+}
\ No newline at end of file