d3f4a13d651b650570db0763cfe151152a511524
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18
19 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test;
20
21 import static org.junit.Assert.assertEquals;
22 import com.google.common.io.Files;
23 import java.io.File;
24 import java.io.IOException;
25 import java.nio.charset.StandardCharsets;
26 import org.junit.After;
27 import org.junit.Test;
28 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
29 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.PNFRegistrationConfig;
30
31 public class PNFRegistrationConfigTest {
32
33     // @formatter:off
34     private static final String TESTCONFIG_CONTENT = "[pnfRegistration]\n"
35             + "TransportType=HTTPNOAUTH\n"
36             + "Protocol=http\n"
37             + "username=username\n"
38             + "password=password\n"
39             + "host=onap-dmap:3904\n"
40             + "topic=unauthenticated.VES_PNFREG_OUTPUT\n"
41             + "contenttype=application/json\n"
42             + "group=myG\n"
43             + "id=C1\n"
44             + "timeout=20000\n"
45             + "limit=10000\n"
46             + "fetchPause=5000\n"
47             + "jersey.config.client.readTimeout=25000\n"
48             + "jersey.config.client.connectTimeout=25000\n"
49             + "jersey.config.client.proxy.uri=http://http-proxy\n"
50             + "jersey.config.client.proxy.username=proxy-user\n"
51             + "jersey.config.client.proxy.password=proxy-password\n"
52             + "";
53     // @formatter:on
54     private ConfigurationFileRepresentation cfg;
55     private static final String configFile = "test.properties";
56
57     @Test
58     public void test() {
59         try {
60             Files.asCharSink(new File(configFile), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT);
61             cfg = new ConfigurationFileRepresentation(configFile);
62             PNFRegistrationConfig pnfCfg = new PNFRegistrationConfig(cfg);
63             assertEquals("pnfRegistration", pnfCfg.getSectionName());
64             assertEquals("HTTPNOAUTH", pnfCfg.getTransportType());
65             assertEquals("onap-dmap:3904", pnfCfg.getHostPort());
66             assertEquals("unauthenticated.VES_PNFREG_OUTPUT", pnfCfg.getTopic());
67             assertEquals("application/json", pnfCfg.getContenttype());
68             assertEquals("myG", pnfCfg.getConsumerGroup());
69             assertEquals("C1", pnfCfg.getConsumerId());
70             assertEquals("20000", pnfCfg.getTimeout());
71             assertEquals("10000", pnfCfg.getLimit());
72             assertEquals("5000", pnfCfg.getFetchPause());
73             assertEquals("http", pnfCfg.getProtocol());
74             assertEquals("username", pnfCfg.getUsername());
75             assertEquals("password", pnfCfg.getPassword());
76             assertEquals("25000", pnfCfg.getClientReadTimeout());
77             assertEquals("25000", pnfCfg.getClientConnectTimeout());
78             assertEquals("http://http-proxy", pnfCfg.getHTTPProxyURI());
79             assertEquals("proxy-user", pnfCfg.getHTTPProxyUsername());
80             assertEquals("proxy-password", pnfCfg.getHTTPProxyPassword());
81
82         } catch (IOException e) {
83             e.printStackTrace();
84         }
85
86     }
87
88     @After
89     public void cleanUp() {
90         File file = new File(configFile);
91         if (file.exists()) {
92             System.out.println("File exists, Deleting it");
93             file.delete();
94         }
95
96     }
97
98 }