diff options
7 files changed, 1599 insertions, 5 deletions
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 new file mode 100755 index 000000000..345ff57bb --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AutoGeneratedRegressionTest.java @@ -0,0 +1,943 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.aai; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.IOException; +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Scanner; +import java.util.Set; +import java.util.Stack; +import java.util.UUID; + +import javax.xml.bind.SchemaOutputResolver; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.Result; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathFactory; + +import org.apache.commons.lang.RandomStringUtils; +import org.apache.commons.lang.StringUtils; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; +import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum; +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; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import com.fasterxml.jackson.annotation.JsonProperty; +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 { + XPathFactory xFactory = XPathFactory.newInstance(); + XPath xPath = xFactory.newXPath(); + String format = "/schema/element[@name='%s']/complexType/sequence/element[@ref]"; + + String path = String.format(format, parent); + +// XPathExpression exp = xPath.compile("/schema/element[@name='generic-vnf']/complexType/sequence/element[@ref]"); + XPathExpression exp = xPath.compile(path); + + NodeList nl = (NodeList)exp.evaluate(doc.getFirstChild(), XPathConstants.NODESET); + LOG.debug("Nodes to process : "+nl.getLength()); + for (int index = 0; index < nl.getLength(); index++) { + + 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(); + } + } + } + } + } + } + + 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); + + localStack.pop(); + + while(!localStack.isEmpty()) { + String instruction = localStack.pop(); + if(instruction.contains(keystring)) { + return true; + } + } + + return false; + } +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/EchoRequestTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/EchoRequestTest.java index 4195d8485..5a3d88ec4 100755 --- a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/EchoRequestTest.java +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/EchoRequestTest.java @@ -75,7 +75,7 @@ public class EchoRequestTest { try { String json = request.toJSONString(); - + assertNotNull(json); } catch (Exception exc) { LOG.error("Failed test", exc); } diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/GenericRequestTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/GenericRequestTest.java new file mode 100755 index 000000000..5f9fc7f8b --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/GenericRequestTest.java @@ -0,0 +1,190 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.aai; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +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.onap.ccsdk.sli.adaptors.aai.data.AAIDatum; +import org.openecomp.aai.inventory.v11.GenericVnf; +import org.openecomp.aai.inventory.v11.LInterface; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.databind.ObjectMapper; + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class GenericRequestTest { + + private static final Logger LOG = LoggerFactory.getLogger(GenericRequestTest.class); + + protected static AAIClient client; + protected static AAIRequest request; + + @BeforeClass + public static void setUp() throws Exception { + URL url = AAIService.class.getResource(AAIService.AAICLIENT_PROPERTIES); + client = new AAIService(url); + request = AAIRequest.createRequest("generic-vnf", new HashMap<String, String>()); + LOG.info("\nTaicAAIResourceTest.setUp\n"); + } + + @AfterClass + public static void tearDown() throws Exception { + client = null; + LOG.info("----------------------- AAIResourceTest.tearDown -----------------------"); + } + + @Test + public void test001() + { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try + { + Map<String, String> key = new HashMap<String, String>(); + AAIRequest request = AAIRequest.createRequest("vserver", key); + key.put("vserver.vserver_id", "e8faf166-2402-4ae2-be45-067954c63aed"); + key.put("tenant.tenant_id", "1863027683132547"); + request.processRequestPathValues(key); + String uri = request.getTargetUri(); + + assertNotNull(uri); + + } + catch (Exception e) + { + LOG.error("Caught exception", e); + fail("Caught exception"); + } + } + + @Test + public void test002() { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + try + { + URL resource = this.getClass().getResource("json/linterfaceJson.txt"); + + 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(); + LInterface request = mapper.readValue(requestFile, LInterface.class); + String vnf_id = request.getInterfaceName(); + LOG.info(vnf_id); + + } + catch (Exception e) + { + LOG.error("Caught exception", e); + } + } + + @Test + public void test003() { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + try + { + String vnf_id = "4718302b-7884-4959-a499-f470c62418ff"; + + GenericVnf genericVnf = client.requestGenericVnfData(vnf_id); + + client.deleteGenericVnfData(vnf_id, genericVnf.getResourceVersion()); + + } + catch (Throwable e) + { + LOG.error("Caught exception", e); + } + } + + + @Test + public void test004() { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + URL url; + try { + url = request.getRequestUrl("GET", null); + assertNotNull(url); + } catch (UnsupportedEncodingException | MalformedURLException exc) { + LOG.error("Failed test", exc); + } + + } + + @Test + public void runToJSONStringTest() { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try { + String json = request.toJSONString(); + assertNotNull(json); + } catch (Exception exc) { + LOG.error("Failed test", exc); + } + + } + + @Test + public void runGetArgsListTest() { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try { + String[] args = request.getArgsList(); + assertNotNull(args); + } catch (Exception exc) { + LOG.error("Failed test", exc); + } + + } + + @Test + public void runGetModelTest() { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try { + Class<? extends AAIDatum> clazz = request.getModelClass(); + assertNotNull(clazz); + } catch (Exception exc) { + LOG.error("Failed test", exc); + } + + } +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/RegressionTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/RegressionTest.java new file mode 100755 index 000000000..4563adfca --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/RegressionTest.java @@ -0,0 +1,417 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.aai; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.net.URL; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.apache.commons.lang.StringUtils; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; +import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class RegressionTest { + + static { + System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "INFO"); +// System.setProperty(org.slf4j.impl.SimpleLogger.LOG_FILE_KEY, String.format("RegressionTest-%d.txt", System.currentTimeMillis())); + } + + private static final Logger LOG = LoggerFactory.getLogger(RegressionTest.class); + + protected static AAIService client; + + @BeforeClass + public static void setUp() throws Exception { +// super.setUp(); + URL url = AAIService.class.getResource(AAIService.AAICLIENT_PROPERTIES); + client = new AAIService(url); + LOG.info("\nTaicAAIResourceTest.setUp\n"); + } + + @AfterClass + public static void tearDown() throws Exception { +// super.tearDown(); + client = null; + LOG.info("----------------------- AAIResourceTest.tearDown -----------------------"); + } + + @Test + public void R1510Test05GenericVnfDataRequestDelete() { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + try + { + String vnf_id = "bpsx0001v-7071"; + boolean response = client.deleteGenericVnfData(vnf_id, null); + assertTrue(response); + + } + catch (Throwable e) + { + assert(true); + } + } + + @Test + public void R1604TestWanConnectorSave01Request() + { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try + { + SvcLogicContext ctx = new SvcLogicContext(); + + Map<String, String> data = new HashMap<String, String>(); + data.put("resource-instance-id", "12345"); + data.put("resource-model-uuid", "45678"); + + data.put("relationship-list.relationship[0].related-to", "service-instance"); + + data.put("relationship-list.relationship[0].relationship-data[0].relationship-key", "customer.global-customer-id"); + data.put("relationship-list.relationship[0].relationship-data[0].relationship-value", "$global-customer-id"); + + data.put("relationship-list.relationship[0].relationship-data[1].relationship-key", "service-subscription.service-type"); + data.put("relationship-list.relationship[0].relationship-data[1].relationship-value", "$service-type"); + + data.put("relationship-list.relationship[0].relationship-data[2].relationship-key", "service-instance.service-instance-id"); + data.put("relationship-list.relationship[0].relationship-data[2].relationship-value", "$serviceInstanceID"); + + + + //(String resource, boolean force, boolean localOnly, String key, Map<String, String> parms, String prefix, SvcLogicContext ctx) + QueryStatus resp = client.save("connector", false, false, "resource-instance-id = '12345'", data, "aaidata", ctx); + + LOG.info("AAIResponse: " + resp.toString()); + } + catch (Exception e) + { + assert(true); + } + } + + + @Test + public void R1604TestWanConnectorSave02Request() + { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try + { + SvcLogicContext ctx = new SvcLogicContext(); + + Map<String, String> data = new HashMap<String, String>(); + data.put("resource-instance-id", "11012345"); + data.put("widget-model-id", "45678"); + data.put("persona-model-version", "0.1"); + data.put("persona-model-id", "dc700a83-c507-47d9-b775-1fdfcdd5f9eb"); + data.put("relationship-list.relationship[0].relationship-data[0].relationship-key", "customer.global-customer-id"); + data.put("metadata.metadatum[0].meta-value", "100640"); + data.put("metadata.metadatum[0].meta-key", "vni"); + data.put("relationship-list.relationship[0].relationship-data[1].relationship-value", "ATT-COLLABORATE"); + data.put("relationship-list.relationship[0].relationship-data[0].relationship-value", "ds828e091614l"); + data.put("relationship-list.relationship[0].relationship-data[2].relationship-key", "service-instance.service-instance-id"); + data.put("relationship-list.relationship[0].relationship-data[1].relationship-key", "service-subscription.service-type"); + data.put("relationship-list.relationship[0].related-to", "service-instance"); + data.put("relationship-list.relationship[0].relationship-data[2].relationship-value", "1990e84d-546d-4b61-8069-e0db1318ade2"); + + + //(String resource, boolean force, boolean localOnly, String key, Map<String, String> parms, String prefix, SvcLogicContext ctx) + QueryStatus resp = client.save("connector", false, false, "resource-instance-id = '11012345'", data, "aaidata", ctx); + + LOG.info("AAIResponse: " + resp.toString()); + } + catch (Exception e) + { + assert(true); + } + } + + + @Test + public void R1604TestLogicalLinkSaveRequest() + { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try + { + SvcLogicContext ctx = new SvcLogicContext(); + + Map<String, String> data = new HashMap<String, String>(); + data.put("link-name" , "1252541"); + data.put("link-type" , "L2 Bridge between IPE and BorderElement"); + data.put("speed-value" , "1000"); + + data.put("speed-units" , "MBPS"); + data.put("ip-version" , "IP-V6"); + data.put("routing-protocol" , "BGP"); + data.put("resource-version" , "1.0.0"); + data.put("resource-model-uuid" , "TEST01"); + + data.put("relationship-list.relationship[0].related-to" , "virtual-data-center"); + data.put("relationship-list.relationship[0].relationship-data[0].relationship-key", "virtual-data-center.vdc-id"); + data.put("relationship-list.relationship[0].relationship-data[0].relationship-value", "dpa2_cci_att_com-1068"); + + data.put("relationship-list.relationship[1].related-to" , "generic-vnf"); + data.put("relationship-list.relationship[1].relationship-data[0].relationship-key", "generic-vnf.vnf-id"); + data.put("relationship-list.relationship[1].relationship-data[0].relationship-value" , "basx0001v-1189"); + + data.put("relationship-list.relationship[2].related-to" , "l-interface"); + data.put("relationship-list.relationship[2].relationship-data[0].relationship-key", "pserver.hostname"); + data.put("relationship-list.relationship[2].relationship-data[0].relationship-value" , "ptpbe101snd"); + + data.put("relationship-list.relationship[2].relationship-data[1].relationship-key", "lag-interface.interface-name"); + data.put("relationship-list.relationship[2].relationship-data[1].relationship-value" , "$name"); + + data.put("relationship-list.relationship[2].relationship-data[2].relationship-key", "l-interface.interface-name"); + data.put("relationship-list.relationship[2].relationship-data[2].relationship-value" , "$hostname"); + + + + //(String resource, boolean force, boolean localOnly, String key, Map<String, String> parms, String prefix, SvcLogicContext ctx) + QueryStatus resp = client.save("logical-link", false, false, "link-name = '1252541'", data, "aaidata", ctx); + + LOG.info("AAIResponse: " + resp.toString()); + } + catch (Exception e) + { + assert(true); + } + } + + @Test + public void R1604TestVDCISaveRequest() + { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try + { + SvcLogicContext ctx = new SvcLogicContext(); + + Map<String, String> data = new HashMap<String, String>(); + data.put("vdc-id" , "1252541"); + data.put("vdc-name" , "put.the.variable.of.your.data.here"); + + data.put("relationship-list.relationship[0].related-to" , "connector"); + + data.put("relationship-list.relationship[0].relationship-data[0].relationship-key" , "connector.resource-instance-id"); + data.put("relationship-list.relationship[0].relationship-data[0].relationship-value" , "$resource-instance-id"); + + + + //(String resource, boolean force, boolean localOnly, String key, Map<String, String> parms, String prefix, SvcLogicContext ctx) + QueryStatus resp = client.save("virtual-data-center", false, false, "vdc-id = '1252541'", data, "aaidata", ctx); + + LOG.info("AAIResponse: " + resp.toString()); + } + catch (Exception e) + { + assert(true); + } + } + +// @Test + public void R1510Test03RequestGenericVnfDataRequest() + { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try + { + SvcLogicContext ctx = new SvcLogicContext(); + + QueryStatus response = client.query("generic-vnf:relationship-list", false, null, "vnf-id = '34e94596-bdfa-411d-a664-16dea8583139' AND related-to = 'l3-network' ", "aaiTest", null, ctx); +// QueryStatus response = client.delete("generic-vnf:relationship-list", "vnf-id = '34e94596-bdfa-411d-a664-16dea8583139' AND related-to = 'pserver' ", ctx); + + assertTrue(response == QueryStatus.SUCCESS); + LOG.info("AAIResponse: " + response.toString()); + } + catch (Exception e) + { + LOG.error("Caught exception", e); + fail("Caught exception"); + } + } + + @Test + public void R1510Test03RequestVserverDataRequest() + { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try + { + SvcLogicContext ctx = new SvcLogicContext(); + QueryStatus response = client.query("vserver", false, null, + "vserver.vserver-id = 'FRNKGEFF1' AND depth = 'all' AND cloud-region.cloud-owner = 'att-aic' AND tenant.tenant-id = '1710vPEPROJECTS::297135PROJECT' AND cloud-region.cloud-region-id = 'FRN1'" + , "aaiTest", null, ctx); + + assertNotNull(response); + } + catch (Exception e) + { + LOG.error("Caught exception", e); + fail("Caught exception"); + } + } + +// @Test + public void R1510Test03UpdateVserverDataRequest() + { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try + { + Properties prop = new Properties(); + String propFileName = "vserver-issue.txt"; + + InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propFileName); + + if (inputStream != null) { + prop.load(inputStream); + } else { + throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath"); + } + + + SvcLogicContext ctx = new SvcLogicContext(); + + Map<String, String> data = new HashMap<String, String>(); + + Enumeration keys = prop.keys(); + while(keys.hasMoreElements()) { + String key = keys.nextElement().toString(); + String value = prop.getProperty(key); + data.put(key, value); + } + + QueryStatus response = client.update("vserver", "vserver-id = '59567c27-706e-4f41-953f-b5d3a525812f' AND tenant-id = 'USITUCAB3NJ0101UJZZ01::uCPE-VMS'", data, "aaiTest", ctx); + + assertTrue(response == QueryStatus.SUCCESS); + LOG.info("AAIResponse: " + response.toString()); + } + catch (Exception e) + { + LOG.error("Caught exception", e); + fail("Caught exception"); + } + } + +// @Test + public void R1510Test03RequestVCloudRegionDataRequest() + { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try + { + SvcLogicContext ctx = new SvcLogicContext(); +// QueryStatus response = client.query("vserver", false, null, "tenant-id = '3220171995171220' AND vserver-id = '4b491df8-cf0e-4f08-88a2-133e82b63432'", "aaiTest", null, ctx); +// QueryStatus response = client.query("vserver", false, null, "vserver-name = 'bpsx0001vm001bps001'", "aaiTest", null, ctx); + QueryStatus response = client.query("cloud-region", false, null, + "depth = '0' AND cloud-region.cloud-owner = 'att-aic' AND cloud-region.cloud-region-id = 'mtn6'" + , "aaiTest", null, ctx); + + assertTrue(response == QueryStatus.SUCCESS); + LOG.info("AAIResponse: " + response.toString()); + } + catch (Exception e) + { + LOG.error("Caught exception", e); + fail("Caught exception"); + } + } + +// @Test + public void R1510Test03RequestVCloudRegionData1Request() + { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try + { + List<String> data = new LinkedList<String>(); + data.add("depth = 0"); + data.add("cloud-region.cloud-owner = 'att-aic'"); + data.add("cloud-region.cloud-region-id = 'mtn6'"); + + + SvcLogicContext ctx = new SvcLogicContext(); + QueryStatus response = client.query("cloud-region", false, null, StringUtils.join(data, " AND ") +// "depth = '0' AND cloud-region.cloud-owner = 'att-aic' AND cloud-region.cloud-region-id = 'mtn6'" + , "aaiTest", null, ctx); + + assertTrue(response == QueryStatus.SUCCESS); + LOG.info("AAIResponse: " + response.toString()); + } + catch (Exception e) + { + LOG.error("Caught exception", e); + fail("Caught exception"); + } + } + + @Test + public void R1510Test03RequestVCloudRegionData2Request() + { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try + { + Map<String, String> nameValues = new HashMap<String, String>(); + nameValues.put("depth","0"); + nameValues.put("cloud-region.cloud-owner", "att-aic"); + nameValues.put("cloud-region.cloud-region-id","mtn6"); + + AAIRequest request = AAIRequest.createRequest("cloud-region", nameValues); + + for(String key : nameValues.keySet()) { + request.addRequestProperty(key, nameValues.get(key).toString()); + } + + String response = client.query(request); + AAIDatum datum = request.jsonStringToObject(response); + +// assertTrue(response == QueryStatus.SUCCESS); + LOG.info("AAIResponse: " + datum.toString()); + } + catch (Exception e) + { + LOG.error("Caught exception", e); + } + } +} diff --git a/aai-service/provider/src/test/resources/aaiclient.properties b/aai-service/provider/src/test/resources/aaiclient.properties index fb9a52feb..84d851a41 100755 --- a/aai-service/provider/src/test/resources/aaiclient.properties +++ b/aai-service/provider/src/test/resources/aaiclient.properties @@ -8,9 +8,9 @@ # 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. @@ -40,8 +40,8 @@ org.onap.ccsdk.sli.adaptors.aai.application=CCSDK # # Configuration file for A&AI Client # -#org.onap.ccsdk.sli.adaptors.aai.uri=https://aai.api.simpledemo.openecomp.org:8443 -org.onap.ccsdk.sli.adaptors.aai.uri=https://aai-int2.test.att.com:8443 +org.onap.ccsdk.sli.adaptors.aai.uri=https://aai.api.simpledemo.openecomp.org:8443 +#org.onap.ccsdk.sli.adaptors.aai.uri=https://aai-int2.test.att.com:8443 # connection.timeout=60000 diff --git a/aai-service/provider/src/test/resources/json/linterfaceJson.txt b/aai-service/provider/src/test/resources/json/linterfaceJson.txt new file mode 100755 index 000000000..22c8db1ee --- /dev/null +++ b/aai-service/provider/src/test/resources/json/linterfaceJson.txt @@ -0,0 +1,43 @@ + { + "interface-name": "example-interface-name-val-1600", + "interface-role": "example-interface-role-val-1600", + "v6-wan-link-ip": "example-v6-wan-link-ip-val-1600", + "resource-version": "1450729537", + "vlans": { + "vlan": [ + { + "vlan-interface": "example-vlan-interface-val-7133", + "vlan-id-inner": 1318, + "vlan-id-outer": 244, + "resource-version": "1450729537", + "relationship-list": { + + }, + "l3-interface-ipv4-address-list": [ + { + "l3-interface-ipv4-address": "example-l3-interface-ipv4-address-val-9533", + "l3-interface-ipv4-prefix-length": 3013, + "vlan-id-inner": 7150, + "vlan-id-outer": 1027, + "resource-version": "1450729537", + "relationship-list": { + + } + } + ], + "l3-interface-ipv6-address-list": [ + { + "l3-interface-ipv6-address": "example-l3-interface-ipv6-address-val-7149", + "l3-interface-ipv6-prefix-length": 4538, + "vlan-id-inner": 8271, + "vlan-id-outer": 8990, + "resource-version": "1450729537", + "relationship-list": { + + } + } + ] + } + ] + } + }
\ No newline at end of file diff --git a/aai-service/provider/src/test/resources/testCommands.txt b/aai-service/provider/src/test/resources/testCommands.txt new file mode 100644 index 000000000..d19b8d306 --- /dev/null +++ b/aai-service/provider/src/test/resources/testCommands.txt @@ -0,0 +1 @@ +query|generic-vnf|generic-vnf.vnf-id:assign:value:adb28ac0-a260-4b7d-9ce5-adf15733c458
\ No newline at end of file |