diff options
author | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2022-10-12 09:23:14 +0200 |
---|---|---|
committer | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2022-10-12 09:15:00 +0000 |
commit | 9adde5462ff9fd281eb5057dbb4c58e4676a9d90 (patch) | |
tree | 527e86981639b7d2599838a34f72e858479a1408 /aai-traversal/src/test/java | |
parent | 538ab0a28c329916c4c76c4574b4f7051d5093a8 (diff) |
Enhancement of AAI-traversal healthcheck
- enhance the EchoResponse endpoint to check for db connectivity when the myAction parameter is provided
Issue-ID: AAI-3547
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Change-Id: I4d5686b63efd139b942cee0c222305a17d2a2497
Diffstat (limited to 'aai-traversal/src/test/java')
-rw-r--r-- | aai-traversal/src/test/java/org/onap/aai/rest/util/AaiGraphCheckerTest.java | 43 | ||||
-rw-r--r-- | aai-traversal/src/test/java/org/onap/aai/rest/util/EchoResponseTest.java | 50 |
2 files changed, 78 insertions, 15 deletions
diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/util/AaiGraphCheckerTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/util/AaiGraphCheckerTest.java new file mode 100644 index 0000000..409c021 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/util/AaiGraphCheckerTest.java @@ -0,0 +1,43 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022 Bell Canada + * Modification Copyright (C) 2022 Deutsche Telekom SA + * ================================================================================ + * 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.aai.rest.util; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.onap.aai.AAISetup; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; + +@ContextConfiguration(classes = {AaiGraphChecker.class}) +public class AaiGraphCheckerTest extends AAISetup { + + @Autowired + private AaiGraphChecker graphChecker; + + @Test + public void testIsAaiGraphDbAvailable() { + Boolean result = graphChecker.isAaiGraphDbAvailable(); + + assertNotNull(result); + assertTrue(result); + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/util/EchoResponseTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/util/EchoResponseTest.java index 97702fa..eb67799 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/util/EchoResponseTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/util/EchoResponseTest.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -21,7 +21,7 @@ package org.onap.aai.rest.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.mockito.ArgumentMatchers.anyObject; +import static org.mockito.ArgumentMatchers.anyObject;import static org.mockito.ArgumentMatchers.anyObject; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -59,6 +59,8 @@ public class EchoResponseTest { private EchoResponse echoResponse; + private final AaiGraphChecker aaiGraphCheckerMock = mock(AaiGraphChecker.class); + private HttpHeaders httpHeaders; private UriInfo uriInfo; @@ -73,15 +75,15 @@ public class EchoResponseTest { private static final Logger logger = LoggerFactory.getLogger(EchoResponseTest.class.getName()); @Before - public void setup() { + public void setup(){ logger.info("Starting the setup for the integration tests of Rest Endpoints"); - echoResponse = new EchoResponse(); - httpHeaders = mock(HttpHeaders.class); - uriInfo = mock(UriInfo.class); + echoResponse = new EchoResponse(aaiGraphCheckerMock); + httpHeaders = mock(HttpHeaders.class); + uriInfo = mock(UriInfo.class); - headersMultiMap = new MultivaluedHashMap<>(); - queryParameters = Mockito.spy(new MultivaluedHashMap<>()); + headersMultiMap = new MultivaluedHashMap<>(); + queryParameters = Mockito.spy(new MultivaluedHashMap<>()); headersMultiMap.add("X-FromAppId", "JUNIT"); headersMultiMap.add("X-TransactionId", UUID.randomUUID().toString()); @@ -102,11 +104,11 @@ public class EchoResponseTest { when(httpHeaders.getRequestHeader("aai-request-context")).thenReturn(aaiRequestContextList); + when(uriInfo.getQueryParameters()).thenReturn(queryParameters); when(uriInfo.getQueryParameters(false)).thenReturn(queryParameters); - // TODO - Check if this is valid since RemoveDME2QueryParameters seems to be very - // unreasonable + // TODO - Check if this is valid since RemoveDME2QueryParameters seems to be very unreasonable Mockito.doReturn(null).when(queryParameters).remove(anyObject()); when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); @@ -115,17 +117,35 @@ public class EchoResponseTest { @Test public void testEchoResultWhenValidHeaders() throws Exception { - Response response = echoResponse.echoResult(httpHeaders, null, ""); + Response response = echoResponse.echoResult(httpHeaders, null, null); assertNotNull(response); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); } @Test + public void testEchoResultWhenActionIsProvidedDbAvailable() throws Exception { + when(aaiGraphCheckerMock.isAaiGraphDbAvailable()).thenReturn(true); + Response response = echoResponse.echoResult(httpHeaders, null, "myAction"); + + assertNotNull(response); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); + } + + @Test + public void testEchoResultWhenActionIsProvidedDbNotAvailable() throws Exception { + when(aaiGraphCheckerMock.isAaiGraphDbAvailable()).thenReturn(false); + Response response = echoResponse.echoResult(httpHeaders, null, "myAction"); + + assertNotNull(response); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); + } + + @Test public void testEchoResultWhenInValidHeadersThrowsBadRequest() throws Exception { httpHeaders = mock(HttpHeaders.class); - Response response = echoResponse.echoResult(httpHeaders, null, ""); + Response response = echoResponse.echoResult(httpHeaders, null, null); assertNotNull(response); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); @@ -135,11 +155,11 @@ public class EchoResponseTest { public void testEchoResultWhenValidHeadersButMediaTypeWrong() throws Exception { when(httpHeaders.getAcceptableMediaTypes()).thenThrow(new IllegalStateException()) - .thenReturn(outputMediaTypes); + .thenReturn(outputMediaTypes); - Response response = echoResponse.echoResult(httpHeaders, null, ""); + Response response = echoResponse.echoResult(httpHeaders, null, null); assertNotNull(response); assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); } -} +}
\ No newline at end of file |