2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 ONAP
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdnc.sli.SliPluginUtils;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
26 import java.util.HashMap;
29 import org.junit.Assert;
30 import org.junit.Test;
31 import org.openecomp.sdnc.sli.SliPluginUtils.DME2;
32 import org.openecomp.sdnc.sli.SliPluginUtils.SliPluginUtilsActivator;
34 public class Dme2Test {
37 public void createInstarUrl() {
38 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";
39 DME2 dme = new DME2("user@sample.com", "fake", "TEST", "DEFAULT", new String[] { "http://localhost:25055" }, "common");
40 String constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
41 assertEquals(instarUrl, constructedUrl);
45 public void createInstarUrlNoSubContext() {
46 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";
47 DME2 dme = new DME2("user@sample.com", "fake", "TEST", "DEFAULT", new String[] { "http://localhost:25055" }, "common");
48 Map<String, String> parameters = new HashMap<String, String>();
49 String constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", parameters.get(null));
50 assertEquals(instarUrl, constructedUrl);
54 public void testRoundRobin() {
55 String[] proxyHostNames = new String[] { "http://one:25055", "http://two:25055", "http://three:25055" };
56 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";
57 DME2 dme = new DME2("user@sample.com", "fake", "TEST", "DEFAULT", proxyHostNames, "common");
58 String constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
59 assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);
60 constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
61 assertEquals(proxyHostNames[1] + urlSuffix, constructedUrl);
62 constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
63 assertEquals(proxyHostNames[2] + urlSuffix, constructedUrl);
64 constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
65 assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);
66 constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
67 assertEquals(proxyHostNames[1] + urlSuffix, constructedUrl);
68 constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
69 assertEquals(proxyHostNames[2] + urlSuffix, constructedUrl);
70 constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
71 assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);
75 public void createDme2EndtoEnd() {
76 SliPluginUtilsActivator activator = new SliPluginUtilsActivator();
77 DME2 dme2 = activator.initDme2("src/test/resources/dme2.e2e.properties");
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);
86 String constructedUrl = dme2.constructUrl("sample.com/restservices/instar/v1/assetSearch", null, "/mySubContext");
87 assertNotNull(constructedUrl);
88 System.out.println(constructedUrl);
92 public void createDme2Prod() {
93 SliPluginUtilsActivator activator = new SliPluginUtilsActivator();
94 DME2 dme2 = activator.initDme2("src/test/resources/dme2.prod.properties");
95 assertEquals("user@sample.com", dme2.aafUserName);
96 assertEquals("fake", dme2.aafPassword);
97 assertEquals("PROD", dme2.envContext);
98 assertEquals("", dme2.routeOffer);
99 Assert.assertArrayEquals("http://sample.com:25055,http://sample.com:25055".split(","), dme2.proxyUrls);
100 assertEquals("1.0", dme2.commonServiceVersion);
101 assertEquals("LPP_PROD", dme2.partner);
103 String constructedUrl = dme2.constructUrl("sample.com/restservices/instar/v1/assetSearch", null, "/mySubContext");
104 assertNotNull(constructedUrl);
105 System.out.println(constructedUrl);