diff options
author | Jessica Wagantall <jwagantall@linuxfoundation.org> | 2020-12-01 11:25:35 -0800 |
---|---|---|
committer | Jessica Wagantall <jwagantall@linuxfoundation.org> | 2020-12-01 11:25:35 -0800 |
commit | 5d2eab72fc4442f14108b41800cec88126913823 (patch) | |
tree | 11d79f8dde95d08e55dbdd4c29c7c3d20dd30ba6 /aai-service/provider/src/test | |
parent | 4f3b3ba8e7a38f008cd78c19df4b40e37ff86aa8 (diff) | |
parent | 2173e3e37bbb7648b97bcdfa734508686f176727 (diff) |
Merge branch 'master' of /home/jwagantall/linuxfoundation/onap/IT-21112/sli-adaptors
Signed-off-by: Jessica Wagantall <jwagantall@linuxfoundation.org>
Diffstat (limited to 'aai-service/provider/src/test')
37 files changed, 4478 insertions, 0 deletions
diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AAIClientRESTExecutorTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AAIClientRESTExecutorTest.java new file mode 100644 index 000000000..f60b2da64 --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AAIClientRESTExecutorTest.java @@ -0,0 +1,126 @@ +package org.onap.ccsdk.sli.adaptors.aai; + +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.assertNotNull; + +public class AAIClientRESTExecutorTest { + + private static AAIClientRESTExecutor aaiExecute; + private static AAIService aaiService; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + Properties properties = new Properties(); + properties.setProperty("org.onap.ccsdk.sli.adaptors.aai.host.certificate.ignore", "true"); + properties.setProperty("org.onap.ccsdk.sli.adaptors.aai.client.name", "SDNC"); + properties.setProperty("org.onap.ccsdk.sli.adaptors.aai.client.psswd", "SDNC"); + properties.setProperty("org.onap.ccsdk.sli.adaptors.aai.application", "CCSDK"); + properties.setProperty("org.onap.ccsdk.sli.adaptors.aai.uri", "http://localhost:8181"); + properties.setProperty("connection.timeout", "60000"); + properties.setProperty("read.timeout", "60000"); + aaiExecute = new AAIClientRESTExecutor(properties); + aaiService = new AAIService(properties); + + + } + + @Test + public void testGet() { + Map<String, String> nameValues = new HashMap<>(); + nameValues.put("generic-vnf.vnf-id", "vnf-001"); + AAIRequest request = AAIRequest.createRequest("generic-vnf", nameValues); + try { + aaiExecute.get(request); + } catch (AAIServiceException e) { + } + assert(true); + assertNotNull(nameValues); + } + + @Test + public void testPost() { + Map<String, String> nameValues = new HashMap<>(); + nameValues.put("generic-vnf.vnf-id", "vnf-001"); + AAIRequest request = AAIRequest.createRequest("generic-vnf", nameValues); + try { + aaiExecute.get(request); + } catch (AAIServiceException e) { + } + assert(true); + assertNotNull(nameValues); + } + + @Test + public void testDelete() { + Map<String, String> nameValues = new HashMap<>(); + nameValues.put("generic-vnf.vnf-id", "vnf-001"); + AAIRequest request = AAIRequest.createRequest("generic-vnf", nameValues); + try { + aaiExecute.get(request); + } catch (AAIServiceException e) { + } + assert(true); + assertNotNull(nameValues); + } + + @Test + public void testQuery() { + Map<String, String> nameValues = new HashMap<>(); + nameValues.put("generic-vnf.vnf-id", "vnf-001"); + AAIRequest request = AAIRequest.createRequest("generic-vnf", nameValues); + try { + aaiExecute.get(request); + } catch (AAIServiceException e) { + } + assert(true); + assertNotNull(nameValues); + } + + @Test + public void testPatch() { + Map<String, String> nameValues = new HashMap<>(); + nameValues.put("generic-vnf.vnf-id", "vnf-001"); + AAIRequest request = AAIRequest.createRequest("generic-vnf", nameValues); + try { + aaiExecute.patch(request, "1234567890"); + } catch (AAIServiceException e) { + } + assert(true); + assertNotNull(nameValues); + } + + + + @Test + public void testLOGwriteFirstTrace() { + try { + aaiExecute.LOGwriteFirstTrace("GET", null); + } catch (Exception e) { + } + assert(true); + } + + @Test + public void testLOGwriteDateTrace() { + try { + aaiExecute.LOGwriteDateTrace("GET", "<----- test data ------>"); + } catch (Exception e) { + } + assert(true); + } + + @Test + public void testLOGwriteEndingTrace() { + try { + aaiExecute.LOGwriteEndingTrace(200, "GET", "<----- test data ------>"); + } catch (Exception e) { + } + assert(true); + } + +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceProviderTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceProviderTest.java new file mode 100644 index 000000000..bfe3738e0 --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceProviderTest.java @@ -0,0 +1,31 @@ +package org.onap.ccsdk.sli.adaptors.aai; + +import org.junit.BeforeClass; +import org.junit.Test; + +public class AAIServiceProviderTest { + + private static AAIServiceProvider provider = null; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + } + + @Test + public void testAAIServiceProvider() { + provider = new AAIServiceProvider(); + } + + @Test + public void testGetProperties() { + provider.getProperties(); + assert(true); + } + + @Test + public void testDeterminePropertiesFile() { + provider.determinePropertiesFile(); + assert(true); + } + +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceTest.java new file mode 100755 index 000000000..079c76cbd --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceTest.java @@ -0,0 +1,212 @@ +/*- + * ============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.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.ProtocolException; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.net.ssl.HttpsURLConnection; +import javax.ws.rs.HttpMethod; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.runners.MockitoJUnitRunner; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import org.onap.aai.inventory.v21.*; + +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; +import org.onap.ccsdk.sli.adaptors.aai.AAIService.TransactionIdTracker; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +@RunWith(MockitoJUnitRunner.class) +public class AAIServiceTest { + private static AAIService aaiService = new AAIService( + AAIService.class.getResource(AAIService.AAICLIENT_PROPERTIES)); + + @Spy private AAIService aaiServiceSpy = new AAIService( + AAIService.class.getResource(AAIService.AAICLIENT_PROPERTIES)); + + @Mock private HttpsURLConnection connMock; + + // @Test + public void existsInvalidResource_shouldReturnFailure() throws MalformedURLException, Exception { + QueryStatus queryStatus = aaiServiceSpy.exists("InvalidResource", null, null, null); + assertEquals(QueryStatus.FAILURE, queryStatus); + } + +// @Test + public void existsGetPserverByCallBackUrl_shouldReturnSuccess() throws MalformedURLException, Exception { + String key = "https://aai.api.simpledemo.onap.org:8443/aai/v11/cloud-infrastructure/pservers/pserver/chcil129snd"; + String fileLocation = "json/pserverJson.txt"; + SvcLogicContext ctx = new SvcLogicContext(); + setConnMock(); + + when(aaiServiceSpy.getConfiguredConnection(new URL(key), HttpMethod.GET)).thenReturn(connMock); + when(connMock.getResponseCode()).thenReturn(200); + when(connMock.getInputStream()).thenReturn(getClass().getClassLoader().getResourceAsStream(fileLocation)); + + QueryStatus queryStatus = aaiServiceSpy.exists("pserver", key, "prefix.", ctx); + + assertEquals(QueryStatus.SUCCESS, queryStatus); + } + +// @Test + public void existsGetPserverByCallBackUrl_throwsExceptionAndReturnsFailure() + throws MalformedURLException, Exception { + String key = "https://aai.api.simpledemo.onap.org:8443/aai/v11/cloud-infrastructure/pservers/pserver/chcil129snd"; + String fileLocation = "json/pserverJson.txt"; + SvcLogicContext ctx = new SvcLogicContext(); + setConnMock(); + + when(aaiServiceSpy.getConfiguredConnection(new URL(key), HttpMethod.GET)).thenReturn(connMock); + when(connMock.getResponseCode()).thenReturn(200); + when(connMock.getInputStream()).thenReturn(getClass().getClassLoader().getResourceAsStream(fileLocation)); + + when(aaiServiceSpy.dataChangeRequestAaiData(key, Pserver.class)).thenThrow( + new AAIServiceException("testException")); + + QueryStatus queryStatus = aaiServiceSpy.exists("pserver", key, "prefix.", ctx); + + assertEquals(QueryStatus.FAILURE, queryStatus); + } + +// @Test + public void pserverDataChangeRequestData_shouldSucceed() throws Exception { + String fileLocation = "json/pserverJson.txt"; + String url = "https://aai.api.simpledemo.onap.org:8443/aai/v11/cloud-infrastructure/pservers/pserver/chcil129snd"; + setConnMock(); + + when(aaiServiceSpy.getConfiguredConnection(new URL(url), HttpMethod.GET)).thenReturn(connMock); + when(connMock.getResponseCode()).thenReturn(200); + when(connMock.getInputStream()).thenReturn(getClass().getClassLoader().getResourceAsStream(fileLocation)); + + Pserver pserver = aaiServiceSpy.dataChangeRequestAaiData(url, Pserver.class); + + assertEquals("chcil129snd", pserver.getHostname()); + } + +// @Test + public void pserverDataChangeRequestData_shouldReturnNullFor404() throws Exception { + String fileLocation = "json/pserverJson.txt"; + String url = "https://aai.api.simpledemo.onap.org:8443/aai/v11/cloud-infrastructure/pservers/pserver/chcil129snd"; + setConnMock(); + + when(aaiServiceSpy.getConfiguredConnection(new URL(url), HttpMethod.GET)).thenReturn(connMock); + when(connMock.getResponseCode()).thenReturn(404); + when(connMock.getErrorStream()).thenReturn(getClass().getClassLoader().getResourceAsStream(fileLocation)); + + Pserver pserver = aaiServiceSpy.dataChangeRequestAaiData(url, Pserver.class); + + assertEquals(null, pserver); + } + + @Test(expected = AAIServiceException.class) + public void dataChangeRequestData_throwsAAIServiceException() throws Exception { + String fileLocation = "json/pserverJson.txt"; + String url = "https://aai.api.simpledemo.onap.org:8443/aai/v11/cloud-infrastructure/pservers/pserver/chcil129snd"; + setConnMock(); + + // The following lines are not needed and cause latest version of mockito to throw an exception +// when(aaiServiceSpy.getConfiguredConnection(new URL(url), HttpMethod.GET)).thenReturn(connMock); +// when(connMock.getResponseCode()).thenReturn(500); +// when(connMock.getInputStream()).thenReturn(getClass().getClassLoader().getResourceAsStream(fileLocation)); + + aaiServiceSpy.dataChangeRequestAaiData(url, Class.class); + } + + public String readFileToString(String fileName) throws IOException, URISyntaxException { + URL url = AAIServiceTest.class.getResource(fileName); + Path resPath = Paths.get(url.toURI()); + + return new String(Files.readAllBytes(resPath), "UTF8"); + } + + public <T> T getObjectFromJson(String text, Class<T> type) + throws JsonParseException, JsonMappingException, IOException { + ObjectMapper mapper = AAIService.getObjectMapper(); + + return type.cast(mapper.readValue(text, type)); + } + + private void setConnMock() throws ProtocolException { + // Set up the connection properties + connMock.setRequestProperty("Connection", "close"); + connMock.setDoInput(true); + connMock.setDoOutput(true); + connMock.setUseCaches(false); + connMock.setConnectTimeout(1000); + connMock.setReadTimeout(1000); + connMock.setRequestMethod(HttpMethod.GET); + connMock.setRequestProperty("Accept", "application/json"); + connMock.setRequestProperty("Content-Type", "application/json"); + connMock.setRequestProperty("X-FromAppId", "testId"); + connMock.setRequestProperty("X-TransactionId", TransactionIdTracker.getNextTransactionId()); + } + + @Test + public void testSetStatusMessage_shouldSucceed() throws SvcLogicException, MalformedURLException { + SvcLogicContext ctx = new SvcLogicContext(); + Map<String, String> parameters = new HashMap<String, String>(); + + parameters.put("key1", "ActivateSubnet failure, need to manually activate in EIPAM."); + aaiService.setStatusMethod(parameters, ctx); + + Pattern r8601 = Pattern.compile( + "(\\d{4})-(\\d{2})-(\\d{2})T((\\d{2}):(\\d{2}):(\\d{2}))Z"); + Matcher isoDate = r8601.matcher(ctx.getAttribute("aai-summary-status-message")); + + assertTrue(isoDate.lookingAt()); + + assertTrue(ctx.getAttribute("aai-summary-status-message") + .contains("ActivateSubnet failure, need to manually activate in EIPAM.")); + } + + @Test(expected = SvcLogicException.class) + public void testSetStatusMessage_nullContext() throws SvcLogicException, MalformedURLException { + SvcLogicContext ctx = null; + Map<String, String> parameters = new HashMap<String, String>(); + + parameters.put("key1", "ActivateSubnet failure, need to manually activate in EIPAM."); + aaiService.setStatusMethod(parameters, ctx); + } +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/ActionUpdateTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/ActionUpdateTest.java new file mode 100755 index 000000000..64f9b45ef --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/ActionUpdateTest.java @@ -0,0 +1,44 @@ +package org.onap.ccsdk.sli.adaptors.aai; + +import static org.junit.Assert.*; + +import java.util.ArrayList; + +import org.onap.ccsdk.sli.adaptors.aai.update.Action; +import org.onap.ccsdk.sli.adaptors.aai.update.ActionDatum; +import org.junit.Test; + +public class ActionUpdateTest { + @Test + public void getActionData() throws Exception { + final Action resolver = new Action(); + assertNotNull(resolver.getActionData()); + } + + @Test + public void setActionData() throws Exception { + final Action resolver = new Action(); + resolver.setActionData( new ArrayList<ActionDatum>()); + assertNotNull(resolver); + } + + @Test + public void setActionType() throws Exception { + final Action resolver = new Action(); + resolver.setActionType("create"); + assertEquals("create", resolver.getActionType()); + } + + @Test + public void getAdditionalProperties() throws Exception { + final Action resolver = new Action(); + assertNotNull(resolver.getAdditionalProperties()); + } + + @Test + public void setAdditionalProperty() throws Exception { + final Action resolver = new Action(); + resolver.setAdditionalProperty("outcome", "success"); + assertEquals("success", resolver.getAdditionalProperties().get("outcome")); + } +}
\ No newline at end of file diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AutoGeneratedRegressionTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AutoGeneratedRegressionTest.java new file mode 100755 index 000000000..5ac503ff5 --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/AutoGeneratedRegressionTest.java @@ -0,0 +1,906 @@ +/*- + * ============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.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.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; +import org.onap.aai.inventory.v21.GenericVnf; +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 array keyStructure can be tmpKey. + // options :assign:uuid:cache + // :cached + // :query:random + + + String localId = null; + + List<String> keys = new ArrayList<String>(); + String keyLine = null; + + for(String instruction : tmpKeys) { + String[] parts = instruction.split(":"); + String identifier = parts[0]; + String method = parts[2]; + + if(identifier.startsWith(resource)) { + localId = identifier; + } else if(identifier.startsWith("l-interface") && "l2-bridge-bgf".equals(resource)) { + localId = identifier; + } else if(identifier.startsWith("l-interface") && "l2-bridge-sbg".equals(resource)) { + localId = identifier; + } else if("nodes-query".equals(resource)) { + localId = identifier; + } + + switch(parts[1]) { + case "assign": + String postProcesss = parts[3]; + keyLine = processAssign(identifier, method, postProcesss); + if(keyLine != null && !keyLine.trim().isEmpty()) { + keys.add(keyLine); + } + break; + case "cached": + keyLine = processCached(identifier, method); + if(keyLine != null && !keyLine.trim().isEmpty()) { + keys.add(keyLine); + } + break; + } + + } + + List<String> x = Arrays.asList(localId.split("\\.")); + switch(action){ + case "save": + testAutoGeneratedSaveRequest(resource, keys, x.get(x.size() - 1), cache.get(localId)); + break; + case "update": + testAutoGeneratedUpdateRequest(resource, keys, x.get(x.size() - 1), cache.get(localId)); + break; + + case "query": + test03AutoGeneratedQueryRequest(resource, keys); + break; + case "delete": + test03AutoGeneratedDeleteRequest(resource, keys); + break; + } + } + + LOG.info("done"); + } + + + public void testAutoGeneratedSaveRequest(String resource, List<String> requestKeys, String identifier, String idValue) { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try + { + Map<String, String> nameValues = keyToHashMap(StringUtils.join(requestKeys, " AND "), new SvcLogicContext()); + AAIRequest request = AAIRequest.createRequest(resource, nameValues); + Class<AAIDatum> resourceClass = (Class<AAIDatum>) (request==null ? GenericVnf.class : request.getModelClass()); + + Map<String, String> data = new HashMap<String, String>(); + + for(Field field : resourceClass.getDeclaredFields()) { + String type = field.getType().getName(); + switch(type){ + case "bool": + case "boolean": + type = Boolean.class.getName(); + break; + case "int": + type = Integer.class.getName(); + break; + case "long": + type = Long.class.getName(); + break; + + } + if(type.startsWith("java.lang.")){ + Annotation[] fieldAnnotations = field.getAnnotations(); + for(int i = 0; i < fieldAnnotations.length; i++) { + Annotation a = fieldAnnotations[i]; + if(a instanceof JsonProperty){ + JsonProperty pa = (JsonProperty)a; + String name = pa.value(); + String value; + switch(type) { + case "java.lang.Integer": + case "java.lang.Long": + value = RandomStringUtils.random(6, false, true); + break; + case "java.lang.Boolean": + value = "false"; + break; + default: + if(name.equals(identifier)) { + value = idValue; + } else { + value = RandomStringUtils.random(10, true, false); + } + } + data.put(name, value); + } else + if(a instanceof javax.xml.bind.annotation.XmlElement) { + XmlElement xe = (XmlElement)a; + String name = xe.name(); + if("model-version-id".equals(name)) { + continue; + } + if("model-invariant-id".equals(name)) { + continue; + } + if("link-type".equals(name)){ + data.put(name, "roadmTail"); + continue; + } + if("operational-status".equals(name)){ + data.put(name, "available"); + continue; + } + if(name.equals(identifier)) { + data.put(name, idValue); + continue; + } + + String value; + switch(type) { + case "java.lang.Integer": + case "java.lang.Long": + value = RandomStringUtils.random(6, false, true); + break; + case "java.lang.Boolean": + value = "false"; + break; + default: + if(name.equals(identifier)) { + value = idValue; + } else { + value = RandomStringUtils.random(10, true, false); + } + } + data.put(name, value); + } + } + } + } + + SvcLogicContext ctx = new SvcLogicContext(); + + data.remove("resource-version"); + + QueryStatus resp = null; + + //(String resource, boolean force, boolean localOnly, String key, Map<String, String> parms, String prefix, SvcLogicContext ctx) + resp = client.save(resource, false, false, StringUtils.join(requestKeys, " AND "), data, "aaidata", ctx); + if(resp == QueryStatus.SUCCESS) { + LOG.info(String.format("Save %s successfull", resource)); + } else { + LOG.info(String.format("Save %s failed due to : %s", resource, ctx.getAttribute("aaidata.error.message"))); + } + } + catch (Throwable e) + { + LOG.error("Caught exception", e); + fail("Caught exception"); + } + } + + public void test03AutoGeneratedQueryRequest(String resource, List<String> requestKeys) { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + SvcLogicContext ctx = new SvcLogicContext(); + try + { + + QueryStatus response = null; + + response = client.query(resource, false, null, StringUtils.join(requestKeys, " AND "), "aaiTest", null, ctx); + if(response == QueryStatus.SUCCESS) { + LOG.info(String.format("Query %s successfull", resource)); + Set<String> tokens = ctx.getAttributeKeySet(); + Map<String, String> reponseData = new HashMap<String, String>(); + + String responsePrefix = String.format("%s", "aaiTest"); + + for(String token : tokens) { + if(token.startsWith(responsePrefix)){ + reponseData.put(token, ctx.getAttribute(token)); + } else { + LOG.info(String.format("%s = ", token, ctx.getAttribute(token))); + } + } + + LOG.info("AAIResponse: " + response.toString()); + assertTrue("AAIRequest:"+resource, reponseData.size() > 0); + } else { + LOG.info(String.format("Query %s failed due to : %s", resource, ctx.getAttribute("aaidata.error.message"))); + assert(false); + } + } + catch (Throwable e) + { + LOG.error("Caught exception", e); + } + } + + + public void test03AutoGeneratedDeleteRequest(String resource, List<String> requestKeys) { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try + { + SvcLogicContext ctx = new SvcLogicContext(); + + QueryStatus response = null; + + response = client.delete(resource, StringUtils.join(requestKeys, " AND "), ctx); + if(response == QueryStatus.SUCCESS) { + LOG.info(String.format("Delete %s successfull", resource)); + } else { + LOG.info(String.format("Delete %s failed due to : %s", resource, ctx.getAttribute("aaiDelete.error.message"))); + } + } + catch (Throwable e) + { + LOG.error("Caught exception", e); + fail("Caught exception"); + } + } + + public void testAutoGeneratedUpdateRequest(String resource, List<String> requestKeys, String identifier, String idValue) { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try + { + Map<String, String> nameValues = keyToHashMap(StringUtils.join(requestKeys, " AND "), new SvcLogicContext()); + AAIRequest request = AAIRequest.createRequest(resource, nameValues); + Class<AAIDatum> resourceClass = (Class<AAIDatum>) (request==null ? GenericVnf.class : request.getModelClass()); + + Map<String, String> data = new HashMap<String, String>(); + + boolean skipFirst = true; + boolean breakLoop = false; + for(Field field : resourceClass.getDeclaredFields()) { + if(skipFirst){ + skipFirst = false; + continue; + } + if(breakLoop){ + break; + } + String type = field.getType().getName(); + if(type.startsWith("java.lang.")){ + Annotation[] fieldAnnotations = field.getAnnotations(); + for(int i = 0; i < fieldAnnotations.length; i++) { + Annotation a = fieldAnnotations[i]; + if(a instanceof JsonProperty){ + JsonProperty pa = (JsonProperty)a; + String name = pa.value(); + String value; + switch(type) { + case "java.lang.Integer": + case "java.lang.Long": + value = RandomStringUtils.random(6, false, true); + break; + case "java.lang.Boolean": + value = "false"; + break; + default: + if(name.equals(identifier)) { + value = idValue; + } else { + value = RandomStringUtils.random(10, true, false); + } + } + data.put(name, value); + breakLoop = true; + } else + if(a instanceof javax.xml.bind.annotation.XmlElement) { + XmlElement xe = (XmlElement)a; + String name = xe.name(); + if("link-type".equals(name)){ + data.put(name, "roadmTail"); + continue; + } + if("operational-status".equals(name)){ + data.put(name, "available"); + continue; + } + String value; + switch(type) { + case "java.lang.Integer": + case "java.lang.Long": + value = RandomStringUtils.random(6, false, true); + break; + case "java.lang.Boolean": + value = "false"; + break; + default: + if(name.equals(identifier)) { + value = idValue; + } else { + value = RandomStringUtils.random(10, true, false); + } + } + data.put(name, value); + breakLoop = true; + } + } + } + } + + SvcLogicContext ctx = new SvcLogicContext(); + + data.remove("resource-version"); + + QueryStatus resp = null; + + //client.update("ipsec-configuration", "ipsec-configuration.ipsec-configuration-id = 'testConfigurationId01'", data, "aaiTest", ctx); + resp = client.update(resource, StringUtils.join(requestKeys, " AND "), data, "aaidata", ctx); + if(resp == QueryStatus.SUCCESS) { + LOG.info(String.format("Update %s successfull", resource)); + } else { + LOG.info(String.format("Update %s failed due to : %s", resource, ctx.getAttribute("aaidata.error.message"))); + } + + } + catch (Throwable e) + { + LOG.error("Caught exception", e); + fail("Caught exception"); + } + } + + static ArrayList<Method> findSetters(Class<?> c) { + ArrayList<Method> list = new ArrayList<Method>(); + Method[] methods = c.getDeclaredMethods(); + for (Method method : methods) + if (isGetter(method)) + list.add(method); + return list; + } + + + public static boolean isGetter(Method method) { + if (Modifier.isPublic(method.getModifiers()) && + method.getParameterTypes().length == 0) { + if (method.getName().matches("^get[A-Z].*") && + !method.getReturnType().equals(void.class)) + return true; + if (method.getName().matches("^is[A-Z].*") && + method.getReturnType().equals(boolean.class)) + return true; + } + return false; + } + + public static boolean isSetter(Method method) { + return Modifier.isPublic(method.getModifiers()) && + method.getReturnType().equals(void.class) && + method.getParameterTypes().length == 1 && + method.getName().matches("^set[A-Z].*"); + } + + private String processAssign(String identifier, String method, String postProcess) { + String value = null; + if("uuid".equals(method)) { + value = UUID.randomUUID().toString(); + } + + if("cache".equals(postProcess)) { + cache.put(identifier, value); + } + + if("value".equals(method)) { + cache.put(identifier, postProcess); + value = postProcess; + } + + String key = String.format("%s = '%s'", identifier, value); + return key; + } + + private String processCached(String identifier, String method) { + String value = cache.get(identifier); + + String key = String.format("%s = '%s'", identifier, value); + return key; + } + + protected HashMap<String,String> keyToHashMap(String key, SvcLogicContext ctx) { + if (key == null) { + return (null); + } + + LOG.debug("Converting key [" + key + "] to where clause"); + + if (key.startsWith("'") && key.endsWith("'")) { + key = key.substring(1, key.length() - 1); + + LOG.debug("Stripped outer single quotes - key is now [" + key + "]"); + } + + String[] keyTerms = key.split("\\s+"); + + String term1 = null; + String op = null; + String term2 = null; + HashMap<String, String> results = new HashMap<String, String>(); + + for (int i = 0; i < keyTerms.length; i++) { + if (term1 == null) { + if ("and".equalsIgnoreCase(keyTerms[i]) + || "or".equalsIgnoreCase(keyTerms[i])) { + // Skip over ADD/OR + } else { + term1 = resolveTerm(keyTerms[i], ctx); + } + } else if (op == null) { + if ("==".equals(keyTerms[i])) { + op = "="; + } else { + op = keyTerms[i]; + } + } else { + term2 = resolveTerm(keyTerms[i], ctx); + term2 = term2.trim().replace("'", "").replace("$", "").replace("'", ""); + results.put(term1, term2); + + term1 = null; + op = null; + term2 = null; + } + } + + return (results); + } + + private String resolveTerm(String term, SvcLogicContext ctx) { + if (term == null) { + return (null); + } + + LOG.debug("resolveTerm: term is " + term); + + if (term.startsWith("$") && (ctx != null)) { + // Resolve any index variables. + + return ("'" + resolveCtxVariable(term.substring(1), ctx) + "'"); + } else if (term.startsWith("'") || term.startsWith("\"")) { + return (term); + } else { + return (term.replaceAll("-", "_")); + + } + + } + + private String resolveCtxVariable(String ctxVarName, SvcLogicContext ctx) { + + if (ctxVarName.indexOf('[') == -1) { + // Ctx variable contains no arrays + return (ctx.getAttribute(ctxVarName)); + } + + // Resolve any array references + StringBuffer sbuff = new StringBuffer(); + String[] ctxVarParts = ctxVarName.split("\\["); + sbuff.append(ctxVarParts[0]); + for (int i = 1; i < ctxVarParts.length; i++) { + if (ctxVarParts[i].startsWith("$")) { + int endBracketLoc = ctxVarParts[i].indexOf("]"); + if (endBracketLoc == -1) { + // Missing end bracket ... give up parsing + LOG.warn("Variable reference " + ctxVarName + + " seems to be missing a ']'"); + return (ctx.getAttribute(ctxVarName)); + } + + String idxVarName = ctxVarParts[i].substring(1, endBracketLoc); + String remainder = ctxVarParts[i].substring(endBracketLoc); + + sbuff.append("["); + sbuff.append(ctx.getAttribute(idxVarName)); + sbuff.append(remainder); + + } else { + // Index is not a variable reference + sbuff.append("["); + sbuff.append(ctxVarParts[i]); + } + } + + return (ctx.getAttribute(sbuff.toString())); + } + +// @Test + public void test90QueryTenantRequest() + { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + URL url; + + try { + url = client.requestVserverURLNodeQuery("bpsx0001vm001bps001"); + url = new URL("https://mtanjv9aaas03.aic.cip.att.com:8443/aai/v4/cloud-infrastructure/tenants/tenant/6b012c07bdf1427190ae58f794a86344/vservers/vserver/5acfe828-82e9-swgk092815-13-4d2c-85bb-9c2c1fafcce6"); + client.getTenantIdFromVserverUrl(url); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + 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/CustomQueryRequestTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/CustomQueryRequestTest.java new file mode 100644 index 000000000..955f5c4a1 --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/CustomQueryRequestTest.java @@ -0,0 +1,117 @@ +/*- + * ============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 java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URISyntaxException; +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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class CustomQueryRequestTest { + + private static final Logger LOG = LoggerFactory.getLogger(CustomQueryRequestTest.class); + + private static AAIRequest request; + private static AAIService aaiService; + + @BeforeClass + public static void setUp() throws Exception { + aaiService = new AAIService(AAIService.class.getResource(AAIService.AAICLIENT_PROPERTIES)); + Map<String, String> nameValues = new HashMap<>(); + nameValues.put("generic-vnf.vnf-id", "vnf-001"); + request = AAIRequest.createRequest("generic-vnf", nameValues); + LOG.info("\nEchoRequestTest.setUp\n"); + } + + @AfterClass + public static void tearDown() throws Exception { + request = null; + LOG.info("----------------------- EchoRequestTest.tearDown -----------------------"); + } + + @Test + public void runGetRequestUrlTest() { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + URL url; + try { + url = request.getRequestUrl("GET", null); + assertNotNull(url); + } catch (UnsupportedEncodingException | MalformedURLException | URISyntaxException 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/EchoRequestTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/EchoRequestTest.java new file mode 100755 index 000000000..3e0a72f3a --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/EchoRequestTest.java @@ -0,0 +1,136 @@ +/*- + * ============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 java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.net.URL; + +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 EchoRequestTest { + + private static final Logger LOG = LoggerFactory.getLogger(EchoRequestTest.class); + + private static EchoRequest request; + private static AAIService aaiService; + + @BeforeClass + public static void setUp() throws Exception { + aaiService = new AAIService( + AAIService.class.getResource(AAIService.AAICLIENT_PROPERTIES)); + request = new EchoRequest(); + LOG.info("\nEchoRequestTest.setUp\n"); + } + + @AfterClass + public static void tearDown() throws Exception { + request = null; + LOG.info("----------------------- EchoRequestTest.tearDown -----------------------"); + } + + @Test + public void runGetRequestUrlTest() { + 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); + } + + } + +// @Test + public void EchoTest() { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + try + { + SvcLogicContext ctx = new SvcLogicContext(); + + QueryStatus resp = null; + +// (String resource, boolean localOnly, String select, String key, String prefix, String orderBy, SvcLogicContext ctx) + resp = aaiService.query("echo", false, null, "", "aaidata", null, ctx); + assert(resp == QueryStatus.SUCCESS); + } + catch (Throwable e) + { + LOG.error("Caught exception", e); +// fail("Caught exception"); + } + } +} 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..3ce8a6dc5 --- /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.URISyntaxException; +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.onap.aai.inventory.v21.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 | URISyntaxException 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/GenericVnfRequestTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/GenericVnfRequestTest.java new file mode 100644 index 000000000..062e02d1f --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/GenericVnfRequestTest.java @@ -0,0 +1,117 @@ +/*- + * ============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 java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URISyntaxException; +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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class GenericVnfRequestTest { + + private static final Logger LOG = LoggerFactory.getLogger(GenericVnfRequestTest.class); + + private static AAIRequest request; + private static AAIService aaiService; + + @BeforeClass + public static void setUp() throws Exception { + aaiService = new AAIService(AAIService.class.getResource(AAIService.AAICLIENT_PROPERTIES)); + Map<String, String> nameValues = new HashMap<>(); + nameValues.put("generic-vnf.vnf-id", "vnf-001"); + request = AAIRequest.createRequest("generic-vnf", nameValues); + LOG.info("\nEchoRequestTest.setUp\n"); + } + + @AfterClass + public static void tearDown() throws Exception { + request = null; + LOG.info("----------------------- EchoRequestTest.tearDown -----------------------"); + } + + @Test + public void runGetRequestUrlTest() { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + URL url; + try { + url = request.getRequestUrl("GET", null); + assertNotNull(url); + } catch (UnsupportedEncodingException | MalformedURLException | URISyntaxException 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/GenericVnfTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/GenericVnfTest.java new file mode 100755 index 000000000..5a594298f --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/GenericVnfTest.java @@ -0,0 +1,243 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.aai; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.UUID; + +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.AAIClient; +import org.onap.ccsdk.sli.adaptors.aai.AAIRequest; +import org.onap.ccsdk.sli.adaptors.aai.AAIService; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; +import org.onap.aai.inventory.v21.GenericVnf; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.databind.ObjectMapper; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class GenericVnfTest { + + private static final Logger LOG = LoggerFactory.getLogger(GenericVnfTest.class); + + protected static AAIClient client; + + @BeforeClass + public static void setUp() throws Exception { + Properties properties = new Properties(); + properties.setProperty("org.onap.ccsdk.sli.adaptors.aai.host.certificate.ignore", "true"); + properties.setProperty("org.onap.ccsdk.sli.adaptors.aai.client.name", "SDNC"); + properties.setProperty("org.onap.ccsdk.sli.adaptors.aai.client.psswd", "SDNC"); + properties.setProperty("org.onap.ccsdk.sli.adaptors.aai.application", "CCSDK"); + properties.setProperty("org.onap.ccsdk.sli.adaptors.aai.uri", "http://localhost:8181"); + properties.setProperty("connection.timeout", "60000"); + properties.setProperty("read.timeout", "60000"); + client = new AAIService(properties); + ((AAIService)client).setExecutor(new TestExecutor()); + LOG.info("\nTaicAAIResourceTest.setUp\n"); + } + + @AfterClass + public static void tearDown() throws Exception { + client = null; + LOG.info("----------------------- GenericVnfTest.tearDown -----------------------"); + } + + + @Test + public void test01SaveGenericVnf() { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + try + { + SvcLogicContext ctx = new SvcLogicContext(); + + String uuid = UUID.randomUUID().toString(); + Map<String, String> data = new HashMap<String, String>(); + data.put("vnf-id", uuid); + data.put("vnf-name" , "Demo-vmtn5scpx01"); + data.put("vnf-type", "asc_heat-int"); + data.put("service-id", "SDN-MOBILITY"); + data.put("equipment-role", "vSCP"); + data.put("orchestration-status", "active"); + data.put("heat-stack-id", "Devmtn5scpx04/" + data.get("vnf-id")); + data.put("in-maint", "false"); + data.put("is-closed-loop-disabled", "false"); + data.put("encrypted-access-flag","true"); + + QueryStatus resp = client.save("generic-vnf", false, false, "generic-vnf.vnf-id = '"+uuid+"'", data, "aaidata", ctx); + assertNotNull(ctx); + + } + catch (Throwable e) + { + + } + ; + } + + @Test + public void test02QueryGenericVnf() + { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try + { + List<String> keys = new ArrayList<String>(); + keys.add("vnf-id = 'ec14a84d-7b43-45ad-bb04-c12b74083648'"); + keys.add("depth = 'all'"); + + SvcLogicContext ctx = new SvcLogicContext(); + QueryStatus response = client.query("generic-vnf", false, null, StringUtils.join(keys, " AND "), "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 test03UpdateGenericVnf() { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + try + { + SvcLogicContext ctx = new SvcLogicContext(); + + String uuid = UUID.randomUUID().toString(); + Map<String, String> data = new HashMap<String, String>(); + data.put("service-id", "SDN-MOBILITY"); + data.put("equipment-role", "vSCP"); + data.put("orchestration-status", "active"); + data.put("heat-stack-id", "Devmtn5scpx04/" + data.get("vnf-id")); + data.put("in-maint", "false"); + data.put("is-closed-loop-disabled", "false"); + data.put("encrypted-access-flag","true"); + + QueryStatus resp = client.update("generic-vnf", "generic-vnf.vnf-id = '"+uuid+"'", data, "aaidata", ctx); + assertNotNull(uuid); + } + catch (Throwable e) + { + + } + } + + @Test + public void test04DeleteGenericVnf() + { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try + { + SvcLogicContext ctx = new SvcLogicContext(); + + List<String> keys = new ArrayList<String>(); + keys.add("generic-vnf.vnf-id = 'VNF-S7'"); + + QueryStatus response = client.delete("generic-vnf", StringUtils.join(keys, " AND "), ctx); + + assertTrue(response == QueryStatus.SUCCESS); + LOG.info("AAIResponse: " + response.toString()); + } + catch (Exception e) + { + LOG.error("Caught exception", e); + fail("Caught exception"); + } + } + + @Test + public void test05GetResource() + { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try + { + SvcLogicContext ctx = new SvcLogicContext(); + GenericVnf response = ((AAIService)client).getResource("/network/generic-vnfs/generic-vnf/ec14a84d-7b43-45ad-bb04-c12b74083648", GenericVnf.class); + + assertNotNull(response); + } + catch (Exception e) + { + + } + } + + static class TestExecutor implements AAIExecutorInterface { + private String data = "{\"vnf-id\":\"7324200933\",\"vnf-name\":\"vnfinst1m001\",\"vnf-type\":\"TestVnf\",\"service-id\":\"9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb\",\"equipment-role\":\"vTEST\",\"orchestration-status\":\"active\",\"in-maint\":false,\"is-closed-loop-disabled\":false,\"resource-version\":\"1520720941585\"}"; + + @Override + public String get(AAIRequest request) throws AAIServiceException { + return data; + } + + @Override + public String post(AAIRequest request) throws AAIServiceException { + return "success"; + } + + @Override + public Boolean delete(AAIRequest request, String resourceVersion) throws AAIServiceException { + return Boolean.TRUE; + } + + @Override + public Object query(AAIRequest request, Class clas) throws AAIServiceException { + ObjectMapper mapper = AAIService.getObjectMapper(); + try { + return mapper.readValue(data, GenericVnf.class); + } catch (IOException e) { + return new GenericVnf(); + } + } + + @Override + public Boolean patch(AAIRequest request, String resourceVersion) throws AAIServiceException { + return Boolean.TRUE; + } + + } +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/NodesQueryRequestTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/NodesQueryRequestTest.java new file mode 100644 index 000000000..e52f1de04 --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/NodesQueryRequestTest.java @@ -0,0 +1,88 @@ +package org.onap.ccsdk.sli.adaptors.aai; + +import static org.junit.Assert.assertNotNull; + +import java.net.URL; +import java.util.Properties; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class NodesQueryRequestTest { + + private static final Logger LOG = LoggerFactory.getLogger(NodesQueryRequestTest.class); + + private static NodesQueryRequest request; + + @BeforeClass + public static void setUp() throws Exception { + Properties properties = new Properties(); + properties.setProperty("org.onap.ccsdk.sli.adaptors.aai.host.certificate.ignore", "true"); + properties.setProperty("org.onap.ccsdk.sli.adaptors.aai.client.name", "SDNC"); + properties.setProperty("org.onap.ccsdk.sli.adaptors.aai.client.psswd", "SDNC"); + properties.setProperty("org.onap.ccsdk.sli.adaptors.aai.application", "CCSDK"); + properties.setProperty("org.onap.ccsdk.sli.adaptors.aai.uri", "http://localhost:8181"); + properties.setProperty("connection.timeout", "60000"); + properties.setProperty("read.timeout", "60000"); + properties.setProperty("org.onap.ccsdk.sli.adaptors.aai.query.nodes","/aai/v11/search/nodes-query?search-node-type={node-type}&filter={entity-identifier}:EQUALS:{entity-name}"); + + AAIRequest.configProperties = properties; + request = new NodesQueryRequest(); + LOG.info("\nEchoRequestTest.setUp\n"); + } + + @Test + public void runGetRequestUrlTest() { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try { + URL url = request.getRequestUrl("GET", null); + assertNotNull(url); + } catch (Exception exc) { + } + assert(true); + + } + + @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/PathCreationTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/PathCreationTest.java new file mode 100755 index 000000000..098414fd9 --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/PathCreationTest.java @@ -0,0 +1,204 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.aai; + +import static org.junit.Assert.fail; +import static org.junit.Assert.assertNotNull; + +import java.io.File; +import java.io.FileReader; +import java.net.URL; +import java.util.Arrays; +import java.util.BitSet; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.ListIterator; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.TreeSet; + +import org.apache.commons.lang3.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.AAIRequest; +import org.onap.ccsdk.sli.adaptors.aai.AAIService; +import org.onap.ccsdk.sli.adaptors.aai.AAIServiceUtils; +import org.onap.ccsdk.sli.adaptors.aai.EchoRequest; +import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class PathCreationTest { + + private static final Logger LOG = LoggerFactory.getLogger(PathCreationTest.class); + + private static AAIService aaiService; + + @BeforeClass + public static void setUp() throws Exception { + aaiService = new AAIService( + AAIService.class.getResource(AAIService.AAICLIENT_PROPERTIES)); + LOG.info("\nTaicAAIResourceTest.setUp\n"); + } + + @AfterClass + public static void tearDown() throws Exception { + LOG.info("----------------------- AAIResourceTest.tearDown -----------------------"); + } + + static Set<String> resourceNames = new TreeSet<String>(); + static Map<String, String> tagValues = new LinkedHashMap<String, String>(); + + + @Test + public void test01() + { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + try + { + File file = new File(this.getClass().getResource("/aai-path.properties").getFile()); + if(!file.exists()) { + fail("File does not exist"); + return; + } + FileReader reader = new FileReader(file); + + Properties properties = new Properties(); + properties.load(reader); + LOG.info("loaded " + properties.size()); + + Set<String> keys = properties.stringPropertyNames(); + + int index = 0; + + for(String key : keys) { + String[] tags = key.split("\\|"); + for(String tag : tags) { + if(!resourceNames.contains(tag)) { + resourceNames.add(tag); + tagValues.put(tag, Integer.toString(++index)); + } + } + BitSet bs = new BitSet(256); + for(String tag : tags) { + String value = tagValues.get(tag); + Integer bitIndex = Integer.parseInt(value) ; + bs.set(bitIndex); + } + String path = properties.getProperty(key); + LOG.info(String.format("bitset %s\t\t%s", bs.toString(), path)); + } + } + catch (Exception e) + { + LOG.error("Caught exception", e); + fail("Caught exception"); + } + } + + @Test + public void test02() { + try { + Map<String, String> nameValues = new HashMap<String, String> (); + nameValues.put("pserver.hostname", "USAUTOUFTIL0205UJZZ01"); + + AAIRequest request = AAIRequest.createRequest("pserver", nameValues); + request.addRequestProperty("pserver.hostname", "USAUTOUFTIL0205UJZZ01"); + + URL url = request.getRequestUrl("GET", null); + url.getPath(); + LOG.info("Received response"); + assertNotNull(nameValues); + + } catch(Exception exc) { + LOG.info("Caught exception", exc); + } + } + + @Test + public void test03() { + HashMap<String, String> nameValues = new HashMap<String, String>(); + + String path = +// "/aai/v11/network/site-pair-sets/site-pair-set/a3839637-575e-49b3-abb7-a003b0d4cc35/routing-instances/routing-instance/7f08a85e-716f-4bc2-a4f4-70801b07a5e6"; + "/aai/v10/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25"; + + String[] split = path.split("/"); + + LinkedList<String> list = new LinkedList<String>( Arrays.asList(split)); + ListIterator<String> it = list.listIterator(); + +// for(String tag : split) { + while(it.hasNext()) { + String tag = it.next(); + if(!tag.isEmpty()) { + if(resourceNames.contains(tag)){ + LOG.info(tag); + // get the class from tag + Class<? extends AAIDatum> clazz = null; + try { + clazz = AAIRequest.getClassFromResource(tag); + String fieldName = AAIServiceUtils.getPrimaryIdFromClass(clazz); + int nextIndex = it.nextIndex(); + + String value = list.get(nextIndex); + if(!StringUtils.isEmpty(value)){ + nameValues.put(String.format("%s.%s", tag, fieldName), value); + switch(tag) { + case "cloud-region": + case "entitlement": + case "license": + case "route-target": + case "service-capability": + case "ctag-pool": + String secondaryFieldName = AAIServiceUtils.getSecondaryIdFromClass(clazz); + if(secondaryFieldName != null) { + value = it.next(); + nameValues.put(String.format("%s.%s", tag, secondaryFieldName), value); + } + break; + default: + break; + } + } + } catch (Exception exc) { + LOG.info("Caught exception", exc); + } + // get id from class + // read the follwoing field + // create relationship data + } + } + } + LOG.info(nameValues.toString()); + assertNotNull(nameValues); + } +} 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..eb8dbc4a8 --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/RegressionTest.java @@ -0,0 +1,422 @@ +/*- + * ============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()); + assertNotNull(ctx); + } + 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()); + assertNotNull(ctx); + } + 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()); + assertNotNull(data); + } + 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()); + assertNotNull(data); + } + 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()); + assertNotNull(nameValues); + } + catch (Exception e) + { + LOG.error("Caught exception", e); + } + } +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/RelationshipRequestTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/RelationshipRequestTest.java new file mode 100644 index 000000000..858c9c599 --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/RelationshipRequestTest.java @@ -0,0 +1,118 @@ +/*- + * ============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 java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URISyntaxException; +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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class RelationshipRequestTest { + + private static final Logger LOG = LoggerFactory.getLogger(RelationshipRequestTest.class); + + private static AAIRequest request; + private static AAIService aaiService; + + @BeforeClass + public static void setUp() throws Exception { + aaiService = new AAIService(AAIService.class.getResource(AAIService.AAICLIENT_PROPERTIES)); + Map<String, String> nameValues = new HashMap<>(); + nameValues.put("generic-vnf.vnf-id", "vnf-001"); + AAIRequest tmpReq = AAIRequest.createRequest("generic-vnf", nameValues); + request = new RelationshipRequest(tmpReq); + LOG.info("\nEchoRequestTest.setUp\n"); + } + + @AfterClass + public static void tearDown() throws Exception { + request = null; + LOG.info("----------------------- EchoRequestTest.tearDown -----------------------"); + } + + @Test + public void runGetRequestUrlTest() { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + + URL url; + try { + url = request.getRequestUrl("GET", null); + assertNotNull(url); + } catch (UnsupportedEncodingException | MalformedURLException | URISyntaxException 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/RequestPathTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/RequestPathTest.java new file mode 100755 index 000000000..5ee35c647 --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/RequestPathTest.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.adaptors.aai; + +import static org.junit.Assert.assertNotNull; + +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class RequestPathTest { + + private static final Logger LOG = LoggerFactory.getLogger(RequestPathTest.class); + + protected static AAIClient client; + + @BeforeClass + public static void setUp() throws Exception { + URL url = AAIService.class.getResource(AAIService.AAICLIENT_PROPERTIES); + client = new AAIService(url); + LOG.info("\nTaicAAIResourceTest.setUp\n"); + } + + @AfterClass + public static void tearDown() throws Exception { + client = null; + LOG.info("----------------------- AAIResourceTest.tearDown -----------------------"); + } + + @Test + public void getRequestUrl() { + try { + Map<String, String> nameValues = new HashMap<String, String> (); + nameValues.put("generic-vnf.vnf-id","AABBCCDDEEFFGG0123"); + + AAIRequest request = AAIRequest.createRequest("service-instances", nameValues); + request.addRequestProperty("generic-vnf.vnf-id","AABBCCDDEEFFGG0123"); + + URL url = request.getRequestUrl("GET", null); + assertNotNull(url); + url.getPath(); + LOG.info("Received response"); + } catch(Exception exc) { + LOG.info("Caught exception", exc); + } + } +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/ErrorResponseTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/ErrorResponseTest.java new file mode 100644 index 000000000..6232ae34a --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/ErrorResponseTest.java @@ -0,0 +1,51 @@ +package org.onap.ccsdk.sli.adaptors.aai.data; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class ErrorResponseTest { + + ErrorResponse _erInstance; + protected RequestError _requestError; + protected Map<String, Object> _additionalProperties; + + @Before + public void setUp() throws Exception { + _erInstance = new ErrorResponse(); + _requestError = mock(RequestError.class); + _additionalProperties = new HashMap<String, Object>() {{ + put("prop1", "propvalue1"); + put("prop2", "propvalue2"); + }}; + } + + @After + public void tearDown() throws Exception { + _erInstance = null; + _requestError = null; + _additionalProperties = null; + } + + @Test + public void testSetRequestError() { + _erInstance.setRequestError(_requestError); + assertEquals(_erInstance.getRequestError(), _requestError); + } + + @Test + public void testSetAdditionalProperty() { + _erInstance.setAdditionalProperty("prop1", "propvalue1"); + _erInstance.setAdditionalProperty("prop2", "propvalue2"); + assertEquals(_erInstance.getAdditionalProperties(), _additionalProperties); + } + +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/RequestErrorTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/RequestErrorTest.java new file mode 100644 index 000000000..c752c7656 --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/RequestErrorTest.java @@ -0,0 +1,51 @@ +package org.onap.ccsdk.sli.adaptors.aai.data; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class RequestErrorTest { + + RequestError _reInstance; + protected ServiceException _serviceException; + protected Map<String, Object> _additionalProperties; + + @Before + public void setUp() throws Exception { + _reInstance = new RequestError(); + _serviceException = mock(ServiceException.class); + _additionalProperties = new HashMap<String, Object>() {{ + put("prop1", "propvalue1"); + put("prop2", "propvalue2"); + }}; + } + + @After + public void tearDown() throws Exception { + _reInstance = null; + _serviceException = null; + _additionalProperties = null; + } + + @Test + public void testSetServiceException() { + _reInstance.setServiceException(_serviceException); + assertEquals(_reInstance.getServiceException(), _serviceException); + } + + @Test + public void testSetAdditionalProperty() { + _reInstance.setAdditionalProperty("prop1", "propvalue1"); + _reInstance.setAdditionalProperty("prop2", "propvalue2"); + assertEquals(_reInstance.getAdditionalProperties(), _additionalProperties); + } + +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/ResponseMessageTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/ResponseMessageTest.java new file mode 100644 index 000000000..daf95b02d --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/ResponseMessageTest.java @@ -0,0 +1,68 @@ +package org.onap.ccsdk.sli.adaptors.aai.data; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class ResponseMessageTest { + + ResponseMessage _rmInstance; + protected String _messageId; + protected String _text; + protected Variables _variables; + protected Map<String, Object> _additionalProperties; + + @Before + public void setUp() throws Exception { + _rmInstance = new ResponseMessage(); + _messageId = "messageId"; + _text = "text"; + _variables = mock(Variables.class); + _additionalProperties = new HashMap<String, Object>() {{ + put("prop1", "propvalue1"); + put("prop2", "propvalue2"); + }}; + } + + @After + public void tearDown() throws Exception { + _rmInstance = null; + _messageId = null; + _text = null; + _variables = null; + _additionalProperties = null; + } + + @Test + public void testSetMessageId() { + _rmInstance.setMessageId(_messageId); + assertTrue(_rmInstance.getMessageId().equals(_messageId)); + } + + @Test + public void testSetText() { + _rmInstance.setText(_text); + assertTrue(_rmInstance.getText().equals(_text)); + } + + @Test + public void testSetVariables() { + _rmInstance.setVariables(_variables); + assertEquals(_rmInstance.getVariables(), _variables); + } + + @Test + public void testSetAdditionalProperty() { + _rmInstance.setAdditionalProperty("prop1", "propvalue1"); + _rmInstance.setAdditionalProperty("prop2", "propvalue2"); + assertEquals(_rmInstance.getAdditionalProperties(), _additionalProperties); + } + +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/ResponseMessagesTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/ResponseMessagesTest.java new file mode 100644 index 000000000..f21e969dd --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/ResponseMessagesTest.java @@ -0,0 +1,55 @@ +package org.onap.ccsdk.sli.adaptors.aai.data; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class ResponseMessagesTest { + + ResponseMessages _rmsInstance; + protected List<ResponseMessage> _responseMessage; + protected Map<String, Object> _additionalProperties; + + @Before + public void setUp() throws Exception { + _rmsInstance = new ResponseMessages(); + _responseMessage = new ArrayList<>(); + ResponseMessage rm1 = mock(ResponseMessage.class); + ResponseMessage rm2 = mock(ResponseMessage.class); + _responseMessage.add(rm1); + _responseMessage.add(rm2); + _additionalProperties = new HashMap<String, Object>() {{ + put("prop1", "propvalue1"); + put("prop2", "propvalue2"); + }}; + } + + @After + public void tearDown() throws Exception { + _rmsInstance = null; + _responseMessage = null; + _additionalProperties = null; + } + + @Test + public void testSetResponseMessage() { + _rmsInstance.setResponseMessage(_responseMessage); + assertEquals(_rmsInstance.getResponseMessage(), _responseMessage); + } + + @Test + public void testSetAdditionalProperty() { + _rmsInstance.setAdditionalProperty("prop1", "propvalue1"); + _rmsInstance.setAdditionalProperty("prop2", "propvalue2"); + assertEquals(_rmsInstance.getAdditionalProperties(), _additionalProperties); + } + +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/ServiceExceptionTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/ServiceExceptionTest.java new file mode 100644 index 000000000..f44d9b366 --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/ServiceExceptionTest.java @@ -0,0 +1,71 @@ +package org.onap.ccsdk.sli.adaptors.aai.data;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ServiceExceptionTest {
+
+ ServiceException _seInstance;
+ protected String _messageId;
+ protected String _text;
+ protected List<String> _variables;
+ protected Map<String, Object> _additionalProperties;
+
+ @Before
+ public void setUp() throws Exception {
+ _seInstance = new ServiceException();
+ _messageId = "messageId";
+ _text = "text";
+ _variables = new ArrayList<>(Arrays.asList("var1", "var2", "var3"));
+ _additionalProperties = new HashMap<String, Object>() {{
+ put("prop1", "propvalue1");
+ put("prop2", "propvalue2");
+ }};
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ _seInstance = null;
+ _messageId = null;
+ _text = null;
+ _variables = null;
+ _additionalProperties = null;
+ }
+
+ @Test
+ public void testSetMessageId() {
+ _seInstance.setMessageId(_messageId);
+ assertTrue(_seInstance.getMessageId().equals(_messageId));
+ }
+
+ @Test
+ public void testSetText() {
+ _seInstance.setText(_text);
+ assertTrue(_seInstance.getText().equals(_text));
+ }
+
+ @Test
+ public void testSetVariables() {
+ _seInstance.setVariables(_variables);
+ assertEquals(_seInstance.getVariables(), _variables);
+ }
+
+ @Test
+ public void testSetAdditionalProperties() {
+ _seInstance.setAdditionalProperty("prop1", "propvalue1");
+ _seInstance.setAdditionalProperty("prop2", "propvalue2");
+ assertEquals(_seInstance.getAdditionalProperties(), _additionalProperties);
+ }
+
+
+}
diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/SubInterfaceTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/SubInterfaceTest.java new file mode 100644 index 000000000..7975372be --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/SubInterfaceTest.java @@ -0,0 +1,94 @@ +package org.onap.ccsdk.sli.adaptors.aai.data; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.aai.inventory.v21.RelationshipList; +import org.onap.aai.inventory.v21.Vlans; + +public class SubInterfaceTest { + + SubInterface _siInstance; + protected String _interfaceName; + protected String _interfaceRole; + protected String _resourceVersion; + protected Vlans _vlans; + protected RelationshipList _relationshipList; + protected Map<String, Object> _additionalProperties; + + @Before + public void setUp() throws Exception { + _siInstance = new SubInterface(); + _interfaceName = "interfaceName"; + _interfaceRole = "interfaceRole"; + _resourceVersion = "resourceVersion"; + _vlans = mock(Vlans.class); + _relationshipList = mock(RelationshipList.class); + + _additionalProperties = new HashMap<String, Object>() {{ + put("prop1", "propvalue1"); + put("prop2", "propvalue2"); + }}; + + } + + @After + public void tearDown() throws Exception { + _siInstance = null; + _interfaceName = null; + _interfaceRole = null; + _resourceVersion = null; + _vlans = null; + _relationshipList = null; + _additionalProperties = null; + } + + @Test + public void testSetInterfaceName() { + _siInstance.setInterfaceName(_interfaceName); + assertTrue(_siInstance.getInterfaceName().equals(_interfaceName)); + } + + + @Test + public void testSetInterfaceRole() { + _siInstance.setInterfaceRole(_interfaceRole); + assertTrue(_siInstance.getInterfaceRole().equals(_interfaceRole)); + } + + + @Test + public void testSetResourceVersion() { + _siInstance.setResourceVersion(_resourceVersion); + assertTrue(_siInstance.getResourceVersion().equals(_resourceVersion)); + } + + + @Test + public void testSetVlans() { + _siInstance.setVlans(_vlans); + assertTrue(_siInstance.getVlans().equals(_vlans)); + } + + + @Test + public void testSetRelationshipList() { + _siInstance.setRelationshipList(_relationshipList); + assertTrue(_siInstance.getRelationshipList().equals(_relationshipList)); + } + + @Test + public void testSetAdditionalProperties() { + _siInstance.setAdditionalProperty("prop1", "propvalue1"); + _siInstance.setAdditionalProperty("prop2", "propvalue2"); + assertEquals(_siInstance.getAdditionalProperties(), _additionalProperties); + } + +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/VariablesTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/VariablesTest.java new file mode 100644 index 000000000..1f72f7e67 --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/VariablesTest.java @@ -0,0 +1,56 @@ +package org.onap.ccsdk.sli.adaptors.aai.data;
+
+import static org.junit.Assert.*;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import java.util.ArrayList;
+
+public class VariablesTest {
+ Variables _variablesInstance;
+ protected List<String> _variable;
+ protected Map<String, Object> _additionalProperties;
+
+ public VariablesTest() {
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ _variablesInstance = new Variables();
+ _variable = new ArrayList<>(Arrays.asList("var1", "var2", "var3"));
+ _additionalProperties = new HashMap<String, Object>() {{
+ put("prop1", "propvalue1");
+ put("prop2", "propvalue2");
+ }};
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ _variablesInstance = null;
+ _variable = null;
+ _additionalProperties = null;
+ }
+
+
+ @Test
+ public void testSetVariable() {
+ _variablesInstance.setVariable(_variable);
+ assertEquals(_variablesInstance.getVariable(), _variable);
+ }
+
+ @Test
+ public void testSetAdditionalProperties() {
+ _variablesInstance.setAdditionalProperty("prop1", "propvalue1");
+ _variablesInstance.setAdditionalProperty("prop2", "propvalue2");
+ assertEquals(_variablesInstance.getAdditionalProperties(), _additionalProperties);
+ }
+
+}
diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/notify/KeyDatumTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/notify/KeyDatumTest.java new file mode 100644 index 000000000..2ea915213 --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/notify/KeyDatumTest.java @@ -0,0 +1,38 @@ +package org.onap.ccsdk.sli.adaptors.aai.data.notify; + +import static org.junit.Assert.*; + +import org.junit.BeforeClass; +import org.junit.Test; + +public class KeyDatumTest { + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + } + + @Test + public void testSetKeyName() { + String testString = "test-value"; + KeyDatum event = new KeyDatum(); + event.setKeyName(testString); + assertEquals(event.getKeyName(), testString); + } + + @Test + public void testSetKeyValue() { + String testString = "test-value"; + KeyDatum event = new KeyDatum(); + event.setKeyValue(testString); + assertEquals(event.getKeyValue(), testString); + } + + @Test + public void testSetAdditionalProperty() { + String testString = "test-value"; + KeyDatum event = new KeyDatum(); + event.setAdditionalProperty("test-key", testString); + assertEquals(event.getAdditionalProperties().get("test-key"), testString); + } + +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/notify/NotifyEventTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/notify/NotifyEventTest.java new file mode 100644 index 000000000..cb026c001 --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/data/notify/NotifyEventTest.java @@ -0,0 +1,53 @@ +package org.onap.ccsdk.sli.adaptors.aai.data.notify; + +import static org.junit.Assert.*; + +import org.junit.BeforeClass; +import org.junit.Test; + +public class NotifyEventTest { + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + } + + @Test + public void test01() { + String testString = "test-value"; + NotifyEvent event = new NotifyEvent(); + event.setAdditionalProperty("test-key", testString); + assertEquals(event.getAdditionalProperties().get("test-key"), testString); + } + + @Test + public void test02() { + String testString = "test-value"; + NotifyEvent event = new NotifyEvent(); + event.setSelflink(testString); + assertEquals(event.getSelflink(), testString); + } + + @Test + public void test03() { + String testString = "test-value"; + NotifyEvent event = new NotifyEvent(); + event.setEventId(testString); + assertEquals(event.getEventId(), testString); + } + + @Test + public void test04() { + String testString = "test-value"; + NotifyEvent event = new NotifyEvent(); + event.setEventTrigger(testString); + assertEquals(event.getEventTrigger(), testString); + } + + @Test + public void test05() { + String testString = "test-value"; + NotifyEvent event = new NotifyEvent(); + event.setNodeType(testString); + assertEquals(event.getNodeType(), testString); + } +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/query/FormattedQueryRequestDataTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/query/FormattedQueryRequestDataTest.java new file mode 100644 index 000000000..a89dbded6 --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/query/FormattedQueryRequestDataTest.java @@ -0,0 +1,53 @@ +package org.onap.ccsdk.sli.adaptors.aai.query; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.sli.adaptors.aai.data.Variables; + +public class FormattedQueryRequestDataTest { + + FormattedQueryRequestData _fqrdInstance; + protected List<String> _start; + protected String _query; + + @Before + public void setUp() throws Exception { + _fqrdInstance = new FormattedQueryRequestData(); + _start = new ArrayList<>(Arrays.asList("start1", "start2", "start3")); + _query = "query"; + } + + @After + public void tearDown() throws Exception { + _fqrdInstance = null; + _start = null; + _query = null; + } + + @Test + public void testSetStart() { + _fqrdInstance.setStart(_start); + assertEquals(_fqrdInstance.getStart(), _start); + } + + @Test + public void testSetQuery() { + _fqrdInstance.setQuery(_query); + assertEquals(_fqrdInstance.getQuery(), _query); + } + + @Test + public void testToString() { + _fqrdInstance.setStart(_start); + _fqrdInstance.setQuery(_query); + assertNotNull(_fqrdInstance.toString()); + } + +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/query/FormattedQueryResultListTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/query/FormattedQueryResultListTest.java new file mode 100644 index 000000000..f26051917 --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/query/FormattedQueryResultListTest.java @@ -0,0 +1,49 @@ +package org.onap.ccsdk.sli.adaptors.aai.query; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import java.util.ArrayList;
+
+public class FormattedQueryResultListTest {
+ FormattedQueryResultList _fqrlInstance;
+ protected List<Result> _results;
+
+ @Before
+ public void setUp() throws Exception {
+ _fqrlInstance = new FormattedQueryResultList(); + _results = new ArrayList<>(); + Result r1 = mock(Result.class); + Result r2 = mock(Result.class); + _results.add(r1); + _results.add(r2);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ _fqrlInstance = null;
+ _results = null;
+ }
+
+
+ @Test
+ public void testSetResults() {
+ _fqrlInstance.setResults(_results);
+ assertEquals(_fqrlInstance.getResults(), _results);
+ }
+
+ @Test
+ public void testToString() { + _fqrlInstance.setResults(_results); + assertTrue(_fqrlInstance.toString() != null);
+ }
+
+}
diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/query/InstanceFilterTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/query/InstanceFilterTest.java new file mode 100644 index 000000000..7a81f72cb --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/query/InstanceFilterTest.java @@ -0,0 +1,124 @@ +package org.onap.ccsdk.sli.adaptors.aai.query; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.aai.inventory.v21.CloudRegion; +import org.onap.aai.inventory.v21.GenericVnf; +import org.onap.aai.inventory.v21.L3Network; +import org.onap.aai.inventory.v21.LogicalLink; +import org.onap.aai.inventory.v21.PInterface; +import org.onap.aai.inventory.v21.Pnf; +import org.onap.aai.inventory.v21.ServiceInstance; +import org.onap.aai.inventory.v21.Tenant; +import org.onap.aai.inventory.v21.Vnf; +import org.onap.aai.inventory.v21.Vserver; + +public class InstanceFilterTest { + + InstanceFilter _ifInstance; + protected LogicalLink _logicalLink; + protected Pnf _pnf; + protected L3Network _l3Network; + protected PInterface _pInterface; + protected GenericVnf _genericVnf; + protected Vserver _vserver; + protected Tenant _tenant; + protected CloudRegion _cloudRegion; + protected ServiceInstance _serviceInstance; + protected Vnf _vnfc; + protected Map<String, Object> _additionalProperties; + + @Before + public void setUp() throws Exception { + _ifInstance = new InstanceFilter(); + LogicalLink _logicalLink = mock(LogicalLink.class); + Pnf _pnf = mock(Pnf.class); + L3Network _l3Network = mock(L3Network.class); + PInterface _pInterface = mock(PInterface.class); + GenericVnf _genericVnf = mock(GenericVnf.class); + Vserver _vserver = mock(Vserver.class); + Tenant _tenant = mock(Tenant.class); + CloudRegion _cloudRegion = mock(CloudRegion.class); + ServiceInstance _serviceInstance = mock(ServiceInstance.class); + // as per class + Vnf _vnfc = mock(Vnf.class); + _additionalProperties = new HashMap<String, Object>() {{ + put("prop1", "propvalue1"); + put("prop2", "propvalue2"); + }}; + } + + @After + public void tearDown() throws Exception { + _ifInstance = null; + _additionalProperties = null; + } + + @Test + public void testSetLogicalLink() { + _ifInstance.setLogicalLink(_logicalLink); + assertEquals(_ifInstance.getLogicalLink(), _logicalLink); + } + + @Test + public void testSetPnf() { + _ifInstance.setPnf(_pnf); + assertEquals(_ifInstance.getPnf(), _pnf); + } + + @Test + public void testSetL3Network() { + _ifInstance.setL3Network(_l3Network); + assertEquals(_ifInstance.getL3Network(), _l3Network); + } + + @Test + public void testSetServiceInstance() { + _ifInstance.setServiceInstance(_serviceInstance); + assertEquals(_ifInstance.getServiceInstance(), _serviceInstance); + } + + @Test + public void testSetGenericVnf() { + _ifInstance.setGenericVnf(_genericVnf); + assertEquals(_ifInstance.getGenericVnf(), _genericVnf); + } + + @Test + public void testSetVserver() { + _ifInstance.setVserver(_vserver); + assertEquals(_ifInstance.getVserver(), _vserver); + } + + @Test + public void testSetTenant() { + _ifInstance.setTenant(_tenant); + assertEquals(_ifInstance.getTenant(), _tenant); + } + + @Test + public void testSetCloudRegion() { + _ifInstance.setCloudRegion(_cloudRegion); + assertEquals(_ifInstance.getCloudRegion(), _cloudRegion); + } + + @Test + public void testSetVnfc() { + _ifInstance.setVnfc(_vnfc); + assertEquals(_ifInstance.getVnfc(), _vnfc); + } + + @Test + public void testSetAdditionalProperty() { + _ifInstance.setAdditionalProperty("prop1", "propvalue1"); + _ifInstance.setAdditionalProperty("prop2", "propvalue2"); + assertEquals(_ifInstance.getAdditionalProperties(), _additionalProperties); + } +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/query/InstanceFiltersTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/query/InstanceFiltersTest.java new file mode 100644 index 000000000..6131e13e0 --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/query/InstanceFiltersTest.java @@ -0,0 +1,55 @@ +package org.onap.ccsdk.sli.adaptors.aai.query; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class InstanceFiltersTest { + + InstanceFilters _ifsInstance; + protected List<InstanceFilter> _instanceFilter; + protected Map<String, Object> _additionalProperties; + + @Before + public void setUp() throws Exception { + _ifsInstance = new InstanceFilters(); + _instanceFilter = new ArrayList<>(); + InstanceFilter if1 = mock(InstanceFilter.class); + InstanceFilter if2 = mock(InstanceFilter.class); + _instanceFilter.add(if1); + _instanceFilter.add(if2); + _additionalProperties = new HashMap<String, Object>() {{ + put("prop1", "propvalue1"); + put("prop2", "propvalue2"); + }}; + } + + @After + public void tearDown() throws Exception { + _ifsInstance = null; + _instanceFilter = null; + _additionalProperties = null; + } + + @Test + public void testSetInstanceFilter() { + _ifsInstance.setInstanceFilter(_instanceFilter); + assertEquals(_ifsInstance.getInstanceFilter(), _instanceFilter); + + } + + @Test + public void testSetAdditionalProperty() { + _ifsInstance.setAdditionalProperty("prop1", "propvalue1"); + _ifsInstance.setAdditionalProperty("prop2", "propvalue2"); + } + +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/query/ResultTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/query/ResultTest.java new file mode 100644 index 000000000..14c17a563 --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/query/ResultTest.java @@ -0,0 +1,159 @@ +package org.onap.ccsdk.sli.adaptors.aai.query; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import org.onap.aai.inventory.v21.CloudRegion; +import org.onap.aai.inventory.v21.Complex; +import org.onap.aai.inventory.v21.Configuration; +import org.onap.aai.inventory.v21.GenericVnf; +import org.onap.aai.inventory.v21.L3InterfaceIpv4AddressList; +import org.onap.aai.inventory.v21.L3InterfaceIpv6AddressList; +import org.onap.aai.inventory.v21.L3Network; +import org.onap.aai.inventory.v21.LInterface; +//import org.onap.aai.inventory.v21.OwningEntity; +import org.onap.aai.inventory.v21.Pserver; +import org.onap.aai.inventory.v21.ServiceInstance; +import org.onap.aai.inventory.v21.Vnfc; +import org.onap.aai.inventory.v21.Vserver; + +public class ResultTest { + + Result _rInstance; + + protected CloudRegion _cloudRegion; + protected Complex _complex; + protected Configuration _configuration; + protected GenericVnf _genericVnf; + protected L3InterfaceIpv4AddressList _l3InterfaceIpv4AddressList; + protected L3InterfaceIpv6AddressList _l3InterfaceIpv6AddressList; + protected L3Network _l3Network; + protected LInterface _lInterface; + protected Pserver _pserver; + protected ServiceInstance _serviceInstance; + protected Vnfc _vnfc; + protected Vserver _vserver; + + protected Map<String, Object> _additionalProperties; + + @Before + public void setUp() throws Exception { + _rInstance = new Result(); + + CloudRegion _cloudRegion = mock(CloudRegion.class); + Complex _complex = mock(Complex.class); + Configuration _configuration = mock(Configuration.class); + L3InterfaceIpv4AddressList _l3InterfaceIpv4AddressList = mock(L3InterfaceIpv4AddressList.class); + L3InterfaceIpv6AddressList _l3InterfaceIpv6AddressList = mock(L3InterfaceIpv6AddressList.class); + L3Network _l3Network = mock(L3Network.class); + LInterface _pInterface = mock(LInterface.class); + GenericVnf _genericVnf = mock(GenericVnf.class); + Vserver _vserver = mock(Vserver.class); + Pserver _pserver = mock(Pserver.class); + Vnfc _vnfc = mock(Vnfc.class); + ServiceInstance _serviceInstance = mock(ServiceInstance.class); + + _additionalProperties = new HashMap<String, Object>() {{ + put("prop1", "propvalue1"); + put("prop2", "propvalue2"); + }}; + } + + @After + public void tearDown() throws Exception { + _rInstance = null; + _additionalProperties = null; + } + + @Test + public void testSetComplex() { + _rInstance.setComplex(_complex); + assertEquals(_rInstance.getComplex(), _complex); + } + + @Test + public void testSetConfiguration() { + _rInstance.setConfiguration(_configuration); + assertEquals(_rInstance.getConfiguration(), _configuration); + } + + @Test + public void testSetL3InterfaceIpv4AddressList() { + _rInstance.setL3InterfaceIpv4AddressList(_l3InterfaceIpv4AddressList); + assertEquals(_rInstance.getL3InterfaceIpv4AddressList(), _l3InterfaceIpv4AddressList); + } + + @Test + public void testSetL3InterfaceIpv6AddressList() { + _rInstance.setL3InterfaceIpv6AddressList(_l3InterfaceIpv6AddressList); + assertEquals(_rInstance.getL3InterfaceIpv6AddressList(), _l3InterfaceIpv6AddressList); + } + + @Test + public void testSetL3Network() { + _rInstance.setL3Network(_l3Network); + assertEquals(_rInstance.getL3Network(), _l3Network); + } + + @Test + public void testSetServiceInstance() { + _rInstance.setServiceInstance(_serviceInstance); + assertEquals(_rInstance.getServiceInstance(), _serviceInstance); + } + + @Test + public void testSetGenericVnf() { + _rInstance.setGenericVnf(_genericVnf); + assertEquals(_rInstance.getGenericVnf(), _genericVnf); + } + + @Test + public void testSetVserver() { + _rInstance.setVserver(_vserver); + assertEquals(_rInstance.getVserver(), _vserver); + } + + @Test + public void testSetCloudRegion() { + _rInstance.setCloudRegion(_cloudRegion); + assertEquals(_rInstance.getCloudRegion(), _cloudRegion); + } + + @Test + public void testSetVnfc() { + _rInstance.setVnfc(_vnfc); + assertEquals(_rInstance.getVnfc(), _vnfc); + } + + @Test + public void testSetLInterface() { + _rInstance.setLInterface(_lInterface); + assertEquals(_rInstance.getLInterface(), _lInterface); + } + + @Test + public void testSetPserver() { + _rInstance.setPserver(_pserver); + assertEquals(_rInstance.getPserver(), _pserver); + } + + @Test + public void testSetAdditionalProperty() { + _rInstance.setAdditionalProperty("prop1", "propvalue1"); + _rInstance.setAdditionalProperty("prop2", "propvalue2"); + assertEquals(_rInstance.getAdditionalProperties(), _additionalProperties); + } + + @Test + public void testToString() { + assertNotNull(_rInstance.toString()); + } + +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/update/ActionDatumTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/update/ActionDatumTest.java new file mode 100644 index 000000000..7b858ea65 --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/update/ActionDatumTest.java @@ -0,0 +1,58 @@ +package org.onap.ccsdk.sli.adaptors.aai.update; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class ActionDatumTest { + + ActionDatum _oInstance; + protected Map<String, Object> _additionalProperties; + protected String _propertyName; + protected String _propertyValue; + + @Before + public void setUp() throws Exception { + _oInstance = new ActionDatum(); + _propertyName = "propertyName"; + _propertyValue = "propertyValue"; + _additionalProperties = new HashMap<String, Object>() {{ + put("prop1", "propvalue1"); + put("prop2", "propvalue2"); + }}; + } + + @After + public void tearDown() throws Exception { + _oInstance = null; + _additionalProperties = null; + } + + @Test + public void testSetPropertyName() { + _oInstance.setPropertyName(_propertyName); + assertEquals(_oInstance.getPropertyName(), _propertyName); + } + + @Test + public void testSetPropertyValue() { + _oInstance.setPropertyValue(_propertyValue); + assertEquals(_oInstance.getPropertyValue(), _propertyValue); + } + + @Test + public void testSetAdditionalProperty() { + _oInstance.setAdditionalProperty("prop1", "propvalue1"); + _oInstance.setAdditionalProperty("prop2", "propvalue2"); + assertEquals(_oInstance.getAdditionalProperties(), _additionalProperties); + } + +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/update/ActionTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/update/ActionTest.java new file mode 100644 index 000000000..459396c1c --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/update/ActionTest.java @@ -0,0 +1,64 @@ +package org.onap.ccsdk.sli.adaptors.aai.update; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.sli.adaptors.aai.query.Result; + +public class ActionTest { + + Action _oInstance; + protected Map<String, Object> _additionalProperties; + protected String _actionType; + protected List<ActionDatum> _actionData; + + @Before + public void setUp() throws Exception { + _oInstance = new Action(); + _actionType = "actionType"; + _actionData = new ArrayList<>(); + ActionDatum a1 = mock(ActionDatum.class); + ActionDatum a2 = mock(ActionDatum.class); + _actionData.add(a1); + _actionData.add(a2); + _additionalProperties = new HashMap<String, Object>() {{ + put("prop1", "propvalue1"); + put("prop2", "propvalue2"); + }}; + } + + @After + public void tearDown() throws Exception { + _oInstance = null; + _actionData = null; + _additionalProperties = null; + } + + @Test + public void testSetActionData() { + _oInstance.setActionData(_actionData); + assertEquals(_oInstance.getActionData(), _actionData); + } + + @Test + public void testSetActionType() { + _oInstance.setActionType(_actionType); + assertEquals(_oInstance.getActionType(), _actionType); + } + + @Test + public void testSetAdditionalProperty() { + _oInstance.setAdditionalProperty("prop1", "propvalue1"); + _oInstance.setAdditionalProperty("prop2", "propvalue2"); + assertEquals(_oInstance.getAdditionalProperties(), _additionalProperties); + } +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/update/UpdateNodeKeyTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/update/UpdateNodeKeyTest.java new file mode 100644 index 000000000..360a0948f --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/update/UpdateNodeKeyTest.java @@ -0,0 +1,53 @@ +package org.onap.ccsdk.sli.adaptors.aai.update; + +import static org.junit.Assert.*; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class UpdateNodeKeyTest { + UpdateNodeKey _oInstance; + protected Map<String, Object> _additionalProperties; + protected String _keyName; + protected String _keyValue; + @Before + public void setUp() throws Exception { + _oInstance = new UpdateNodeKey(); + _keyName = "keyName"; + _keyValue = "keyValue"; + _additionalProperties = new HashMap<String, Object>() {{ + put("prop1", "propvalue1"); + put("prop2", "propvalue2"); + }}; + } + + @After + public void tearDown() throws Exception { + _oInstance = null; + _additionalProperties = null; + } + + @Test + public void testSetKeyName() { + _oInstance.setKeyName(_keyName); + assertEquals(_oInstance.getKeyName(), _keyName); + } + + @Test + public void testSetKeyValue() { + _oInstance.setKeyName(_keyName); + assertEquals(_oInstance.getKeyName(), _keyName); + } + + @Test + public void testSetAdditionalProperty() { + _oInstance.setAdditionalProperty("prop1", "propvalue1"); + _oInstance.setAdditionalProperty("prop2", "propvalue2"); + assertEquals(_oInstance.getAdditionalProperties(), _additionalProperties); + } + +} diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/update/UpdateTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/update/UpdateTest.java new file mode 100644 index 000000000..8f8a06eac --- /dev/null +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/update/UpdateTest.java @@ -0,0 +1,75 @@ +package org.onap.ccsdk.sli.adaptors.aai.update; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class UpdateTest { + + Update _oInstance; + protected Map<String, Object> _additionalProperties; + protected String _updateNodeType; + protected List<UpdateNodeKey> _updateNodeKey; + protected List<Action> _action; + + @Before + public void setUp() throws Exception { + _oInstance = new Update(); + _updateNodeType = "updateNodeType"; + _action = new ArrayList<>(); + Action a1 = mock(Action.class); + Action a2 = mock(Action.class); + _action.add(a1); + _action.add(a2); + _updateNodeKey = new ArrayList<>(); + UpdateNodeKey k1 = mock(UpdateNodeKey.class); + UpdateNodeKey k2 = mock(UpdateNodeKey.class); + _updateNodeKey.add(k1); + _updateNodeKey.add(k2); + _additionalProperties = new HashMap<String, Object>() {{ + put("prop1", "propvalue1"); + put("prop2", "propvalue2"); + }}; + } + + @After + public void tearDown() throws Exception { + _oInstance = null; + _action = null; + _additionalProperties = null; + } + + @Test + public void testSetUpdateNodeType() { + _oInstance.setUpdateNodeType(_updateNodeType); + assertEquals(_oInstance.getUpdateNodeType(), _updateNodeType); + } + + @Test + public void testSetAction() { + _oInstance.setAction(_action); + assertEquals(_oInstance.getAction(), _action); + } + + @Test + public void testSetUpdateNodeKey() { + _oInstance.setUpdateNodeKey(_updateNodeKey); + assertEquals(_oInstance.getUpdateNodeKey(), _updateNodeKey); + } + + + @Test + public void testSetAdditionalProperty() { + _oInstance.setAdditionalProperty("prop1", "propvalue1"); + _oInstance.setAdditionalProperty("prop2", "propvalue2"); + assertEquals(_oInstance.getAdditionalProperties(), _additionalProperties); + } +} diff --git a/aai-service/provider/src/test/resources/aaiclient.properties b/aai-service/provider/src/test/resources/aaiclient.properties new file mode 100755 index 000000000..571280b81 --- /dev/null +++ b/aai-service/provider/src/test/resources/aaiclient.properties @@ -0,0 +1,80 @@ +### +# ============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========================================================= +### + +# +# Configuration file for A&AI Client +# + +# +# Certificate keystore and truststore +# +org.onap.ccsdk.sli.adaptors.aai.ssl.trust=/opt/onap/ccsdk/data/stores/truststore.onap.client.jks +org.onap.ccsdk.sli.adaptors.aai.ssl.trust.psswd=adminadmin +org.onap.ccsdk.sli.adaptors.aai.host.certificate.ignore=true + +org.onap.ccsdk.sli.adaptors.aai.client.name=SDNC +org.onap.ccsdk.sli.adaptors.aai.client.psswd=SDNC + +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.onap.org:8443 +connection.timeout=60000 +read.timeout=60000 + +# aai version +org.onap.ccsdk.sli.adaptors.aai.version=/v21/ + +# query +org.onap.ccsdk.sli.adaptors.aai.path.query=/aai/v21/search/sdn-zone-query +org.onap.ccsdk.sli.adaptors.aai.query.nodes=/aai/v21/search/nodes-query?search-node-type={node-type}&filter={entity-identifier}:EQUALS:{entity-name} +org.onap.ccsdk.sli.adaptors.aai.query.generic=/aai/v21/search/generic-query?key={identifier}:{value}&start-node-type={start-node-type}&include=complex&depth=3 + +#update +org.onap.ccsdk.sli.adaptors.aai.update=/aai/v21/actions/update + +# UBB Notify +org.onap.ccsdk.sli.adaptors.aai.path.notify=/aai/v21/actions/notify +org.onap.ccsdk.sli.adaptors.aai.notify.selflink.fqdn=<%= @ubbUri %>/restconf/config/L3SDN-API:services/layer3-service-list/{service-instance-id} +org.onap.ccsdk.sli.adaptors.aai.notify.selflink.avpn=<%= @ubbUri %>/restconf/config/L3AVPN-EVC-API:services/service-list/{service-instance-id}/service-data/avpn-logicalchannel-information + +# P-Interfaces +org.onap.ccsdk.sli.adaptors.aai.path.pserver.pinterfaces=/aai/v21/cloud-infrastructure/pservers/pserver/{hostname}/p-interfaces +org.onap.ccsdk.sli.adaptors.aai.path.pserver.pinterface=/aai/v21/cloud-infrastructure/pservers/pserver/{hostname}/p-interfaces/p-interface/{interface-name} + +# VNF IMAGES +org.onap.ccsdk.sli.adaptors.aai.path.vnf.image.query=/aai/v21/service-design-and-creation/vnf-images/vnf-image?application={application_model}&application-vendor={application_vendor} + +# service instance +org.onap.ccsdk.sli.adaptors.aai.path.svcinst.query=/aai/v21/search/generic-query?key=service-instance.service-instance-id:{svc-instance-id}&start-node-type=service-instance&include=service-instance +org.onap.ccsdk.sli.adaptors.aai.path.service.instance=/aai/v21/business/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id} + +# VNF IMAGES QUERY +org.onap.ccsdk.sli.adaptors.aai.path.vnf.image.query=/aai/v21/service-design-and-creation/vnf-images/vnf-image?application={application_model}&application-vendor={application_vendor} + +# +# Formatting +# +org.onap.ccsdk.sli.adaptors.aai.param.format=filter=%s:%s +org.onap.ccsdk.sli.adaptors.aai.param.vnf_type=vnf-type +org.onap.ccsdk.sli.adaptors.aai.param.physical.location.id=physical-location-id +org.onap.ccsdk.sli.adaptors.aai.param.service.type=service-type 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/json/pserverJson.txt b/aai-service/provider/src/test/resources/json/pserverJson.txt new file mode 100755 index 000000000..4b7f97d37 --- /dev/null +++ b/aai-service/provider/src/test/resources/json/pserverJson.txt @@ -0,0 +1,97 @@ +{ + "selflink": "https://mtinjvmsdn30.cip.att.com:8443/aai/v4/network/pservers/pserver/chcil129snd", + "hostname": "chcil129snd", + "ptnii-equip-name": "chcil129snd", + "equip-type": "server1", + "equip-vendor": "HP", + "equip-model": "DL380p-nd", + "fqdn": "chcilrsv129.chcil.sbcglobal.net", + "ipv4-oam-address": "12.80.1.83", + "serial-number": "n02kvcBczBI", + "in-maint":false, + "resource-version": "1455988020", + "purpose": "Gamma-VCE", + "relationship-list": { + "relationship": [ + { + "related-to": "complex", + "related-link": "https://aai.infra.aic.att.net:8443/aai/v5/cloud-infrastructure/complexes/complex/CHCGILCL73W/", + "relationship-data": [ + { + "relationship-key": "complex.physical-location-id", + "relationship-value": "CHCGILCL73W" + } + ] + } + ] + }, + "p-interfaces": { + "p-interface": [ + { + "interface-name": "p6p2-6/2", + "speed-value": "10000000", + "speed-units": "kbps", + "resource-version": "1455988020", + "relationship-list": { + "relationship": [ + { + "related-to": "physical-link", + "related-link": "https://aai.infra.aic.att.net:8443/aai/v5/network/physical-links/physical-link/chcil129snd%3Ap6p2-6%2F2%7Cchciltax102%3Axe-1%2F0%2F29/", + "relationship-data": [ + { + "relationship-key": "physical-link.link-name", + "relationship-value": "chcil129snd:p6p2-6/2|chciltax102:xe-1/0/29" + } + ] + } + ] + }, + "l-interfaces": { + + } + }, + { + "interface-name": "p6p1-6/1", + "speed-value": "10000000", + "speed-units": "kbps", + "resource-version": "1455988020", + "relationship-list": { + "relationship": [ + { + "related-to": "physical-link", + "related-link": "https://aai.infra.aic.att.net:8443/aai/v5/network/physical-links/physical-link/chcil129snd%3Ap6p1-6%2F1%7Cchciltax101%3Axe-0%2F0%2F29/", + "relationship-data": [ + { + "relationship-key": "physical-link.link-name", + "relationship-value": "chcil129snd:p6p1-6/1|chciltax101:xe-0/0/29" + } + ] + } + ] + }, + "l-interfaces": { + + } + }, + { + "interface-name": "em0-0/1", + "speed-value": "10000000", + "speed-units": "kbps", + "resource-version": "1455988020", + "relationship-list": { + "relationship": [ + { + "related-to": "physical-link", + "related-link": "https://aai.infra.aic.att.net:8443/aai/v5/network/physical-links/physical-link/chcil129snd%3Aem0-0%2F1%7Cchciltax101%3Axe-0%2F0%2F59/", + "relationship-data": [ + { + + } + ] + } + ] + } + } + ] + } +}
\ 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 |