diff options
author | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2024-09-06 13:54:33 +0200 |
---|---|---|
committer | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2024-09-06 14:29:37 +0200 |
commit | 089252de752d987756ae339b4a719ad689d02aa9 (patch) | |
tree | 7f73d120df6ec194014d96a3d92da00f57ec1a68 /aai-core/src/test/java | |
parent | 0b348940476f4264aa0c1f3976760e8e70afbc25 (diff) |
AAI events are not being published
- create e2e test case for notification sending
- fix notification sending
- disable tests since they can only be active with some larger refactoring
Issue-ID: AAI-3988
Change-Id: I498b3b02218d81821dd17c3d8ad0da4de859924b
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Diffstat (limited to 'aai-core/src/test/java')
-rw-r--r-- | aai-core/src/test/java/org/onap/aai/kafka/AAIKafkaEventIntegrationTest.java | 77 |
1 files changed, 76 insertions, 1 deletions
diff --git a/aai-core/src/test/java/org/onap/aai/kafka/AAIKafkaEventIntegrationTest.java b/aai-core/src/test/java/org/onap/aai/kafka/AAIKafkaEventIntegrationTest.java index 0f5f47ad..56a6a857 100644 --- a/aai-core/src/test/java/org/onap/aai/kafka/AAIKafkaEventIntegrationTest.java +++ b/aai-core/src/test/java/org/onap/aai/kafka/AAIKafkaEventIntegrationTest.java @@ -20,16 +20,38 @@ package org.onap.aai.kafka; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.Mockito.when; +import java.io.IOException; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; import java.util.Collections; +import java.util.List; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.UriInfo; import org.apache.kafka.clients.consumer.Consumer; -import org.apache.kafka.clients.consumer.ConsumerRecord; import org.apache.kafka.clients.consumer.ConsumerRecords; +import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.mockito.Mock; import org.onap.aai.AAISetup; import org.onap.aai.PayloadUtil; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.introspection.Introspector; +import org.onap.aai.introspection.Loader; +import org.onap.aai.parsers.query.QueryParser; +import org.onap.aai.rest.db.DBRequest; +import org.onap.aai.restcore.HttpMethod; +import org.onap.aai.serialization.engines.TransactionalGraphEngine; +import org.onap.aai.setup.SchemaVersion; import org.skyscreamer.jsonassert.JSONAssert; import org.skyscreamer.jsonassert.JSONCompareMode; import org.springframework.beans.factory.annotation.Autowired; @@ -41,8 +63,10 @@ import org.springframework.kafka.test.utils.KafkaTestUtils; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.TestPropertySource; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; +@Ignore @Slf4j @ActiveProfiles("kafka") @Import(KafkaTestConfiguration.class) @@ -66,6 +90,18 @@ public class AAIKafkaEventIntegrationTest extends AAISetup { @Autowired private ConsumerFactory<String, String> consumerFactory; + @Mock UriInfo uriInfoMock; + @Mock MultivaluedMap<String, String> queryParamsMock; + @Mock HttpHeaders headersMock; + + @Before + public void setup() { + when(headersMock.getAcceptableMediaTypes()).thenReturn(Collections.singletonList(MediaType.APPLICATION_JSON_TYPE)); + when(uriInfoMock.getQueryParameters(anyBoolean())).thenReturn(queryParamsMock); + when(queryParamsMock.getFirst("depth")).thenReturn("0"); + when(headersMock.getRequestHeader("aai-request-context")).thenReturn(null); + } + @Test public void onMessage_shouldSendMessageToKafkaTopic_whenAAIEventReceived() throws Exception { @@ -84,4 +120,43 @@ public class AAIKafkaEventIntegrationTest extends AAISetup { }); } + @Test + @Ignore + // only works when aai.jms.enable=true in aaiconfig.properties + public void thatEventsAreBeingCreated() throws AAIException, IOException { + Consumer<String, String> consumer = consumerFactory.createConsumer(); + consumer.subscribe(Collections.singletonList("AAI-EVENT")); + + traversalUriHttpEntry.setHttpEntryProperties(new SchemaVersion("v14")); + String pserverUri = "/aai/v14/cloud-infrastructure/pservers/pserver/pserver1"; + String entity = new String(Files.readAllBytes(Paths.get("src/test/resources/payloads/templates/pserver.json"))).replace("${hostname}", "pserver1"); + DBRequest dbRequest = createDBRequest(pserverUri, entity); + List<DBRequest> dbRequests = new ArrayList<>(); + dbRequests.add(dbRequest); + + traversalUriHttpEntry.process(dbRequests, "test"); + + ConsumerRecords<String, String> consumerRecords = KafkaTestUtils.getRecords(consumer, 100000); + assertFalse(consumerRecords.isEmpty()); + String expectedResponse = PayloadUtil.getExpectedPayload("pserver-event.json"); + + consumerRecords.forEach(consumerRecord -> { + JSONAssert.assertEquals(expectedResponse, consumerRecord.value(), JSONCompareMode.LENIENT); + }); + } + + @SneakyThrows + private DBRequest createDBRequest(String uri, String entity) { + TransactionalGraphEngine dbEngine = traversalUriHttpEntry.getDbEngine(); + Loader loader = traversalUriHttpEntry.getLoader(); + URI uriObject = new URI(uri); + QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject); + String objName = uriQuery.getResultType(); + Introspector obj = loader.unmarshal(objName, entity, + org.onap.aai.restcore.MediaType.getEnum("application/json")); + return new DBRequest.Builder(HttpMethod.PUT, uriObject, uriQuery, obj, headersMock, uriInfoMock, "someTransaction") + .rawRequestContent(entity) + .build(); + } + } |