aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xaai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClient.java5
-rwxr-xr-xaai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClientRESTExecutor.java35
-rwxr-xr-xaai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIDeclarations.java2
-rwxr-xr-xaai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIService.java2
-rw-r--r--aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceException.java97
-rwxr-xr-xaai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceUtils.java41
-rwxr-xr-xaai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/ActionUpdateTest.java43
-rwxr-xr-xaai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AutoGeneratedRegressionTest.java1677
-rwxr-xr-xaai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/RequestPathTest.java76
9 files changed, 1045 insertions, 933 deletions
diff --git a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClient.java b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClient.java
index 3684cf21..6f466c3b 100755
--- a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClient.java
+++ b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClient.java
@@ -24,7 +24,6 @@ package org.onap.ccsdk.sli.adaptors.aai;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.HashMap;
import java.util.Map;
import org.openecomp.aai.inventory.v11.*;
@@ -76,9 +75,9 @@ public interface AAIClient extends SvcLogicResource, SvcLogicJavaPlugin {
public void logKeyError(String keys);
- public QueryStatus processResponseData(String rv, String resource, AAIRequest request, String prefix, SvcLogicContext ctx, HashMap<String, String> nameValues, String modifier) throws JsonParseException, JsonMappingException, IOException, AAIServiceException ;
+ public QueryStatus processResponseData(String rv, String resource, AAIRequest request, String prefix, SvcLogicContext ctx, Map<String, String> nameValues, String modifier) throws JsonParseException, JsonMappingException, IOException, AAIServiceException ;
public String getPathTemplateForResource(String resoourceName, String join, SvcLogicContext ctx) throws MalformedURLException;
- public boolean isDeprecatedFormat(String resource, HashMap<String, String> nameValues);
+ public boolean isDeprecatedFormat(String resource, Map<String, String> nameValues);
String query(AAIRequest request) throws AAIServiceException;
String save(AAIRequest request) throws AAIServiceException;
diff --git a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClientRESTExecutor.java b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClientRESTExecutor.java
index 252f3197..906cd838 100755
--- a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClientRESTExecutor.java
+++ b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClientRESTExecutor.java
@@ -103,7 +103,6 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
truststorePassword = props.getProperty(AAIService.TRUSTSTORE_PSSWD);
keystorePath = props.getProperty(AAIService.KEYSTORE_PATH);
keystorePassword = props.getProperty(AAIService.KEYSTORE_PSSWD);
-// this.read_timeout = read_timeout;
String tmpApplicationId =props.getProperty(AAIService.APPLICATION_ID);
if(tmpApplicationId == null || tmpApplicationId.isEmpty()) {
@@ -310,14 +309,12 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
errorresponse.setRequestError(requestError);
throw new AAIServiceException(responseCode, errorresponse);
} else {
-// StringBuilder errorStringBuilder = new StringBuilder();
String line = null;
while( ( line = reader.readLine() ) != null ) {
errorStringBuilder.append("\n").append( line );
}
ErrorResponse errorresponse = mapper.readValue(errorStringBuilder.toString(), ErrorResponse.class);
-// ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class);
LOGwriteEndingTrace(responseCode, responseMessage, mapper.writeValueAsString(errorresponse));
throw new AAIServiceException(responseCode, errorresponse);
}
@@ -373,16 +370,16 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
LOG.error("", exc);
}
- URL requestUrl = null;
- HttpURLConnection con = getConfiguredConnection(requestUrl = request.getRequestUrl(HttpMethod.PUT, resourceVersion), HttpMethod.PUT);
+ URL requestUrl = request.getRequestUrl(HttpMethod.PUT, resourceVersion);
+ HttpURLConnection con = getConfiguredConnection(requestUrl, HttpMethod.PUT);
ObjectMapper mapper = AAIService.getObjectMapper();
- String json_text = request.toJSONString();
+ String jsonText = request.toJSONString();
- LOGwriteDateTrace("data", json_text);
- logMetricRequest("PUT "+requestUrl.getPath(), json_text, requestUrl.getPath());
+ LOGwriteDateTrace("data", jsonText);
+ logMetricRequest("PUT "+requestUrl.getPath(), jsonText, requestUrl.getPath());
OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream());
- osw.write(json_text);
+ osw.write(jsonText);
osw.flush();
// Check for errors
@@ -454,8 +451,8 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
}
try {
- URL requestUrl = null;
- HttpURLConnection conn = getConfiguredConnection(requestUrl = request.getRequestUrl(HttpMethod.DELETE, resourceVersion), HttpMethod.DELETE);
+ URL requestUrl = request.getRequestUrl(HttpMethod.DELETE, resourceVersion);
+ HttpURLConnection conn = getConfiguredConnection(requestUrl, HttpMethod.DELETE);
logMetricRequest("DELETE "+requestUrl.getPath(), "", requestUrl.getPath());
conn.setDoOutput(true);
@@ -527,11 +524,10 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
public Object query(AAIRequest request, Class clas) throws AAIServiceException {
Object response = null;
InputStream inputStream = null;
- HttpURLConnection con = null;
- URL requestUrl = null;
try {
- con = getConfiguredConnection(requestUrl = request.getRequestQueryUrl(HttpMethod.GET), HttpMethod.GET);
+ URL requestUrl = request.getRequestQueryUrl(HttpMethod.GET);
+ HttpURLConnection con = getConfiguredConnection(requestUrl, HttpMethod.GET);
logMetricRequest("GET "+requestUrl.getPath(), "", requestUrl.getPath());
// Check for errors
@@ -574,7 +570,6 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
LOG.warn("GET", exc);
}
}
- con = null;
}
return response;
}
@@ -592,13 +587,13 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
URL requestUrl = null;
HttpURLConnection con = getConfiguredConnection(requestUrl = request.getRequestUrl("PATCH", resourceVersion), "PATCH");
ObjectMapper mapper = AAIService.getObjectMapper();
- String json_text = request.toJSONString();
+ String jsonText = request.toJSONString();
- LOGwriteDateTrace("data", json_text);
- logMetricRequest("PATCH "+requestUrl.getPath(), json_text, requestUrl.getPath());
+ LOGwriteDateTrace("data", jsonText);
+ logMetricRequest("PATCH "+requestUrl.getPath(), jsonText, requestUrl.getPath());
OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream());
- osw.write(json_text);
+ osw.write(jsonText);
osw.flush();
// Check for errors
@@ -723,8 +718,6 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
String targetEntity = "A&AI";
String targetVirtualEntity = null;
- targetServiceName = "";
-
ml.logRequest(svcInstanceId, svcName, partnerName, targetEntity, targetServiceName, targetVirtualEntity, msg);
}
diff --git a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIDeclarations.java b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIDeclarations.java
index 7966fa97..d1b148d5 100755
--- a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIDeclarations.java
+++ b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIDeclarations.java
@@ -818,7 +818,7 @@ public abstract class AAIDeclarations implements AAIClient {
return retval;
}
- public QueryStatus processResponseData(String rv, String resource, AAIRequest request, String prefix, SvcLogicContext ctx, HashMap<String, String> nameValues, String modifier) throws JsonParseException, JsonMappingException, IOException, AAIServiceException
+ public QueryStatus processResponseData(String rv, String resource, AAIRequest request, String prefix, SvcLogicContext ctx, Map<String, String> nameValues, String modifier) throws JsonParseException, JsonMappingException, IOException, AAIServiceException
{
Object response;
diff --git a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIService.java b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIService.java
index 73454694..9e6e60f9 100755
--- a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIService.java
+++ b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIService.java
@@ -1520,7 +1520,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe
}
@Override
- public boolean isDeprecatedFormat(String resource, HashMap<String, String> nameValues) {
+ public boolean isDeprecatedFormat(String resource, Map<String, String> nameValues) {
return !AAIServiceUtils.isValidFormat(resource, nameValues);
}
diff --git a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceException.java b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceException.java
index ff182f2d..9fac977d 100644
--- a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceException.java
+++ b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceException.java
@@ -3,14 +3,14 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
+ * 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.
@@ -25,53 +25,62 @@ import org.onap.ccsdk.sli.adaptors.aai.data.ErrorResponse;
public class AAIServiceException extends Exception {
- /**
- *
- */
- private static final long serialVersionUID = -9039257722542999522L;
-
- protected ErrorResponse errorResponse = null;
- protected int returnCode = -1;
+ /**
+ *
+ */
+ private static final long serialVersionUID = -9039257722542999522L;
- public AAIServiceException() {
+ protected final ErrorResponse errorResponse;
+ protected final int returnCode;
- }
+ public AAIServiceException() {
+ returnCode = -1;
+ errorResponse = null;
+ }
- public AAIServiceException(String message) {
- super(message);
- }
+ public AAIServiceException(String message) {
+ super(message);
+ returnCode = -1;
+ errorResponse = null;
+ }
- public AAIServiceException(Throwable cause) {
- super(cause);
- }
+ public AAIServiceException(Throwable cause) {
+ super(cause);
+ returnCode = -1;
+ errorResponse = null;
+ }
- public AAIServiceException(String message, Throwable cause) {
- super(message, cause);
- }
+ public AAIServiceException(String message, Throwable cause) {
+ super(message, cause);
+ returnCode = -1;
+ errorResponse = null;
+ }
- public AAIServiceException(String message, Throwable cause,
- boolean enableSuppression, boolean writableStackTrace) {
- super(message, cause, enableSuppression, writableStackTrace);
- }
+ public AAIServiceException(String message, Throwable cause,
+ boolean enableSuppression, boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ returnCode = -1;
+ errorResponse = null;
+ }
- public AAIServiceException(int returnCode, ErrorResponse errorresponse) {
- this.errorResponse = errorresponse;
- this.returnCode = returnCode;
- }
-
- public ErrorResponse getErrorResponse() {
- return errorResponse;
- }
+ public AAIServiceException(int returnCode, ErrorResponse errorresponse) {
+ this.errorResponse = errorresponse;
+ this.returnCode = returnCode;
+ }
- public int getReturnCode() {
- return returnCode;
- }
-
- public String getMessage() {
- if(errorResponse != null) {
- return errorResponse.getRequestError().getServiceException().getText();
- } else {
- return super.getMessage();
- }
- }
+ public ErrorResponse getErrorResponse() {
+ return errorResponse;
+ }
+
+ public int getReturnCode() {
+ return returnCode;
+ }
+
+ public String getMessage() {
+ if(errorResponse != null) {
+ return errorResponse.getRequestError().getServiceException().getText();
+ } else {
+ return super.getMessage();
+ }
+ }
}
diff --git a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceUtils.java b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceUtils.java
index 102835d9..ca2af1df 100755
--- a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceUtils.java
+++ b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceUtils.java
@@ -28,6 +28,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.Map;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
@@ -49,14 +50,14 @@ public class AAIServiceUtils {
private static final Logger LOG = LoggerFactory.getLogger(AAIService.class);
+ private AAIServiceUtils() {
+ }
+
public static String getPrimaryIdFromClass(Class<? extends AAIDatum> resourceClass){
// 1. find class
getLogger().debug(resourceClass.getName());
- AAIDatum instance = null;
try {
- instance = resourceClass.newInstance();
-
Annotation[] annotations = resourceClass.getAnnotations();
for(Annotation annotation : annotations) {
Class<? extends Annotation> anotationType = annotation.annotationType();
@@ -73,19 +74,15 @@ public class AAIServiceUtils {
}
}
} catch(Exception exc) {
-
+ getLogger().warn("getPrimaryIdFromClass failed", exc);
}
return null;
}
public static String getSecondaryIdFromClass(Class<? extends AAIDatum> resourceClass){
- // 1. find class
getLogger().debug(resourceClass.getName());
- AAIDatum instance = null;
try {
- instance = resourceClass.newInstance();
-
Annotation[] annotations = resourceClass.getAnnotations();
for(Annotation annotation : annotations) {
Class<? extends Annotation> anotationType = annotation.annotationType();
@@ -112,16 +109,16 @@ public class AAIServiceUtils {
return null;
}
- public static Method getRelationshipListGetterMethodFromClassDefinition(Class resourceClass) {
- Method getRelationshipListMethod = null;
-
- try {
- getRelationshipListMethod = resourceClass.getMethod("getRelationshipList");
- } catch(Exception exc) {
- getLogger().debug("Retrofiting relationship data: " + exc.getMessage());
- }
- return getRelationshipListMethod;
- }
+ public static Method getRelationshipListGetterMethodFromClassDefinition(Class resourceClass) {
+ Method getRelationshipListMethod = null;
+
+ try {
+ getRelationshipListMethod = resourceClass.getMethod("getRelationshipList");
+ } catch(Exception exc) {
+ getLogger().debug("Retrofiting relationship data: " + exc.getMessage());
+ }
+ return getRelationshipListMethod;
+ }
private static Logger getLogger() {
return LOG;
@@ -314,10 +311,10 @@ public class AAIServiceUtils {
return request.getRequestPath();
}
- public static boolean isValidFormat(String resource, HashMap<String, String> nameValues) {
+ public static boolean isValidFormat(String resource, Map<String, String> nameValues) {
switch(resource){
- case "custom-query":
+ case "custom-query":
case "formatted-query":
case "generic-query":
case "named-query":
@@ -336,10 +333,10 @@ public class AAIServiceUtils {
Set<String> keys = nameValues.keySet();
for(String key : keys) {
if(!key.contains(".")) {
- if("depth".equals(key) || "related-to".equals(key) || "related_to".equals(key) || "related-link".equals(key) || "related_link".equals(key) || "selflink".equals(key) || "resource_path".equals(key))
+ if("depth".equals(key) || "related-to".equals(key) || "related_to".equals(key) || "related-link".equals(key) || "related_link".equals(key) || "selflink".equals(key) || "resource_path".equals(key))
continue;
else {
- getLogger().warn(String.format("key '%s' is incompatible with resource type '%s'", key, resource));
+ getLogger().warn(String.format("key '%s' is incompatible with resource type '%s'", key, resource));
}
}
}
diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/ActionUpdateTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/ActionUpdateTest.java
new file mode 100755
index 00000000..607182ea
--- /dev/null
+++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/ActionUpdateTest.java
@@ -0,0 +1,43 @@
+package org.onap.ccsdk.sli.adaptors.aai;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+
+import org.onap.ccsdk.sli.adaptors.aai.update.Action;
+import org.onap.ccsdk.sli.adaptors.aai.update.ActionDatum;
+import org.junit.Test;
+
+public class ActionUpdateTest {
+ @Test
+ public void getActionData() throws Exception {
+ final Action resolver = new Action();
+ assertNotNull(resolver.getActionData());
+ }
+
+ @Test
+ public void setActionData() throws Exception {
+ final Action resolver = new Action();
+ resolver.setActionData( new ArrayList<ActionDatum>());
+ }
+
+ @Test
+ public void setActionType() throws Exception {
+ final Action resolver = new Action();
+ resolver.setActionType("create");
+ assertEquals("create", resolver.getActionType());
+ }
+
+ @Test
+ public void getAdditionalProperties() throws Exception {
+ final Action resolver = new Action();
+ assertNotNull(resolver.getAdditionalProperties());
+ }
+
+ @Test
+ public void setAdditionalProperty() throws Exception {
+ final Action resolver = new Action();
+ resolver.setAdditionalProperty("outcome", "success");
+ assertEquals("success", resolver.getAdditionalProperties().get("outcome"));
+ }
+} \ No newline at end of file
diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AutoGeneratedRegressionTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AutoGeneratedRegressionTest.java
index 345ff57b..9bc93609 100755
--- a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AutoGeneratedRegressionTest.java
+++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AutoGeneratedRegressionTest.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
package org.onap.ccsdk.sli.adaptors.aai;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -65,7 +64,6 @@ import org.onap.ccsdk.sli.adaptors.aai.query.NamedQueryData;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
import org.openecomp.aai.inventory.v11.GenericVnf;
-import org.openecomp.aai.inventory.v11.InventoryResponseItems;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.AnnotationUtils;
@@ -81,697 +79,694 @@ import com.fasterxml.jackson.databind.ObjectMapper;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class AutoGeneratedRegressionTest {
- static {
- System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "INFO");
- System.setProperty(org.slf4j.impl.SimpleLogger.LOG_FILE_KEY, String.format("AutoGeneratedRegressionTest-%d.txt", System.currentTimeMillis()));
- }
- private static final Logger LOG = LoggerFactory.getLogger(AutoGeneratedRegressionTest.class);
-
-
- protected static AAIClient client;
-
- protected Map<String, String> cache = new HashMap<String, String>();
-
- @BeforeClass
- public static void setUp() throws Exception {
- URL url = AAIService.class.getResource(AAIService.AAICLIENT_PROPERTIES);
- client = new AAIService(url);
- LOG.info("----------------------- aicAAIResourceTest.setUp -----------------------");
- }
-
- @AfterClass
- public static void tearDown() throws Exception {
- client = null;
- LOG.info("----------------------- AAIResourceTest.tearDown -----------------------");
- }
-
-
- @Test
- public void mainLoadTest ()
- {
- try
- {
- String currentDir = System.getProperty("user.dir");
- File dir = new File(currentDir);
- if(!dir.exists()) {
- System.exit(1);
- }
- dir = new File(dir, "src/main/resources");
- if(!dir.exists()) {
- System.exit(1);
- }
- // parse the document
- File file = new File(dir, "aai_schema_v11.xsd");
- if(!file.exists()) {
- assert(false);
- return;
- }
-
- DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
- Document doc = dBuilder.parse(file);
-
- Stack<String> stack = new Stack<String>();
- List<String> commands = new ArrayList<String>();
- listSubNodes("network", doc, stack, commands);
- listSubNodes("cloud-infrastructure", doc, stack, commands);
- listSubNodes("service-design-and-creation", doc, stack, commands);
- listSubNodes("license-management", doc, stack, commands);
- listSubNodes("business", doc, stack, commands);
-
- String[] requestDefinition = commands.toArray(new String[0]);
- LOG.info("\n----------------------------");
-
- executeTests(requestDefinition);
- }
- catch (Throwable e)
- {
- LOG.error("", e);
- }
- }
-
- @Test
- public void testFromFile() {
- String filename = "testCommands.txt";
- List<String> lines = new ArrayList<String>();
- Scanner scanner = null;
-
- try {
- File testFile = new File(filename);
- if(!testFile.exists())
- return;
- scanner = new Scanner(testFile);
- while (scanner.hasNextLine()) {
- lines.add(scanner.nextLine());
- }
- } catch (Exception exc) {
-
- } finally {
- if(scanner != null)
- scanner.close();
- }
-
- String[] requestDefinition = lines.toArray(new String[0]);
- executeTests(requestDefinition);
- }
-
-
- @Test
- public void test01AutoGeneratedRequest() {
-
- String[] requestDefinition = {
- "save|generic-vnf|generic-vnf.vnf-id:assign:value:adb28ac0-a260-4b7d-9ce5-adf15733c458",
- "update|generic-vnf|generic-vnf.vnf-id:assign:value:adb28ac0-a260-4b7d-9ce5-adf15733c458",
- "query|generic-vnf|generic-vnf.vnf-id:assign:value:adb28ac0-a260-4b7d-9ce5-adf15733c458",
- "delete|generic-vnf|generic-vnf.vnf-id:assign:value:adb28ac0-a260-4b7d-9ce5-adf15733c458"
- };
-
- executeTests(requestDefinition);
- }
-
- public void executeTests(String[] requestDefinition) {
-
- for(String line : requestDefinition){
- LOG.info("Executing: " + line);
-
- // parse request line resource | key structure
- String[] segments = line.split("\\|");
- String action = segments[0];
- String resource = segments[1];
- String[] tmpKeys = segments[2].split("&");
-// String[] keyStructure = tmpKey.;
- // options :assign:uuid:cache
- // :cached
- // :query:random
-
-
- String localId = null;
-
- List<String> keys = new ArrayList<String>();
- String keyLine = null;
-
- for(String instruction : tmpKeys) {
- String[] parts = instruction.split(":");
- String identifier = parts[0];
- String method = parts[2];
-
- if(identifier.startsWith(resource)) {
- localId = identifier;
- } else if(identifier.startsWith("l-interface") && "l2-bridge-bgf".equals(resource)) {
- localId = identifier;
- } else if(identifier.startsWith("l-interface") && "l2-bridge-sbg".equals(resource)) {
- localId = identifier;
- } else if("nodes-query".equals(resource)) {
- localId = identifier;
- }
-
- switch(parts[1]) {
- case "assign":
- String postProcesss = parts[3];
- keyLine = processAssign(identifier, method, postProcesss);
- if(keyLine != null && !keyLine.trim().isEmpty()) {
- keys.add(keyLine);
- }
- break;
- case "cached":
- keyLine = processCached(identifier, method);
- if(keyLine != null && !keyLine.trim().isEmpty()) {
- keys.add(keyLine);
- }
- break;
- }
-
- }
-
- List<String> x = Arrays.asList(localId.split("\\."));
- switch(action){
- case "save":
- testAutoGeneratedSaveRequest(resource, keys, x.get(x.size() - 1), cache.get(localId));
- break;
- case "update":
- testAutoGeneratedUpdateRequest(resource, keys, x.get(x.size() - 1), cache.get(localId));
- break;
-
- case "query":
- test03AutoGeneratedQueryRequest(resource, keys);
- break;
- case "delete":
- test03AutoGeneratedDeleteRequest(resource, keys);
- break;
- }
- }
-
- LOG.info("done");
- }
-
-
- public void testAutoGeneratedSaveRequest(String resource, List<String> requestKeys, String identifier, String idValue) {
- LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
-
- try
- {
- Map<String, String> nameValues = keyToHashMap(StringUtils.join(requestKeys, " AND "), new SvcLogicContext());
- AAIRequest request = AAIRequest.createRequest(resource, nameValues);
- Class<AAIDatum> resourceClass = (Class<AAIDatum>) (request==null ? GenericVnf.class : request.getModelClass());
-
- Map<String, String> data = new HashMap<String, String>();
-
- for(Field field : resourceClass.getDeclaredFields()) {
- String type = field.getType().getName();
- switch(type){
- case "bool":
- case "boolean":
- type = Boolean.class.getName();
- break;
- case "int":
- type = Integer.class.getName();
- break;
- case "long":
- type = Long.class.getName();
- break;
-
- }
- if(type.startsWith("java.lang.")){
- Annotation[] fieldAnnotations = field.getAnnotations();
- for(int i = 0; i < fieldAnnotations.length; i++) {
- Annotation a = fieldAnnotations[i];
- if(a instanceof JsonProperty){
- JsonProperty pa = (JsonProperty)a;
- String name = pa.value();
- String value;
- switch(type) {
- case "java.lang.Integer":
- case "java.lang.Long":
- value = RandomStringUtils.random(6, false, true);
- break;
- case "java.lang.Boolean":
- value = "false";
- break;
- default:
- if(name.equals(identifier)) {
- value = idValue;
- } else {
- value = RandomStringUtils.random(10, true, false);
- }
- }
- data.put(name, value);
- } else
- if(a instanceof javax.xml.bind.annotation.XmlElement) {
- XmlElement xe = (XmlElement)a;
- String name = xe.name();
- if("model-version-id".equals(name)) {
- continue;
- }
- if("model-invariant-id".equals(name)) {
- continue;
- }
- if("link-type".equals(name)){
- data.put(name, "roadmTail");
- continue;
- }
- if("operational-status".equals(name)){
- data.put(name, "available");
- continue;
- }
- if(name.equals(identifier)) {
- data.put(name, idValue);
- continue;
- }
-
- String value;
- switch(type) {
- case "java.lang.Integer":
- case "java.lang.Long":
- value = RandomStringUtils.random(6, false, true);
- break;
- case "java.lang.Boolean":
- value = "false";
- break;
- default:
- if(name.equals(identifier)) {
- value = idValue;
- } else {
- value = RandomStringUtils.random(10, true, false);
- }
- }
- data.put(name, value);
- }
- }
- }
- }
-
- SvcLogicContext ctx = new SvcLogicContext();
-
- data.remove("resource-version");
-
- QueryStatus resp = null;
-
- //(String resource, boolean force, boolean localOnly, String key, Map<String, String> parms, String prefix, SvcLogicContext ctx)
- resp = client.save(resource, false, false, StringUtils.join(requestKeys, " AND "), data, "aaidata", ctx);
- if(resp == QueryStatus.SUCCESS) {
- LOG.info(String.format("Save %s successfull", resource));
- } else {
- LOG.info(String.format("Save %s failed due to : %s", resource, ctx.getAttribute("aaidata.error.message")));
- }
- }
- catch (Throwable e)
- {
- LOG.error("Caught exception", e);
- fail("Caught exception");
- }
- }
-
- public void test03AutoGeneratedQueryRequest(String resource, List<String> requestKeys) {
- LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
-
- SvcLogicContext ctx = new SvcLogicContext();
- try
- {
-
- QueryStatus response = null;
-
- response = client.query(resource, false, null, StringUtils.join(requestKeys, " AND "), "aaiTest", null, ctx);
- if(response == QueryStatus.SUCCESS) {
- LOG.info(String.format("Query %s successfull", resource));
- Set<String> tokens = ctx.getAttributeKeySet();
- Map<String, String> reponseData = new HashMap<String, String>();
-
- String responsePrefix = String.format("%s", "aaiTest");
-
- for(String token : tokens) {
- if(token.startsWith(responsePrefix)){
- reponseData.put(token, ctx.getAttribute(token));
- } else {
- LOG.info(String.format("%s = ", token, ctx.getAttribute(token)));
- }
- }
-
- LOG.info("AAIResponse: " + response.toString());
- assertTrue("AAIRequest:"+resource, reponseData.size() > 0);
- } else {
- LOG.info(String.format("Query %s failed due to : %s", resource, ctx.getAttribute("aaidata.error.message")));
- assert(false);
- }
- }
- catch (Throwable e)
- {
- LOG.error("Caught exception", e);
- }
- }
-
-
- public void test03AutoGeneratedDeleteRequest(String resource, List<String> requestKeys) {
- LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
-
- try
- {
- SvcLogicContext ctx = new SvcLogicContext();
-
- QueryStatus response = null;
-
- response = client.delete(resource, StringUtils.join(requestKeys, " AND "), ctx);
- if(response == QueryStatus.SUCCESS) {
- LOG.info(String.format("Delete %s successfull", resource));
- } else {
- LOG.info(String.format("Delete %s failed due to : %s", resource, ctx.getAttribute("aaiDelete.error.message")));
- }
- }
- catch (Throwable e)
- {
- LOG.error("Caught exception", e);
- fail("Caught exception");
- }
- }
-
- public void testAutoGeneratedUpdateRequest(String resource, List<String> requestKeys, String identifier, String idValue) {
- LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
-
- try
- {
- Map<String, String> nameValues = keyToHashMap(StringUtils.join(requestKeys, " AND "), new SvcLogicContext());
- AAIRequest request = AAIRequest.createRequest(resource, nameValues);
- Class<AAIDatum> resourceClass = (Class<AAIDatum>) (request==null ? GenericVnf.class : request.getModelClass());
-
- Map<String, String> data = new HashMap<String, String>();
-
- boolean skipFirst = true;
- boolean breakLoop = false;
- for(Field field : resourceClass.getDeclaredFields()) {
- if(skipFirst){
- skipFirst = false;
- continue;
- }
- if(breakLoop){
- break;
- }
- String type = field.getType().getName();
- if(type.startsWith("java.lang.")){
- Annotation[] fieldAnnotations = field.getAnnotations();
- for(int i = 0; i < fieldAnnotations.length; i++) {
- Annotation a = fieldAnnotations[i];
- if(a instanceof JsonProperty){
- JsonProperty pa = (JsonProperty)a;
- String name = pa.value();
- String value;
- switch(type) {
- case "java.lang.Integer":
- case "java.lang.Long":
- value = RandomStringUtils.random(6, false, true);
- break;
- case "java.lang.Boolean":
- value = "false";
- break;
- default:
- if(name.equals(identifier)) {
- value = idValue;
- } else {
- value = RandomStringUtils.random(10, true, false);
- }
- }
- data.put(name, value);
- breakLoop = true;
- } else
- if(a instanceof javax.xml.bind.annotation.XmlElement) {
- XmlElement xe = (XmlElement)a;
- String name = xe.name();
- if("link-type".equals(name)){
- data.put(name, "roadmTail");
- continue;
- }
- if("operational-status".equals(name)){
- data.put(name, "available");
- continue;
- }
- String value;
- switch(type) {
- case "java.lang.Integer":
- case "java.lang.Long":
- value = RandomStringUtils.random(6, false, true);
- break;
- case "java.lang.Boolean":
- value = "false";
- break;
- default:
- if(name.equals(identifier)) {
- value = idValue;
- } else {
- value = RandomStringUtils.random(10, true, false);
- }
- }
- data.put(name, value);
- breakLoop = true;
- }
- }
- }
- }
-
- SvcLogicContext ctx = new SvcLogicContext();
-
- data.remove("resource-version");
-
- QueryStatus resp = null;
-
- //client.update("ipsec-configuration", "ipsec-configuration.ipsec-configuration-id = 'testConfigurationId01'", data, "aaiTest", ctx);
- resp = client.update(resource, StringUtils.join(requestKeys, " AND "), data, "aaidata", ctx);
- if(resp == QueryStatus.SUCCESS) {
- LOG.info(String.format("Update %s successfull", resource));
- } else {
- LOG.info(String.format("Update %s failed due to : %s", resource, ctx.getAttribute("aaidata.error.message")));
- }
-
- }
- catch (Throwable e)
- {
- LOG.error("Caught exception", e);
- fail("Caught exception");
- }
- }
-
- static ArrayList<Method> findSetters(Class<?> c) {
- ArrayList<Method> list = new ArrayList<Method>();
- Method[] methods = c.getDeclaredMethods();
- for (Method method : methods)
- if (isGetter(method))
- list.add(method);
- return list;
- }
-
-
- public static boolean isGetter(Method method) {
- if (Modifier.isPublic(method.getModifiers()) &&
- method.getParameterTypes().length == 0) {
- if (method.getName().matches("^get[A-Z].*") &&
- !method.getReturnType().equals(void.class))
- return true;
- if (method.getName().matches("^is[A-Z].*") &&
- method.getReturnType().equals(boolean.class))
- return true;
- }
- return false;
- }
-
- public static boolean isSetter(Method method) {
- return Modifier.isPublic(method.getModifiers()) &&
- method.getReturnType().equals(void.class) &&
- method.getParameterTypes().length == 1 &&
- method.getName().matches("^set[A-Z].*");
- }
-
- private String processAssign(String identifier, String method, String postProcess) {
- String value = null;
- if("uuid".equals(method)) {
- value = UUID.randomUUID().toString();
- }
-
- if("cache".equals(postProcess)) {
- cache.put(identifier, value);
- }
-
- if("value".equals(method)) {
- cache.put(identifier, postProcess);
- value = postProcess;
- }
-
- String key = String.format("%s = '%s'", identifier, value);
- return key;
- }
-
- private String processCached(String identifier, String method) {
- String value = cache.get(identifier);
-
- String key = String.format("%s = '%s'", identifier, value);
- return key;
- }
-
- protected HashMap<String,String> keyToHashMap(String key, SvcLogicContext ctx) {
- if (key == null) {
- return (null);
- }
-
- LOG.debug("Converting key [" + key + "] to where clause");
-
- if (key.startsWith("'") && key.endsWith("'")) {
- key = key.substring(1, key.length() - 1);
-
- LOG.debug("Stripped outer single quotes - key is now [" + key + "]");
- }
-
- String[] keyTerms = key.split("\\s+");
-
- String term1 = null;
- String op = null;
- String term2 = null;
- HashMap<String, String> results = new HashMap<String, String>();
-
- for (int i = 0; i < keyTerms.length; i++) {
- if (term1 == null) {
- if ("and".equalsIgnoreCase(keyTerms[i])
- || "or".equalsIgnoreCase(keyTerms[i])) {
- // Skip over ADD/OR
- } else {
- term1 = resolveTerm(keyTerms[i], ctx);
- }
- } else if (op == null) {
- if ("==".equals(keyTerms[i])) {
- op = "=";
- } else {
- op = keyTerms[i];
- }
- } else {
- term2 = resolveTerm(keyTerms[i], ctx);
- term2 = term2.trim().replace("'", "").replace("$", "").replace("'", "");
- results.put(term1, term2);
-
- term1 = null;
- op = null;
- term2 = null;
- }
- }
-
- return (results);
- }
-
- private String resolveTerm(String term, SvcLogicContext ctx) {
- if (term == null) {
- return (null);
- }
-
- LOG.debug("resolveTerm: term is " + term);
-
- if (term.startsWith("$") && (ctx != null)) {
- // Resolve any index variables.
-
- return ("'" + resolveCtxVariable(term.substring(1), ctx) + "'");
- } else if (term.startsWith("'") || term.startsWith("\"")) {
- return (term);
- } else {
- return (term.replaceAll("-", "_"));
-
- }
-
- }
-
- private String resolveCtxVariable(String ctxVarName, SvcLogicContext ctx) {
-
- if (ctxVarName.indexOf('[') == -1) {
- // Ctx variable contains no arrays
- return (ctx.getAttribute(ctxVarName));
- }
-
- // Resolve any array references
- StringBuffer sbuff = new StringBuffer();
- String[] ctxVarParts = ctxVarName.split("\\[");
- sbuff.append(ctxVarParts[0]);
- for (int i = 1; i < ctxVarParts.length; i++) {
- if (ctxVarParts[i].startsWith("$")) {
- int endBracketLoc = ctxVarParts[i].indexOf("]");
- if (endBracketLoc == -1) {
- // Missing end bracket ... give up parsing
- LOG.warn("Variable reference " + ctxVarName
- + " seems to be missing a ']'");
- return (ctx.getAttribute(ctxVarName));
- }
-
- String idxVarName = ctxVarParts[i].substring(1, endBracketLoc);
- String remainder = ctxVarParts[i].substring(endBracketLoc);
-
- sbuff.append("[");
- sbuff.append(ctx.getAttribute(idxVarName));
- sbuff.append(remainder);
-
- } else {
- // Index is not a variable reference
- sbuff.append("[");
- sbuff.append(ctxVarParts[i]);
- }
- }
-
- return (ctx.getAttribute(sbuff.toString()));
- }
-
-// @Test
- public void test90QueryTenantRequest()
- {
- LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
-
- URL url;
-
- try {
- url = client.requestVserverURLNodeQuery("bpsx0001vm001bps001");
- url = new URL("https://mtanjv9aaas03.aic.cip.att.com:8443/aai/v4/cloud-infrastructure/tenants/tenant/6b012c07bdf1427190ae58f794a86344/vservers/vserver/5acfe828-82e9-swgk092815-13-4d2c-85bb-9c2c1fafcce6");
- client.getTenantIdFromVserverUrl(url);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- @Test
- public void R1702NamedQueryRequest()
- {
- LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
- try
- {
- SvcLogicContext ctx = new SvcLogicContext();
- URL resource = this.getClass().getResource("/json/nquery2.json");
-
- LOG.info("Resource is " + resource.getFile());
- File requestFile = new File(resource.getFile());
- if(!requestFile.exists()) {
- fail("Test file does not exist");
- }
- ObjectMapper mapper = AAIService.getObjectMapper();
- NamedQueryData request = mapper.readValue(requestFile, NamedQueryData.class);
- Map<String, Object> map = mapper.convertValue(request, Map.class);
-// AAIDeclartations.class.cast(client).writeMap(map, String.format("%s.%s", "aaiTmp", "inventory-response-items"), ctx);
-
-
- Map<String, String> data = new HashMap<String, String>();
- ctx.setAttribute("namedQueryData.instance-filters.instance-filter[0].l3-network.network-role", "example-network-role-val-432223");
- ctx.setAttribute("namedQueryData.instance-filters.instance-filter_length", "1");
- QueryStatus resp = client.query("named-query", false, null, "named-query-uuid = '4f448e43-339f-4c1c-85f6-896c444e25ca' AND prefix = 'namedQueryData' ", "zdzich", null, ctx);
-
- LOG.info("AAIResponse: " + resp.toString());
- }
- catch (Throwable e)
- {
- assert(true);
- }
- }
-
-
- static class MySchemaOutputResolver extends SchemaOutputResolver {
-
- public Result createOutput(String namespaceURI, String suggestedFileName) throws IOException {
- File file = new File(suggestedFileName);
- StreamResult result = new StreamResult(file);
- result.setSystemId(file.getAbsolutePath());
- return result;
- }
-
- }
-
- private static void listSubNodes(String parent, Document doc, Stack<String> stack, List<String> commands) throws Exception {
+ static {
+ System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "INFO");
+ System.setProperty(org.slf4j.impl.SimpleLogger.LOG_FILE_KEY, String.format("AutoGeneratedRegressionTest-%d.txt", System.currentTimeMillis()));
+ }
+ private static final Logger LOG = LoggerFactory.getLogger(AutoGeneratedRegressionTest.class);
+
+
+ protected static AAIClient client;
+
+ protected Map<String, String> cache = new HashMap<String, String>();
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ URL url = AAIService.class.getResource(AAIService.AAICLIENT_PROPERTIES);
+ client = new AAIService(url);
+ LOG.info("----------------------- aicAAIResourceTest.setUp -----------------------");
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ client = null;
+ LOG.info("----------------------- AAIResourceTest.tearDown -----------------------");
+ }
+
+
+ @Test
+ public void mainLoadTest ()
+ {
+ try
+ {
+ String currentDir = System.getProperty("user.dir");
+ File dir = new File(currentDir);
+ if(!dir.exists()) {
+ System.exit(1);
+ }
+ dir = new File(dir, "src/main/resources");
+ if(!dir.exists()) {
+ System.exit(1);
+ }
+ // parse the document
+ File file = new File(dir, "aai_schema_v11.xsd");
+ if(!file.exists()) {
+ assert(false);
+ return;
+ }
+
+ DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+ Document doc = dBuilder.parse(file);
+
+ Stack<String> stack = new Stack<String>();
+ List<String> commands = new ArrayList<String>();
+ listSubNodes("network", doc, stack, commands);
+ listSubNodes("cloud-infrastructure", doc, stack, commands);
+ listSubNodes("service-design-and-creation", doc, stack, commands);
+ listSubNodes("license-management", doc, stack, commands);
+ listSubNodes("business", doc, stack, commands);
+
+ String[] requestDefinition = commands.toArray(new String[0]);
+ LOG.info("\n----------------------------");
+
+ executeTests(requestDefinition);
+ }
+ catch (Throwable e)
+ {
+ LOG.error("", e);
+ }
+ }
+
+ @Test
+ public void testFromFile() {
+ String filename = "testCommands.txt";
+ List<String> lines = new ArrayList<String>();
+ Scanner scanner = null;
+
+ try {
+ File testFile = new File(filename);
+ if(!testFile.exists())
+ return;
+ scanner = new Scanner(testFile);
+ while (scanner.hasNextLine()) {
+ lines.add(scanner.nextLine());
+ }
+ } catch (Exception exc) {
+
+ } finally {
+ if(scanner != null)
+ scanner.close();
+ }
+
+ String[] requestDefinition = lines.toArray(new String[0]);
+ executeTests(requestDefinition);
+ }
+
+
+ @Test
+ public void test01AutoGeneratedRequest() {
+
+ String[] requestDefinition = {
+ "save|generic-vnf|generic-vnf.vnf-id:assign:value:adb28ac0-a260-4b7d-9ce5-adf15733c458",
+ "update|generic-vnf|generic-vnf.vnf-id:assign:value:adb28ac0-a260-4b7d-9ce5-adf15733c458",
+ "query|generic-vnf|generic-vnf.vnf-id:assign:value:adb28ac0-a260-4b7d-9ce5-adf15733c458",
+ "delete|generic-vnf|generic-vnf.vnf-id:assign:value:adb28ac0-a260-4b7d-9ce5-adf15733c458"
+ };
+
+ executeTests(requestDefinition);
+ }
+
+ public void executeTests(String[] requestDefinition) {
+
+ for(String line : requestDefinition){
+ LOG.info("Executing: " + line);
+
+ // parse request line resource | key structure
+ String[] segments = line.split("\\|");
+ String action = segments[0];
+ String resource = segments[1];
+ String[] tmpKeys = segments[2].split("&");
+ // String array keyStructure can be tmpKey.
+ // options :assign:uuid:cache
+ // :cached
+ // :query:random
+
+
+ String localId = null;
+
+ List<String> keys = new ArrayList<String>();
+ String keyLine = null;
+
+ for(String instruction : tmpKeys) {
+ String[] parts = instruction.split(":");
+ String identifier = parts[0];
+ String method = parts[2];
+
+ if(identifier.startsWith(resource)) {
+ localId = identifier;
+ } else if(identifier.startsWith("l-interface") && "l2-bridge-bgf".equals(resource)) {
+ localId = identifier;
+ } else if(identifier.startsWith("l-interface") && "l2-bridge-sbg".equals(resource)) {
+ localId = identifier;
+ } else if("nodes-query".equals(resource)) {
+ localId = identifier;
+ }
+
+ switch(parts[1]) {
+ case "assign":
+ String postProcesss = parts[3];
+ keyLine = processAssign(identifier, method, postProcesss);
+ if(keyLine != null && !keyLine.trim().isEmpty()) {
+ keys.add(keyLine);
+ }
+ break;
+ case "cached":
+ keyLine = processCached(identifier, method);
+ if(keyLine != null && !keyLine.trim().isEmpty()) {
+ keys.add(keyLine);
+ }
+ break;
+ }
+
+ }
+
+ List<String> x = Arrays.asList(localId.split("\\."));
+ switch(action){
+ case "save":
+ testAutoGeneratedSaveRequest(resource, keys, x.get(x.size() - 1), cache.get(localId));
+ break;
+ case "update":
+ testAutoGeneratedUpdateRequest(resource, keys, x.get(x.size() - 1), cache.get(localId));
+ break;
+
+ case "query":
+ test03AutoGeneratedQueryRequest(resource, keys);
+ break;
+ case "delete":
+ test03AutoGeneratedDeleteRequest(resource, keys);
+ break;
+ }
+ }
+
+ LOG.info("done");
+ }
+
+
+ public void testAutoGeneratedSaveRequest(String resource, List<String> requestKeys, String identifier, String idValue) {
+ LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
+
+ try
+ {
+ Map<String, String> nameValues = keyToHashMap(StringUtils.join(requestKeys, " AND "), new SvcLogicContext());
+ AAIRequest request = AAIRequest.createRequest(resource, nameValues);
+ Class<AAIDatum> resourceClass = (Class<AAIDatum>) (request==null ? GenericVnf.class : request.getModelClass());
+
+ Map<String, String> data = new HashMap<String, String>();
+
+ for(Field field : resourceClass.getDeclaredFields()) {
+ String type = field.getType().getName();
+ switch(type){
+ case "bool":
+ case "boolean":
+ type = Boolean.class.getName();
+ break;
+ case "int":
+ type = Integer.class.getName();
+ break;
+ case "long":
+ type = Long.class.getName();
+ break;
+
+ }
+ if(type.startsWith("java.lang.")){
+ Annotation[] fieldAnnotations = field.getAnnotations();
+ for(int i = 0; i < fieldAnnotations.length; i++) {
+ Annotation a = fieldAnnotations[i];
+ if(a instanceof JsonProperty){
+ JsonProperty pa = (JsonProperty)a;
+ String name = pa.value();
+ String value;
+ switch(type) {
+ case "java.lang.Integer":
+ case "java.lang.Long":
+ value = RandomStringUtils.random(6, false, true);
+ break;
+ case "java.lang.Boolean":
+ value = "false";
+ break;
+ default:
+ if(name.equals(identifier)) {
+ value = idValue;
+ } else {
+ value = RandomStringUtils.random(10, true, false);
+ }
+ }
+ data.put(name, value);
+ } else
+ if(a instanceof javax.xml.bind.annotation.XmlElement) {
+ XmlElement xe = (XmlElement)a;
+ String name = xe.name();
+ if("model-version-id".equals(name)) {
+ continue;
+ }
+ if("model-invariant-id".equals(name)) {
+ continue;
+ }
+ if("link-type".equals(name)){
+ data.put(name, "roadmTail");
+ continue;
+ }
+ if("operational-status".equals(name)){
+ data.put(name, "available");
+ continue;
+ }
+ if(name.equals(identifier)) {
+ data.put(name, idValue);
+ continue;
+ }
+
+ String value;
+ switch(type) {
+ case "java.lang.Integer":
+ case "java.lang.Long":
+ value = RandomStringUtils.random(6, false, true);
+ break;
+ case "java.lang.Boolean":
+ value = "false";
+ break;
+ default:
+ if(name.equals(identifier)) {
+ value = idValue;
+ } else {
+ value = RandomStringUtils.random(10, true, false);
+ }
+ }
+ data.put(name, value);
+ }
+ }
+ }
+ }
+
+ SvcLogicContext ctx = new SvcLogicContext();
+
+ data.remove("resource-version");
+
+ QueryStatus resp = null;
+
+ //(String resource, boolean force, boolean localOnly, String key, Map<String, String> parms, String prefix, SvcLogicContext ctx)
+ resp = client.save(resource, false, false, StringUtils.join(requestKeys, " AND "), data, "aaidata", ctx);
+ if(resp == QueryStatus.SUCCESS) {
+ LOG.info(String.format("Save %s successfull", resource));
+ } else {
+ LOG.info(String.format("Save %s failed due to : %s", resource, ctx.getAttribute("aaidata.error.message")));
+ }
+ }
+ catch (Throwable e)
+ {
+ LOG.error("Caught exception", e);
+ fail("Caught exception");
+ }
+ }
+
+ public void test03AutoGeneratedQueryRequest(String resource, List<String> requestKeys) {
+ LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ try
+ {
+
+ QueryStatus response = null;
+
+ response = client.query(resource, false, null, StringUtils.join(requestKeys, " AND "), "aaiTest", null, ctx);
+ if(response == QueryStatus.SUCCESS) {
+ LOG.info(String.format("Query %s successfull", resource));
+ Set<String> tokens = ctx.getAttributeKeySet();
+ Map<String, String> reponseData = new HashMap<String, String>();
+
+ String responsePrefix = String.format("%s", "aaiTest");
+
+ for(String token : tokens) {
+ if(token.startsWith(responsePrefix)){
+ reponseData.put(token, ctx.getAttribute(token));
+ } else {
+ LOG.info(String.format("%s = ", token, ctx.getAttribute(token)));
+ }
+ }
+
+ LOG.info("AAIResponse: " + response.toString());
+ assertTrue("AAIRequest:"+resource, reponseData.size() > 0);
+ } else {
+ LOG.info(String.format("Query %s failed due to : %s", resource, ctx.getAttribute("aaidata.error.message")));
+ assert(false);
+ }
+ }
+ catch (Throwable e)
+ {
+ LOG.error("Caught exception", e);
+ }
+ }
+
+
+ public void test03AutoGeneratedDeleteRequest(String resource, List<String> requestKeys) {
+ LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
+
+ try
+ {
+ SvcLogicContext ctx = new SvcLogicContext();
+
+ QueryStatus response = null;
+
+ response = client.delete(resource, StringUtils.join(requestKeys, " AND "), ctx);
+ if(response == QueryStatus.SUCCESS) {
+ LOG.info(String.format("Delete %s successfull", resource));
+ } else {
+ LOG.info(String.format("Delete %s failed due to : %s", resource, ctx.getAttribute("aaiDelete.error.message")));
+ }
+ }
+ catch (Throwable e)
+ {
+ LOG.error("Caught exception", e);
+ fail("Caught exception");
+ }
+ }
+
+ public void testAutoGeneratedUpdateRequest(String resource, List<String> requestKeys, String identifier, String idValue) {
+ LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
+
+ try
+ {
+ Map<String, String> nameValues = keyToHashMap(StringUtils.join(requestKeys, " AND "), new SvcLogicContext());
+ AAIRequest request = AAIRequest.createRequest(resource, nameValues);
+ Class<AAIDatum> resourceClass = (Class<AAIDatum>) (request==null ? GenericVnf.class : request.getModelClass());
+
+ Map<String, String> data = new HashMap<String, String>();
+
+ boolean skipFirst = true;
+ boolean breakLoop = false;
+ for(Field field : resourceClass.getDeclaredFields()) {
+ if(skipFirst){
+ skipFirst = false;
+ continue;
+ }
+ if(breakLoop){
+ break;
+ }
+ String type = field.getType().getName();
+ if(type.startsWith("java.lang.")){
+ Annotation[] fieldAnnotations = field.getAnnotations();
+ for(int i = 0; i < fieldAnnotations.length; i++) {
+ Annotation a = fieldAnnotations[i];
+ if(a instanceof JsonProperty){
+ JsonProperty pa = (JsonProperty)a;
+ String name = pa.value();
+ String value;
+ switch(type) {
+ case "java.lang.Integer":
+ case "java.lang.Long":
+ value = RandomStringUtils.random(6, false, true);
+ break;
+ case "java.lang.Boolean":
+ value = "false";
+ break;
+ default:
+ if(name.equals(identifier)) {
+ value = idValue;
+ } else {
+ value = RandomStringUtils.random(10, true, false);
+ }
+ }
+ data.put(name, value);
+ breakLoop = true;
+ } else
+ if(a instanceof javax.xml.bind.annotation.XmlElement) {
+ XmlElement xe = (XmlElement)a;
+ String name = xe.name();
+ if("link-type".equals(name)){
+ data.put(name, "roadmTail");
+ continue;
+ }
+ if("operational-status".equals(name)){
+ data.put(name, "available");
+ continue;
+ }
+ String value;
+ switch(type) {
+ case "java.lang.Integer":
+ case "java.lang.Long":
+ value = RandomStringUtils.random(6, false, true);
+ break;
+ case "java.lang.Boolean":
+ value = "false";
+ break;
+ default:
+ if(name.equals(identifier)) {
+ value = idValue;
+ } else {
+ value = RandomStringUtils.random(10, true, false);
+ }
+ }
+ data.put(name, value);
+ breakLoop = true;
+ }
+ }
+ }
+ }
+
+ SvcLogicContext ctx = new SvcLogicContext();
+
+ data.remove("resource-version");
+
+ QueryStatus resp = null;
+
+ //client.update("ipsec-configuration", "ipsec-configuration.ipsec-configuration-id = 'testConfigurationId01'", data, "aaiTest", ctx);
+ resp = client.update(resource, StringUtils.join(requestKeys, " AND "), data, "aaidata", ctx);
+ if(resp == QueryStatus.SUCCESS) {
+ LOG.info(String.format("Update %s successfull", resource));
+ } else {
+ LOG.info(String.format("Update %s failed due to : %s", resource, ctx.getAttribute("aaidata.error.message")));
+ }
+
+ }
+ catch (Throwable e)
+ {
+ LOG.error("Caught exception", e);
+ fail("Caught exception");
+ }
+ }
+
+ static ArrayList<Method> findSetters(Class<?> c) {
+ ArrayList<Method> list = new ArrayList<Method>();
+ Method[] methods = c.getDeclaredMethods();
+ for (Method method : methods)
+ if (isGetter(method))
+ list.add(method);
+ return list;
+ }
+
+
+ public static boolean isGetter(Method method) {
+ if (Modifier.isPublic(method.getModifiers()) &&
+ method.getParameterTypes().length == 0) {
+ if (method.getName().matches("^get[A-Z].*") &&
+ !method.getReturnType().equals(void.class))
+ return true;
+ if (method.getName().matches("^is[A-Z].*") &&
+ method.getReturnType().equals(boolean.class))
+ return true;
+ }
+ return false;
+ }
+
+ public static boolean isSetter(Method method) {
+ return Modifier.isPublic(method.getModifiers()) &&
+ method.getReturnType().equals(void.class) &&
+ method.getParameterTypes().length == 1 &&
+ method.getName().matches("^set[A-Z].*");
+ }
+
+ private String processAssign(String identifier, String method, String postProcess) {
+ String value = null;
+ if("uuid".equals(method)) {
+ value = UUID.randomUUID().toString();
+ }
+
+ if("cache".equals(postProcess)) {
+ cache.put(identifier, value);
+ }
+
+ if("value".equals(method)) {
+ cache.put(identifier, postProcess);
+ value = postProcess;
+ }
+
+ String key = String.format("%s = '%s'", identifier, value);
+ return key;
+ }
+
+ private String processCached(String identifier, String method) {
+ String value = cache.get(identifier);
+
+ String key = String.format("%s = '%s'", identifier, value);
+ return key;
+ }
+
+ protected HashMap<String,String> keyToHashMap(String key, SvcLogicContext ctx) {
+ if (key == null) {
+ return (null);
+ }
+
+ LOG.debug("Converting key [" + key + "] to where clause");
+
+ if (key.startsWith("'") && key.endsWith("'")) {
+ key = key.substring(1, key.length() - 1);
+
+ LOG.debug("Stripped outer single quotes - key is now [" + key + "]");
+ }
+
+ String[] keyTerms = key.split("\\s+");
+
+ String term1 = null;
+ String op = null;
+ String term2 = null;
+ HashMap<String, String> results = new HashMap<String, String>();
+
+ for (int i = 0; i < keyTerms.length; i++) {
+ if (term1 == null) {
+ if ("and".equalsIgnoreCase(keyTerms[i])
+ || "or".equalsIgnoreCase(keyTerms[i])) {
+ // Skip over ADD/OR
+ } else {
+ term1 = resolveTerm(keyTerms[i], ctx);
+ }
+ } else if (op == null) {
+ if ("==".equals(keyTerms[i])) {
+ op = "=";
+ } else {
+ op = keyTerms[i];
+ }
+ } else {
+ term2 = resolveTerm(keyTerms[i], ctx);
+ term2 = term2.trim().replace("'", "").replace("$", "").replace("'", "");
+ results.put(term1, term2);
+
+ term1 = null;
+ op = null;
+ term2 = null;
+ }
+ }
+
+ return (results);
+ }
+
+ private String resolveTerm(String term, SvcLogicContext ctx) {
+ if (term == null) {
+ return (null);
+ }
+
+ LOG.debug("resolveTerm: term is " + term);
+
+ if (term.startsWith("$") && (ctx != null)) {
+ // Resolve any index variables.
+
+ return ("'" + resolveCtxVariable(term.substring(1), ctx) + "'");
+ } else if (term.startsWith("'") || term.startsWith("\"")) {
+ return (term);
+ } else {
+ return (term.replaceAll("-", "_"));
+
+ }
+
+ }
+
+ private String resolveCtxVariable(String ctxVarName, SvcLogicContext ctx) {
+
+ if (ctxVarName.indexOf('[') == -1) {
+ // Ctx variable contains no arrays
+ return (ctx.getAttribute(ctxVarName));
+ }
+
+ // Resolve any array references
+ StringBuffer sbuff = new StringBuffer();
+ String[] ctxVarParts = ctxVarName.split("\\[");
+ sbuff.append(ctxVarParts[0]);
+ for (int i = 1; i < ctxVarParts.length; i++) {
+ if (ctxVarParts[i].startsWith("$")) {
+ int endBracketLoc = ctxVarParts[i].indexOf("]");
+ if (endBracketLoc == -1) {
+ // Missing end bracket ... give up parsing
+ LOG.warn("Variable reference " + ctxVarName
+ + " seems to be missing a ']'");
+ return (ctx.getAttribute(ctxVarName));
+ }
+
+ String idxVarName = ctxVarParts[i].substring(1, endBracketLoc);
+ String remainder = ctxVarParts[i].substring(endBracketLoc);
+
+ sbuff.append("[");
+ sbuff.append(ctx.getAttribute(idxVarName));
+ sbuff.append(remainder);
+
+ } else {
+ // Index is not a variable reference
+ sbuff.append("[");
+ sbuff.append(ctxVarParts[i]);
+ }
+ }
+
+ return (ctx.getAttribute(sbuff.toString()));
+ }
+
+// @Test
+ public void test90QueryTenantRequest()
+ {
+ LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
+
+ URL url;
+
+ try {
+ url = client.requestVserverURLNodeQuery("bpsx0001vm001bps001");
+ url = new URL("https://mtanjv9aaas03.aic.cip.att.com:8443/aai/v4/cloud-infrastructure/tenants/tenant/6b012c07bdf1427190ae58f794a86344/vservers/vserver/5acfe828-82e9-swgk092815-13-4d2c-85bb-9c2c1fafcce6");
+ client.getTenantIdFromVserverUrl(url);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void R1702NamedQueryRequest()
+ {
+ LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
+ try
+ {
+ SvcLogicContext ctx = new SvcLogicContext();
+ URL resource = this.getClass().getResource("/json/nquery2.json");
+
+ LOG.info("Resource is " + resource.getFile());
+ File requestFile = new File(resource.getFile());
+ if(!requestFile.exists()) {
+ fail("Test file does not exist");
+ }
+ ObjectMapper mapper = AAIService.getObjectMapper();
+ NamedQueryData request = mapper.readValue(requestFile, NamedQueryData.class);
+ Map<String, Object> map = mapper.convertValue(request, Map.class);
+
+ ctx.setAttribute("namedQueryData.instance-filters.instance-filter[0].l3-network.network-role", "example-network-role-val-432223");
+ ctx.setAttribute("namedQueryData.instance-filters.instance-filter_length", "1");
+ QueryStatus resp = client.query("named-query", false, null, "named-query-uuid = '4f448e43-339f-4c1c-85f6-896c444e25ca' AND prefix = 'namedQueryData' ", "zdzich", null, ctx);
+
+ LOG.info("AAIResponse: " + resp.toString());
+ }
+ catch (Throwable e)
+ {
+ assert(true);
+ }
+ }
+
+
+ static class MySchemaOutputResolver extends SchemaOutputResolver {
+
+ public Result createOutput(String namespaceURI, String suggestedFileName) throws IOException {
+ File file = new File(suggestedFileName);
+ StreamResult result = new StreamResult(file);
+ result.setSystemId(file.getAbsolutePath());
+ return result;
+ }
+
+ }
+
+ private static void listSubNodes(String parent, Document doc, Stack<String> stack, List<String> commands) throws Exception {
XPathFactory xFactory = XPathFactory.newInstance();
XPath xPath = xFactory.newXPath();
String format = "/schema/element[@name='%s']/complexType/sequence/element[@ref]";
@@ -787,157 +782,157 @@ public class AutoGeneratedRegressionTest {
Node node = nl.item(index);
- if(!(node instanceof Element))
- continue;
-
- String classAlias = null;
-
- if(node.hasAttributes())
- {
- String nm = ((Element)node).getAttribute("ref");
- if(nm != null && !nm.isEmpty()) {
- String[] split = nm.split(":");
- classAlias = split[split.length - 1];
- if("relationship-list".equals(classAlias))
- continue;
- if("metadata".equals(classAlias))
- continue;
- if("classes-of-service".equals(classAlias)) {
- classAlias = "class-of-service";
- } else if("l3-interface-ipv4-address-list".equals(classAlias)) {
- ;
- } else if("l3-interface-ipv6-address-list".equals(classAlias)) {
- ;
- } else if("cvlan-tags".equals(classAlias)) {
- classAlias = "cvlan-tag-entry";
- } else if("network-policies".equals(classAlias)) {
- classAlias = "network-policy";
- } else if("complexes".equals(classAlias)) {
- classAlias = "complex";
- } else if("dvs-switches".equals(classAlias)) {
- classAlias = "dvs-switch";
- } else if("service-capabilities".equals(classAlias)) {
- classAlias = "service-capability";
- } else {
- classAlias = classAlias.substring(0, classAlias.length() -1);
- }
- AAIRequest request = AAIRequest.createRequest(classAlias, new HashMap<String, String>());
- if(request != null) {
- Class<?> clazz = request.getModelClass();
- Field[] fieldz = clazz.getDeclaredFields();
- Field field = fieldz[0];
- String fieldName = field.getName();
- XmlElement annotation = field.getAnnotation(XmlElement.class);
-
- Map<String, Object> map = AnnotationUtils.getAnnotationAttributes(annotation);
- String id = (String)map.get("name");
- if("##default".equals(id)) {
- id = fieldName;
- }
-
- if("cloud-region".equals(classAlias)) {
- String keystring = "cloud-region.cloud-owner:assign:value:att-aic&cloud-region.cloud-region-id:assign:value:AAIAIC25";
- stack.push(keystring);
- String[] array = stack.toArray(new String[0]);
- String key = StringUtils.join(array, "&");
-
- String query = String.format("query|%s|%s", classAlias, key);
- commands.add(query);
- listSubNodes(classAlias, doc, stack, commands);
- stack.pop();
- } else if("entitlement".equals(classAlias)) {
- String keystring = "entitlement.group-uuid:assign:value:"+UUID.randomUUID()+"&entitlement.resource-uuid:assign:value:"+UUID.randomUUID();
- stack.push(keystring);
- String[] array = stack.toArray(new String[0]);
- String key = StringUtils.join(array, "&");
-
- String query = String.format("query|%s|%s", classAlias, key);
- commands.add(query);
- listSubNodes(classAlias, doc, stack, commands);
- stack.pop();
- } else if("license".equals(classAlias)) {
- String keystring = "license.group-uuid:assign:value:"+UUID.randomUUID()+"&license.resource-uuid:assign:value:"+UUID.randomUUID();
- stack.push(keystring);
- String[] array = stack.toArray(new String[0]);
- String key = StringUtils.join(array, "&");
-
- String query = String.format("query|%s|%s", classAlias, key);
- commands.add(query);
- listSubNodes(classAlias, doc, stack, commands);
- stack.pop();
- } else if("route-target".equals(classAlias)) {
- String keystring = "route-target.global-route-target:assign:value:"+UUID.randomUUID()+"&route-target.route-target-role:assign:value:"+UUID.randomUUID();
- stack.push(keystring);
- String[] array = stack.toArray(new String[0]);
- String key = StringUtils.join(array, "&");
-
- String query = String.format("query|%s|%s", classAlias, key);
- commands.add(query);
- listSubNodes(classAlias, doc, stack, commands);
- stack.pop();
- } else if("service-capability".equals(classAlias)) {
- String keystring = "service-capability.service-type:assign:value:"+UUID.randomUUID()+"&service-capability.vnf-type:assign:value:"+UUID.randomUUID();
- stack.push(keystring);
- String[] array = stack.toArray(new String[0]);
- String key = StringUtils.join(array, "&");
-
- String query = String.format("query|%s|%s", classAlias, key);
- commands.add(query);
- listSubNodes(classAlias, doc, stack, commands);
- stack.pop();
- } else if("ctag-pool".equals(classAlias)) {
- String keystring = "ctag-pool.target-pe:assign:value:"+UUID.randomUUID()+"&ctag-pool.availability-zone-name:assign:value:"+UUID.randomUUID();
- stack.push(keystring);
- String[] array = stack.toArray(new String[0]);
- String key = StringUtils.join(array, "&");
-
- String query = String.format("query|%s|%s", classAlias, key);
- commands.add(query);
- listSubNodes(classAlias, doc, stack, commands);
- stack.pop();
- } else {
- String keystring = String.format("%s.%s:assign:value:%s", classAlias, id, UUID.randomUUID());
- stack.push(keystring);
- String[] array = stack.toArray(new String[0]);
- String key = StringUtils.join(array, "&");
-
- String save = String.format("save|%s|%s", classAlias, key);
- commands.add(save);
-
- String query = String.format("query|%s|%s", classAlias, key);
- commands.add(query);
-
- String update = String.format("update|%s|%s", classAlias, key);
- commands.add(update);
-
- if(!parent.equals(classAlias) && !containsCircular(classAlias, id, stack)) {
- listSubNodes(classAlias, doc, stack, commands);
- }
- String delete = String.format("delete|%s|%s", classAlias, key);
- commands.add(delete);
- stack.pop();
- }
- }
- }
- }
+ if(!(node instanceof Element))
+ continue;
+
+ String classAlias = null;
+
+ if(node.hasAttributes())
+ {
+ String nm = ((Element)node).getAttribute("ref");
+ if(nm != null && !nm.isEmpty()) {
+ String[] split = nm.split(":");
+ classAlias = split[split.length - 1];
+ if("relationship-list".equals(classAlias))
+ continue;
+ if("metadata".equals(classAlias))
+ continue;
+ if("classes-of-service".equals(classAlias)) {
+ classAlias = "class-of-service";
+ } else if("l3-interface-ipv4-address-list".equals(classAlias)) {
+ ;
+ } else if("l3-interface-ipv6-address-list".equals(classAlias)) {
+ ;
+ } else if("cvlan-tags".equals(classAlias)) {
+ classAlias = "cvlan-tag-entry";
+ } else if("network-policies".equals(classAlias)) {
+ classAlias = "network-policy";
+ } else if("complexes".equals(classAlias)) {
+ classAlias = "complex";
+ } else if("dvs-switches".equals(classAlias)) {
+ classAlias = "dvs-switch";
+ } else if("service-capabilities".equals(classAlias)) {
+ classAlias = "service-capability";
+ } else {
+ classAlias = classAlias.substring(0, classAlias.length() -1);
+ }
+ AAIRequest request = AAIRequest.createRequest(classAlias, new HashMap<String, String>());
+ if(request != null) {
+ Class<?> clazz = request.getModelClass();
+ Field[] fieldz = clazz.getDeclaredFields();
+ Field field = fieldz[0];
+ String fieldName = field.getName();
+ XmlElement annotation = field.getAnnotation(XmlElement.class);
+
+ Map<String, Object> map = AnnotationUtils.getAnnotationAttributes(annotation);
+ String id = (String)map.get("name");
+ if("##default".equals(id)) {
+ id = fieldName;
+ }
+
+ if("cloud-region".equals(classAlias)) {
+ String keystring = "cloud-region.cloud-owner:assign:value:att-aic&cloud-region.cloud-region-id:assign:value:AAIAIC25";
+ stack.push(keystring);
+ String[] array = stack.toArray(new String[0]);
+ String key = StringUtils.join(array, "&");
+
+ String query = String.format("query|%s|%s", classAlias, key);
+ commands.add(query);
+ listSubNodes(classAlias, doc, stack, commands);
+ stack.pop();
+ } else if("entitlement".equals(classAlias)) {
+ String keystring = "entitlement.group-uuid:assign:value:"+UUID.randomUUID()+"&entitlement.resource-uuid:assign:value:"+UUID.randomUUID();
+ stack.push(keystring);
+ String[] array = stack.toArray(new String[0]);
+ String key = StringUtils.join(array, "&");
+
+ String query = String.format("query|%s|%s", classAlias, key);
+ commands.add(query);
+ listSubNodes(classAlias, doc, stack, commands);
+ stack.pop();
+ } else if("license".equals(classAlias)) {
+ String keystring = "license.group-uuid:assign:value:"+UUID.randomUUID()+"&license.resource-uuid:assign:value:"+UUID.randomUUID();
+ stack.push(keystring);
+ String[] array = stack.toArray(new String[0]);
+ String key = StringUtils.join(array, "&");
+
+ String query = String.format("query|%s|%s", classAlias, key);
+ commands.add(query);
+ listSubNodes(classAlias, doc, stack, commands);
+ stack.pop();
+ } else if("route-target".equals(classAlias)) {
+ String keystring = "route-target.global-route-target:assign:value:"+UUID.randomUUID()+"&route-target.route-target-role:assign:value:"+UUID.randomUUID();
+ stack.push(keystring);
+ String[] array = stack.toArray(new String[0]);
+ String key = StringUtils.join(array, "&");
+
+ String query = String.format("query|%s|%s", classAlias, key);
+ commands.add(query);
+ listSubNodes(classAlias, doc, stack, commands);
+ stack.pop();
+ } else if("service-capability".equals(classAlias)) {
+ String keystring = "service-capability.service-type:assign:value:"+UUID.randomUUID()+"&service-capability.vnf-type:assign:value:"+UUID.randomUUID();
+ stack.push(keystring);
+ String[] array = stack.toArray(new String[0]);
+ String key = StringUtils.join(array, "&");
+
+ String query = String.format("query|%s|%s", classAlias, key);
+ commands.add(query);
+ listSubNodes(classAlias, doc, stack, commands);
+ stack.pop();
+ } else if("ctag-pool".equals(classAlias)) {
+ String keystring = "ctag-pool.target-pe:assign:value:"+UUID.randomUUID()+"&ctag-pool.availability-zone-name:assign:value:"+UUID.randomUUID();
+ stack.push(keystring);
+ String[] array = stack.toArray(new String[0]);
+ String key = StringUtils.join(array, "&");
+
+ String query = String.format("query|%s|%s", classAlias, key);
+ commands.add(query);
+ listSubNodes(classAlias, doc, stack, commands);
+ stack.pop();
+ } else {
+ String keystring = String.format("%s.%s:assign:value:%s", classAlias, id, UUID.randomUUID());
+ stack.push(keystring);
+ String[] array = stack.toArray(new String[0]);
+ String key = StringUtils.join(array, "&");
+
+ String save = String.format("save|%s|%s", classAlias, key);
+ commands.add(save);
+
+ String query = String.format("query|%s|%s", classAlias, key);
+ commands.add(query);
+
+ String update = String.format("update|%s|%s", classAlias, key);
+ commands.add(update);
+
+ if(!parent.equals(classAlias) && !containsCircular(classAlias, id, stack)) {
+ listSubNodes(classAlias, doc, stack, commands);
+ }
+ String delete = String.format("delete|%s|%s", classAlias, key);
+ commands.add(delete);
+ stack.pop();
+ }
+ }
+ }
+ }
}
- }
+ }
- public static boolean containsCircular(String classAlias, String id, Stack<String> stack) {
- String keystring = String.format("%s.%s", classAlias, id);
+ public static boolean containsCircular(String classAlias, String id, Stack<String> stack) {
+ String keystring = String.format("%s.%s", classAlias, id);
- Stack<String> localStack = new Stack<String>();
- localStack.addAll(stack);
+ Stack<String> localStack = new Stack<String>();
+ localStack.addAll(stack);
- localStack.pop();
+ localStack.pop();
- while(!localStack.isEmpty()) {
- String instruction = localStack.pop();
- if(instruction.contains(keystring)) {
- return true;
- }
- }
+ while(!localStack.isEmpty()) {
+ String instruction = localStack.pop();
+ if(instruction.contains(keystring)) {
+ return true;
+ }
+ }
- return false;
- }
+ return false;
+ }
}
diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/RequestPathTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/RequestPathTest.java
new file mode 100755
index 00000000..5ee35c64
--- /dev/null
+++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/RequestPathTest.java
@@ -0,0 +1,76 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 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.adaptors.aai;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class RequestPathTest {
+
+ private static final Logger LOG = LoggerFactory.getLogger(RequestPathTest.class);
+
+ protected static AAIClient client;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ URL url = AAIService.class.getResource(AAIService.AAICLIENT_PROPERTIES);
+ client = new AAIService(url);
+ LOG.info("\nTaicAAIResourceTest.setUp\n");
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ client = null;
+ LOG.info("----------------------- AAIResourceTest.tearDown -----------------------");
+ }
+
+ @Test
+ public void getRequestUrl() {
+ try {
+ Map<String, String> nameValues = new HashMap<String, String> ();
+ nameValues.put("generic-vnf.vnf-id","AABBCCDDEEFFGG0123");
+
+ AAIRequest request = AAIRequest.createRequest("service-instances", nameValues);
+ request.addRequestProperty("generic-vnf.vnf-id","AABBCCDDEEFFGG0123");
+
+ URL url = request.getRequestUrl("GET", null);
+ assertNotNull(url);
+ url.getPath();
+ LOG.info("Received response");
+ } catch(Exception exc) {
+ LOG.info("Caught exception", exc);
+ }
+ }
+}