3c746940280df17fc680ce89051516d867e3d865
[dcaegen2/services/prh.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * PNF-REGISTRATION-HANDLER
4  * ================================================================================
5  * Copyright (C) 2018 NOKIA Intellectual Property. 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
21 package org.onap.dcaegen2.services.prh.configuration;
22
23 import static java.lang.ClassLoader.getSystemResource;
24 import static org.assertj.core.api.Assertions.assertThat;
25
26 import com.google.gson.Gson;
27 import com.google.gson.JsonObject;
28 import java.nio.file.Files;
29 import java.nio.file.Paths;
30 import org.junit.jupiter.api.Test;
31 import org.onap.dcaegen2.services.prh.TestAppConfiguration;
32 import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
33 import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.ImmutableAaiClientConfiguration;
34 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration;
35 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
36 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapConsumerConfiguration;
37 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapPublisherConfiguration;
38
39
40 class ConsulConfigurationParserTest {
41
42     private final String correctJson =
43             new String(Files.readAllBytes(Paths.get(getSystemResource("flattened_configuration.json").toURI())));
44     private final ImmutableAaiClientConfiguration correctAaiClientConfig =
45             TestAppConfiguration.createDefaultAaiClientConfiguration();
46     private final ImmutableDmaapConsumerConfiguration correctDmaapConsumerConfig =
47             TestAppConfiguration.createDefaultDmaapConsumerConfiguration();
48     private final ImmutableDmaapPublisherConfiguration correctDmaapPublisherConfig =
49             TestAppConfiguration.createDefaultDmaapPublisherConfiguration();
50     private final ConsulConfigurationParser consulConfigurationParser = new ConsulConfigurationParser(
51             new Gson().fromJson(correctJson, JsonObject.class));
52
53     ConsulConfigurationParserTest() throws Exception {
54     }
55
56     @Test
57     void shouldCreateAaiConfigurationCorrectly() {
58         // when
59         AaiClientConfiguration aaiClientConfig = consulConfigurationParser.getAaiClientConfig();
60
61         // then
62         assertThat(aaiClientConfig).isNotNull();
63         assertThat(aaiClientConfig).isEqualToComparingFieldByField(correctAaiClientConfig);
64     }
65
66
67     @Test
68     void shouldCreateDmaapConsumerConfigurationCorrectly() {
69         // when
70         DmaapConsumerConfiguration dmaapConsumerConfig = consulConfigurationParser.getDmaapConsumerConfig();
71
72         // then
73         assertThat(dmaapConsumerConfig).isNotNull();
74         assertThat(dmaapConsumerConfig).isEqualToComparingFieldByField(correctDmaapConsumerConfig);
75     }
76
77
78     @Test
79     void shouldCreateDmaapPublisherConfigurationCorrectly() {
80         // when
81         DmaapPublisherConfiguration dmaapPublisherConfig = consulConfigurationParser.getDmaapPublisherConfig();
82
83         // then
84         assertThat(dmaapPublisherConfig).isNotNull();
85         assertThat(dmaapPublisherConfig).isEqualToComparingFieldByField(correctDmaapPublisherConfig);
86     }
87 }