2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.ccsdk.sli.core.slipluginutils;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
27 import java.util.HashMap;
30 import org.junit.Assert;
31 import org.junit.Test;
33 public class Dme2Test {
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);
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);
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);
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);
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 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);
104 String constructedUrl = dme2.constructUrl("sample.com/restservices/instar/v1/assetSearch", null, "/mySubContext");
105 assertNotNull(constructedUrl);
106 System.out.println(constructedUrl);