aboutsummaryrefslogtreecommitdiffstats
path: root/ajsc-aai/src/main/java/org/openecomp/aai/testing
diff options
context:
space:
mode:
Diffstat (limited to 'ajsc-aai/src/main/java/org/openecomp/aai/testing')
-rw-r--r--ajsc-aai/src/main/java/org/openecomp/aai/testing/GenerateFitNesseTests.java134
-rw-r--r--ajsc-aai/src/main/java/org/openecomp/aai/testing/GenerationTest.java77
-rw-r--r--ajsc-aai/src/main/java/org/openecomp/aai/testing/InjectResourceVersion.java132
-rw-r--r--ajsc-aai/src/main/java/org/openecomp/aai/testing/LocateEndPoints.java579
-rw-r--r--ajsc-aai/src/main/java/org/openecomp/aai/testing/OXMTest.java63
-rw-r--r--ajsc-aai/src/main/java/org/openecomp/aai/testing/PopulateObject.java232
-rw-r--r--ajsc-aai/src/main/java/org/openecomp/aai/testing/TestDataGenerator.java66
-rw-r--r--ajsc-aai/src/main/java/org/openecomp/aai/testing/UpdateObject.java205
8 files changed, 1488 insertions, 0 deletions
diff --git a/ajsc-aai/src/main/java/org/openecomp/aai/testing/GenerateFitNesseTests.java b/ajsc-aai/src/main/java/org/openecomp/aai/testing/GenerateFitNesseTests.java
new file mode 100644
index 0000000..e32d7c2
--- /dev/null
+++ b/ajsc-aai/src/main/java/org/openecomp/aai/testing/GenerateFitNesseTests.java
@@ -0,0 +1,134 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.aai
+ * ================================================================================
+ * 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.openecomp.aai.testing;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.xml.bind.JAXBException;
+
+import org.apache.commons.io.FileUtils;
+import org.json.JSONException;
+import org.openecomp.aai.db.AAIProperties;
+import org.openecomp.aai.introspection.Version;
+import org.openecomp.aai.testsuitegeneration.TestSuite;
+
+public class GenerateFitNesseTests {
+
+ private static final String currentEndpointsLocation = "../../automated-testing/FitNesseRoot/AAI/1702/Endpoints/";
+ private static final String currentRelationshipsLocation = "../../automated-testing/FitNesseRoot/AAI/1702/Relationships/";
+ private static final String regressionEndpointsLocation = "../../automated-testing/FitNesseRoot/AAI/Regression/Endpoints/";
+ private static final String regressionRelationshipsLocation = "../../automated-testing/FitNesseRoot/AAI/Regression/Relationships/";
+
+ /**
+ * The main method.
+ *
+ * @param args the arguments
+ * @throws IllegalAccessException the illegal access exception
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws InvocationTargetException the invocation target exception
+ * @throws InstantiationException the instantiation exception
+ * @throws JSONException the JSON exception
+ * @throws NoSuchMethodException the no such method exception
+ * @throws SecurityException the security exception
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws ClassNotFoundException the class not found exception
+ * @throws NoSuchFieldException the no such field exception
+ * @throws JAXBException the JAXB exception
+ */
+ public static void main(String[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, JSONException, NoSuchMethodException, SecurityException, IOException, ClassNotFoundException, NoSuchFieldException, JAXBException {
+
+ /* set up properties */
+ System.setProperty("AJSC_HOME", ".");
+ System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
+
+ System.out.println("Starting FitNesse generation...");
+
+ TestSuite.TestSuiteBuilder builder = new TestSuite.TestSuiteBuilder();
+ builder
+ .setDbModelPackage("org.openecomp.aai.dbmodel")
+ .setApiVersion(AAIProperties.LATEST);
+
+ TestSuite suite = builder.build();
+ /*
+ String root = System.getenv(testCaseRootVar);
+
+ if (root == null) {
+ throw new IOException("No environment variable " + testCaseRootVar + " found. Please set it before continuing.");
+ }
+ root = System.getenv(jUnitRootVar);
+ if (root == null) {
+ throw new IOException("No environment variable " + jUnitRootVar + " found. Please set it before continuing.");
+ }
+ */
+
+ File endpoints = new File(currentEndpointsLocation + AAIProperties.LATEST);
+ File relationships = new File(currentRelationshipsLocation + AAIProperties.LATEST);
+ FileUtils.deleteDirectory(endpoints);
+ FileUtils.deleteDirectory(relationships);
+ suite.create(endpoints, relationships);
+ System.out.println("Generating current version suite.");
+
+ for (int i = 8; i > 1; i--) {
+ System.out.println("Generating v" + i + " suite.");
+
+ createVersionedTestSuite(Version.valueOf("v" + i));
+ }
+
+ System.out.println("Finished.");
+
+
+ }
+
+ /**
+ * Creates the versioned test suite.
+ *
+ * @param version the version
+ * @throws IllegalAccessException the illegal access exception
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws InvocationTargetException the invocation target exception
+ * @throws NoSuchMethodException the no such method exception
+ * @throws SecurityException the security exception
+ * @throws JSONException the JSON exception
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws ClassNotFoundException the class not found exception
+ * @throws NoSuchFieldException the no such field exception
+ * @throws InstantiationException the instantiation exception
+ * @throws JAXBException the JAXB exception
+ */
+ private static void createVersionedTestSuite(Version version) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, JSONException, IOException, ClassNotFoundException, NoSuchFieldException, InstantiationException, JAXBException {
+
+ TestSuite.TestSuiteBuilder builder = new TestSuite.TestSuiteBuilder();
+ File endpoints = new File(regressionEndpointsLocation + version);
+ File relationships = new File(regressionRelationshipsLocation + version);
+
+
+ builder
+ .setDbModelPackage("org.openecomp.aai.dbmodel." + version + ".gen")
+ .setApiVersion(version);
+
+ TestSuite suite = builder.build();
+ suite.create(endpoints, relationships);
+ }
+
+
+}
diff --git a/ajsc-aai/src/main/java/org/openecomp/aai/testing/GenerationTest.java b/ajsc-aai/src/main/java/org/openecomp/aai/testing/GenerationTest.java
new file mode 100644
index 0000000..325ad7c
--- /dev/null
+++ b/ajsc-aai/src/main/java/org/openecomp/aai/testing/GenerationTest.java
@@ -0,0 +1,77 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.aai
+ * ================================================================================
+ * 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.openecomp.aai.testing;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.xml.bind.JAXBException;
+
+import org.json.JSONException;
+import org.openecomp.aai.introspection.Introspector;
+import org.openecomp.aai.introspection.IntrospectorFactory;
+import org.openecomp.aai.introspection.Loader;
+import org.openecomp.aai.introspection.LoaderFactory;
+import org.openecomp.aai.introspection.ModelType;
+import org.openecomp.aai.introspection.Version;
+import org.springframework.web.util.UriUtils;
+
+public class GenerationTest {
+
+ /**
+ * The main method.
+ *
+ * @param args the arguments
+ * @throws IllegalAccessException the illegal access exception
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws InvocationTargetException the invocation target exception
+ * @throws InstantiationException the instantiation exception
+ * @throws JSONException the JSON exception
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws JAXBException the JAXB exception
+ */
+ public static void main(String[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, JSONException, IOException, JAXBException {
+ /*
+ PopulateObject pop = new PopulateObject();
+ UpdateObject update = new UpdateObject();
+ InjectResourceVersion inject = new InjectResourceVersion();
+ Loader v7Loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v8);
+ Introspector wrappedObj = v7Loader.introspectorFromName("tenant");
+ pop.populateRecursively(wrappedObj, 1, 3, false);
+
+ System.out.println(wrappedObj.marshal(true));
+
+ System.out.println(wrappedObj.getURI());
+ System.out.println("-----------------------");
+ wrappedObj = inject.addResourceVersionDeep(wrappedObj);
+
+ Introspector obj2 = update.randomlyUpdateFieldValues(wrappedObj);
+ System.out.println(obj2.marshal(true));
+
+ */
+ String encode = UriUtils.encodePath("~hello/:()", "UTF-8");
+ String decode = UriUtils.decode(encode, "UTF-8");
+ System.out.println(encode);
+ System.out.println(decode);
+
+ }
+
+}
diff --git a/ajsc-aai/src/main/java/org/openecomp/aai/testing/InjectResourceVersion.java b/ajsc-aai/src/main/java/org/openecomp/aai/testing/InjectResourceVersion.java
new file mode 100644
index 0000000..d4505bd
--- /dev/null
+++ b/ajsc-aai/src/main/java/org/openecomp/aai/testing/InjectResourceVersion.java
@@ -0,0 +1,132 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.aai
+ * ================================================================================
+ * 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.openecomp.aai.testing;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.openecomp.aai.introspection.Introspector;
+import org.openecomp.aai.introspection.IntrospectorWalker;
+import org.openecomp.aai.logging.LogLineBuilder;
+
+import com.google.common.base.Joiner;
+
+
+public class InjectResourceVersion extends TestDataGenerator {
+
+ protected List<String> blacklist = new ArrayList<>();
+ protected final LogLineBuilder llBuilder = new LogLineBuilder();
+
+ /**
+ * Instantiates a new inject resource version.
+ */
+ public InjectResourceVersion() {
+ blacklist.add("any");
+ blacklist.add("relationship-list");
+ }
+
+ /**
+ * Adds the resource version deep.
+ *
+ * @param wrappedObj the wrapped obj
+ * @return the introspector
+ */
+ public Introspector addResourceVersionDeep(Introspector wrappedObj) {
+
+ Introspector clone = (Introspector)wrappedObj.clone();
+ IntrospectorWalker walker = new IntrospectorWalker(this, llBuilder);
+ walker.setBlacklist(blacklist);
+ walker.walk(clone);
+ return clone;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void processPrimitive(String propName, Introspector obj) {
+ Object result = null;
+ if (propName.equals("resource-version")) {
+ List<String> keys = obj.getAllKeys();
+ List<Object> list = new ArrayList<>();
+ for (String key : keys) {
+ //Only add the first key for now, there should not be a problem with this method
+ //because the it is only being inspected at the object level itself
+ list.add(obj.getValue(key));
+ break;
+ }
+
+ result = Joiner.on("/").join(list);
+
+ } else {
+ result = obj.getValue(propName);
+
+ }
+ obj.setValue(propName, result);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void processPrimitiveList(String propName, Introspector obj) {
+
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void processComplexObj(Introspector obj) {
+
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void modifyComplexList(List<Object> list, Introspector parent, Introspector child) {
+
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean createComplexObjIfNull() {
+
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int createComplexListSize(Introspector parent, Introspector child) {
+
+ return 0;
+ }
+
+
+}
diff --git a/ajsc-aai/src/main/java/org/openecomp/aai/testing/LocateEndPoints.java b/ajsc-aai/src/main/java/org/openecomp/aai/testing/LocateEndPoints.java
new file mode 100644
index 0000000..8803df8
--- /dev/null
+++ b/ajsc-aai/src/main/java/org/openecomp/aai/testing/LocateEndPoints.java
@@ -0,0 +1,579 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.aai
+ * ================================================================================
+ * 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.openecomp.aai.testing;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.xml.bind.JAXBException;
+
+import org.apache.commons.lang.StringUtils;
+import org.json.JSONException;
+import org.openecomp.aai.audit.ListEndpoints;
+import org.openecomp.aai.introspection.Introspector;
+import org.openecomp.aai.introspection.IntrospectorFactory;
+import org.openecomp.aai.introspection.Loader;
+import org.openecomp.aai.introspection.LoaderFactory;
+import org.openecomp.aai.introspection.ModelType;
+import org.openecomp.aai.introspection.Version;
+import org.openecomp.aai.logging.LogLineBuilder;
+
+import com.google.common.base.CaseFormat;
+import com.google.common.base.Joiner;
+
+public class LocateEndPoints {
+
+ private String restPath = "";
+ private String pojoPath = "";
+
+ private PopulateObject populator = null;
+ private ArrayList<String> parentEndPoints = null;
+ private ArrayList<String> childEndPoints = null;
+ private final Pattern parentPattern = Pattern.compile("\\/(?:[\\w\\-]+?\\/)+?(?:\\{[\\w\\-]+?\\}\\/?)+");
+
+ private Map<String, List<String>> deprecatedEndpoints = new HashMap<>();
+ private Pattern apiVersionPattern = Pattern.compile("\\/(v\\d+)\\/");
+ private Version version = null;
+ private ModelType modelType = ModelType.MOXY;
+ private Loader loader = null;
+ protected final LogLineBuilder llBuilder = new LogLineBuilder();
+
+ /**
+ * Instantiates a new locate end points.
+ *
+ * @param version the version
+ * @throws FileNotFoundException the file not found exception
+ * @throws JSONException the JSON exception
+ */
+ public LocateEndPoints (Version version) throws FileNotFoundException, JSONException {
+
+ this.version = version;
+ populator = new PopulateObject();
+ loader = LoaderFactory.createLoaderForVersion(modelType, version, llBuilder);
+ this.parentEndPoints = new ArrayList<>();
+ this.childEndPoints = new ArrayList<>();
+ String[] versions = {"v2","v3", "v4", "v5"};
+ deprecatedEndpoints.put("site-pair-set", Arrays.asList(versions));
+
+ this.process();
+
+ }
+
+ /**
+ * Instantiates a new locate end points.
+ */
+ @SuppressWarnings("unused")
+ private LocateEndPoints() {}
+
+ /**
+ * Process.
+ */
+ private void process(){
+
+ ListEndpoints endpoints = new ListEndpoints(this.version);
+ String filterOut = "relationship-list";
+ List<String> uris = endpoints.getEndpoints(filterOut);
+
+ for (String uri : uris) {
+ this.addEndPointName(uri);
+ }
+
+ }
+
+ /**
+ * Checks if is deprecated.
+ *
+ * @param name the name
+ * @return true, if is deprecated
+ */
+ private boolean isDeprecated(String name) {
+
+ Matcher m = apiVersionPattern.matcher(name);
+ name = name.substring(name.lastIndexOf('.') + 1, name.length());
+ String apiVersion = "";
+
+ if (m.find()) {
+ apiVersion = m.group(1);
+ }
+ for (String key : deprecatedEndpoints.keySet()) {
+ if (name.contains(key)) {
+ List<String> deprecatedVersions = this.deprecatedEndpoints.get(key);
+
+ if (deprecatedVersions != null && deprecatedVersions.contains(apiVersion)) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Gets the parent paths.
+ *
+ * @return the parent paths
+ */
+ public List<String> getParentPaths() {
+
+ return (List<String>)this.parentEndPoints.clone();
+ }
+
+ /**
+ * Gets the child paths.
+ *
+ * @return the child paths
+ */
+ public List<String> getChildPaths() {
+
+ return (List<String>)this.childEndPoints.clone();
+ }
+
+ /**
+ * Gets the all paths.
+ *
+ * @return the all paths
+ */
+ public List<String> getAllPaths() {
+ List<String> returnList = new ArrayList<>();
+ returnList.addAll(getParentPaths());
+ returnList.addAll(getChildPaths());
+ return returnList;
+ }
+
+ /**
+ * Adds the end point name.
+ *
+ * @param path the path
+ */
+ private void addEndPointName(String path) {
+
+ if (!this.isDeprecated(path)) {
+ if (parentPattern.matcher(path).matches()) {
+ parentEndPoints.add(path);
+ } else {
+ childEndPoints.add(path);
+ }
+ }
+ }
+
+ /**
+ * Child path.
+ *
+ * @param path the path
+ * @return the string
+ */
+ public String childPath(String path) {
+
+ String childPath = "";
+ String[] pathSegments = path.split("/");
+ boolean foundNonVariable = false;
+ for (int i = pathSegments.length-1; i >= 0; i--) {
+
+ if (!foundNonVariable && pathSegments[i].contains("{")) {
+ childPath = pathSegments[i] + "/" + childPath;
+ } else if (foundNonVariable && pathSegments[i].contains("{")) {
+ break;
+ } else {
+ foundNonVariable = true;
+ childPath = pathSegments[i] + "/" + childPath;
+ }
+
+ }
+
+ childPath = childPath.substring(0, childPath.length()-1).replace("//", "/");
+
+ return childPath;
+
+ }
+
+ /**
+ * Creates the child for path.
+ *
+ * @param path the path
+ * @param min the min
+ * @param max the max
+ * @return the introspector
+ * @throws IllegalAccessException the illegal access exception
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws InvocationTargetException the invocation target exception
+ * @throws InstantiationException the instantiation exception
+ * @throws JSONException the JSON exception
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws JAXBException the JAXB exception
+ */
+ public Introspector createChildForPath(String path, int min, int max) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, JSONException, IOException, JAXBException {
+ return createChildForPath(path, min, max, false);
+ }
+
+ /**
+ * Creates the child for path.
+ *
+ * @param path the path
+ * @param min the min
+ * @param max the max
+ * @param minimized the minimized
+ * @return the introspector
+ * @throws IllegalAccessException the illegal access exception
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws InvocationTargetException the invocation target exception
+ * @throws InstantiationException the instantiation exception
+ * @throws JSONException the JSON exception
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws JAXBException the JAXB exception
+ */
+ public Introspector createChildForPath(String path, int min, int max, boolean minimized) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, JSONException, IOException, JAXBException {
+ Pattern p = Pattern.compile("([\\w\\-]+?)\\/(\\{[\\w\\-]+?\\}\\/?)+$");
+ Matcher m = p.matcher(path);
+ String objectName = "";
+ if (m.find()) {
+ objectName = m.group(1);
+ }
+ if (objectName.equals("cvlan-tag")) {
+ objectName = "cvlan-tag-entry";
+ }
+
+ return createChildFromClassName(objectName, min, max, minimized);
+ }
+
+ /**
+ * Creates the child from class name.
+ *
+ * @param objectName the object name
+ * @param min the min
+ * @param max the max
+ * @return the introspector
+ * @throws IllegalAccessException the illegal access exception
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws InvocationTargetException the invocation target exception
+ * @throws InstantiationException the instantiation exception
+ * @throws JSONException the JSON exception
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws JAXBException the JAXB exception
+ */
+ public Introspector createChildFromClassName(String objectName, int min, int max) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, JSONException, IOException, JAXBException {
+ return createChildFromClassName(objectName, min, max, false);
+ }
+
+ /**
+ * Creates the child from class name.
+ *
+ * @param objectName the object name
+ * @param min the min
+ * @param max the max
+ * @param minimized the minimized
+ * @return the introspector
+ * @throws IllegalAccessException the illegal access exception
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws InvocationTargetException the invocation target exception
+ * @throws InstantiationException the instantiation exception
+ * @throws JSONException the JSON exception
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws JAXBException the JAXB exception
+ */
+ public Introspector createChildFromClassName(String objectName, int min, int max, boolean minimized) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, JSONException, IOException, JAXBException {
+ Introspector returnObject = null;
+
+ returnObject = loader.introspectorFromName(objectName);
+ populator.populateRecursively(returnObject, min, max, minimized);
+
+
+ return returnObject;
+ }
+
+ /**
+ * Populate relationship.
+ *
+ * @param parent the parent
+ * @param dbName the db name
+ * @param fullPath the full path
+ * @return the introspector
+ */
+ public Introspector populateRelationship(Introspector parent, String dbName, String fullPath) {
+
+ String formattedClassName = parent.getDbName();
+
+ String advancedPath = StringUtils.substringAfter(fullPath, formattedClassName + "/");
+ String[] pathTokens = advancedPath.split("/");
+
+ // Create and format the relationship
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", dbName);
+ populateRelationshipHelper(parent, pathTokens, 0, relationship);
+
+ return relationship;
+ }
+
+ /**
+ * Populate relationship helper.
+ *
+ * @param parent the parent
+ * @param pathTokens the path tokens
+ * @param index the index
+ * @param relationship the relationship
+ */
+ // Recursively iterate through each token and add the necessary information to the relationship data array
+ private void populateRelationshipHelper(Introspector parent, String[] pathTokens, int index, Introspector relationship) {
+ Pattern p = Pattern.compile("\\{(.+?)\\}");
+ for(int i = index; i < pathTokens.length; ++i) {
+ Matcher m = p.matcher(pathTokens[i]);
+ if(m.find()) {
+ String pathVariable = m.group(1);
+ String trimmedClassName = parent.getDbName();
+ pathVariable = pathVariable.replaceFirst(trimmedClassName+ "-", "");
+ String key = this.callGetMethod(parent, pathVariable).toString();
+ pathTokens[i] = pathTokens[i].replaceAll("\\{.+?\\}", key);
+
+ // Add the relationship data object from token information
+ Introspector data = relationship.newIntrospectorInstanceOfNestedProperty("relationship-data");
+ data.setValue("relationship-key", trimmedClassName + "." + pathVariable);
+ data.setValue("relationship-value", key);
+ ((List)relationship.getValue("relationship-data")).add(data.getUnderlyingObject());
+ if (i == pathTokens.length-1) {
+ List<Introspector> relatedTos = new ArrayList<>();
+ String nameProps = parent.getMetadata("nameProps");
+ if (nameProps != null) {
+ String[] props = nameProps.split(",");
+ for (String prop : props) {
+ Introspector relatedTo = this.loader.introspectorFromName("related-to-property");
+ relatedTo.setValue("property-key", parent.getDbName() + "." + prop);
+ relatedTo.setValue("property-value", parent.getValue(prop));
+ relatedTos.add(relatedTo);
+ }
+
+ if (relatedTos.size() > 0) {
+ List list = (List)relationship.getValue("related-to-property");
+ for (Introspector obj : relatedTos) {
+ list.add(obj.getUnderlyingObject());
+ }
+ }
+ }
+ }
+ } else {
+ String getMethodName;
+ if (pathTokens[i].equals("cvlan-tag")) {
+ getMethodName = "cvlan-tag-entry";
+ } else {
+ getMethodName = pathTokens[i];
+ }
+ Object child = this.callGetMethod(parent, getMethodName);
+ if (child != null) {
+ if (child.getClass().getName().contains("List")) {
+ child = ((List)child).get(0);
+ }
+ populateRelationshipHelper(IntrospectorFactory.newInstance(parent.getModelType(), child, llBuilder), pathTokens, i+1, relationship);
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * Populate path.
+ *
+ * @param parent the parent
+ * @param path the path
+ * @return the list
+ * @throws IllegalAccessException the illegal access exception
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws InvocationTargetException the invocation target exception
+ * @throws NoSuchMethodException the no such method exception
+ * @throws SecurityException the security exception
+ */
+ public List<Object> populatePath(Introspector parent, String path) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
+
+ String formattedClassName = parent.getDbName();
+
+ String prefix = StringUtils.substringBefore(path, "{");
+ String advancedPath = StringUtils.substringAfter(path, formattedClassName+"/");
+ String[] pathTokens = advancedPath.split("/");
+
+ Introspector end = populatePathHelper(parent, pathTokens, 0);
+ String parentPath = prefix + Joiner.on("/").join(pathTokens);
+ List<Object> result = new ArrayList<>();
+ result.add(parentPath);
+ result.add(end.clone());
+ return result;
+ }
+
+ /**
+ * Populate child path.
+ *
+ * @param topLevelObj the top level obj
+ * @param obj the obj
+ * @param path the path
+ * @return the string
+ * @throws IllegalAccessException the illegal access exception
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws InvocationTargetException the invocation target exception
+ * @throws NoSuchMethodException the no such method exception
+ * @throws SecurityException the security exception
+ */
+ public String populateChildPath(Introspector topLevelObj, Introspector obj, String path) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
+ String childPath = "/" + this.childPath(path);
+ String parentPath = path.replace(childPath, "");
+ String resultPath = (String)this.populatePath(topLevelObj, parentPath).get(0) + (String)this.populatePath(obj, childPath).get(0);
+
+ return resultPath;
+ }
+
+ /**
+ * Populate path helper.
+ *
+ * @param parent the parent
+ * @param pathTokens the path tokens
+ * @param index the index
+ * @return the introspector
+ */
+ private Introspector populatePathHelper(Introspector parent, String[] pathTokens, int index) {
+
+ Pattern p = Pattern.compile("\\{(.+?)\\}");
+ Matcher m = null;
+ String pathVariable = "";
+ String key = "";
+ Object child = null;
+ String getMethodName = "";
+ for (int i = index; i < pathTokens.length; i++) {
+ m = p.matcher(pathTokens[i]);
+ if (m.find()) {
+ pathVariable = m.group(1);
+
+ pathVariable = pathVariable.replaceFirst(parent.getDbName() + "-", "");
+
+ key = this.callGetMethod(parent, pathVariable).toString();
+ pathTokens[i] = pathTokens[i].replaceAll("\\{.+?\\}", key);
+ } else {
+
+ if (pathTokens[i].equals("cvlan-tag")) {
+ getMethodName = "cvlan-tag-entry";
+ } else {
+ getMethodName = pathTokens[i];
+ }
+ child = this.callGetMethod(parent, getMethodName);
+ if (child != null) {
+ if (child.getClass().getName().contains("List")) {
+ child = ((List)child).get(0);
+ }
+ return populatePathHelper(IntrospectorFactory.newInstance(parent.getModelType(), child, llBuilder), pathTokens, i+1);
+ }
+ }
+ }
+
+ return parent;
+ }
+
+ /**
+ * Gets the path for object.
+ *
+ * @param parentPath the parent path
+ * @param obj the obj
+ * @return the path for object
+ */
+ public String getPathForObject(String parentPath, Object obj) {
+
+ String name = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, this.trimClassName(obj));
+ String result = "";
+ Pattern p = Pattern.compile(".*?\\/" + name + "\\/\\{.*?\\}");
+ Matcher m = null;
+ for (String childPath : this.childEndPoints) {
+
+ m = p.matcher(childPath);
+ if (m.find()) {
+ result = m.group();
+ break;
+ }
+
+ }
+
+ return result;
+
+ }
+
+ /**
+ * Format path string.
+ *
+ * @param item the item
+ * @return the string
+ */
+ private String formatPathString(String item) {
+
+ String value = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, item);
+
+ return value;
+ }
+
+ /**
+ * Call get method.
+ *
+ * @param obj the obj
+ * @param variableName the variable name
+ * @return the object
+ */
+ private Object callGetMethod(Introspector obj, String variableName) {
+ Object key = null;
+
+ key = obj.getValue(variableName);
+
+ return key;
+ }
+
+ /**
+ * Make singular.
+ *
+ * @param word the word
+ * @return the string
+ */
+ private String makeSingular(String word) {
+
+ String result = word;
+ result = result.replaceAll("ies$", "y");
+ result = result.replaceAll("(?:s|([hox])es)$", "$1");
+
+ return result;
+ }
+
+ /**
+ * Trim class name.
+ *
+ * @param obj the obj
+ * @return the string
+ */
+ public String trimClassName (Object obj) {
+ String returnValue = "";
+ String name = obj.getClass().getName();
+ returnValue = name.substring(name.lastIndexOf('.') + 1, name.length());
+
+ if (returnValue.equals("CvlanTagEntry")) {
+ returnValue = "CvlanTag";
+ }
+ return returnValue;
+ }
+
+
+
+}
diff --git a/ajsc-aai/src/main/java/org/openecomp/aai/testing/OXMTest.java b/ajsc-aai/src/main/java/org/openecomp/aai/testing/OXMTest.java
new file mode 100644
index 0000000..70bab01
--- /dev/null
+++ b/ajsc-aai/src/main/java/org/openecomp/aai/testing/OXMTest.java
@@ -0,0 +1,63 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.aai
+ * ================================================================================
+ * 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.openecomp.aai.testing;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+
+import javax.xml.bind.JAXBException;
+
+import org.eclipse.persistence.internal.oxm.mappings.Descriptor;
+import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
+import org.json.JSONException;
+import org.openecomp.aai.introspection.ModelInjestor;
+import org.openecomp.aai.introspection.Version;
+
+public class OXMTest {
+
+ /**
+ * The main method.
+ *
+ * @param args the arguments
+ * @throws JAXBException the JAXB exception
+ * @throws IllegalAccessException the illegal access exception
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws InvocationTargetException the invocation target exception
+ * @throws InstantiationException the instantiation exception
+ * @throws JSONException the JSON exception
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ public static void main(String[] args) throws JAXBException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, JSONException, IOException {
+
+
+ ModelInjestor injestor = ModelInjestor.getInstance();
+
+ DynamicJAXBContext context =injestor.getContextForVersion(Version.v8);
+
+ List<Descriptor> test = context.getXMLContext().getDescriptors();
+
+ for (Descriptor d : test) {
+ System.out.println(context.newDynamicEntity(d.getJavaClass().getSimpleName()).getClass().getName());
+ }
+ }
+
+}
diff --git a/ajsc-aai/src/main/java/org/openecomp/aai/testing/PopulateObject.java b/ajsc-aai/src/main/java/org/openecomp/aai/testing/PopulateObject.java
new file mode 100644
index 0000000..d86ae9b
--- /dev/null
+++ b/ajsc-aai/src/main/java/org/openecomp/aai/testing/PopulateObject.java
@@ -0,0 +1,232 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.aai
+ * ================================================================================
+ * 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.openecomp.aai.testing;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
+
+import javax.xml.bind.JAXBException;
+
+import org.json.JSONException;
+import org.openecomp.aai.exceptions.AAIException;
+import org.openecomp.aai.introspection.Introspector;
+import org.openecomp.aai.introspection.IntrospectorWalker;
+import org.openecomp.aai.logging.LogLineBuilder;
+import org.openecomp.aai.serialization.db.EdgeRule;
+import org.openecomp.aai.serialization.db.EdgeRules;
+import org.openecomp.aai.serialization.db.MultiplicityRule;
+import org.openecomp.aai.testsuitegeneration.AbstractWriter;
+
+public class PopulateObject extends TestDataGenerator {
+
+ protected boolean isMinimumObject = false;
+ protected List<String> blacklist = new ArrayList<>();
+ protected final LogLineBuilder llBuilder = new LogLineBuilder();
+
+ /**
+ * Instantiates a new populate object.
+ */
+ public PopulateObject() {
+ blacklist.add("any");
+ blacklist.add("relationship-list");
+ blacklist.add("resource-version");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void processPrimitive(String propName, Introspector obj) {
+ Object val = null;
+ String type = obj.getType(propName);
+ if (this.isMinimumObject) {
+ List<String> required = obj.getRequiredProperties();
+ if (!required.contains(propName)) {
+ return;
+ }
+ }
+ /* If the key is not a string, don't worry about it being unique */
+ if (type.contains("java.lang.String") && isKey(obj, propName)) {
+ val = UUID.randomUUID().toString() + AbstractWriter.USERNAME_PLACEHOLDER;
+ }else{
+ val = createNewRandomObj(type);
+ String uniqueProps = obj.getMetadata("uniqueProps");
+ if (uniqueProps != null) {
+ String[] props = uniqueProps.split(",");
+ List<String> list = Arrays.asList(props);
+ if (list.contains(propName)) {
+ val += AbstractWriter.USERNAME_PLACEHOLDER;
+ }
+ }
+
+ }
+ obj.setValue(propName, val);
+
+ }
+
+ /**
+ * Populate.
+ *
+ * @param obj the obj
+ * @param isMinimumObject the is minimum object
+ * @return the introspector
+ * @throws JSONException the JSON exception
+ * @throws IllegalAccessException the illegal access exception
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws InvocationTargetException the invocation target exception
+ * @throws InstantiationException the instantiation exception
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws JAXBException the JAXB exception
+ */
+ public Introspector populate(Introspector obj, boolean isMinimumObject) throws JSONException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, IOException, JAXBException {
+ this.isMinimumObject = isMinimumObject;
+
+ IntrospectorWalker walker = new IntrospectorWalker(this, llBuilder);
+ walker.setBlacklist(this.blacklist);
+ walker.walk(obj);
+ return obj;
+ }
+
+ /**
+ * Populate recursively.
+ *
+ * @param obj the obj
+ * @param min the min
+ * @param max the max
+ * @param isMinimumObject the is minimum object
+ * @return the introspector
+ * @throws IllegalAccessException the illegal access exception
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws InvocationTargetException the invocation target exception
+ * @throws JSONException the JSON exception
+ * @throws InstantiationException the instantiation exception
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws JAXBException the JAXB exception
+ */
+ public Introspector populateRecursively(Introspector obj, int min, int max, boolean isMinimumObject) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, JSONException, InstantiationException, IOException, JAXBException {
+
+ IntrospectorWalker walker = new IntrospectorWalker(this, llBuilder);
+ this.isMinimumObject = isMinimumObject;
+ this.min = min;
+ this.max = max;
+ walker.setBlacklist(this.blacklist);
+ walker.preventCycles(true);
+ walker.walk(obj);
+ return obj;
+ //return populateHelper(o, min, max, true);
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void processPrimitiveList(String propName, Introspector obj) {
+ int numberOfObjects = getRandomInt();
+
+ String propType = "";
+ List<Object> list = new ArrayList<>();
+ for (int i = 0; i < numberOfObjects; i++) {
+ propType = obj.getGenericType(propName);
+ Object val = this.createNewRandomObj(propType);
+ list.add(val);
+ }
+ obj.setValue(propName, list);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void processComplexObj(Introspector obj) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void modifyComplexList(List<Object> list, Introspector parent, Introspector child) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean createComplexObjIfNull() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int createComplexListSize(Introspector parent, Introspector child) {
+
+ EdgeRule rule;
+ int numberOfObjects = getRandomInt();
+
+ try {
+ rule = EdgeRules.getInstance().getEdgeRule(parent.getDbName(), child.getDbName());
+ if (rule.getMultiplicityRule().equals(MultiplicityRule.ONE2ONE)) {
+ numberOfObjects = 1;
+ } else if (rule.getMultiplicityRule().equals(MultiplicityRule.ONE2MANY) || rule.getMultiplicityRule().equals(MultiplicityRule.MANY2MANY)) {
+ if (numberOfObjects < max) {
+ numberOfObjects = max;
+ }
+ }
+ } catch (AAIException e) {
+ System.out.println(e.getErrorObject().getDetails());
+ }
+
+
+ return numberOfObjects;
+ }
+
+ /**
+ * Checks if is key.
+ *
+ * @param obj the obj
+ * @param prop the prop
+ * @return true, if is key
+ */
+ private boolean isKey(Introspector obj, String prop) {
+ /*String className = trimClassName(obj.getClass().getName());
+ Collection<String> keys = keyProps.get(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, className));
+ Collection<String> altKeys = altKeysProps.get(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, className));
+ String lowerHyphenFieldName = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN,f.getName());
+ if (keys.contains(lowerHyphenFieldName) || altKeys.contains(lowerHyphenFieldName)){
+ return true;
+ }
+ return false;*/
+
+ return obj.getAllKeys().contains(prop);
+
+ }
+
+}
diff --git a/ajsc-aai/src/main/java/org/openecomp/aai/testing/TestDataGenerator.java b/ajsc-aai/src/main/java/org/openecomp/aai/testing/TestDataGenerator.java
new file mode 100644
index 0000000..25ff2e7
--- /dev/null
+++ b/ajsc-aai/src/main/java/org/openecomp/aai/testing/TestDataGenerator.java
@@ -0,0 +1,66 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.aai
+ * ================================================================================
+ * 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.openecomp.aai.testing;
+
+import java.util.Random;
+import java.util.concurrent.ThreadLocalRandom;
+
+import org.apache.commons.lang.RandomStringUtils;
+import org.openecomp.aai.introspection.Wanderer;
+
+public abstract class TestDataGenerator implements Wanderer {
+
+ protected int minStringLength = 3;
+ protected int maxStringLength = 13;
+ protected int min = 1;
+ protected int max = 2;
+
+ /**
+ * Creates the new random obj.
+ *
+ * @param type the type
+ * @return the object
+ */
+ protected Object createNewRandomObj (String type) {
+ Object newObj = null;
+ if ( type.contains("java.lang.String")) {
+ newObj = RandomStringUtils.randomAlphanumeric(ThreadLocalRandom.current().nextInt(minStringLength, maxStringLength + 1));
+ } else if ( type.toLowerCase().equals("long") ||type.contains("java.lang.Long")) {
+ newObj = new Long(RandomStringUtils.randomNumeric(ThreadLocalRandom.current().nextInt(minStringLength, minStringLength + 1)));
+ } else if(type.toLowerCase().equals("boolean") || type.contains("java.lang.Boolean")){
+ Random rand = new Random();
+ newObj = rand.nextBoolean();
+ }else if ( type.toLowerCase().equals("int") || type.contains("java.lang.Integer")){
+ newObj = new Integer(RandomStringUtils.randomNumeric(ThreadLocalRandom.current().nextInt(minStringLength, minStringLength + 1)));
+ }
+
+ return newObj;
+ }
+
+ /**
+ * Gets the random int.
+ *
+ * @return the random int
+ */
+ protected int getRandomInt() {
+ return ThreadLocalRandom.current().nextInt(this.min, this.max + 1);
+ }
+}
diff --git a/ajsc-aai/src/main/java/org/openecomp/aai/testing/UpdateObject.java b/ajsc-aai/src/main/java/org/openecomp/aai/testing/UpdateObject.java
new file mode 100644
index 0000000..9d8500c
--- /dev/null
+++ b/ajsc-aai/src/main/java/org/openecomp/aai/testing/UpdateObject.java
@@ -0,0 +1,205 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.aai
+ * ================================================================================
+ * 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.openecomp.aai.testing;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Random;
+
+import javax.xml.bind.JAXBException;
+
+import org.json.JSONException;
+import org.openecomp.aai.exceptions.AAIException;
+import org.openecomp.aai.introspection.Introspector;
+import org.openecomp.aai.introspection.IntrospectorWalker;
+import org.openecomp.aai.logging.LogLineBuilder;
+import org.openecomp.aai.serialization.db.EdgeRule;
+import org.openecomp.aai.serialization.db.EdgeRules;
+import org.openecomp.aai.serialization.db.MultiplicityRule;
+
+public class UpdateObject extends TestDataGenerator {
+
+ private PopulateObject pop = new PopulateObject();
+
+ protected List<String> blacklist = new ArrayList<>();
+ protected final LogLineBuilder llBuilder = new LogLineBuilder();
+
+ /**
+ * Instantiates a new update object.
+ */
+ public UpdateObject() {
+ blacklist.add("any");
+ blacklist.add("relationship-list");
+ blacklist.add("resource-version");
+ }
+
+ /**
+ * Randomly update field values.
+ *
+ * @param obj the obj
+ * @return the introspector
+ */
+ public Introspector randomlyUpdateFieldValues(Introspector obj){
+ Introspector clone = null;
+
+ clone = (Introspector)obj.clone();
+
+ IntrospectorWalker walker = new IntrospectorWalker(this, llBuilder);
+ walker.setBlacklist(blacklist);
+ walker.walk(clone);
+
+ return clone;
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void processPrimitive(String propName, Introspector obj) {
+ List<String> keys = obj.getKeys();
+ if (!keys.contains(propName)) {
+ Random random = new Random();
+ int num = random.nextInt(100);
+ if (num <= 33) {
+ Object val = this.createNewRandomObj(obj.getType(propName));
+ obj.setValue(propName, val);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void processPrimitiveList(String propName, Introspector obj) {
+ Random random = new Random();
+ int num = random.nextInt(100);
+ if (num <= 33) {
+ List<Object> list = (List<Object>) obj.getValue(propName);
+ int size = list.size();
+ Random rand = new Random();
+ int newSize = 0;
+ if (size == 0) {
+ newSize = rand.nextInt(max);
+ } else {
+ newSize = rand.nextInt(size);
+ }
+ list.clear();
+ for (int i = 0; i < newSize; i++) {
+ list.add(this.createNewRandomObj(obj.getGenericType(propName)));
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void processComplexObj(Introspector obj) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void modifyComplexList(List<Object> list, Introspector parent, Introspector child) {
+
+ EdgeRule rule;
+ int numberOfObjects = max;
+
+ try {
+ rule = EdgeRules.getInstance().getEdgeRule(parent.getDbName(), child.getDbName());
+ if (rule.getMultiplicityRule().equals(MultiplicityRule.ONE2ONE)) {
+ numberOfObjects = 1;
+ }
+ } catch (AAIException e) {
+ System.out.println(e.getErrorObject().getDetails());
+ }
+
+ int editRemoveOrAdd;
+ List<Integer> randNumList = new ArrayList<Integer>();
+ Random rand = new Random();
+ int numOfItemstoUpdate = 0;
+
+ if (numberOfObjects == 1) {
+ numOfItemstoUpdate = rand.nextInt(numberOfObjects);
+ } else {
+ numOfItemstoUpdate = rand.nextInt(numberOfObjects-1)+1;
+ }
+ for (int i = 0; i < numOfItemstoUpdate; i++){
+ randNumList.add(i);
+ }
+ Collections.shuffle(randNumList);
+ for (int i = 0; i < numOfItemstoUpdate; i++) {
+ editRemoveOrAdd = rand.nextInt(numberOfObjects);
+ int index = randNumList.get(i);
+ Introspector newObject = null;
+ try {
+ newObject = pop.populateRecursively((Introspector)child.clone(), min, max, false);
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
+ | InstantiationException | JSONException | IOException | JAXBException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ if (list.size() < numberOfObjects){
+ if (editRemoveOrAdd == 0 && index < list.size()){
+ if (newObject != null) {
+ list.set(index, newObject.getUnderlyingObject());
+ }
+ }else if (editRemoveOrAdd == 1 && index < list.size()){
+ if (list.size() != 1) {
+ list.remove(index);
+ }
+ }else if (editRemoveOrAdd == 2 && list.size() + 1 <= numberOfObjects){
+ if (newObject != null) {
+ list.add(index, newObject.getUnderlyingObject());
+ }
+ }
+ }
+
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean createComplexObjIfNull() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int createComplexListSize(Introspector parent, Introspector child) {
+ return 0;
+ }
+
+}