b67fac2393dfee6c039ed7052722728b8fff8ccf
[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     private static final ImmutableDmaapConsumerConfiguration CORRECT_DMAAP_CONSUMER_CONFIG = //
32             new ImmutableDmaapConsumerConfiguration.Builder() //
33                     .timeoutMs(-1) //
34                     .dmaapHostName("message-router.onap.svc.cluster.local") //
35                     .dmaapUserName("admin") //
36                     .dmaapUserPassword("admin") //
37                     .dmaapTopicName("/events/unauthenticated.VES_NOTIFICATION_OUTPUT") //
38                     .dmaapPortNumber(2222) //
39                     .dmaapContentType("application/json") //
40                     .messageLimit(-1) //
41                     .dmaapProtocol("http") //
42                     .consumerId("C12") //
43                     .consumerGroup("OpenDCAE-c12") //
44                     .trustStorePath("trustStorePath") //
45                     .trustStorePasswordPath("trustStorePasswordPath") //
46                     .keyStorePath("keyStorePath") //
47                     .keyStorePasswordPath("keyStorePasswordPath") //
48                     .enableDmaapCertAuth(true) //
49                     .build();
50
51     private static final ImmutableDmaapPublisherConfiguration CORRECT_DMAAP_PUBLISHER_CONFIG = //
52             new ImmutableDmaapPublisherConfiguration.Builder() //
53                     .dmaapTopicName("publish") //
54                     .dmaapUserPassword("dradmin") //
55                     .dmaapPortNumber(3907) //
56                     .dmaapProtocol("https") //
57                     .dmaapContentType("application/json") //
58                     .dmaapHostName("message-router.onap.svc.cluster.local") //
59                     .dmaapUserName("dradmin") //
60                     .trustStorePath("trustStorePath") //
61                     .trustStorePasswordPath("trustStorePasswordPath") //
62                     .keyStorePath("keyStorePath") //
63                     .keyStorePasswordPath("keyStorePasswordPath") //
64                     .enableDmaapCertAuth(true) //
65                     .build();
66
67     private static final ImmutableFtpesConfig CORRECT_FTPES_CONFIGURATION = //
68             new ImmutableFtpesConfig.Builder() //
69                     .keyCert("/config/ftpKey.jks") //
70                     .keyPassword("secret") //
71                     .trustedCA("config/cacerts") //
72                     .trustedCAPassword("secret") //
73                     .build();
74
75     private CloudConfigParser cloudConfigParser = new CloudConfigParser(getCloudConfigJsonObject());
76
77     @Test
78     public void shouldCreateDmaapConsumerConfigurationCorrectly() {
79         DmaapConsumerConfiguration dmaapConsumerConfig = cloudConfigParser.getDmaapConsumerConfig();
80
81         assertThat(dmaapConsumerConfig).isNotNull();
82         assertThat(dmaapConsumerConfig).isEqualToComparingFieldByField(CORRECT_DMAAP_CONSUMER_CONFIG);
83     }
84
85     @Test
86     public void shouldCreateDmaapPublisherConfigurationCorrectly() {
87         DmaapPublisherConfiguration dmaapPublisherConfig = cloudConfigParser.getDmaapPublisherConfig();
88
89         assertThat(dmaapPublisherConfig).isNotNull();
90         assertThat(dmaapPublisherConfig).isEqualToComparingFieldByField(CORRECT_DMAAP_PUBLISHER_CONFIG);
91     }
92
93     @Test
94     public void shouldCreateFtpesConfigurationCorrectly() {
95         FtpesConfig ftpesConfig = cloudConfigParser.getFtpesConfig();
96
97         assertThat(ftpesConfig).isNotNull();
98         assertThat(ftpesConfig).isEqualToComparingFieldByField(CORRECT_FTPES_CONFIGURATION);
99     }
100
101     public JsonObject getCloudConfigJsonObject() {
102         JsonObject config = new JsonObject();
103         config.addProperty("dmaap.dmaapConsumerConfiguration.timeoutMs", -1);
104         config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapHostName", "message-router.onap.svc.cluster.local");
105         config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapUserName", "admin");
106         config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapUserPassword", "admin");
107         config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapTopicName",
108                 "/events/unauthenticated.VES_NOTIFICATION_OUTPUT");
109         config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapPortNumber", 2222);
110         config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapContentType", "application/json");
111         config.addProperty("dmaap.dmaapConsumerConfiguration.messageLimit", -1);
112         config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapProtocol", "http");
113         config.addProperty("dmaap.dmaapConsumerConfiguration.consumerId", "C12");
114         config.addProperty("dmaap.dmaapConsumerConfiguration.consumerGroup", "OpenDCAE-c12");
115         config.addProperty("dmaap.dmaapProducerConfiguration.dmaapTopicName", "publish");
116         config.addProperty("dmaap.dmaapProducerConfiguration.dmaapProtocol", "https");
117         config.addProperty("dmaap.dmaapProducerConfiguration.dmaapContentType", "application/json");
118         config.addProperty("dmaap.dmaapProducerConfiguration.dmaapHostName", "message-router.onap.svc.cluster.local");
119         config.addProperty("dmaap.dmaapProducerConfiguration.dmaapPortNumber", 3907);
120         config.addProperty("dmaap.dmaapProducerConfiguration.dmaapUserName", "dradmin");
121         config.addProperty("dmaap.dmaapProducerConfiguration.dmaapUserPassword", "dradmin");
122         config.addProperty("dmaap.ftpesConfig.keyCert", "/config/ftpKey.jks");
123         config.addProperty("dmaap.ftpesConfig.keyPassword", "secret");
124         config.addProperty("dmaap.ftpesConfig.trustedCA", "config/cacerts");
125         config.addProperty("dmaap.ftpesConfig.trustedCAPassword", "secret");
126
127         config.addProperty("dmaap.security.trustStorePath", "trustStorePath");
128         config.addProperty("dmaap.security.trustStorePasswordPath", "trustStorePasswordPath");
129         config.addProperty("dmaap.security.keyStorePath", "keyStorePath");
130         config.addProperty("dmaap.security.keyStorePasswordPath", "keyStorePasswordPath");
131         config.addProperty("dmaap.security.enableDmaapCertAuth", "true");
132
133         return config;
134     }
135 }