2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2021 Nokia. All rights reserved.
6 * Copyright (C) 2023 AT&T Intellectual Property. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.dcae.common.publishing;
23 import com.google.gson.JsonElement;
24 import io.vavr.collection.List;
25 import io.vavr.control.Option;
26 import org.junit.jupiter.api.Test;
27 import org.junit.Assume;
28 import org.junit.Before;
30 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.ImmutableMessageRouterPublishResponse;
31 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishResponse;
32 import org.testcontainers.containers.DockerComposeContainer;
33 import org.testcontainers.junit.jupiter.Container;
34 import org.testcontainers.junit.jupiter.Testcontainers;
35 import reactor.core.publisher.Flux;
36 import reactor.test.StepVerifier;
38 import java.time.Duration;
40 import static org.onap.dcae.common.publishing.DMaapContainer.createContainerInstance;
41 import static org.onap.dcae.common.publishing.DmaapRequestConfiguration.getAsJsonElements;
44 @Testcontainers(disabledWithoutDocker = true)
45 public class PublisherTest {
48 private final DockerComposeContainer CONTAINER = createContainerInstance();
51 public void linuxOnly() {
53 (System.getProperty("os.name").toLowerCase().startsWith("win"));
57 public void publishEvent_shouldSuccessfullyPublishSingleMessage() {
59 final Publisher publisher = new Publisher();
60 final String simpleEvent = "{\"message\":\"message1\"}";
61 final List<String> twoJsonMessages = List.of(simpleEvent);
62 final MessageRouterPublishResponse expectedResponse = successPublishResponse(getAsJsonElements(twoJsonMessages));
65 final Flux<MessageRouterPublishResponse> result = publisher.publishEvents(twoJsonMessages, createPublishConfig());
68 StepVerifier.create(result)
69 .expectNext(expectedResponse)
71 .verify(Duration.ofSeconds(10));
75 private Option<PublisherConfig> createPublishConfig() {
76 List<String> desc = List.of("127.0.0.1:3904");
77 PublisherConfig conf = new PublisherConfig(desc, "topic");
78 return Option.of(conf);
81 private MessageRouterPublishResponse successPublishResponse(List<JsonElement> items) {
82 return ImmutableMessageRouterPublishResponse