[SDNC-5] Rebase sdnc-core
[sdnc/core.git] / sliPluginUtils / provider / src / test / java / org / openecomp / sdnc / sli / SliPluginUtils / Dme2Test.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
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.openecomp.sdnc.sli.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 import org.openecomp.sdnc.sli.SliPluginUtils.DME2;
33 import org.openecomp.sdnc.sli.SliPluginUtils.SliPluginUtilsActivator;
34
35 public class Dme2Test {
36
37     @Test
38     public void createInstarUrl() {
39         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";
40         DME2 dme = new DME2("user@sample.com", "fake", "TEST", "DEFAULT", new String[] { "http://localhost:25055" }, "common");
41         String constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
42         assertEquals(instarUrl, constructedUrl);
43     }
44
45     @Test
46     public void createInstarUrlNoSubContext() {
47         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";
48         DME2 dme = new DME2("user@sample.com", "fake", "TEST", "DEFAULT", new String[] { "http://localhost:25055" }, "common");
49         Map<String, String> parameters = new HashMap<String, String>();
50         String constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", parameters.get(null));
51         assertEquals(instarUrl, constructedUrl);
52     }
53
54     @Test
55     public void testRoundRobin() {
56         String[] proxyHostNames = new String[] { "http://one:25055", "http://two:25055", "http://three:25055" };
57         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";
58         DME2 dme = new DME2("user@sample.com", "fake", "TEST", "DEFAULT", proxyHostNames, "common");
59         String constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
60         assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);
61         constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
62         assertEquals(proxyHostNames[1] + urlSuffix, constructedUrl);
63         constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
64         assertEquals(proxyHostNames[2] + urlSuffix, constructedUrl);
65         constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
66         assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);
67         constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
68         assertEquals(proxyHostNames[1] + urlSuffix, constructedUrl);
69         constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
70         assertEquals(proxyHostNames[2] + urlSuffix, constructedUrl);
71         constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
72         assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);
73     }
74
75     @Test
76     public void createDme2EndtoEnd() {
77         SliPluginUtilsActivator activator = new SliPluginUtilsActivator();
78         DME2 dme2 = activator.initDme2("src/test/resources/dme2.e2e.properties");
79         assertEquals("user@sample.com", dme2.aafUserName);
80         assertEquals("fake", dme2.aafPassword);
81         assertEquals("UAT", dme2.envContext);
82         assertEquals("UAT", dme2.routeOffer);
83         Assert.assertArrayEquals("http://sample.com:25055,http://sample.com:25055".split(","), dme2.proxyUrls);
84         assertEquals("1702.0", dme2.commonServiceVersion);
85         assertEquals(null, dme2.partner);
86
87         String constructedUrl = dme2.constructUrl("sample.com/restservices/instar/v1/assetSearch", null, "/mySubContext");
88         assertNotNull(constructedUrl);
89         System.out.println(constructedUrl);
90     }
91
92     @Test
93     public void createDme2Prod() {
94         SliPluginUtilsActivator activator = new SliPluginUtilsActivator();
95         DME2 dme2 = activator.initDme2("src/test/resources/dme2.prod.properties");
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 }