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 {
31 private static final ImmutableDmaapConsumerConfiguration CORRECT_DMAAP_CONSUMER_CONFIG = //
32 new ImmutableDmaapConsumerConfiguration.Builder() //
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") //
41 .dmaapProtocol("http") //
43 .consumerGroup("OpenDCAE-c12") //
44 .trustStorePath("trustStorePath") //
45 .trustStorePasswordPath("trustStorePasswordPath") //
46 .keyStorePath("keyStorePath") //
47 .keyStorePasswordPath("keyStorePasswordPath") //
48 .enableDmaapCertAuth(true) //
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) //
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") //
75 private CloudConfigParser cloudConfigParser = new CloudConfigParser(getCloudConfigJsonObject());
78 public void shouldCreateDmaapConsumerConfigurationCorrectly() {
79 DmaapConsumerConfiguration dmaapConsumerConfig = cloudConfigParser.getDmaapConsumerConfig();
81 assertThat(dmaapConsumerConfig).isNotNull();
82 assertThat(dmaapConsumerConfig).isEqualToComparingFieldByField(CORRECT_DMAAP_CONSUMER_CONFIG);
86 public void shouldCreateDmaapPublisherConfigurationCorrectly() {
87 DmaapPublisherConfiguration dmaapPublisherConfig = cloudConfigParser.getDmaapPublisherConfig();
89 assertThat(dmaapPublisherConfig).isNotNull();
90 assertThat(dmaapPublisherConfig).isEqualToComparingFieldByField(CORRECT_DMAAP_PUBLISHER_CONFIG);
94 public void shouldCreateFtpesConfigurationCorrectly() {
95 FtpesConfig ftpesConfig = cloudConfigParser.getFtpesConfig();
97 assertThat(ftpesConfig).isNotNull();
98 assertThat(ftpesConfig).isEqualToComparingFieldByField(CORRECT_FTPES_CONFIGURATION);
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");
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");