2e6b63b83702118156c5c6383b0d4ccd168d141c
[dcaegen2/collectors/datafile.git] /
1 /*
2  * ============LICENSE_START======================================================================
3  * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved.
4  * ===============================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6  * in compliance with the License. You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software distributed under the License
11  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12  * or implied. See the License for the specific language governing permissions and limitations under
13  * the License.
14  * ============LICENSE_END========================================================================
15  */
16
17 package org.onap.dcaegen2.collectors.datafile.configuration;
18
19 import static org.assertj.core.api.Assertions.assertThat;
20
21 import com.google.gson.JsonObject;
22
23 import org.junit.jupiter.api.Test;
24 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration;
25 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
26 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapConsumerConfiguration;
27 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapPublisherConfiguration;
28
29
30 class CloudConfigParserTest {
31
32     private static final ImmutableDmaapConsumerConfiguration CORRECT_DMAAP_CONSUMER_CONFIG =
33             new ImmutableDmaapConsumerConfiguration.Builder().timeoutMs(-1)
34                     .dmaapHostName("message-router.onap.svc.cluster.local").dmaapUserName("admin")
35                     .dmaapUserPassword("admin").dmaapTopicName("/events/unauthenticated.VES_NOTIFICATION_OUTPUT")
36                     .dmaapPortNumber(2222).dmaapContentType("application/json").messageLimit(-1).dmaapProtocol("http")
37                     .consumerId("C12").consumerGroup("OpenDCAE-c12").trustStorePath("trustStorePath")
38                     .trustStorePasswordPath("trustStorePasswordPath").keyStorePath("keyStorePath")
39                     .keyStorePasswordPath("keyStorePasswordPath").enableDmaapCertAuth(true)
40                     .build();
41
42     private static final ImmutableDmaapPublisherConfiguration CORRECT_DMAAP_PUBLISHER_CONFIG =
43             new ImmutableDmaapPublisherConfiguration.Builder().dmaapTopicName("publish").dmaapUserPassword("dradmin")
44                     .dmaapPortNumber(3907).dmaapProtocol("https").dmaapContentType("application/json")
45                     .dmaapHostName("message-router.onap.svc.cluster.local").dmaapUserName("dradmin")
46                     .trustStorePath("trustStorePath")
47                     .trustStorePasswordPath("trustStorePasswordPath").keyStorePath("keyStorePath")
48                     .keyStorePasswordPath("keyStorePasswordPath").enableDmaapCertAuth(true)
49                     .build();
50
51     private static final ImmutableFtpesConfig CORRECT_FTPES_CONFIGURATION =
52             new ImmutableFtpesConfig.Builder().keyCert("/config/ftpKey.jks").keyPassword("secret")
53                     .trustedCA("config/cacerts").trustedCAPassword("secret").build();
54
55     private CloudConfigParser cloudConfigParser = new CloudConfigParser(getCloudConfigJsonObject());
56
57     @Test
58     public void shouldCreateDmaapConsumerConfigurationCorrectly() {
59         DmaapConsumerConfiguration dmaapConsumerConfig = cloudConfigParser.getDmaapConsumerConfig();
60
61         assertThat(dmaapConsumerConfig).isNotNull();
62         assertThat(dmaapConsumerConfig).isEqualToComparingFieldByField(CORRECT_DMAAP_CONSUMER_CONFIG);
63     }
64
65     @Test
66     public void shouldCreateDmaapPublisherConfigurationCorrectly() {
67         DmaapPublisherConfiguration dmaapPublisherConfig = cloudConfigParser.getDmaapPublisherConfig();
68
69         assertThat(dmaapPublisherConfig).isNotNull();
70         assertThat(dmaapPublisherConfig).isEqualToComparingFieldByField(CORRECT_DMAAP_PUBLISHER_CONFIG);
71     }
72
73     @Test
74     public void shouldCreateFtpesConfigurationCorrectly() {
75         FtpesConfig ftpesConfig = cloudConfigParser.getFtpesConfig();
76
77         assertThat(ftpesConfig).isNotNull();
78         assertThat(ftpesConfig).isEqualToComparingFieldByField(CORRECT_FTPES_CONFIGURATION);
79     }
80
81     public JsonObject getCloudConfigJsonObject() {
82         JsonObject config = new JsonObject();
83         config.addProperty("dmaap.dmaapConsumerConfiguration.timeoutMS", -1);
84         config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapHostName", "message-router.onap.svc.cluster.local");
85         config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapUserName", "admin");
86         config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapUserPassword", "admin");
87         config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapTopicName",
88                 "/events/unauthenticated.VES_NOTIFICATION_OUTPUT");
89         config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapPortNumber", 2222);
90         config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapContentType", "application/json");
91         config.addProperty("dmaap.dmaapConsumerConfiguration.messageLimit", -1);
92         config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapProtocol", "http");
93         config.addProperty("dmaap.dmaapConsumerConfiguration.consumerId", "C12");
94         config.addProperty("dmaap.dmaapConsumerConfiguration.consumerGroup", "OpenDCAE-c12");
95         config.addProperty("dmaap.dmaapProducerConfiguration.dmaapTopicName", "publish");
96         config.addProperty("dmaap.dmaapProducerConfiguration.dmaapProtocol", "https");
97         config.addProperty("dmaap.dmaapProducerConfiguration.dmaapContentType", "application/json");
98         config.addProperty("dmaap.dmaapProducerConfiguration.dmaapHostName", "message-router.onap.svc.cluster.local");
99         config.addProperty("dmaap.dmaapProducerConfiguration.dmaapPortNumber", 3907);
100         config.addProperty("dmaap.dmaapProducerConfiguration.dmaapUserName", "dradmin");
101         config.addProperty("dmaap.dmaapProducerConfiguration.dmaapUserPassword", "dradmin");
102         config.addProperty("dmaap.ftpesConfig.keyCert", "/config/ftpKey.jks");
103         config.addProperty("dmaap.ftpesConfig.keyPassword", "secret");
104         config.addProperty("dmaap.ftpesConfig.trustedCA", "config/cacerts");
105         config.addProperty("dmaap.ftpesConfig.trustedCAPassword", "secret");
106
107         config.addProperty("dmaap.security.trustStorePath", "trustStorePath");
108         config.addProperty("dmaap.security.trustStorePasswordPath", "trustStorePasswordPath");
109         config.addProperty("dmaap.security.keyStorePath", "keyStorePath");
110         config.addProperty("dmaap.security.keyStorePasswordPath", "keyStorePasswordPath");
111         config.addProperty("dmaap.security.enableDmaapCertAuth", "true");
112
113         return config;
114     }
115 }