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;
20 import com.google.gson.JsonObject;
21 import org.junit.jupiter.api.Test;
22 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration;
23 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
24 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapConsumerConfiguration;
25 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapPublisherConfiguration;
28 class CloudConfigParserTest {
29 private static final ImmutableDmaapConsumerConfiguration CORRECT_DMAAP_CONSUMER_CONFIG = //
30 new ImmutableDmaapConsumerConfiguration.Builder() //
32 .dmaapHostName("message-router.onap.svc.cluster.local") //
33 .dmaapUserName("admin") //
34 .dmaapUserPassword("admin") //
35 .dmaapTopicName("/events/unauthenticated.VES_NOTIFICATION_OUTPUT") //
36 .dmaapPortNumber(2222) //
37 .dmaapContentType("application/json") //
39 .dmaapProtocol("http") //
41 .consumerGroup("OpenDCAE-c12") //
42 .trustStorePath("trustStorePath") //
43 .trustStorePasswordPath("trustStorePasswordPath") //
44 .keyStorePath("keyStorePath") //
45 .keyStorePasswordPath("keyStorePasswordPath") //
46 .enableDmaapCertAuth(true) //
49 private static final ImmutableDmaapPublisherConfiguration CORRECT_DMAAP_PUBLISHER_CONFIG = //
50 new ImmutableDmaapPublisherConfiguration.Builder() //
51 .dmaapTopicName("publish") //
52 .dmaapUserPassword("dradmin") //
53 .dmaapPortNumber(3907) //
54 .dmaapProtocol("https") //
55 .dmaapContentType("application/json") //
56 .dmaapHostName("message-router.onap.svc.cluster.local") //
57 .dmaapUserName("dradmin") //
58 .trustStorePath("trustStorePath") //
59 .trustStorePasswordPath("trustStorePasswordPath") //
60 .keyStorePath("keyStorePath") //
61 .keyStorePasswordPath("keyStorePasswordPath") //
62 .enableDmaapCertAuth(true) //
65 private static final ImmutableFtpesConfig CORRECT_FTPES_CONFIGURATION = //
66 new ImmutableFtpesConfig.Builder() //
67 .keyCert("/config/dfc.jks") //
68 .keyPassword("secret") //
69 .trustedCA("config/ftp.jks") //
70 .trustedCAPassword("secret") //
73 private CloudConfigParser cloudConfigParser = new CloudConfigParser(getCloudConfigJsonObject());
76 public void shouldCreateDmaapConsumerConfigurationCorrectly() {
77 DmaapConsumerConfiguration dmaapConsumerConfig = cloudConfigParser.getDmaapConsumerConfig();
79 assertThat(dmaapConsumerConfig).isNotNull();
80 assertThat(dmaapConsumerConfig).isEqualToComparingFieldByField(CORRECT_DMAAP_CONSUMER_CONFIG);
84 public void shouldCreateDmaapPublisherConfigurationCorrectly() {
85 DmaapPublisherConfiguration dmaapPublisherConfig = cloudConfigParser.getDmaapPublisherConfig();
87 assertThat(dmaapPublisherConfig).isNotNull();
88 assertThat(dmaapPublisherConfig).isEqualToComparingFieldByField(CORRECT_DMAAP_PUBLISHER_CONFIG);
92 public void shouldCreateFtpesConfigurationCorrectly() {
93 FtpesConfig ftpesConfig = cloudConfigParser.getFtpesConfig();
95 assertThat(ftpesConfig).isNotNull();
96 assertThat(ftpesConfig).isEqualToComparingFieldByField(CORRECT_FTPES_CONFIGURATION);
99 public JsonObject getCloudConfigJsonObject() {
100 JsonObject config = new JsonObject();
101 config.addProperty("dmaap.dmaapConsumerConfiguration.timeoutMs", -1);
102 config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapHostName", "message-router.onap.svc.cluster.local");
103 config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapUserName", "admin");
104 config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapUserPassword", "admin");
105 config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapTopicName",
106 "/events/unauthenticated.VES_NOTIFICATION_OUTPUT");
107 config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapPortNumber", 2222);
108 config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapContentType", "application/json");
109 config.addProperty("dmaap.dmaapConsumerConfiguration.messageLimit", -1);
110 config.addProperty("dmaap.dmaapConsumerConfiguration.dmaapProtocol", "http");
111 config.addProperty("dmaap.dmaapConsumerConfiguration.consumerId", "C12");
112 config.addProperty("dmaap.dmaapConsumerConfiguration.consumerGroup", "OpenDCAE-c12");
113 config.addProperty("dmaap.dmaapProducerConfiguration.dmaapTopicName", "publish");
114 config.addProperty("dmaap.dmaapProducerConfiguration.dmaapProtocol", "https");
115 config.addProperty("dmaap.dmaapProducerConfiguration.dmaapContentType", "application/json");
116 config.addProperty("dmaap.dmaapProducerConfiguration.dmaapHostName", "message-router.onap.svc.cluster.local");
117 config.addProperty("dmaap.dmaapProducerConfiguration.dmaapPortNumber", 3907);
118 config.addProperty("dmaap.dmaapProducerConfiguration.dmaapUserName", "dradmin");
119 config.addProperty("dmaap.dmaapProducerConfiguration.dmaapUserPassword", "dradmin");
120 config.addProperty("dmaap.ftpesConfig.keyCert", "/config/dfc.jks");
121 config.addProperty("dmaap.ftpesConfig.keyPassword", "secret");
122 config.addProperty("dmaap.ftpesConfig.trustedCA", "config/ftp.jks");
123 config.addProperty("dmaap.ftpesConfig.trustedCAPassword", "secret");
125 config.addProperty("dmaap.security.trustStorePath", "trustStorePath");
126 config.addProperty("dmaap.security.trustStorePasswordPath", "trustStorePasswordPath");
127 config.addProperty("dmaap.security.keyStorePath", "keyStorePath");
128 config.addProperty("dmaap.security.keyStorePasswordPath", "keyStorePasswordPath");
129 config.addProperty("dmaap.security.enableDmaapCertAuth", "true");