Replace cambria with DmaaP client
[dcaegen2/collectors/ves.git] / src / test / java / org / onap / dcae / multiplestreamreducer / MultipleStreamReducerTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * VES Collector
4  * ================================================================================
5  * Copyright (C) 2021 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.dcae.multiplestreamreducer;
21
22 import io.vavr.collection.HashMap;
23 import io.vavr.collection.Map;
24 import org.junit.jupiter.api.Test;
25
26 import static org.junit.jupiter.api.Assertions.*;
27
28 class MultipleStreamReducerTest {
29
30     private final MultipleStreamReducer multipleStreamReducer = new MultipleStreamReducer();
31     private final Map<String, String[]> domainToStreams = HashMap.of(
32             "fault", new String[]{"ves-fault", "stream1", "stream2"},
33             "log", new String[]{"ves-syslog", "stream3", "stream4", "stream5"},
34             "test", new String[]{"stream6"}
35     );
36
37     @Test
38     void shouldReduceStreamsToTheFirstOne() {
39         //given
40         Map<String, String> expected = HashMap.of(
41                 "fault", "ves-fault",
42                 "log", "ves-syslog",
43                 "test", "stream6"
44         );
45
46         //when
47         final Map<String, String> domainToStreamsAfterReduce = multipleStreamReducer.reduce(domainToStreams);
48
49         //then
50         assertEquals(expected, domainToStreamsAfterReduce);
51     }
52
53     @Test
54     void shouldReturnInfoAboutDomainToStreamsConfig() {
55         //given
56         final Map<String, String> domainToStreamsAfterReduce = multipleStreamReducer.reduce(domainToStreams);
57         String expectedRedundantStreamsInfo =
58                 "Domain: fault has active stream: ves-fault\n" +
59                 "Domain: log has active stream: ves-syslog\n" +
60                 "Domain: test has active stream: stream6\n";
61
62         //when
63         final String domainToStreamsConfigInfo = multipleStreamReducer.getDomainToStreamsInfo(domainToStreamsAfterReduce);
64
65         //then
66         assertEquals(expectedRedundantStreamsInfo, domainToStreamsConfigInfo);
67     }
68
69 }