-/*-\r
- * ============LICENSE_START=======================================================\r
- * ONAP : CCSDK\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property. All rights\r
- * reserved.\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ============LICENSE_END=========================================================\r
- */\r
-\r
-package org.onap.ccsdk.sli.core.slipluginutils;\r
-\r
-import java.util.Iterator;\r
-import java.util.Map;\r
-import java.util.Map.Entry;\r
-import java.util.Properties;\r
-import org.onap.ccsdk.sli.core.sli.SvcLogicContext;\r
-import org.onap.ccsdk.sli.core.sli.SvcLogicException;\r
-import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-/**\r
- * A SvcLogicJavaPlugin that generates DME2 proxy urls (for calling the DME2 ingress proxy) using\r
- * parameters from context memory.\r
- */\r
-public class DME2 implements SvcLogicJavaPlugin {\r
-\r
- private static final Logger LOG = LoggerFactory.getLogger(DME2.class);\r
- // the key for <code>proxyUrl</code>, which represents a CSV list of urls\r
- static final String PROXY_URL_KEY = "proxyUrl";\r
- static final String PROXY_URLS_VALUE_SEPARATOR = ",";\r
- static final String AAF_USERNAME_KEY = "aafUserName";\r
- static final String AAF_PASSWORD_KEY = "aafPassword";\r
- static final String ENV_CONTEXT_KEY = "envContext";\r
- static final String ROUTE_OFFER_KEY = "routeOffer";\r
- static final String COMMON_SERVICE_VERSION_KEY = "commonServiceVersion";\r
- static final String PARTNER_KEY = "partner";\r
- static final String VERSION_KEY = "version";\r
- static final String SERVICE_KEY = "service";\r
- static final String SUBCONTEXT_KEY = "subContext";\r
- static final String ENDPOINT_READ_TIMEOUT_KEY = "endpointReadTimeout";\r
- static final String OUTPUT_PATH_KEY = "outputPath";\r
-\r
- final String aafUserName;\r
- final String aafPassword;\r
- final String envContext;\r
- final String routeOffer;\r
- final String[] proxyUrls;\r
- final String commonServiceVersion;\r
- final String partner;\r
- final String endpointReadTimeout;\r
- Integer index;\r
-\r
- public DME2(Properties properties) {\r
- Iterator<Entry<Object, Object>> it = properties.entrySet().iterator();\r
- while (it.hasNext()) {\r
- Entry<Object, Object> entry = it.next();\r
- if (entry.getValue() == null || entry.getValue().toString().length() < 1) {\r
- it.remove();\r
- }\r
- }\r
- this.aafUserName = properties.getProperty(AAF_USERNAME_KEY, null);\r
- this.aafPassword = properties.getProperty(AAF_PASSWORD_KEY, null);\r
- this.envContext = properties.getProperty(ENV_CONTEXT_KEY, null);\r
- this.routeOffer = properties.getProperty(ROUTE_OFFER_KEY, null);\r
- this.commonServiceVersion = properties.getProperty(COMMON_SERVICE_VERSION_KEY, null);\r
- this.partner = properties.getProperty(PARTNER_KEY, null);\r
- this.endpointReadTimeout = properties.getProperty(ENDPOINT_READ_TIMEOUT_KEY, null);\r
- String proxyUrlString = properties.getProperty(PROXY_URL_KEY, null);\r
- if (proxyUrlString != null && proxyUrlString.length() > 0) {\r
- this.proxyUrls = proxyUrlString.split(PROXY_URLS_VALUE_SEPARATOR);\r
- } else {\r
- String[] local = {"http://localhost:5000"};\r
- this.proxyUrls = local;\r
- }\r
- this.index = 0;\r
- }\r
-\r
- // constructs a URL to contact the proxy which contacts a DME2 service\r
- public String constructUrl(Map<String, String> parameters) {\r
- StringBuilder sb = new StringBuilder();\r
-\r
- // The hostname is assigned in a round robin fashion\r
- sb.append(acquireHostName());\r
- sb.append("/service=" + parameters.get(SERVICE_KEY));\r
-\r
- // If the directedGraph passes an explicit version use that, if not use the commonServiceVersion\r
- // found in the properties file\r
- String version = parameters.getOrDefault(VERSION_KEY, this.commonServiceVersion);\r
- sb.append("/version=" + version);\r
- String envContext = parameters.getOrDefault(ENV_CONTEXT_KEY, this.envContext);\r
- sb.append("/envContext=" + envContext);\r
- String routeOffer = parameters.getOrDefault(ROUTE_OFFER_KEY, this.routeOffer);\r
- sb.append("/routeOffer=" + routeOffer);\r
-\r
- String subContext = parameters.get(SUBCONTEXT_KEY);\r
- if (subContext != null && subContext.length() > 0) {\r
- sb.append("/subContext=" + subContext);\r
- }\r
- sb.append("?dme2.password=" + this.aafPassword);\r
- sb.append("&dme2.username=" + this.aafUserName);\r
- if (this.partner != null) {\r
- sb.append("&partner=" + this.partner);\r
- }\r
- sb.append("&dme2.allowhttpcode=true");\r
- String endpointReadTimeout = parameters.getOrDefault(ENDPOINT_READ_TIMEOUT_KEY, this.endpointReadTimeout);\r
- if (endpointReadTimeout != null) {\r
- sb.append("&dme2.endpointReadTimeout=" + endpointReadTimeout);\r
- }\r
- String incompleteUrl = sb.toString();\r
-\r
- // Support optional parameters in a flexible way\r
- for (Entry<String, String> param : parameters.entrySet()) {\r
- if (!incompleteUrl.contains(param.getKey() + "=") && param.getValue() != null\r
- && param.getValue().length() > 0 && !OUTPUT_PATH_KEY.equals(param.getKey())) {\r
- sb.append("&" + param.getKey() + "=" + param.getValue());\r
- }\r
- }\r
- return sb.toString();\r
- }\r
-\r
- public synchronized String acquireHostName() {\r
- String retVal = proxyUrls[index];\r
- index++;\r
- if (index == this.proxyUrls.length) {\r
- index = 0;\r
- }\r
- return retVal;\r
- }\r
-\r
- // Node entry point\r
- public void constructUrl(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {\r
- SliPluginUtils.checkParameters(parameters, new String[] {SERVICE_KEY, OUTPUT_PATH_KEY}, LOG);\r
- String completeProxyUrl = constructUrl(parameters);\r
- ctx.setAttribute(parameters.get(OUTPUT_PATH_KEY), completeProxyUrl);\r
- }\r
-\r
-}\r
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : CCSDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.core.slipluginutils;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A SvcLogicJavaPlugin that generates DME2 proxy urls (for calling the DME2 ingress proxy) using
+ * parameters from context memory.
+ */
+public class DME2 implements SvcLogicJavaPlugin {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DME2.class);
+ // the key for <code>proxyUrl</code>, which represents a CSV list of urls
+ static final String PROXY_URL_KEY = "proxyUrl";
+ static final String PROXY_URLS_VALUE_SEPARATOR = ",";
+ static final String AAF_USERNAME_KEY = "aafUserName";
+ static final String AAF_PASSWORD_KEY = "aafPassword";
+ static final String ENV_CONTEXT_KEY = "envContext";
+ static final String ROUTE_OFFER_KEY = "routeOffer";
+ static final String COMMON_SERVICE_VERSION_KEY = "commonServiceVersion";
+ static final String PARTNER_KEY = "partner";
+ static final String VERSION_KEY = "version";
+ static final String SERVICE_KEY = "service";
+ static final String SUBCONTEXT_KEY = "subContext";
+ static final String ENDPOINT_READ_TIMEOUT_KEY = "endpointReadTimeout";
+ static final String OUTPUT_PATH_KEY = "outputPath";
+
+ final String aafUserName;
+ final String aafPassword;
+ final String envContext;
+ final String routeOffer;
+ final String[] proxyUrls;
+ final String commonServiceVersion;
+ final String partner;
+ final String endpointReadTimeout;
+ Integer index;
+
+ public DME2(Properties properties) {
+ Iterator<Entry<Object, Object>> it = properties.entrySet().iterator();
+ while (it.hasNext()) {
+ Entry<Object, Object> entry = it.next();
+ if (entry.getValue() == null || entry.getValue().toString().length() < 1) {
+ it.remove();
+ }
+ }
+ this.aafUserName = properties.getProperty(AAF_USERNAME_KEY, null);
+ this.aafPassword = properties.getProperty(AAF_PASSWORD_KEY, null);
+ this.envContext = properties.getProperty(ENV_CONTEXT_KEY, null);
+ this.routeOffer = properties.getProperty(ROUTE_OFFER_KEY, null);
+ this.commonServiceVersion = properties.getProperty(COMMON_SERVICE_VERSION_KEY, null);
+ this.partner = properties.getProperty(PARTNER_KEY, null);
+ this.endpointReadTimeout = properties.getProperty(ENDPOINT_READ_TIMEOUT_KEY, null);
+ String proxyUrlString = properties.getProperty(PROXY_URL_KEY, null);
+ if (proxyUrlString != null && proxyUrlString.length() > 0) {
+ this.proxyUrls = proxyUrlString.split(PROXY_URLS_VALUE_SEPARATOR);
+ } else {
+ String[] local = {"http://localhost:5000"};
+ this.proxyUrls = local;
+ }
+ this.index = 0;
+ }
+
+ // constructs a URL to contact the proxy which contacts a DME2 service
+ public String constructUrl(Map<String, String> parameters) {
+ StringBuilder sb = new StringBuilder();
+
+ // The hostname is assigned in a round robin fashion
+ sb.append(acquireHostName());
+ sb.append("/service=" + parameters.get(SERVICE_KEY));
+
+ // If the directedGraph passes an explicit version use that, if not use the commonServiceVersion
+ // found in the properties file
+ String version = parameters.get(VERSION_KEY);
+ if (version != null && version.length() > 0) {
+ sb.append("/version=" + version);
+ }else {
+ sb.append("/version=" + this.commonServiceVersion);
+ }
+ String envContext = parameters.getOrDefault(ENV_CONTEXT_KEY, this.envContext);
+ sb.append("/envContext=" + envContext);
+
+ String routeOffer = parameters.getOrDefault(ROUTE_OFFER_KEY, this.routeOffer);
+ if (routeOffer != null && routeOffer.length() > 0) {
+ sb.append("/routeOffer=" + routeOffer);
+ }
+
+ String subContext = parameters.get(SUBCONTEXT_KEY);
+ if (subContext != null && subContext.length() > 0) {
+ sb.append("/subContext=" + subContext);
+ }
+ sb.append("?dme2.password=" + this.aafPassword);
+ sb.append("&dme2.username=" + this.aafUserName);
+ if (this.partner != null) {
+ sb.append("&partner=" + this.partner);
+ }
+ sb.append("&dme2.allowhttpcode=true");
+ String endpointReadTimeout = parameters.getOrDefault(ENDPOINT_READ_TIMEOUT_KEY, this.endpointReadTimeout);
+ if (endpointReadTimeout != null) {
+ sb.append("&dme2.endpointReadTimeout=" + endpointReadTimeout);
+ }
+ String incompleteUrl = sb.toString();
+
+ // Support optional parameters in a flexible way
+ for (Entry<String, String> param : parameters.entrySet()) {
+ if (!incompleteUrl.contains(param.getKey() + "=") && param.getValue() != null
+ && param.getValue().length() > 0 && !OUTPUT_PATH_KEY.equals(param.getKey())) {
+ sb.append("&" + param.getKey() + "=" + param.getValue());
+ }
+ }
+ return sb.toString();
+ }
+
+ public synchronized String acquireHostName() {
+ String retVal = proxyUrls[index];
+ index++;
+ if (index == this.proxyUrls.length) {
+ index = 0;
+ }
+ return retVal;
+ }
+
+ // Node entry point
+ public void constructUrl(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
+ SliPluginUtils.checkParameters(parameters, new String[] {SERVICE_KEY, OUTPUT_PATH_KEY}, LOG);
+ String completeProxyUrl = constructUrl(parameters);
+ ctx.setAttribute(parameters.get(OUTPUT_PATH_KEY), completeProxyUrl);
+ }
+
+ // Support legacy direct java call
+ public String constructUrl(String service, String version, String subContext) {
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put(SERVICE_KEY, service);
+ if (version != null) {
+ parameters.put(VERSION_KEY, version);
+ }
+ parameters.put(SUBCONTEXT_KEY, subContext);
+ return constructUrl(parameters);
+ }
+
+}
-/*-\r
- * ============LICENSE_START=======================================================\r
- * ONAP : CCSDK\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property. All rights\r
- * reserved.\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ============LICENSE_END=========================================================\r
- */\r
-\r
-package org.onap.ccsdk.sli.core.slipluginutils;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNotNull;\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileNotFoundException;\r
-import java.io.IOException;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-import java.util.Properties;\r
-import org.junit.Assert;\r
-import org.junit.Test;\r
-\r
-public class Dme2Test {\r
- public Properties makesProperties(String aafUserName, String aafPassword, String envContext, String routeOffer,\r
- String proxyUrls, String commonServiceVersion) {\r
- Properties props = new Properties();\r
- props.put(DME2.AAF_USERNAME_KEY, aafUserName);\r
- props.put(DME2.AAF_PASSWORD_KEY, aafPassword);\r
- props.put(DME2.ENV_CONTEXT_KEY, envContext);\r
- props.put(DME2.ROUTE_OFFER_KEY, routeOffer);\r
- props.put(DME2.PROXY_URL_KEY, proxyUrls);\r
- props.put(DME2.COMMON_SERVICE_VERSION_KEY, commonServiceVersion);\r
- return props;\r
- }\r
-\r
- @Test\r
- public void createUrl() {\r
- String instarUrl =\r
- "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&dme2.allowhttpcode=true";\r
- Properties props =\r
- makesProperties("user@sample.com", "fake", "TEST", "DEFAULT", "http://localhost:25055", "common");\r
- DME2 dme = new DME2(props);\r
- Map<String, String> parameters = new HashMap<String, String>();\r
- parameters.put(DME2.SERVICE_KEY, "sample.com/services/eim/v1/rest");\r
- parameters.put(DME2.VERSION_KEY, "1702.0");\r
- parameters.put(DME2.SUBCONTEXT_KEY, "/enterpriseConnection/getEnterpriseConnectionDetails/v1");\r
- parameters.put(DME2.OUTPUT_PATH_KEY, "tmp.test");\r
-\r
- String constructedUrl = dme.constructUrl(parameters);\r
- assertEquals(instarUrl, constructedUrl);\r
- }\r
-\r
- @Test\r
- public void createUrlNoSubContext() {\r
- String instarUrl =\r
- "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&dme2.allowhttpcode=true";\r
- Properties props =\r
- makesProperties("user@sample.com", "fake", "TEST", "DEFAULT", "http://localhost:25055", "common");\r
- DME2 dme = new DME2(props);\r
- Map<String, String> parameters = new HashMap<String, String>();\r
- parameters.put(DME2.SERVICE_KEY, "sample.com/services/eim/v1/rest");\r
- parameters.put(DME2.VERSION_KEY, "1702.0");\r
- parameters.put(DME2.SUBCONTEXT_KEY, null);\r
- String constructedUrl = dme.constructUrl(parameters);\r
- assertEquals(instarUrl, constructedUrl);\r
- }\r
-\r
- @Test\r
- public void testRoundRobin() {\r
- String[] proxyHostNames = new String[] {"http://one:25055", "http://two:25055", "http://three:25055"};\r
- String proxyHostNameString = proxyHostNames[0] + "," + proxyHostNames[1] + "," + proxyHostNames[2];\r
-\r
- String urlSuffix =\r
- "/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&dme2.allowhttpcode=true";\r
- Properties props = makesProperties("user@sample.com", "fake", "TEST", "DEFAULT", proxyHostNameString, "common");\r
- DME2 dme = new DME2(props);\r
- Map<String, String> parameters = new HashMap<String, String>();\r
- parameters.put(DME2.SERVICE_KEY, "sample.com/services/eim/v1/rest");\r
- parameters.put(DME2.VERSION_KEY, "1702.0");\r
- parameters.put(DME2.SUBCONTEXT_KEY, "/enterpriseConnection/getEnterpriseConnectionDetails/v1");\r
- String constructedUrl = dme.constructUrl(parameters);\r
- assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);\r
- constructedUrl = dme.constructUrl(parameters);\r
- assertEquals(proxyHostNames[1] + urlSuffix, constructedUrl);\r
- constructedUrl = dme.constructUrl(parameters);\r
- assertEquals(proxyHostNames[2] + urlSuffix, constructedUrl);\r
- constructedUrl = dme.constructUrl(parameters);\r
- assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);\r
- constructedUrl = dme.constructUrl(parameters);\r
- assertEquals(proxyHostNames[1] + urlSuffix, constructedUrl);\r
- constructedUrl = dme.constructUrl(parameters);\r
- assertEquals(proxyHostNames[2] + urlSuffix, constructedUrl);\r
- constructedUrl = dme.constructUrl(parameters);\r
- assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);\r
- }\r
-\r
- @Test\r
- public void createDme2EndtoEnd() throws FileNotFoundException, IOException {\r
- Properties props = new Properties();\r
- props.load(new FileInputStream("src/test/resources/dme2.e2e.properties"));\r
- DME2 dme2 = new DME2(props);\r
- assertEquals("user@sample.com", dme2.aafUserName);\r
- assertEquals("fake", dme2.aafPassword);\r
- assertEquals("UAT", dme2.envContext);\r
- assertEquals("UAT", dme2.routeOffer);\r
- Assert.assertArrayEquals(\r
- "http://sample.com:25055,http://sample.com:25055".split(DME2.PROXY_URLS_VALUE_SEPARATOR),\r
- dme2.proxyUrls);\r
- assertEquals("1702.0", dme2.commonServiceVersion);\r
- assertEquals(null, dme2.partner);\r
- Map<String, String> parameters = new HashMap<String, String>();\r
- parameters.put(DME2.SERVICE_KEY, "sample.com/restservices/instar/v1/assetSearch");\r
- parameters.put(DME2.VERSION_KEY, null);\r
- parameters.put(DME2.SUBCONTEXT_KEY, "/mySubContext");\r
- String constructedUrl = dme2.constructUrl(parameters);\r
- assertNotNull(constructedUrl);\r
- }\r
-\r
- @Test\r
- public void createDme2Prod() throws FileNotFoundException, IOException {\r
- Properties props = new Properties();\r
- props.load(new FileInputStream("src/test/resources/dme2.prod.properties"));\r
- DME2 dme2 = new DME2(props);\r
- assertEquals("user@sample.com", dme2.aafUserName);\r
- assertEquals("fake", dme2.aafPassword);\r
- assertEquals("PROD", dme2.envContext);\r
- assertEquals(null, dme2.routeOffer);\r
- Assert.assertArrayEquals(\r
- "http://sample.com:25055,http://sample.com:25055".split(DME2.PROXY_URLS_VALUE_SEPARATOR),\r
- dme2.proxyUrls);\r
- assertEquals("1.0", dme2.commonServiceVersion);\r
- assertEquals("LPP_PROD", dme2.partner);\r
- Map<String, String> parameters = new HashMap<String, String>();\r
- parameters.put(DME2.SERVICE_KEY, "sample.com/services/eim/v1/rest");\r
- parameters.put(DME2.VERSION_KEY, "1702.0");\r
- parameters.put(DME2.SUBCONTEXT_KEY, "/enterpriseConnection/getEnterpriseConnectionDetails/v1");\r
- String constructedUrl = dme2.constructUrl(parameters);\r
- assertNotNull(constructedUrl);\r
- }\r
-\r
- @Test\r
- public void blankProperties() throws Exception {\r
- Properties props = new Properties();\r
- DME2 dme2 = new DME2(props);\r
- Map<String, String> parameters = new HashMap<String, String>();\r
- parameters.put(DME2.SERVICE_KEY, "easyService");\r
- parameters.put(DME2.VERSION_KEY, "3");\r
- parameters.put(DME2.SUBCONTEXT_KEY, "/sub");\r
- assertEquals(\r
- "http://localhost:5000/service=easyService/version=3/envContext=null/routeOffer=null/subContext=/sub?dme2.password=null&dme2.username=null&dme2.allowhttpcode=true",\r
- dme2.constructUrl(parameters));\r
- }\r
-\r
- @Test\r
- public void optionalParameters() {\r
- String instarUrl =\r
- "http://localhost:25055/service=serv/version=4/envContext=TEST/routeOffer=DEFAULT/subContext=/sub?dme2.password=fake&dme2.username=user@sample.com&dme2.allowhttpcode=true&test=123";\r
- Properties props =\r
- makesProperties("user@sample.com", "fake", "TEST", "DEFAULT", "http://localhost:25055", "common");\r
- DME2 dme = new DME2(props);\r
- Map<String, String> parameters = new HashMap<String, String>();\r
- parameters.put(DME2.SERVICE_KEY, "serv");\r
- parameters.put(DME2.VERSION_KEY, "4");\r
- parameters.put(DME2.SUBCONTEXT_KEY, "/sub");\r
- parameters.put("test", "123");\r
-\r
- String constructedUrl = dme.constructUrl(parameters);\r
- assertEquals(instarUrl, constructedUrl);\r
- }\r
-\r
-}\r
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : CCSDK
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.core.slipluginutils;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class Dme2Test {
+ public Properties makesProperties(String aafUserName, String aafPassword, String envContext, String routeOffer,
+ String proxyUrls, String commonServiceVersion) {
+ Properties props = new Properties();
+ props.put(DME2.AAF_USERNAME_KEY, aafUserName);
+ props.put(DME2.AAF_PASSWORD_KEY, aafPassword);
+ props.put(DME2.ENV_CONTEXT_KEY, envContext);
+ props.put(DME2.ROUTE_OFFER_KEY, routeOffer);
+ props.put(DME2.PROXY_URL_KEY, proxyUrls);
+ props.put(DME2.COMMON_SERVICE_VERSION_KEY, commonServiceVersion);
+ return props;
+ }
+
+ @Test
+ public void createUrl() {
+ String localUrl =
+ "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&dme2.allowhttpcode=true";
+ Properties props =
+ makesProperties("user@sample.com", "fake", "TEST", "DEFAULT", "http://localhost:25055", "common");
+ DME2 dme = new DME2(props);
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put(DME2.SERVICE_KEY, "sample.com/services/eim/v1/rest");
+ parameters.put(DME2.VERSION_KEY, "1702.0");
+ parameters.put(DME2.SUBCONTEXT_KEY, "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
+ parameters.put(DME2.OUTPUT_PATH_KEY, "tmp.test");
+
+ String constructedUrl = dme.constructUrl(parameters);
+ assertEquals(localUrl, constructedUrl);
+ }
+
+ @Test
+ public void createUrlNoSubContext() {
+ String localUrl =
+ "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&dme2.allowhttpcode=true";
+ Properties props =
+ makesProperties("user@sample.com", "fake", "TEST", "DEFAULT", "http://localhost:25055", "common");
+ DME2 dme = new DME2(props);
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put(DME2.SERVICE_KEY, "sample.com/services/eim/v1/rest");
+ parameters.put(DME2.VERSION_KEY, "1702.0");
+ parameters.put(DME2.SUBCONTEXT_KEY, null);
+ String constructedUrl = dme.constructUrl(parameters);
+ assertEquals(localUrl, constructedUrl);
+ }
+
+ @Test
+ public void testRoundRobin() {
+ String[] proxyHostNames = new String[] {"http://one:25055", "http://two:25055", "http://three:25055"};
+ String proxyHostNameString = proxyHostNames[0] + "," + proxyHostNames[1] + "," + proxyHostNames[2];
+
+ 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&dme2.allowhttpcode=true";
+ Properties props = makesProperties("user@sample.com", "fake", "TEST", "DEFAULT", proxyHostNameString, "common");
+ DME2 dme = new DME2(props);
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put(DME2.SERVICE_KEY, "sample.com/services/eim/v1/rest");
+ parameters.put(DME2.VERSION_KEY, "1702.0");
+ parameters.put(DME2.SUBCONTEXT_KEY, "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
+ String constructedUrl = dme.constructUrl(parameters);
+ assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);
+ constructedUrl = dme.constructUrl(parameters);
+ assertEquals(proxyHostNames[1] + urlSuffix, constructedUrl);
+ constructedUrl = dme.constructUrl(parameters);
+ assertEquals(proxyHostNames[2] + urlSuffix, constructedUrl);
+ constructedUrl = dme.constructUrl(parameters);
+ assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);
+ constructedUrl = dme.constructUrl(parameters);
+ assertEquals(proxyHostNames[1] + urlSuffix, constructedUrl);
+ constructedUrl = dme.constructUrl(parameters);
+ assertEquals(proxyHostNames[2] + urlSuffix, constructedUrl);
+ constructedUrl = dme.constructUrl(parameters);
+ assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);
+ }
+
+ @Test
+ public void createDme2EndtoEnd() throws FileNotFoundException, IOException {
+ Properties props = new Properties();
+ props.load(new FileInputStream("src/test/resources/dme2.e2e.properties"));
+ DME2 dme2 = new DME2(props);
+ assertEquals("user@sample.com", dme2.aafUserName);
+ assertEquals("fake", dme2.aafPassword);
+ assertEquals("UAT", dme2.envContext);
+ assertEquals("UAT", dme2.routeOffer);
+ Assert.assertArrayEquals(
+ "http://sample.com:25055,http://sample.com:25055".split(DME2.PROXY_URLS_VALUE_SEPARATOR),
+ dme2.proxyUrls);
+ assertEquals("1702.0", dme2.commonServiceVersion);
+ assertEquals(null, dme2.partner);
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put(DME2.SERVICE_KEY, "sample.com/restservices/sys/v1/assetSearch");
+ parameters.put(DME2.VERSION_KEY, null);
+ parameters.put(DME2.SUBCONTEXT_KEY, "/mySubContext");
+ String constructedUrl = dme2.constructUrl(parameters);
+ assertNotNull(constructedUrl);
+ String expected =
+ "http://sample.com:25055/service=sample.com/restservices/sys/v1/assetSearch/version=1702.0/envContext=UAT/routeOffer=UAT/subContext=/mySubContext?dme2.password=fake&dme2.username=user@sample.com&dme2.allowhttpcode=true";
+ assertEquals(expected, constructedUrl);
+ }
+
+ @Test
+ public void createDme2Prod() throws FileNotFoundException, IOException {
+ Properties props = new Properties();
+ props.load(new FileInputStream("src/test/resources/dme2.prod.properties"));
+ DME2 dme2 = new DME2(props);
+ assertEquals("user@sample.com", dme2.aafUserName);
+ assertEquals("fake", dme2.aafPassword);
+ assertEquals("PROD", dme2.envContext);
+ assertEquals(null, dme2.routeOffer);
+ Assert.assertArrayEquals(
+ "http://sample.com:25055,http://sample.com:25055".split(DME2.PROXY_URLS_VALUE_SEPARATOR),
+ dme2.proxyUrls);
+ assertEquals("1.0", dme2.commonServiceVersion);
+ assertEquals("LPP_PROD", dme2.partner);
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put(DME2.SERVICE_KEY, "sample.com/services/eim/v1/rest");
+ parameters.put(DME2.VERSION_KEY, "1702.0");
+ parameters.put(DME2.SUBCONTEXT_KEY, "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
+ String constructedUrl = dme2.constructUrl(parameters);
+ assertNotNull(constructedUrl);
+ String expected =
+ "http://sample.com:25055/service=sample.com/services/eim/v1/rest/version=1702.0/envContext=PROD/subContext=/enterpriseConnection/getEnterpriseConnectionDetails/v1?dme2.password=fake&dme2.username=user@sample.com&partner=LPP_PROD&dme2.allowhttpcode=true";
+ assertEquals(expected, constructedUrl);
+ }
+
+ @Test
+ public void blankProperties() throws Exception {
+ Properties props = new Properties();
+ DME2 dme2 = new DME2(props);
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put(DME2.SERVICE_KEY, "easyService");
+ parameters.put(DME2.VERSION_KEY, "3");
+ parameters.put(DME2.SUBCONTEXT_KEY, "/sub");
+ assertEquals(
+ "http://localhost:5000/service=easyService/version=3/envContext=null/subContext=/sub?dme2.password=null&dme2.username=null&dme2.allowhttpcode=true",
+ dme2.constructUrl(parameters));
+ }
+
+ @Test
+ public void optionalParameters() {
+ String localUrl =
+ "http://localhost:25055/service=serv/version=4/envContext=TEST/routeOffer=DEFAULT/subContext=/sub?dme2.password=fake&dme2.username=user@sample.com&dme2.allowhttpcode=true&test=123";
+ Properties props =
+ makesProperties("user@sample.com", "fake", "TEST", "DEFAULT", "http://localhost:25055", "common");
+ DME2 dme = new DME2(props);
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put(DME2.SERVICE_KEY, "serv");
+ parameters.put(DME2.VERSION_KEY, "4");
+ parameters.put(DME2.SUBCONTEXT_KEY, "/sub");
+ parameters.put("test", "123");
+
+ String constructedUrl = dme.constructUrl(parameters);
+ assertEquals(localUrl, constructedUrl);
+ }
+
+ @Test
+ public void createLocalUrlLegacy() {
+ String localUrl =
+ "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&dme2.allowhttpcode=true";
+ Properties props =
+ makesProperties("user@sample.com", "fake", "TEST", "DEFAULT", "http://localhost:25055", "common");
+ DME2 dme = new DME2(props);
+ String constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0",
+ "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
+ assertEquals(localUrl, constructedUrl);
+ }
+
+ @Test
+ public void createLocalUrlNoSubContextLegacy() {
+ String localUrl =
+ "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&dme2.allowhttpcode=true";
+ Properties props =
+ makesProperties("user@sample.com", "fake", "TEST", "DEFAULT", "http://localhost:25055", "common");
+ DME2 dme = new DME2(props);
+ Map<String, String> parameters = new HashMap<String, String>();
+ String constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", parameters.get(null));
+ assertEquals(localUrl, constructedUrl);
+ }
+
+ @Test
+ public void testRoundRobinLegacy() {
+ String[] proxyHostNames = new String[] {"http://one:25055", "http://two:25055", "http://three:25055"};
+ 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&dme2.allowhttpcode=true";
+ Properties props = makesProperties("user@sample.com", "fake", "TEST", "DEFAULT",
+ "http://one:25055,http://two:25055,http://three:25055", "common");
+ DME2 dme = new DME2(props);
+ String constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0",
+ "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
+ assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);
+ constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0",
+ "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
+ assertEquals(proxyHostNames[1] + urlSuffix, constructedUrl);
+ constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0",
+ "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
+ assertEquals(proxyHostNames[2] + urlSuffix, constructedUrl);
+ constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0",
+ "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
+ assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);
+ constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0",
+ "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
+ assertEquals(proxyHostNames[1] + urlSuffix, constructedUrl);
+ constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0",
+ "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
+ assertEquals(proxyHostNames[2] + urlSuffix, constructedUrl);
+ constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0",
+ "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
+ assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);
+ }
+
+ @Test
+ public void createDme2EndtoEndLegacy() throws Exception {
+ Properties props = new Properties();
+ props.load(new FileInputStream("src/test/resources/dme2.e2e.properties"));
+ DME2 dme2 = new DME2(props);
+ assertEquals("user@sample.com", dme2.aafUserName);
+ assertEquals("fake", dme2.aafPassword);
+ assertEquals("UAT", dme2.envContext);
+ assertEquals("UAT", dme2.routeOffer);
+ Assert.assertArrayEquals("http://sample.com:25055,http://sample.com:25055".split(","), dme2.proxyUrls);
+ assertEquals("1702.0", dme2.commonServiceVersion);
+ assertEquals(null, dme2.partner);
+ String constructedUrl = dme2.constructUrl("sample.com/restservices/sys/v1/assetSearch", null, "/mySubContext");
+ assertNotNull(constructedUrl);
+ String expected =
+ "http://sample.com:25055/service=sample.com/restservices/sys/v1/assetSearch/version=1702.0/envContext=UAT/routeOffer=UAT/subContext=/mySubContext?dme2.password=fake&dme2.username=user@sample.com&dme2.allowhttpcode=true";
+ assertEquals(expected, constructedUrl);
+ }
+
+ @Test
+ public void createDme2ProdLegacy() throws Exception {
+ Properties props = new Properties();
+ props.load(new FileInputStream("src/test/resources/dme2.prod.properties"));
+ DME2 dme2 = new DME2(props);
+ assertEquals("user@sample.com", dme2.aafUserName);
+ assertEquals("fake", dme2.aafPassword);
+ assertEquals("PROD", dme2.envContext);
+ assertEquals(null, dme2.routeOffer);
+ Assert.assertArrayEquals("http://sample.com:25055,http://sample.com:25055".split(","), dme2.proxyUrls);
+ assertEquals("1.0", dme2.commonServiceVersion);
+ assertEquals("LPP_PROD", dme2.partner);
+ String constructedUrl = dme2.constructUrl("sample.com/restservices/sys/v1/assetSearch", null, "/mySubContext");
+ assertNotNull(constructedUrl);
+ String expected =
+ "http://sample.com:25055/service=sample.com/restservices/sys/v1/assetSearch/version=1.0/envContext=PROD/subContext=/mySubContext?dme2.password=fake&dme2.username=user@sample.com&partner=LPP_PROD&dme2.allowhttpcode=true";
+ assertEquals(expected, constructedUrl);
+ }
+
+}