gabriel-farache commented on code in PR #3944: URL: https://github.com/apache/incubator-kie-kogito-runtimes/pull/3944#discussion_r2207482627
########## quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/EventWithHeaderIT.java: ########## @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.kie.kogito.quarkus.workflows; + +import java.net.URI; +import java.time.OffsetDateTime; +import java.util.UUID; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.kie.kogito.test.quarkus.QuarkusTestProperty; +import org.kie.kogito.test.quarkus.kafka.KafkaTestClient; +import org.kie.kogito.testcontainers.quarkus.KafkaQuarkusTestResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; + +import io.cloudevents.core.builder.CloudEventBuilder; +import io.cloudevents.jackson.JsonCloudEventData; +import io.cloudevents.jackson.JsonFormat; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusIntegrationTest; +import io.restassured.path.json.JsonPath; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.kie.kogito.test.utils.ProcessInstancesRESTTestUtils.assertProcessInstanceHasFinished; + +@QuarkusIntegrationTest +@QuarkusTestResource(SimpleServerServicesMock.class) +@QuarkusTestResource(KafkaQuarkusTestResource.class) +class EventWithHeaderIT { + + private static final String SERVICE_URL = "/event-with-headers"; + private static final String SERVICE_GET_BY_ID_URL = SERVICE_URL + "/{id}"; + private static final String EVENT_TYPE = "lock-event"; + private static final String EVENT_TOPIC = "lock-event"; + + private static final String DEFAULT_OUT_EVENT_TOPIC = "kogito-sw-out-events"; + + public static final String SIMPLE_TOKEN = "TEST_TOKEN"; + + @QuarkusTestProperty(name = KafkaQuarkusTestResource.KOGITO_KAFKA_PROPERTY) + String kafkaBootstrapServers; + ObjectMapper objectMapper; + KafkaTestClient kafkaClient; + + private static final Logger LOGGER = LoggerFactory.getLogger(EventWithHeaderIT.class); + + @BeforeEach + void setup() { + kafkaClient = new KafkaTestClient(kafkaBootstrapServers); + objectMapper = new ObjectMapper() + .registerModule(new JavaTimeModule()) + .registerModule(JsonFormat.getCloudEventJacksonModule()) + .disable(com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + } + + @AfterEach + void cleanUp() { + if (kafkaClient != null) { + kafkaClient.shutdown(); + } + } + + @Test + @SuppressWarnings("squid:S2699") + void callbackStateSuccessful() throws Exception { + + String response = objectMapper.writeValueAsString(CloudEventBuilder.v1() + .withId(UUID.randomUUID().toString()) + .withSource(URI.create("")) + .withType(EventWithHeaderIT.EVENT_TYPE) + .withTime(OffsetDateTime.now()) + .withExtension("xauthorizationsimple", SIMPLE_TOKEN) + .withData(JsonCloudEventData.wrap(objectMapper.createObjectNode().put("name", "The Kraken"))) + .build()); + + final CountDownLatch countDownLatch = new CountDownLatch(1); + final AtomicReference<String> cloudEvent = new AtomicReference<>(); + kafkaClient.consume(DEFAULT_OUT_EVENT_TOPIC, rawCloudEvent -> { + cloudEvent.set(rawCloudEvent); + countDownLatch.countDown(); Review Comment: I cannot really test the processInstanceID in itself as I cannot know which it is until I received the callback `id-event` CloudEvent, what I can do is to test that the event is of type `lock-event` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
