diff options
author | 2024-11-22 13:53:42 +0100 | |
---|---|---|
committer | 2025-01-07 09:58:46 +0100 | |
commit | dd4a7968d539a958b2ddccb77d00fcb68eb177b7 (patch) | |
tree | 7cba2ac4c6b414c35dc57f255cceb849f6cebe05 /aai-resources/src/test | |
parent | cd19e26cd9fd7f74662053c06d0cde4513faddf5 (diff) |
Use GraphChecker from aai-common
Issue-ID: AAI-4069
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Change-Id: I52e5d412d038dd3e89091cbbcb4e0b23fefc6541
Diffstat (limited to 'aai-resources/src/test')
4 files changed, 19 insertions, 137 deletions
diff --git a/aai-resources/src/test/java/org/onap/aai/rest/util/EchoHealthIndicatorTest.java b/aai-resources/src/test/java/org/onap/aai/rest/util/EchoHealthIndicatorTest.java index f6f74804..5040e5d3 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/util/EchoHealthIndicatorTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/util/EchoHealthIndicatorTest.java @@ -24,8 +24,7 @@ import static org.mockito.Mockito.when; import org.junit.jupiter.api.Test; import org.onap.aai.config.WebClientConfiguration; -import org.onap.aai.tasks.AaiGraphChecker; -import org.onap.aai.tasks.AaiGraphChecker.CheckerType; +import org.onap.aai.util.GraphChecker; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.context.SpringBootTest; @@ -44,11 +43,12 @@ public class EchoHealthIndicatorTest { @Qualifier("mgmtClient") WebTestClient webClient; - @MockBean private AaiGraphChecker aaiGraphChecker; + // @MockBean private AaiGraphChecker aaiGraphChecker; + @MockBean private GraphChecker graphChecker; @Test public void thatActuatorCheckIsHealthy() { - when(aaiGraphChecker.isAaiGraphDbAvailable(CheckerType.ACTUAL)).thenReturn(true); + when(graphChecker.isAaiGraphDbAvailable()).thenReturn(true); webClient.get() .uri("/actuator/health") @@ -59,7 +59,7 @@ public class EchoHealthIndicatorTest { @Test public void thatActuatorCheckIsUnhealthy() { - when(aaiGraphChecker.isAaiGraphDbAvailable(CheckerType.ACTUAL)).thenReturn(false); + when(graphChecker.isAaiGraphDbAvailable()).thenReturn(false); webClient.get() .uri("/actuator/health") diff --git a/aai-resources/src/test/java/org/onap/aai/rest/util/EchoResponseTest.java b/aai-resources/src/test/java/org/onap/aai/rest/util/EchoResponseTest.java index 030e870a..f483cd91 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/util/EchoResponseTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/util/EchoResponseTest.java @@ -44,28 +44,25 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.onap.aai.AAISetup; -import org.onap.aai.tasks.AaiGraphChecker; -import org.onap.aai.tasks.AaiGraphChecker.CheckerType; +import org.onap.aai.config.GraphConfig; +import org.onap.aai.util.GraphChecker; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = {AaiGraphChecker.class}) +@ContextConfiguration(classes = {GraphConfig.class, GraphChecker.class}) public class EchoResponseTest extends AAISetup { private static final Logger logger = LoggerFactory.getLogger(EchoResponseTest.class); protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); - private static final String CHECK_DB_ACTION = "checkDB"; - private static final String CHECK_DB_STATUS_NOW_ACTION = "checkDBNow"; - private final EchoResponse echoResponse; - private final AaiGraphChecker aaiGraphCheckerMock = mock(AaiGraphChecker.class); + private final GraphChecker graphCheckerMock = mock(GraphChecker.class); private HttpHeaders httpHeaders; private List<MediaType> outputMediaTypes; public EchoResponseTest() { - this.echoResponse = new EchoResponse(aaiGraphCheckerMock); + this.echoResponse = new EchoResponse(graphCheckerMock); } @BeforeEach @@ -105,79 +102,33 @@ public class EchoResponseTest extends AAISetup { } @Test - public void testEchoResultWhenValidHeaders() { - - Response response = echoResponse.echoResult(httpHeaders, null, ""); - - assertNotNull(response); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); - } - - @Test public void testEchoResultWhenInValidHeadersThrowsBadRequest() { httpHeaders = mock(HttpHeaders.class); - Response response = echoResponse.echoResult(httpHeaders, null, ""); + Response response = echoResponse.echoResult(httpHeaders, null); assertNotNull(response); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @Test - public void testCheckDbAction_CachedSuccess() { - // Prepare - when(aaiGraphCheckerMock.isAaiGraphDbAvailable(CheckerType.CACHED)).thenReturn(Boolean.TRUE); - // Run - Response response = echoResponse.echoResult(httpHeaders, null, CHECK_DB_ACTION); - // Verify - verify(aaiGraphCheckerMock, never()).isAaiGraphDbAvailable(CheckerType.ACTUAL); - assertNotNull(response); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); - } + public void testCheckDbNowAction_Success() { + when(graphCheckerMock.isAaiGraphDbAvailable()).thenReturn(true); - @Test - public void testCheckDbAction_CachedFailure() { - // Prepare - when(aaiGraphCheckerMock.isAaiGraphDbAvailable(CheckerType.CACHED)).thenReturn(Boolean.FALSE); - // Run - Response response = echoResponse.echoResult(httpHeaders, null, CHECK_DB_ACTION); - // Verify - verify(aaiGraphCheckerMock, never()).isAaiGraphDbAvailable(CheckerType.ACTUAL); - assertNotNull(response); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); - } + Response response = echoResponse.echoResult(httpHeaders, null); - @Test - public void testCheckDbNowAction_Success() { - // Prepare - when(aaiGraphCheckerMock.isAaiGraphDbAvailable(CheckerType.ACTUAL)).thenReturn(Boolean.TRUE); - // Run - Response response = echoResponse.echoResult(httpHeaders, null, CHECK_DB_STATUS_NOW_ACTION); - // Verify assertNotNull(response); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); } @Test public void testCheckDbNowAction_Failure() { - // Prepare - when(aaiGraphCheckerMock.isAaiGraphDbAvailable(CheckerType.ACTUAL)).thenReturn(Boolean.FALSE); - // Run - Response response = echoResponse.echoResult(httpHeaders, null, CHECK_DB_STATUS_NOW_ACTION); - // Verify - assertNotNull(response); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); - } + when(graphCheckerMock.isAaiGraphDbAvailable()).thenReturn(false); + + Response response = echoResponse.echoResult(httpHeaders, null); - @Test - public void testCheckDbNowAction_Unknown() { - // Prepare - when(aaiGraphCheckerMock.isAaiGraphDbAvailable(CheckerType.ACTUAL)).thenReturn(null); - // Run - Response response = echoResponse.echoResult(httpHeaders, null, CHECK_DB_STATUS_NOW_ACTION); - // Verify assertNotNull(response); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); } } diff --git a/aai-resources/src/test/java/org/onap/aai/task/AaiGraphCheckerTest.java b/aai-resources/src/test/java/org/onap/aai/task/AaiGraphCheckerTest.java deleted file mode 100644 index a4e83309..00000000 --- a/aai-resources/src/test/java/org/onap/aai/task/AaiGraphCheckerTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2022 Bell Canada - * ================================================================================ - * 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.task; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; -import org.onap.aai.AAISetup; -import org.onap.aai.tasks.AaiGraphChecker; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.TestPropertySource; - -@ContextConfiguration(classes = {AaiGraphChecker.class}) -@TestPropertySource(properties = "aai.graph.checker.task.enabled=true") -public class AaiGraphCheckerTest extends AAISetup { - - @Autowired - private AaiGraphChecker subject; - - @Test - public void testIsAaiGraphDbAvailable_Actual() { - // Run - Boolean result = subject.isAaiGraphDbAvailable(AaiGraphChecker.CheckerType.ACTUAL); - // Verify - assertNotNull(result); - assertTrue(result); - } - - @Test - public void testIsAaiGraphDbAvailable_CachedAfterClear() { - // Prepare - subject.clearDbAvailabilityCachedIndicator(); - // Run - Boolean result = subject.isAaiGraphDbAvailable(AaiGraphChecker.CheckerType.CACHED); - // Verify - assertNull(result); - } - - @Test - public void testIsAaiGraphDbAvailable_CachedAfterActual() { - // Prepare - subject.clearDbAvailabilityCachedIndicator(); - subject.isAaiGraphDbAvailable(AaiGraphChecker.CheckerType.ACTUAL); - // Run - Boolean result = subject.isAaiGraphDbAvailable(AaiGraphChecker.CheckerType.CACHED); - // Verify - assertNotNull(result); - assertTrue(result); - } - -} diff --git a/aai-resources/src/test/resources/application-test.properties b/aai-resources/src/test/resources/application-test.properties index 2118d045..622715d8 100644 --- a/aai-resources/src/test/resources/application-test.properties +++ b/aai-resources/src/test/resources/application-test.properties @@ -81,3 +81,4 @@ management.metrics.web.server.request.autotime.enabled=false scrape.uri.metrics=true aai.notifications.enabled=false +aai.graph.properties.path=src/test/resources/etc/appprops/janusgraph-realtime.properties |