2 * ============LICENSE_START====================================
3 * DCAEGEN2-SERVICES-SDK
4 * =========================================================
5 * Copyright (C) 2019 Nokia. All rights reserved.
6 * =========================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=====================================
21 package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api;
23 import static org.onap.dcaegen2.services.sdk.rest.services.adapters.http.test.DummyHttpServer.sendString;
25 import com.google.gson.JsonElement;
26 import com.google.gson.JsonPrimitive;
27 import io.vavr.collection.List;
28 import java.time.Duration;
29 import org.junit.jupiter.api.BeforeAll;
30 import org.junit.jupiter.api.Test;
31 import org.onap.dcaegen2.services.sdk.model.streams.dmaap.ImmutableMessageRouterSink;
32 import org.onap.dcaegen2.services.sdk.model.streams.dmaap.MessageRouterSink;
33 import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.test.DummyHttpServer;
34 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.ImmutableMessageRouterPublishRequest;
35 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.ImmutableMessageRouterPublishResponse;
36 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishRequest;
37 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishResponse;
38 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.config.MessageRouterPublisherConfig;
39 import reactor.core.publisher.Flux;
40 import reactor.core.publisher.Mono;
41 import reactor.test.StepVerifier;
44 * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a>
47 class MessageRouterPublisherIT {
48 private MessageRouterPublisher sut = DmaapClientFactory.createMessageRouterPublisher(MessageRouterPublisherConfig.createDefault());
49 private static DummyHttpServer server;
50 private static MessageRouterSink sinkDefinition;
54 server = DummyHttpServer.start(routes ->
55 routes.post("/events/TOPIC", (req, resp) -> sendString(resp, Mono.just("TODO")))
57 sinkDefinition = ImmutableMessageRouterSink.builder()
59 .topicUrl(String.format("http://%s:%d/events/TOPIC", server.host(), server.port()))
65 final MessageRouterPublishRequest mrRequest = ImmutableMessageRouterPublishRequest.builder()
66 .sinkDefinition(sinkDefinition)
69 final Flux<MessageRouterPublishResponse> result = sut
70 .put(mrRequest, Flux.just("ala", "ma", "kota").map(JsonPrimitive::new));
72 final List<JsonElement> expectedItems = List.of("ala", "ma", "kota").map(JsonPrimitive::new);
73 StepVerifier.create(result)
74 .expectNext(ImmutableMessageRouterPublishResponse.builder().items(expectedItems).build())
76 .verify(Duration.ofSeconds(10));