diff --git a/notification-core/src/test/java/org/opengroup/osdu/notification/api/GlobalErrorControllerTest.java b/notification-core/src/test/java/org/opengroup/osdu/notification/api/GlobalErrorControllerTest.java index 8a4ff8663c8dafad0ad1922fb9e0edb54ca6fb8c..6c4570a42587a93a1fcaf22703c41c44588e6bc7 100644 --- a/notification-core/src/test/java/org/opengroup/osdu/notification/api/GlobalErrorControllerTest.java +++ b/notification-core/src/test/java/org/opengroup/osdu/notification/api/GlobalErrorControllerTest.java @@ -1,3 +1,17 @@ +// Copyright © Microsoft Corporation +// +// 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.opengroup.osdu.notification.api; import org.junit.Before; @@ -19,6 +33,7 @@ public class GlobalErrorControllerTest { @Mock HttpServletRequest httpServletRequest; + @InjectMocks private GlobalErrorController globalErrorController; @@ -33,7 +48,6 @@ public class GlobalErrorControllerTest { when(httpServletRequest.getAttribute(eq("javax.servlet.error.status_code"))).thenReturn(500); String expected = globalErrorController.handleErrorGet(httpServletRequest); assertEquals(expected, "{\"code\": 500, \"reason:\": \"Internal Server Error\" \"message\":\"An unknown error has occurred\" }"); - } @Test @@ -41,7 +55,6 @@ public class GlobalErrorControllerTest { when(httpServletRequest.getAttribute(eq("javax.servlet.error.status_code"))).thenReturn(404); String expected = globalErrorController.handleErrorPut(httpServletRequest); assertEquals(expected, "{\"code\": 404, \"reason:\": \"Not Found\" \"message\":\"sample exception\" }"); - } @Test @@ -49,7 +62,6 @@ public class GlobalErrorControllerTest { when(httpServletRequest.getAttribute(eq("javax.servlet.error.status_code"))).thenReturn(500); String expected = globalErrorController.handleErrorPatch(httpServletRequest); assertEquals(expected, "{\"code\": 500, \"reason:\": \"Internal Server Error\" \"message\":\"An unknown error has occurred\" }"); - } @Test @@ -69,7 +81,6 @@ public class GlobalErrorControllerTest { @Test public void getErrorPathTest() { assertEquals(globalErrorController.getErrorPath(), "/error"); - } } \ No newline at end of file diff --git a/notification-core/src/test/java/org/opengroup/osdu/notification/api/PubsubEndpointTest.java b/notification-core/src/test/java/org/opengroup/osdu/notification/api/PubsubEndpointTest.java index de0af9ef8435d2fc870edb5c21c3ef5f3224c7ba..75c9461fd3eddba5e0776cd65b87ed924cf78c49 100644 --- a/notification-core/src/test/java/org/opengroup/osdu/notification/api/PubsubEndpointTest.java +++ b/notification-core/src/test/java/org/opengroup/osdu/notification/api/PubsubEndpointTest.java @@ -36,8 +36,10 @@ import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class PubsubEndpointTest { + private static final String NOTIFICATION_ID = "test-notification-id"; private static final String PUBSUB_MESSAGE = "test-pubsub-message-data"; + private final HttpResponse response = new HttpResponse(); @Mock private IPubsubRequestBodyExtractor pubsubRequestBodyExtractor; @Mock @@ -46,7 +48,6 @@ public class PubsubEndpointTest { private JaxRsDpsLog log; @InjectMocks private PubsubEndpoint sut; - private final HttpResponse response = new HttpResponse(); @Before public void setup() throws Exception { diff --git a/notification-core/src/test/java/org/opengroup/osdu/notification/auth/AuthorizationServiceEntitlementsTest.java b/notification-core/src/test/java/org/opengroup/osdu/notification/auth/AuthorizationServiceEntitlementsTest.java index 529de08815759e1361892625fd875ec1b2fc3a18..82895fd06ecc9a7735fca872b9aa113ef424f690 100644 --- a/notification-core/src/test/java/org/opengroup/osdu/notification/auth/AuthorizationServiceEntitlementsTest.java +++ b/notification-core/src/test/java/org/opengroup/osdu/notification/auth/AuthorizationServiceEntitlementsTest.java @@ -61,7 +61,7 @@ public class AuthorizationServiceEntitlementsTest { } @Test - public void should_returnUser_when_ussrHasPermission() throws EntitlementsException { + public void should_returnUser_when_userHasPermission() throws EntitlementsException { sut = createSut("service.register.user"); AuthorizationResponse result = sut.authorizeAny(DpsHeaders.createFromMap(new HashMap<>()), "service.register.user"); @@ -70,7 +70,7 @@ public class AuthorizationServiceEntitlementsTest { } @Test - public void should_returnUser_when_ussrHasAnyPermission() throws EntitlementsException { + public void should_returnUser_when_userHasAnyPermission() throws EntitlementsException { sut = createSut("service.register.editor"); AuthorizationResponse result = sut.authorizeAny(DpsHeaders.createFromMap(new HashMap<>()), "service.register.user", "service.register.editor"); diff --git a/notification-core/src/test/java/org/opengroup/osdu/notification/auth/factory/AuthFactoryTest.java b/notification-core/src/test/java/org/opengroup/osdu/notification/auth/factory/AuthFactoryTest.java index 5c00336e8bc7aefee275afad5a503307b56300bd..a1acb7de90ab752bf55a9a0afe2d5b03ce142b8a 100644 --- a/notification-core/src/test/java/org/opengroup/osdu/notification/auth/factory/AuthFactoryTest.java +++ b/notification-core/src/test/java/org/opengroup/osdu/notification/auth/factory/AuthFactoryTest.java @@ -1,3 +1,17 @@ +// Copyright © Microsoft Corporation +// +// 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.opengroup.osdu.notification.auth.factory; import org.junit.Before; diff --git a/notification-core/src/test/java/org/opengroup/osdu/notification/di/CredentialHeadersProviderTest.java b/notification-core/src/test/java/org/opengroup/osdu/notification/di/CredentialHeadersProviderTest.java index 2d604ac9460c7c3f5cc2fe02e8ede830208b672b..83a349952ccb1cc50364408f0caa313d799bca4f 100644 --- a/notification-core/src/test/java/org/opengroup/osdu/notification/di/CredentialHeadersProviderTest.java +++ b/notification-core/src/test/java/org/opengroup/osdu/notification/di/CredentialHeadersProviderTest.java @@ -58,8 +58,6 @@ public class CredentialHeadersProviderTest { assertEquals(dpsHeaders.getHeaders().get("content-type"), "application/json"); assertEquals(dpsHeaders.getHeaders().get("authorization"), "sampleAuthToken"); assertEquals(dpsHeaders.getHeaders().get("data-partition-id"), "opendes"); - - } } \ No newline at end of file diff --git a/notification-core/src/test/java/org/opengroup/osdu/notification/di/RequestInfoExtTest.java b/notification-core/src/test/java/org/opengroup/osdu/notification/di/RequestInfoExtTest.java index 366bb5a9abc40d67c601692cf7a612214565e0a4..3ea97c72192daa6e8c5fe99153a188c18d4d1cab 100644 --- a/notification-core/src/test/java/org/opengroup/osdu/notification/di/RequestInfoExtTest.java +++ b/notification-core/src/test/java/org/opengroup/osdu/notification/di/RequestInfoExtTest.java @@ -64,13 +64,11 @@ public class RequestInfoExtTest { @Test public void assignPartitionIdIfNotInHeaderTest() { - when(http.getMethod()).thenReturn("POST"); when(headers.getPartitionId()).thenReturn(null); when(requestBodyExtractor.extractAttributesFromRequestBody()).thenReturn(httpHeaders); this.sut.assignPartitionIdIfNotInHeader(); verify(requestBodyExtractor, times(1)).extractAttributesFromRequestBody(); - } } diff --git a/notification-core/src/test/java/org/opengroup/osdu/notification/di/SubscriptionCacheFactoryTest.java b/notification-core/src/test/java/org/opengroup/osdu/notification/di/SubscriptionCacheFactoryTest.java index 8b17bbec285ec4c57eb84251300e9ecc86ada56e..893e635020565ab2e8d9a906de6742c055ffa210 100644 --- a/notification-core/src/test/java/org/opengroup/osdu/notification/di/SubscriptionCacheFactoryTest.java +++ b/notification-core/src/test/java/org/opengroup/osdu/notification/di/SubscriptionCacheFactoryTest.java @@ -1,3 +1,17 @@ +// Copyright © Microsoft Corporation +// +// 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.opengroup.osdu.notification.di; import org.junit.Before; @@ -30,7 +44,6 @@ public class SubscriptionCacheFactoryTest { @Mock private TenantInfo tenantInfo; - @Before public void setup() { subscriptionCacheFactory = new SubscriptionCacheFactory(1234567, 1000); @@ -42,13 +55,10 @@ public class SubscriptionCacheFactoryTest { when(headers.getPartitionIdWithFallbackToAccountId()).thenReturn("opendes"); when(tenantInfo.getDataPartitionId()).thenReturn("opendes"); subscriptionCacheFactory.put("testKey", "testVal"); - } - @Test public void getTest() { - String actual = subscriptionCacheFactory.get("testKey"); assertEquals("testVal", actual); } @@ -57,7 +67,6 @@ public class SubscriptionCacheFactoryTest { public void deleteTest() { subscriptionCacheFactory.delete("testKey"); assertNull(subscriptionCacheFactory.get("testKey")); - } @Test diff --git a/notification-core/src/test/java/org/opengroup/osdu/notification/errors/SpringExceptionMapperTest.java b/notification-core/src/test/java/org/opengroup/osdu/notification/errors/SpringExceptionMapperTest.java index 8594ff84d0500bf9feb1968fa741d7a42d31fdb8..718055c61368c6908a9dc2eac56ed9c65a285f13 100644 --- a/notification-core/src/test/java/org/opengroup/osdu/notification/errors/SpringExceptionMapperTest.java +++ b/notification-core/src/test/java/org/opengroup/osdu/notification/errors/SpringExceptionMapperTest.java @@ -1,3 +1,17 @@ +// Copyright © Microsoft Corporation +// +// 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.opengroup.osdu.notification.errors; import org.junit.Before; @@ -48,36 +62,35 @@ public class SpringExceptionMapperTest { appException.setOriginalException(new NullPointerException()); ResponseEntity<Object> actual = springExceptionMapper.handleAppException(appException); AppError appError = (AppError) actual.getBody(); + assertNotNull(actual); assertEquals(400, Objects.requireNonNull(appError).getCode()); assertEquals("Sample app exception reason", appError.getReason()); assertEquals("Sample app exception message", appError.getMessage()); } - @Test public void handleValidationException() { ValidationException validationException = new ValidationException("Sample Validation Exception"); ResponseEntity<Object> actual = springExceptionMapper.handleValidationException(validationException); - assertNotNull(actual); AppError appError = (AppError) actual.getBody(); + + assertNotNull(actual); assertEquals(400, appError.getCode()); assertEquals("Sample Validation Exception", appError.getMessage()); assertEquals("Bad request", appError.getReason()); - - } @Test public void handleAccessDeniedException() { AccessDeniedException accessDeniedException = new AccessDeniedException("Sample Access Denied Exception"); ResponseEntity<Object> actual = springExceptionMapper.handleAccessDeniedException(accessDeniedException, request); - assertNotNull(actual); AppError appError = (AppError) actual.getBody(); + + assertNotNull(actual); assertEquals(401, appError.getCode()); assertEquals("Sample Access Denied Exception", appError.getMessage()); assertEquals("Unauthorized", appError.getReason()); - } @Test @@ -85,31 +98,30 @@ public class SpringExceptionMapperTest { Exception exception = new Exception("A General Exception"); ResponseEntity<Object> actual = springExceptionMapper.handleGeneralException(exception); AppError appError = (AppError) actual.getBody(); + assertNotNull(appError); assertEquals(500, appError.getCode()); assertEquals("An unknown error has occurred.", appError.getMessage()); assertEquals("Server Error", appError.getReason()); - - } @Test public void handleIOException_connectionClosed() { IOException ioException = new IOException("Sample IO Exception due to broken pipe"); ResponseEntity<Object> actual = springExceptionMapper.handleIOException(ioException); - assertEquals(actual, null); + assertEquals(actual, null); } @Test public void handleIOExceptionTest() { IOException ioException = new IOException("Sample IO Exception"); ResponseEntity<Object> actual = springExceptionMapper.handleIOException(ioException); - assertNotNull(actual); AppError appError = (AppError) actual.getBody(); + + assertNotNull(actual); assertEquals("Unknown error", appError.getReason()); assertEquals("Sample IO Exception", appError.getMessage()); assertEquals(503, appError.getCode()); - } } \ No newline at end of file diff --git a/notification-core/src/test/java/org/opengroup/osdu/notification/logging/ResponseLogFilterTest.java b/notification-core/src/test/java/org/opengroup/osdu/notification/logging/ResponseLogFilterTest.java index b9c79256cfa098a423c531daae4994934ddb2465..c78c8743fd17fa3f859c650ef863edf720ec7002 100644 --- a/notification-core/src/test/java/org/opengroup/osdu/notification/logging/ResponseLogFilterTest.java +++ b/notification-core/src/test/java/org/opengroup/osdu/notification/logging/ResponseLogFilterTest.java @@ -1,3 +1,17 @@ +// Copyright © Microsoft Corporation +// +// 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.opengroup.osdu.notification.logging; import org.junit.Before; diff --git a/notification-core/src/test/java/org/opengroup/osdu/notification/service/NotificationHandlerTest.java b/notification-core/src/test/java/org/opengroup/osdu/notification/service/NotificationHandlerTest.java index 38c6e32ec61c00724c24997e8cb37d5ff378e94d..783597c911e3bdabf02eedc7db76f5cde8ae652b 100644 --- a/notification-core/src/test/java/org/opengroup/osdu/notification/service/NotificationHandlerTest.java +++ b/notification-core/src/test/java/org/opengroup/osdu/notification/service/NotificationHandlerTest.java @@ -16,7 +16,6 @@ package org.opengroup.osdu.notification.service; -import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -37,6 +36,7 @@ import org.opengroup.osdu.notification.auth.interfaces.SecretAuth; import java.util.HashMap; import java.util.Map; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -82,7 +82,6 @@ public class NotificationHandlerTest { value.setKey("keyFile"); secret.setValue(value); gsa_subscription.setSecret(secret); - } private static void setHmac_subscription() { @@ -109,7 +108,7 @@ public class NotificationHandlerTest { when(this.secretAuth.getPushUrl(gsa_subscription.getPushEndpoint())).thenReturn(gsa_subscription.getPushEndpoint()); when(this.secretAuth.getRequestHeaders()).thenReturn(headers); HttpResponse response = this.sut.notifySubscriber(NOTIFICATION_ID, PUBSUB_MESSAGE, headers); - Assert.assertEquals(200, response.getResponseCode()); + assertEquals(200, response.getResponseCode()); } @Test @@ -122,13 +121,12 @@ public class NotificationHandlerTest { when(this.secretAuth.getPushUrl(hmac_subscription.getPushEndpoint())).thenReturn(hmac_subscription.getPushEndpoint()); when(this.secretAuth.getRequestHeaders()).thenReturn(headers); HttpResponse response = this.sut.notifySubscriber(NOTIFICATION_ID, PUBSUB_MESSAGE, headers); - Assert.assertEquals(200, response.getResponseCode()); + assertEquals(200, response.getResponseCode()); } @Test(expected = SubscriptionException.class) public void should_throwException_whenSubscriptionHandlerThrowsException() throws Exception { Map<String, String> headers = new HashMap<String, String>(); - when(subscriptionHandler.getSubscriptionFromCache(NOTIFICATION_ID)).thenThrow(new SubscriptionException("error", response)); this.sut.notifySubscriber(NOTIFICATION_ID, PUBSUB_MESSAGE, headers); fail("should throw SubscriptionException"); diff --git a/notification-core/src/test/java/org/opengroup/osdu/notification/service/SubscriptionHandlerTest.java b/notification-core/src/test/java/org/opengroup/osdu/notification/service/SubscriptionHandlerTest.java index ff1be17857647b5f857ac8fb8136b23853e940a2..f917f1fe9282d4f386a93cd0e03561e64ea2a949 100644 --- a/notification-core/src/test/java/org/opengroup/osdu/notification/service/SubscriptionHandlerTest.java +++ b/notification-core/src/test/java/org/opengroup/osdu/notification/service/SubscriptionHandlerTest.java @@ -63,7 +63,6 @@ public class SubscriptionHandlerTest { fail("should throw AppException"); } - @Test public void should_return200_whenSubscriptionGotFromRegistration() throws Exception { when(this.subscriptionCacheFactory.get(any())).thenReturn(null); diff --git a/notification-core/src/test/java/org/opengroup/osdu/notification/utils/NotificationFilterTest.java b/notification-core/src/test/java/org/opengroup/osdu/notification/utils/NotificationFilterTest.java index ba2c6125bac39578628e60660320e05edbb24f3d..ed6d109d71ef49d91b1f59983251400323b0f967 100644 --- a/notification-core/src/test/java/org/opengroup/osdu/notification/utils/NotificationFilterTest.java +++ b/notification-core/src/test/java/org/opengroup/osdu/notification/utils/NotificationFilterTest.java @@ -1,3 +1,17 @@ +// Copyright © Microsoft Corporation +// +// 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.opengroup.osdu.notification.utils; import org.junit.Before; @@ -41,7 +55,6 @@ public class NotificationFilterTest { @Mock private HttpServletResponse servletResponse; - @Before public void setup() throws ServletException, IOException { MockitoAnnotations.initMocks(NotificationFilterTest.this); @@ -53,7 +66,6 @@ public class NotificationFilterTest { notificationFilter.doFilter(servletRequest, servletResponse, filterChain); assertNotNull(dpsHeaders.getHeaders().get("correlation-id")); - assertEquals(dpsHeaders.getHeaders().get("content-type"),"application/json"); - + assertEquals(dpsHeaders.getHeaders().get("content-type"), "application/json"); } } \ No newline at end of file