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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
14 * ============LICENSE_END========================================================================
17 package org.onap.dcaegen2.collectors.datafile.configuration;
19 import static org.assertj.core.api.Assertions.assertThat;
21 import com.google.gson.JsonObject;
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;
30 class CloudConfigParserTest {
32 private static final ImmutableDmaapConsumerConfiguration CORRECT_DMAAP_CONSUMER_CONFIG =
34 new ImmutableDmaapConsumerConfiguration.Builder()
36 .dmaapHostName("message-router.onap.svc.cluster.local")
37 .dmaapUserName("admin")
38 .dmaapUserPassword("admin")
39 .dmaapTopicName("/events/unauthenticated.VES_NOTIFICATION_OUTPUT")
40 .dmaapPortNumber(2222)
41 .dmaapContentType("application/json")
43 .dmaapProtocol("http")
45 .consumerGroup("OpenDCAE-c12")
46 .trustStorePath("trustStorePath")
47 .trustStorePasswordPath("trustStorePasswordPath")
48 .keyStorePath("keyStorePath")
49 .keyStorePasswordPath("keyStorePasswordPath")
50 .enableDmaapCertAuth(true)
54 private static final ImmutableDmaapPublisherConfiguration CORRECT_DMAAP_PUBLISHER_CONFIG =
56 new ImmutableDmaapPublisherConfiguration.Builder()
57 .dmaapTopicName("publish")
58 .dmaapUserPassword("dradmin")
59 .dmaapPortNumber(3907)
60 .dmaapProtocol("https")
61 .dmaapContentType("application/json")
62 .dmaapHostName("message-router.onap.svc.cluster.local")
63 .dmaapUserName("dradmin")
64 .trustStorePath("trustStorePath")
65 .trustStorePasswordPath("trustStorePasswordPath")
66 .keyStorePath("keyStorePath")
67 .keyStorePasswordPath("keyStorePasswordPath")
68 .enableDmaapCertAuth(true)
72 private static final ImmutableFtpesConfig CORRECT_FTPES_CONFIGURATION =
74 new ImmutableFtpesConfig.Builder()
75 .keyCert("/config/ftpKey.jks")
76 .keyPassword("secret")
77 .trustedCA("config/cacerts")
78 .trustedCAPassword("secret")
82 private CloudConfigParser cloudConfigParser = new CloudConfigParser(getCloudConfigJsonObject());
85 public void shouldCreateDmaapConsumerConfigurationCorrectly() {
86 DmaapConsumerConfiguration dmaapConsumerConfig = cloudConfigParser.getDmaapConsumerConfig();
88 assertThat(dmaapConsumerConfig).isNotNull();
89 assertThat(dmaapConsumerConfig).isEqualToComparingFieldByField(CORRECT_DMAAP_CONSUMER_CONFIG);
93 public void shouldCreateDmaapPublisherConfigurationCorrectly() {
94 DmaapPublisherConfiguration dmaapPublisherConfig = cloudConfigParser.getDmaapPublisherConfig();
96 assertThat(dmaapPublisherConfig).isNotNull();
97 assertThat(dmaapPublisherConfig).isEqualToComparingFieldByField(CORRECT_DMAAP_PUBLISHER_CONFIG);
101 public void shouldCreateFtpesConfigurationCorrectly() {
102 FtpesConfig ftpesConfig = cloudConfigParser.getFtpesConfig();
104 assertThat(ftpesConfig).isNotNull();
105 assertThat(ftpesConfig).isEqualToComparingFieldByField(CORRECT_FTPES_CONFIGURATION);
108 public JsonObject getCloudConfigJsonObject() {
109 JsonObject config = new JsonObject();
110 config.addProperty("dmaap.dmaapConsumerConfiguration.timeoutMs", -1);
111 config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapHostName", "message-router.onap.svc.cluster.local");
112 config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapUserName", "admin");
113 config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapUserPassword", "admin");
114 config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapTopicName",
115 "/events/unauthenticated.VES_NOTIFICATION_OUTPUT");
116 config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapPortNumber", 2222);
117 config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapContentType", "application/json");
118 config.addProperty("dmaap.dmaapConsumerConfiguration.messageLimit", -1);
119 config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapProtocol", "http");
120 config.addProperty("dmaap.dmaapConsumerConfiguration.consumerId", "C12");
121 config.addProperty("dmaap.dmaapConsumerConfiguration.consumerGroup", "OpenDCAE-c12");
122 config.addProperty("dmaap.dmaapProducerConfiguration.dmaapTopicName", "publish");
123 config.addProperty("dmaap.dmaapProducerConfiguration.dmaapProtocol", "https");
124 config.addProperty("dmaap.dmaapProducerConfiguration.dmaapContentType", "application/json");
125 config.addProperty("dmaap.dmaapProducerConfiguration.dmaapHostName", "message-router.onap.svc.cluster.local");
126 config.addProperty("dmaap.dmaapProducerConfiguration.dmaapPortNumber", 3907);
127 config.addProperty("dmaap.dmaapProducerConfiguration.dmaapUserName", "dradmin");
128 config.addProperty("dmaap.dmaapProducerConfiguration.dmaapUserPassword", "dradmin");
129 config.addProperty("dmaap.ftpesConfig.keyCert", "/config/ftpKey.jks");
130 config.addProperty("dmaap.ftpesConfig.keyPassword", "secret");
131 config.addProperty("dmaap.ftpesConfig.trustedCA", "config/cacerts");
132 config.addProperty("dmaap.ftpesConfig.trustedCAPassword", "secret");
134 config.addProperty("dmaap.security.trustStorePath", "trustStorePath");
135 config.addProperty("dmaap.security.trustStorePasswordPath", "trustStorePasswordPath");
136 config.addProperty("dmaap.security.keyStorePath", "keyStorePath");
137 config.addProperty("dmaap.security.keyStorePasswordPath", "keyStorePasswordPath");
138 config.addProperty("dmaap.security.enableDmaapCertAuth", "true");