2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.dcaegen2.collectors.datafile.configuration;
23 import static org.junit.jupiter.api.Assertions.assertEquals;
24 import static org.junit.jupiter.api.Assertions.assertThrows;
26 import org.junit.jupiter.api.Test;
27 import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
28 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration;
30 public class ConsumerConfigurationTest {
32 public void toDmaapSuccess() throws DatafileTaskException {
33 ConsumerConfiguration configurationUnderTest = ImmutableConsumerConfiguration.builder() //
35 "http://admin:admin@message-router.onap.svc.cluster.local:2222/events/unauthenticated.VES_NOTIFICATION_OUTPUT/OpenDcae-c12/C12")
36 .trustStorePath("") //
37 .trustStorePasswordPath("") //
39 .keyStorePasswordPath("") //
40 .enableDmaapCertAuth(Boolean.FALSE) //
43 DmaapConsumerConfiguration dmaapConsumerConfiguration = configurationUnderTest.toDmaap();
44 assertEquals("http", dmaapConsumerConfiguration.dmaapProtocol());
45 assertEquals("message-router.onap.svc.cluster.local", dmaapConsumerConfiguration.dmaapHostName());
46 assertEquals(Integer.valueOf("2222"), dmaapConsumerConfiguration.dmaapPortNumber());
47 assertEquals("OpenDcae-c12", dmaapConsumerConfiguration.consumerGroup());
48 assertEquals("C12", dmaapConsumerConfiguration.consumerId());
52 public void toDmaapNoUserInfoSuccess() throws DatafileTaskException {
53 ConsumerConfiguration configurationUnderTest = ImmutableConsumerConfiguration.builder() //
55 "http://message-router.onap.svc.cluster.local:2222/events/unauthenticated.VES_NOTIFICATION_OUTPUT/OpenDcae-c12/C12")
56 .trustStorePath("") //
57 .trustStorePasswordPath("") //
59 .keyStorePasswordPath("") //
60 .enableDmaapCertAuth(Boolean.FALSE) //
63 DmaapConsumerConfiguration dmaapConsumerConfiguration = configurationUnderTest.toDmaap();
64 assertEquals("http", dmaapConsumerConfiguration.dmaapProtocol());
65 assertEquals("message-router.onap.svc.cluster.local", dmaapConsumerConfiguration.dmaapHostName());
66 assertEquals(Integer.valueOf("2222"), dmaapConsumerConfiguration.dmaapPortNumber());
67 assertEquals("OpenDcae-c12", dmaapConsumerConfiguration.consumerGroup());
68 assertEquals("C12", dmaapConsumerConfiguration.consumerId());
72 public void toDmaapWhenInvalidUrlThrowException() throws DatafileTaskException {
73 ConsumerConfiguration configurationUnderTest = ImmutableConsumerConfiguration.builder() //
74 .topicUrl("//admin:admin@message-router.onap.svc.cluster.local:2222//events/").trustStorePath("") //
75 .trustStorePasswordPath("") //
77 .keyStorePasswordPath("") //
78 .enableDmaapCertAuth(Boolean.FALSE) //
81 DatafileTaskException exception =
82 assertThrows(DatafileTaskException.class, () -> configurationUnderTest.toDmaap());
83 assertEquals("Could not parse the URL", exception.getMessage());
87 public void toDmaapWhenInvalidPathThrowException() throws DatafileTaskException {
88 ConsumerConfiguration configurationUnderTest = ImmutableConsumerConfiguration.builder() //
89 .topicUrl("http://admin:admin@message-router.onap.svc.cluster.local:2222//events/") //
90 .trustStorePath("") //
91 .trustStorePasswordPath("") //
93 .keyStorePasswordPath("") //
94 .enableDmaapCertAuth(Boolean.FALSE) //
97 DatafileTaskException exception =
98 assertThrows(DatafileTaskException.class, () -> configurationUnderTest.toDmaap());
99 assertEquals("The path has incorrect syntax: //events/", exception.getMessage());