Fix service registration for SDNC
[ccsdk/sli/core.git] / sliPluginUtils / provider / src / test / java / org / onap / ccsdk / sli / core / slipluginutils / Dme2Test.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.ccsdk.sli.core.slipluginutils;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26
27 import java.util.HashMap;
28 import java.util.Map;
29
30 import org.junit.Assert;
31 import org.junit.Test;
32
33 public class Dme2Test {
34
35     @Test
36     public void createInstarUrl() {
37         String instarUrl = "http://localhost:25055/service=sample.com/services/eim/v1/rest/version=1702.0/envContext=TEST/routeOffer=DEFAULT/subContext=/enterpriseConnection/getEnterpriseConnectionDetails/v1?dme2.password=fake&dme2.username=user@sample.com";
38         DME2 dme = new DME2("user@sample.com", "fake", "TEST", "DEFAULT", new String[] { "http://localhost:25055" }, "common");
39         String constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
40         assertEquals(instarUrl, constructedUrl);
41     }
42
43     @Test
44     public void createInstarUrlNoSubContext() {
45         String instarUrl = "http://localhost:25055/service=sample.com/services/eim/v1/rest/version=1702.0/envContext=TEST/routeOffer=DEFAULT?dme2.password=fake&dme2.username=user@sample.com";
46         DME2 dme = new DME2("user@sample.com", "fake", "TEST", "DEFAULT", new String[] { "http://localhost:25055" }, "common");
47         Map<String, String> parameters = new HashMap<String, String>();
48         String constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", parameters.get(null));
49         assertEquals(instarUrl, constructedUrl);
50     }
51
52     @Test
53     public void testRoundRobin() {
54         String[] proxyHostNames = new String[] { "http://one:25055", "http://two:25055", "http://three:25055" };
55         String urlSuffix = "/service=sample.com/services/eim/v1/rest/version=1702.0/envContext=TEST/routeOffer=DEFAULT/subContext=/enterpriseConnection/getEnterpriseConnectionDetails/v1?dme2.password=fake&dme2.username=user@sample.com";
56         DME2 dme = new DME2("user@sample.com", "fake", "TEST", "DEFAULT", proxyHostNames, "common");
57         String constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
58         assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);
59         constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
60         assertEquals(proxyHostNames[1] + urlSuffix, constructedUrl);
61         constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
62         assertEquals(proxyHostNames[2] + urlSuffix, constructedUrl);
63         constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
64         assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);
65         constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
66         assertEquals(proxyHostNames[1] + urlSuffix, constructedUrl);
67         constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
68         assertEquals(proxyHostNames[2] + urlSuffix, constructedUrl);
69         constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
70         assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);
71     }
72
73     @Test
74     public void createDme2EndtoEnd() {
75         Dme2PropertiesProvider provider =
76                 new Dme2PropertiesProvider("src/test/resources/dme2.e2e.properties");
77         DME2 dme2 = new DME2(provider);
78         assertEquals("user@sample.com", dme2.aafUserName);
79         assertEquals("fake", dme2.aafPassword);
80         assertEquals("UAT", dme2.envContext);
81         assertEquals("UAT", dme2.routeOffer);
82         Assert.assertArrayEquals("http://sample.com:25055,http://sample.com:25055".split(","), dme2.proxyUrls);
83         assertEquals("1702.0", dme2.commonServiceVersion);
84         assertEquals(null, dme2.partner);
85
86         String constructedUrl = dme2.constructUrl("sample.com/restservices/instar/v1/assetSearch", null, "/mySubContext");
87         assertNotNull(constructedUrl);
88         System.out.println(constructedUrl);
89     }
90
91     @Test
92     public void createDme2Prod() {
93         Dme2PropertiesProvider provider =
94                 new Dme2PropertiesProvider("src/test/resources/dme2.prod.properties");
95         DME2 dme2 = new DME2(provider);
96         assertEquals("user@sample.com", dme2.aafUserName);
97         assertEquals("fake", dme2.aafPassword);
98         assertEquals("PROD", dme2.envContext);
99         assertEquals("", dme2.routeOffer);
100         Assert.assertArrayEquals("http://sample.com:25055,http://sample.com:25055".split(","), dme2.proxyUrls);
101         assertEquals("1.0", dme2.commonServiceVersion);
102         assertEquals("LPP_PROD", dme2.partner);
103
104         String constructedUrl = dme2.constructUrl("sample.com/restservices/instar/v1/assetSearch", null, "/mySubContext");
105         assertNotNull(constructedUrl);
106         System.out.println(constructedUrl);
107     }
108
109 }