bdeb1c1efa47c4cbf02765aa1bc60ba6ce4d5cf0
[dcaegen2/collectors/datafile.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.dcaegen2.collectors.datafile.configuration;
22
23 import static org.junit.jupiter.api.Assertions.assertEquals;
24 import static org.junit.jupiter.api.Assertions.assertThrows;
25
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;
29
30 public class ConsumerConfigurationTest {
31     @Test
32     public void toDmaapSuccess() throws DatafileTaskException {
33         ConsumerConfiguration configurationUnderTest = ImmutableConsumerConfiguration.builder() //
34             .topicUrl(
35                 "http://admin:admin@message-router.onap.svc.cluster.local:2222/events/unauthenticated.VES_NOTIFICATION_OUTPUT/OpenDcae-c12/C12")
36             .trustStorePath("") //
37             .trustStorePasswordPath("") //
38             .keyStorePath("") //
39             .keyStorePasswordPath("") //
40             .enableDmaapCertAuth(Boolean.FALSE) //
41             .build();
42
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());
49     }
50
51     @Test
52     public void toDmaapNoUserInfoSuccess() throws DatafileTaskException {
53         ConsumerConfiguration configurationUnderTest = ImmutableConsumerConfiguration.builder() //
54             .topicUrl(
55                 "http://message-router.onap.svc.cluster.local:2222/events/unauthenticated.VES_NOTIFICATION_OUTPUT/OpenDcae-c12/C12")
56             .trustStorePath("") //
57             .trustStorePasswordPath("") //
58             .keyStorePath("") //
59             .keyStorePasswordPath("") //
60             .enableDmaapCertAuth(Boolean.FALSE) //
61             .build();
62
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());
69     }
70
71     @Test
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("") //
76             .keyStorePath("") //
77             .keyStorePasswordPath("") //
78             .enableDmaapCertAuth(Boolean.FALSE) //
79             .build();
80
81         DatafileTaskException exception =
82             assertThrows(DatafileTaskException.class, () -> configurationUnderTest.toDmaap());
83         assertEquals("Could not parse the URL", exception.getMessage());
84     }
85
86     @Test
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("") //
92             .keyStorePath("") //
93             .keyStorePasswordPath("") //
94             .enableDmaapCertAuth(Boolean.FALSE) //
95             .build();
96
97         DatafileTaskException exception =
98             assertThrows(DatafileTaskException.class, () -> configurationUnderTest.toDmaap());
99         assertEquals("The path has incorrect syntax: //events/", exception.getMessage());
100     }
101 }