diff options
Diffstat (limited to 'aai-traversal/src/test/java')
75 files changed, 5690 insertions, 1925 deletions
diff --git a/aai-traversal/src/test/java/org/onap/aai/AAIGremlinQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/AAIGremlinQueryTest.java index a2be3d0..0a9ec97 100644 --- a/aai-traversal/src/test/java/org/onap/aai/AAIGremlinQueryTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/AAIGremlinQueryTest.java @@ -20,12 +20,13 @@ package org.onap.aai; import com.jayway.jsonpath.JsonPath; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.janusgraph.core.JanusGraphTransaction; +import org.junit.*; import org.onap.aai.config.PropertyPasswordConfiguration; +import org.onap.aai.dbmap.AAIGraph; import org.onap.aai.exceptions.AAIException; +import org.onap.aai.util.AAIConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; @@ -33,16 +34,19 @@ import org.springframework.context.annotation.Import; import org.springframework.http.*; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit4.rules.SpringClassRule; +import org.springframework.test.context.junit4.rules.SpringMethodRule; import org.springframework.web.client.RestTemplate; -import javax.ws.rs.core.Response; -import java.io.UnsupportedEncodingException; -import java.util.*; +import java.util.Base64; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; /** * A sample junit test using spring boot that provides the ability to spin @@ -55,18 +59,17 @@ import static org.junit.Assert.assertNotNull; * This can be used to potentially replace a lot of the fitnesse tests since * they will be testing against the same thing except fitnesse uses hbase */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TraversalApp.class) @TestPropertySource(locations = "classpath:application-test.properties") @ContextConfiguration(initializers = PropertyPasswordConfiguration.class) @Import(TraversalTestConfiguration.class) public class AAIGremlinQueryTest { - private HttpTestUtil httpTestUtil; + @ClassRule + public static final SpringClassRule springClassRule = new SpringClassRule(); - private String pserverUri; - - private String hostname; + @Rule + public final SpringMethodRule springMethodRule = new SpringMethodRule(); @Autowired RestTemplate restTemplate; @@ -80,20 +83,50 @@ public class AAIGremlinQueryTest { private String baseUrl; - @Before - public void setup() throws Exception { + @BeforeClass + public static void setupConfig() throws AAIException { + System.setProperty("AJSC_HOME", "./"); + System.setProperty("BUNDLECONFIG_DIR", "src/main/resources/"); + AAIConfig.init(); + } + + public void createGraph(){ + + JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); + + boolean success = true; - httpTestUtil = new HttpTestUtil(); + try { - hostname = UUID.randomUUID().toString(); + GraphTraversalSource g = transaction.traversal(); - pserverUri ="/aai/v11/cloud-infrastructure/pservers/pserver/" + hostname; + g.addV() + .property("aai-node-type", "pserver") + .property("hostname", "test-pserver") + .property("in-maint", false) + .property("source-of-truth", "JUNIT") + .property("aai-uri", "/cloud-infrastructure/pservers/pserver/test-pserver") + .next(); - Map<String, String> pserverMap = new HashMap<>(); - pserverMap.put("hostname", hostname); - String payload = PayloadUtil.getTemplatePayload("pserver.json", pserverMap); - httpTestUtil.doPut(pserverUri, payload); + } catch(Exception ex){ + success = false; + } finally { + if(success){ + transaction.commit(); + } else { + transaction.rollback(); + fail("Unable to setup the graph"); + } + } + } + + @Before + public void setup() throws Exception { + AAIConfig.init(); + AAIGraph.getInstance(); + + createGraph(); headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); @@ -109,9 +142,9 @@ public class AAIGremlinQueryTest { } @Test - public void testPserverCount() throws Exception { + public void testPserverCountUsingGremlin() throws Exception { Map<String, String> gremlinQueryMap = new HashMap<>(); - gremlinQueryMap.put("gremlin-query", "g.V().has('hostname', '" + hostname + "').count()"); + gremlinQueryMap.put("gremlin-query", "g.V().has('hostname', 'test-pserver').count()"); String payload = PayloadUtil.getTemplatePayload("gremlin-query.json", gremlinQueryMap); @@ -127,19 +160,49 @@ public class AAIGremlinQueryTest { assertThat(result, is("1")); } + @Test + public void testPserverCountUsingDsl() throws Exception { + Map<String, String> dslQuerymap = new HashMap<>(); + dslQuerymap.put("dsl-query", "pserver*('hostname', 'test-pserver')"); + + String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQuerymap); + + ResponseEntity responseEntity = null; + + String endpoint = "/aai/v11/dsl?format=console"; + + httpEntity = new HttpEntity(payload, headers); + responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK)); + + String result = JsonPath.read(responseEntity.getBody().toString(), "$.results[0].result"); + assertThat(result, containsString("v[")); + } + @After - public void tearDown() throws UnsupportedEncodingException, AAIException { + public void tearDown() { + + JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); + boolean success = true; + + try { - Response response = httpTestUtil.doGet(pserverUri); + GraphTraversalSource g = transaction.traversal(); - assertNotNull("Expected the response to be returned", response); - assertThat(response.getStatus(), is(200)); + g.V().has("source-of-truth", "JUNIT") + .toList() + .forEach(v -> v.remove()); - String body = response.getEntity().toString(); - String resourceVersion = JsonPath.read(body, "$.resource-version"); + } catch(Exception ex){ + success = false; + } finally { + if(success){ + transaction.commit(); + } else { + transaction.rollback(); + fail("Unable to teardown the graph"); + } + } - response = httpTestUtil.doDelete(pserverUri, resourceVersion); - assertNotNull("Expected the response to be returned", response); - assertThat(response.getStatus(), is(204)); } } diff --git a/aai-traversal/src/test/java/org/onap/aai/AAISetup.java b/aai-traversal/src/test/java/org/onap/aai/AAISetup.java new file mode 100644 index 0000000..42964eb --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/AAISetup.java @@ -0,0 +1,141 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai; + +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.junit.BeforeClass; +import org.onap.aai.config.*; +import org.onap.aai.dbgraphmap.SearchGraph; +import org.onap.aai.edges.EdgeIngestor; +import org.onap.aai.introspection.LoaderFactory; +import org.onap.aai.nodes.NodeIngestor; +import org.onap.aai.rest.db.HttpEntry; +import org.onap.aai.rest.dsl.DslQueryProcessor; +import org.onap.aai.rest.search.GremlinServerSingleton; +import org.onap.aai.serialization.db.EdgeSerializer; +import org.onap.aai.setup.AAIConfigTranslator; +import org.onap.aai.setup.SchemaVersion; +import org.onap.aai.setup.SchemaVersions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.test.context.ContextConfiguration; +import org.onap.aai.introspection.MoxyLoader; +import org.onap.aai.setup.SchemaLocationsBean; +import org.junit.ClassRule; +import org.junit.Rule; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.rules.SpringClassRule; +import org.springframework.test.context.junit4.rules.SpringMethodRule; + +@ContextConfiguration(classes = { + SchemaLocationsBean.class, + SchemaVersions.class, + AAIConfigTranslator.class, + EdgeIngestor.class, + EdgeSerializer.class, + NodeIngestor.class, + SpringContextAware.class, + IntrospectionConfig.class , + RestBeanConfig.class, + SearchConfiguration.class, + DslConfiguration.class, + GremlinServerSingleton.class +}) +@TestPropertySource(properties = { + "schema.uri.base.path = /aai", + "schema.ingest.file = src/test/resources/application-test.properties" +}) +public abstract class AAISetup { + @Autowired + protected NodeIngestor nodeIngestor; + + @Autowired + protected LoaderFactory loaderFactory; + + @Autowired + protected Map<SchemaVersion, MoxyLoader> moxyLoaderInstance; + + @Autowired + protected HttpEntry traversalHttpEntry; + + @Autowired + protected HttpEntry traversalUriHttpEntry; + + @Autowired + protected SearchGraph searchGraph; + + @Autowired + protected EdgeSerializer edgeSer; + + @Autowired + protected EdgeIngestor edgeIngestor; + + @Autowired + protected DslQueryProcessor dslQueryProcessor; + + @Autowired + protected SchemaVersions schemaVersions; + + @Autowired + protected GremlinServerSingleton gremlinServerSingleton; + + @Value("${schema.uri.base.path}") + protected String basePath; + + @ClassRule + public static final SpringClassRule springClassRule = new SpringClassRule(); + + @Rule + public final SpringMethodRule springMethodRule = new SpringMethodRule(); + + @BeforeClass + public static void setupBundleconfig() throws Exception { + System.setProperty("AJSC_HOME", "./"); + System.setProperty("BUNDLECONFIG_DIR", "src/main/resources/"); + + } + + public String getPayload(String filename) throws IOException { + + InputStream inputStream = getClass() + .getClassLoader() + .getResourceAsStream(filename); + + String message = String.format("Unable to find the %s in src/test/resources", filename); + assertNotNull(message, inputStream); + + String resource = IOUtils.toString(inputStream); + return resource; + } +} + + + + + + + + diff --git a/aai-traversal/src/test/java/org/onap/aai/HttpTestUtil.java b/aai-traversal/src/test/java/org/onap/aai/HttpTestUtil.java index 7284593..79e6cac 100644 --- a/aai-traversal/src/test/java/org/onap/aai/HttpTestUtil.java +++ b/aai-traversal/src/test/java/org/onap/aai/HttpTestUtil.java @@ -23,20 +23,20 @@ import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import org.javatuples.Pair; import org.mockito.Mockito; +import org.onap.aai.config.SpringContextAware; import org.onap.aai.dbmap.DBConnectionType; import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.Introspector; import org.onap.aai.introspection.Loader; -import org.onap.aai.introspection.ModelType; -import org.onap.aai.introspection.Version; import org.onap.aai.parsers.query.QueryParser; import org.onap.aai.parsers.uri.URIToObject; import org.onap.aai.rest.db.DBRequest; import org.onap.aai.rest.db.HttpEntry; import org.onap.aai.restcore.HttpMethod; import org.onap.aai.restcore.RESTAPI; -import org.onap.aai.serialization.engines.QueryStyle; import org.onap.aai.serialization.engines.TransactionalGraphEngine; +import org.onap.aai.setup.SchemaVersion; +import org.onap.aai.setup.SchemaVersions; import javax.ws.rs.core.*; import java.io.UnsupportedEncodingException; @@ -64,8 +64,11 @@ public class HttpTestUtil extends RESTAPI { protected List<String> aaiRequestContextList; protected List<MediaType> outputMediaTypes; + private SchemaVersions schemaVersions; + public void init(){ + schemaVersions = SpringContextAware.getBean(SchemaVersions.class); httpHeaders = Mockito.mock(HttpHeaders.class); uriInfo = Mockito.mock(UriInfo.class); @@ -110,24 +113,26 @@ public class HttpTestUtil extends RESTAPI { String [] arr = uri.split("/"); - Version version = null; + SchemaVersion version = null; if(arr != null && arr.length > 1){ if(arr[0].matches("^v\\d+")){ - version = Version.valueOf(arr[0]); + version = new SchemaVersion(arr[0]); uri = uri.replaceAll("^v\\d+", ""); } } if(version == null){ - version = Version.getLatest(); + version = schemaVersions.getDefaultVersion(); } Mockito.when(uriInfo.getPath()).thenReturn(uri); DBConnectionType type = DBConnectionType.REALTIME; - HttpEntry httpEntry = new HttpEntry(version, ModelType.MOXY, QueryStyle.TRAVERSAL, type); - Loader loader = httpEntry.getLoader(); - dbEngine = httpEntry.getDbEngine(); + HttpEntry resourceHttpEntry = SpringContextAware.getBean("traversalHttpEntry", HttpEntry.class); + resourceHttpEntry.setHttpEntryProperties(version, type); + // HttpEntry httpEntry = new HttpEntry(version, ModelType.MOXY, QueryStyle.TRAVERSAL, type); + Loader loader = resourceHttpEntry.getLoader(); + dbEngine = resourceHttpEntry.getDbEngine(); URI uriObject = UriBuilder.fromPath(uri).build(); URIToObject uriToObject = new URIToObject(loader, uriObject); @@ -157,7 +162,7 @@ public class HttpTestUtil extends RESTAPI { List<DBRequest> dbRequestList = new ArrayList<>(); dbRequestList.add(dbRequest); - Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = httpEntry.process(dbRequestList, "JUNIT"); + Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = resourceHttpEntry.process(dbRequestList, "JUNIT"); response = responsesTuple.getValue1().get(0).getValue1(); } catch (AAIException e) { @@ -202,23 +207,27 @@ public class HttpTestUtil extends RESTAPI { String [] arr = uri.split("/"); - Version version = null; + SchemaVersion version = null; if(arr != null && arr.length > 1){ if(arr[0].matches("^v\\d+")){ - version = Version.valueOf(arr[0]); + version = new SchemaVersion(arr[0]); uri = uri.replaceAll("^v\\d+", ""); } } if(version == null){ - version = Version.getLatest(); + version = schemaVersions.getDefaultVersion(); } DBConnectionType type = DBConnectionType.REALTIME; - HttpEntry httpEntry = new HttpEntry(version, ModelType.MOXY, QueryStyle.TRAVERSAL, type); - Loader loader = httpEntry.getLoader(); - dbEngine = httpEntry.getDbEngine(); + + //HttpEntry httpEntry = new HttpEntry(version, ModelType.MOXY, QueryStyle.TRAVERSAL, type); + HttpEntry resourceHttpEntry = SpringContextAware.getBean("traversalHttpEntry", HttpEntry.class); + resourceHttpEntry.setHttpEntryProperties(version, type); + + Loader loader = resourceHttpEntry.getLoader(); + dbEngine = resourceHttpEntry.getDbEngine(); URI uriObject = UriBuilder.fromPath(uri).build(); URIToObject uriToObject = new URIToObject(loader, uriObject); @@ -240,7 +249,7 @@ public class HttpTestUtil extends RESTAPI { List<DBRequest> dbRequestList = new ArrayList<>(); dbRequestList.add(dbRequest); - Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = httpEntry.process(dbRequestList, "JUNIT"); + Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = resourceHttpEntry.process(dbRequestList, "JUNIT"); response = responsesTuple.getValue1().get(0).getValue1(); } catch (AAIException e) { @@ -283,11 +292,11 @@ public class HttpTestUtil extends RESTAPI { String [] arr = uri.split("/"); - Version version = null; + SchemaVersion version = null; if(arr != null && arr.length > 1){ if(arr[0].matches("^v\\d+")){ - version = Version.valueOf(arr[0]); + version = new SchemaVersion(arr[0]); if(!uri.contains("relationship-list/relationship")){ uri = uri.replaceAll("^v\\d+", ""); } @@ -295,14 +304,16 @@ public class HttpTestUtil extends RESTAPI { } if(version == null){ - version = Version.getLatest(); + version = schemaVersions.getDefaultVersion(); } Mockito.when(uriInfo.getPath()).thenReturn(uri); DBConnectionType type = DBConnectionType.REALTIME; - HttpEntry httpEntry = new HttpEntry(version, ModelType.MOXY, QueryStyle.TRAVERSAL, type); - Loader loader = httpEntry.getLoader(); - dbEngine = httpEntry.getDbEngine(); + HttpEntry resourceHttpEntry = SpringContextAware.getBean("traversalHttpEntry", HttpEntry.class); + resourceHttpEntry.setHttpEntryProperties(version, type); + // HttpEntry httpEntry = new HttpEntry(version, ModelType.MOXY, QueryStyle.TRAVERSAL, type); + Loader loader = resourceHttpEntry.getLoader(); + dbEngine = resourceHttpEntry.getDbEngine(); URI uriObject = UriBuilder.fromPath(uri).build(); URIToObject uriToObject = new URIToObject(loader, uriObject); @@ -330,7 +341,7 @@ public class HttpTestUtil extends RESTAPI { List<DBRequest> dbRequestList = new ArrayList<>(); dbRequestList.add(dbRequest); - Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = httpEntry.process(dbRequestList, "JUNIT"); + Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = resourceHttpEntry.process(dbRequestList, "JUNIT"); response = responsesTuple.getValue1().get(0).getValue1(); } catch (AAIException e) { diff --git a/aai-traversal/src/test/java/org/onap/aai/QueryParameterTest.java b/aai-traversal/src/test/java/org/onap/aai/QueryParameterTest.java new file mode 100644 index 0000000..3956b70 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/QueryParameterTest.java @@ -0,0 +1,188 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.config.PropertyPasswordConfiguration; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.http.*; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.client.RestTemplate; + +import javax.ws.rs.core.Response; +import java.util.*; + +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TraversalApp.class) +@TestPropertySource(locations = "classpath:application-test.properties") +@ContextConfiguration(initializers = PropertyPasswordConfiguration.class) +@Import(TraversalTestConfiguration.class) +public class QueryParameterTest { + + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(QueryParameterTest.class); + + private HttpTestUtil httpTestUtil; + + private String configurationId; + + private String configurationUri; + + private String configurationId2; + + private String configurationUri2; + + + @Autowired + RestTemplate restTemplate; + + @LocalServerPort + int randomPort; + + private HttpEntity httpEntity; + + private HttpHeaders headers; + + private String baseUrl; + private String customerId; + private String customerUri; + private String customerId2; + private String customerUri2; + + private String vnfId; + private String vnfUri; + + private String vnfId2; + private String vnfUri2; + + private String serviceInstanceId; + private String serviceInstanceName; + private String serviceInstanceId2; + private String serviceInstanceName2; + + @Before + public void setup() throws Exception { + + httpTestUtil = new HttpTestUtil(); + + configurationId = "test-" + UUID.randomUUID().toString(); + configurationUri ="/aai/v13/network/configurations/configuration/" + configurationId; + Map<String, String> configurationMap = new HashMap<>(); + configurationMap.put("configuration-id", configurationId); + String payload = PayloadUtil.getTemplatePayload("configuration.json", configurationMap); + httpTestUtil.doPut(configurationUri, payload); + + configurationId2 = "test-" + UUID.randomUUID().toString(); + configurationUri2 ="/aai/v13/network/configurations/configuration/" + configurationId2; + configurationMap.put("configuration-id", configurationId2); + payload = PayloadUtil.getTemplatePayload("configuration.json", configurationMap); + httpTestUtil.doPut(configurationUri2, payload); + + customerId = "test-" + UUID.randomUUID().toString(); + serviceInstanceId = "test-service-instance1"; + serviceInstanceName = "test service instance1"; + + customerUri ="/aai/v13/business/network/customers/customer/" + customerId; + Map<String, String> customerMap = new HashMap<>(); + customerMap.put("customer-id", customerId); + customerMap.put("service-instance-id", serviceInstanceId); + customerMap.put("configuration-id1", configurationId); + customerMap.put("configuration-id2", configurationId2); + customerMap.put("service-instance-name", serviceInstanceName); + payload = PayloadUtil.getTemplatePayload("customer-with-configurations.json", customerMap); + httpTestUtil.doPut(customerUri, payload); + + customerId2 = "test-" + UUID.randomUUID().toString(); + serviceInstanceId2 = "test-service-instance2"; + serviceInstanceName2 = "test service instance1"; + customerUri2 ="/aai/v13/business/customers/customer/" + customerId2; + + customerMap = new HashMap<>(); + customerMap.put("customer-id", customerId2); + customerMap.put("service-instance-id", serviceInstanceId2); + customerMap.put("service-instance-name", serviceInstanceName2); + payload = PayloadUtil.getTemplatePayload("customer-with-serviceinstance.json", customerMap); + httpTestUtil.doPut(customerUri2, payload); + + vnfId = "test-" + UUID.randomUUID().toString(); + vnfUri ="/aai/v13/network/generic-vnfs/generic-vnf/" + vnfId; + Map<String, String> vnfMap = new HashMap<>(); + vnfMap.put("vnf-id", vnfId); + vnfMap.put("configuration-id", configurationId); + vnfMap.put("interface-name", "test-interface-name1"); + vnfMap.put("vlan-interface", "test-vlan-name1"); + payload = PayloadUtil.getTemplatePayload("generic-vnf-to-configuration.json", vnfMap); + httpTestUtil.doPut(vnfUri, payload); + + vnfId2 = "test-" + UUID.randomUUID().toString(); + vnfUri2 ="/aai/v13/network/generic-vnfs/generic-vnf/" + vnfId2; + vnfMap = new HashMap<>(); + vnfMap.put("vnf-id", vnfId2); + vnfMap.put("configuration-id", configurationId2); + vnfMap.put("interface-name", "test-interface-name2"); + vnfMap.put("vlan-interface", "test-vlan-name2"); + payload = PayloadUtil.getTemplatePayload("generic-vnf-to-configuration.json", vnfMap); + httpTestUtil.doPut(vnfUri2, payload); + + headers = new HttpHeaders(); + + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.add("Real-Time", "true"); + headers.add("X-FromAppId", "JUNIT"); + headers.add("X-TransactionId", "JUNIT"); + String authorization = Base64.getEncoder().encodeToString("AAI:AAI".getBytes("UTF-8")); + headers.add("Authorization", "Basic " + authorization); + + baseUrl = "https://localhost:" + randomPort; + } + + @Test + public void testQueryApi() throws Exception { + + String endpoint = "/aai/v13/query?format=pathed"; + + Map<String, String> customQueryMap = new HashMap<>(); + String service = serviceInstanceName.replaceAll(" ", "+"); + System.out.println("Service " + service); + customQueryMap.put("start", "nodes/service-instances?service-instance-name=" + service); + customQueryMap.put("query", "containment-path"); + + String payload = PayloadUtil.getTemplatePayload("custom-query.json", customQueryMap); + httpEntity = new HttpEntity(payload, headers); + ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + LOGGER.info("Response of custom query : {}", responseEntity.getBody().toString()); + assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK)); + assertThat(responseEntity.getBody().toString(), containsString(customerUri2)); + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/SubgraphPruneTest.java b/aai-traversal/src/test/java/org/onap/aai/SubgraphPruneTest.java new file mode 100644 index 0000000..efb9e89 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/SubgraphPruneTest.java @@ -0,0 +1,129 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.config.PropertyPasswordConfiguration; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.http.*; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.client.RestTemplate; + +import javax.ws.rs.core.Response; +import java.util.*; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TraversalApp.class) +@TestPropertySource(locations = "classpath:application-test.properties") +@ContextConfiguration(initializers = PropertyPasswordConfiguration.class) +@Import(TraversalTestConfiguration.class) +public class SubgraphPruneTest { + + + private HttpTestUtil httpTestUtil; + + private String pserverUri; + + private String hostname; + + @Autowired + RestTemplate restTemplate; + + @LocalServerPort + int randomPort; + + private HttpEntity httpEntity; + + private HttpHeaders headers; + + private String baseUrl; + + private String vserverId; + + @Before + public void setup() throws Exception { + + httpTestUtil = new HttpTestUtil(); + + hostname = "test-" + UUID.randomUUID().toString(); + pserverUri ="/aai/v11/cloud-infrastructure/pservers/pserver/" + hostname; + Map<String, String> pserverMap = new HashMap<>(); + pserverMap.put("hostname", hostname); + String payload = PayloadUtil.getTemplatePayload("pserver.json", pserverMap); + httpTestUtil.doPut(pserverUri, payload); + + Map<String, String> cloudRegionMap = new HashMap<>(); + + vserverId = "some-vserver-id-id1111"; + + cloudRegionMap.put("cloud-owner", "some-owner-id1111"); + cloudRegionMap.put("cloud-region-id", "some-region-id1111"); + cloudRegionMap.put("tenant-id", "some-tenant-id1111"); + cloudRegionMap.put("tenant-name", "some-tenant-name-id1111"); + cloudRegionMap.put("vserver-id", vserverId); + cloudRegionMap.put("vserver-name", "some-vserver-name-id1111"); + cloudRegionMap.put("pserver-uri", pserverUri); + + String cloudRegionPayload = PayloadUtil.getTemplatePayload("cloud-region-with-vserver.json", cloudRegionMap); + String cloudRegionUri = "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/some-owner-id1111/some-region-id1111"; + + Response response = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload); + + headers = new HttpHeaders(); + + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.add("Real-Time", "true"); + headers.add("X-FromAppId", "JUNIT"); + headers.add("X-TransactionId", "JUNIT"); + String authorization = Base64.getEncoder().encodeToString("AAI:AAI".getBytes("UTF-8")); + headers.add("Authorization", "Basic " + authorization); + + baseUrl = "https://localhost:" + randomPort; + } + + @Test + public void testSubgraphPruneWorksAsExpectedWithValidResults() throws Exception { + + Map<String, String> gremlinQueryMap = new HashMap<>(); + // Having the cap('x') here causes the subgraph to fail + gremlinQueryMap.put("gremlin-query", "g.V().has('vserver-id', '" + vserverId + "').store('x').out().has('aai-node-type', 'pserver').store('x').cap('x').unfold()"); + + String payload = PayloadUtil.getTemplatePayload("gremlin-query.json", gremlinQueryMap); + String endpoint = "/aai/v13/query?format=console&subgraph=prune"; + + httpEntity = new HttpEntity(payload, headers); + ResponseEntity responseEntity = null; + responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + System.out.println(responseEntity.getBody().toString()); + assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK)); + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingInvalidDataTest.java b/aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingInvalidDataTest.java index 62bc7ce..e1515e3 100644 --- a/aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingInvalidDataTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingInvalidDataTest.java @@ -19,963 +19,949 @@ */ package org.onap.aai.dbgraphgen; -import static org.junit.Assert.*; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyMap; -import static org.mockito.Matchers.anyMapOf; -import static org.mockito.Mockito.*; - -import com.bazaarvoice.jolt.modifier.DataType; import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.Multimap; -import org.janusgraph.graphdb.olap.computer.VertexMapJob; -import org.janusgraph.graphdb.types.VertexLabelVertex; +import org.apache.tinkerpop.gremlin.structure.Vertex; import org.janusgraph.graphdb.types.system.BaseVertexLabel; import org.janusgraph.graphdb.types.system.EmptyVertex; -import org.janusgraph.graphdb.types.vertices.EdgeLabelVertex; -import org.janusgraph.graphdb.types.vertices.PropertyKeyVertex; -import org.apache.commons.lang.ObjectUtils; -import org.apache.tinkerpop.gremlin.structure.Graph; -import org.apache.tinkerpop.gremlin.structure.T; -import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.apache.tinkerpop.gremlin.structure.VertexProperty; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.*; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import org.mockito.runners.MockitoJUnitRunner; +import org.onap.aai.AAISetup; import org.onap.aai.db.DbMethHelper; import org.onap.aai.db.props.AAIProperties; import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.Loader; -import org.onap.aai.introspection.LoaderFactory; import org.onap.aai.introspection.ModelType; -import org.onap.aai.introspection.exceptions.AAIUnknownObjectException; import org.onap.aai.serialization.db.DBSerializer; import org.onap.aai.serialization.engines.TransactionalGraphEngine; -import javax.inject.Inject; import java.util.*; + +import static org.junit.Assert.*; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyMapOf; +import static org.mockito.Mockito.when; + @RunWith(MockitoJUnitRunner.class) -public class ModelBasedProcessingInvalidDataTest { - - @Mock - private static TransactionalGraphEngine dbEngine; - private static Loader loader; - @Mock - private static DBSerializer serializer; - ModelBasedProcessing processor; - - @Mock - private ModelBasedProcessing mockProcessor; - - - @Mock - private DbMethHelper dbMethHelper; - - @BeforeClass - public static void configure() throws Exception { - System.setProperty("AJSC_HOME", "."); - System.setProperty("BUNDLECONFIG_DIR", "src/main/resources"); - loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, AAIProperties.LATEST); - - - } - - @Before - public void init() { - MockitoAnnotations.initMocks(this); - processor = new ModelBasedProcessing(loader, dbEngine, serializer); - - dbMethHelper = new DbMethHelper(loader, dbEngine); - - } - - @Test - public void getStartNodesAndModVersionIdsTest() throws AAIException { - - - List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); - Map<String, Object> map = new HashMap<String, Object>(); - map.put("test", new Object()); - startNodeFilterArrayOfHashes.add(map); - Map<String, String> result=new HashMap<>(); - - Map<String, String> result1 = mockProcessor.getStartNodesAndModVersionIds("test", "test", - "test", "test", "test", - "test", startNodeFilterArrayOfHashes, - "test"); - assertNotNull(result); - - } - - - @Test(expected = NullPointerException.class) - public void getStartNodesAndModVersionIdsTest2() throws AAIException { - List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); - Map<String, Object> map = new HashMap<String, Object>(); - map.put("test", new Object()); - startNodeFilterArrayOfHashes.add(map); - Map<String, String> result1 = processor.getStartNodesAndModVersionIds("test", "test", - "", "test", "test", - "test", startNodeFilterArrayOfHashes, - "test"); - assertNotNull(result1); - } - - - @Test(expected = NullPointerException.class) - public void getStartNodesAndModVersionIdsTest3() throws AAIException { - List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); - Map<String, Object> map = new HashMap<String, Object>(); - map.put("test", new Object()); - startNodeFilterArrayOfHashes.add(map); - Map<String, String> result1 = processor.getStartNodesAndModVersionIds("test", "test", - "", "", "test", - "test", startNodeFilterArrayOfHashes, - "test"); - assertNotNull(result1); - } - - - @Test(expected = AAIException.class) - public void getStartNodesAndModVersionIdsTest4() throws AAIException { - List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); - Map<String, Object> map = new HashMap<String, Object>(); - map.put("test", new Object()); - startNodeFilterArrayOfHashes.add(map); - Map<String, String> result1 = processor.getStartNodesAndModVersionIds("test", "test", - "", "", "", - "test", startNodeFilterArrayOfHashes, - "test"); - assertNotNull(result1); - } - - - @Test(expected = AAIException.class) - public void getStartNodesAndModVersionIdsTest5() throws AAIException { - List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); - Map<String, Object> map = new HashMap<String, Object>(); - map.put("test", new Object()); - startNodeFilterArrayOfHashes.add(map); - Map<String, String> result1 = processor.getStartNodesAndModVersionIds("test", "test", - "", "", "", - "", startNodeFilterArrayOfHashes, - "test"); - assertNotNull(result1); - } - - - @Test(expected = AAIException.class) - public void getStartNodesAndModVersionIdsNullTest() throws AAIException { - List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); - - Map<String, String> result = null; - result = processor.getStartNodesAndModVersionIds("test", "test", - "", "", "", - "", startNodeFilterArrayOfHashes, - "test"); - - assertNotNull(result); - } - - - @Test(expected = NullPointerException.class) - public void getStartNodesAndModVersionIdsNullTest1() throws AAIException { - List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); - - Map<String, String> result = null; - result = processor.getStartNodesAndModVersionIds("test", "test", - "Test", "", "", - "", startNodeFilterArrayOfHashes, - "test"); - - assertNotNull(result); - } - - @Test(expected = NullPointerException.class) - public void getStartNodesAndModVersionIdsNullTest2() throws AAIException { - List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); - - Map<String, String> result = null; - result = processor.getStartNodesAndModVersionIds("test", "test", - "", "test", "", - "", startNodeFilterArrayOfHashes, - "test"); - assertNotNull(result); - } - - - @Test(expected = NullPointerException.class) - public void getStartNodesAndModVersionIdsNullTest3() throws AAIException { - List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); - - Map<String, String> result = null; - result = processor.getStartNodesAndModVersionIds("test", "test", - "", "", "test", - "", startNodeFilterArrayOfHashes, - "test"); - assertNotNull(result); - } - - @Test(expected = NullPointerException.class) - public void getModelVerTopWidgetTypeTest() throws AAIException { - Vertex vertex = new EmptyVertex(); - //Mockito.when(mockProcessor.getModelVerTopWidgetType(Mockito.any(Vertex.class), Mockito.any(String.class))).thenReturn("Sucess"); - String result = processor.getModelVerTopWidgetType(vertex, "test"); - assertEquals("result has -local tacked on the end as it should", "Sucess", result - ); - - } - - @Test(expected = NullPointerException.class) - public void getModelVerTopWidgetType() throws AAIException { +public class ModelBasedProcessingInvalidDataTest extends AAISetup { + + @Mock + private static TransactionalGraphEngine dbEngine; + private static Loader loader; + @Mock + private static DBSerializer serializer; + ModelBasedProcessing processor; + + @Mock + private ModelBasedProcessing mockProcessor; + + + @Mock + private DbMethHelper dbMethHelper; + + @BeforeClass + public static void configure() throws Exception { + System.setProperty("AJSC_HOME", "."); + System.setProperty("BUNDLECONFIG_DIR", "src/main/resources"); + } + + @Before + public void init() { + MockitoAnnotations.initMocks(this); + loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); + processor = new ModelBasedProcessing(loader, dbEngine, serializer); + + dbMethHelper = new DbMethHelper(loader, dbEngine); + + } + + @Test + public void getStartNodesAndModVersionIdsTest() throws AAIException { + + + List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); + Map<String, Object> map = new HashMap<String, Object>(); + map.put("test", new Object()); + startNodeFilterArrayOfHashes.add(map); + Map<String, String> result = new HashMap<>(); + + Map<String, String> result1 = mockProcessor.getStartNodesAndModVersionIds("test", "test", + "test", "test", "test", + "test", startNodeFilterArrayOfHashes, + "test"); + assertNotNull(result); + + } + + + @Test(expected = NullPointerException.class) + public void getStartNodesAndModVersionIdsTest2() throws AAIException { + List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); + Map<String, Object> map = new HashMap<String, Object>(); + map.put("test", new Object()); + startNodeFilterArrayOfHashes.add(map); + Map<String, String> result1 = processor.getStartNodesAndModVersionIds("test", "test", + "", "test", "test", + "test", startNodeFilterArrayOfHashes, + "test"); + assertNotNull(result1); + } + + + @Test(expected = NullPointerException.class) + public void getStartNodesAndModVersionIdsTest3() throws AAIException { + List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); + Map<String, Object> map = new HashMap<String, Object>(); + map.put("test", new Object()); + startNodeFilterArrayOfHashes.add(map); + Map<String, String> result1 = processor.getStartNodesAndModVersionIds("test", "test", + "", "", "test", + "test", startNodeFilterArrayOfHashes, + "test"); + assertNotNull(result1); + } + + + @Test(expected = AAIException.class) + public void getStartNodesAndModVersionIdsTest4() throws AAIException { + List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); + Map<String, Object> map = new HashMap<String, Object>(); + map.put("test", new Object()); + startNodeFilterArrayOfHashes.add(map); + Map<String, String> result1 = processor.getStartNodesAndModVersionIds("test", "test", + "", "", "", + "test", startNodeFilterArrayOfHashes, + "test"); + assertNotNull(result1); + } + + + @Test(expected = AAIException.class) + public void getStartNodesAndModVersionIdsTest5() throws AAIException { + List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); + Map<String, Object> map = new HashMap<String, Object>(); + map.put("test", new Object()); + startNodeFilterArrayOfHashes.add(map); + Map<String, String> result1 = processor.getStartNodesAndModVersionIds("test", "test", + "", "", "", + "", startNodeFilterArrayOfHashes, + "test"); + assertNotNull(result1); + } + + + @Test(expected = AAIException.class) + public void getStartNodesAndModVersionIdsNullTest() throws AAIException { + List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); + + Map<String, String> result = null; + result = processor.getStartNodesAndModVersionIds("test", "test", + "", "", "", + "", startNodeFilterArrayOfHashes, + "test"); + + assertNotNull(result); + } + + + @Test(expected = NullPointerException.class) + public void getStartNodesAndModVersionIdsNullTest1() throws AAIException { + List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); + + Map<String, String> result = null; + result = processor.getStartNodesAndModVersionIds("test", "test", + "Test", "", "", + "", startNodeFilterArrayOfHashes, + "test"); + + assertNotNull(result); + } + + @Test(expected = NullPointerException.class) + public void getStartNodesAndModVersionIdsNullTest2() throws AAIException { + List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); + + Map<String, String> result = null; + result = processor.getStartNodesAndModVersionIds("test", "test", + "", "test", "", + "", startNodeFilterArrayOfHashes, + "test"); + assertNotNull(result); + } + + + @Test(expected = NullPointerException.class) + public void getStartNodesAndModVersionIdsNullTest3() throws AAIException { + List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); + + Map<String, String> result = null; + result = processor.getStartNodesAndModVersionIds("test", "test", + "", "", "test", + "", startNodeFilterArrayOfHashes, + "test"); + assertNotNull(result); + } + + @Test(expected = NullPointerException.class) + public void getModelVerTopWidgetTypeTest() throws AAIException { + Vertex vertex = new EmptyVertex(); + //Mockito.when(mockProcessor.getModelVerTopWidgetType(Mockito.any(Vertex.class), Mockito.any(String.class))).thenReturn("Sucess"); + String result = processor.getModelVerTopWidgetType(vertex, "test"); + assertEquals("result has -local tacked on the end as it should", "Sucess", result + ); + + } + + @Test(expected = NullPointerException.class) + public void getModelVerTopWidgetType() throws AAIException { /*Mockito.when(mockProcessor.getModelVerTopWidgetType(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class)) ).thenReturn("Sucess");*/ - String result = processor.getModelVerTopWidgetType("test", "test", "test", "Test", "test"); - assertEquals("result has -local tacked on the end as it should", "Sucess", result - ); + String result = processor.getModelVerTopWidgetType("test", "test", "test", "Test", "test"); + assertEquals("result has -local tacked on the end as it should", "Sucess", result + ); - } + } - @Test(expected = AAIException.class) - public void queryByModel() throws AAIException { + @Test(expected = AAIException.class) + public void queryByModel() throws AAIException { /*Mockito.when(mockProcessor.getModelVerTopWidgetType(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class)) ).thenReturn("Sucess");*/ - List<ResultSet> result = processor.queryByModel("test", "test", - "test", "test", "test", - "generic-vnf", null, - "test"); - assertEquals("result has -local tacked on the end as it should", 0, result.size()); - - - } + List<ResultSet> result = processor.queryByModel("test", "test", + "test", "test", "test", + "generic-vnf", null, + "test"); + assertEquals("result has -local tacked on the end as it should", 0, result.size()); - @Test(expected = NullPointerException.class) - public void queryByModel_Timed() throws AAIException { - List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); - Map<String, Object> map = new HashMap<String, Object>(); - map.put("test", new Object()); - startNodeFilterArrayOfHashes.add(map); - List<ResultSet> result = processor.queryByModel_Timed("test", "test", - "test", "test", "test", - "test", startNodeFilterArrayOfHashes, - "test"); - assertEquals("result has -local tacked on the end as it should", 0, result.size()); - + } - } - @Mock - Map<String, Object> startNodeFilterHash; - - @Test(expected = NullPointerException.class) - public void runDeleteByModel() throws AAIException { - Map<String, String> resultMock = new HashMap<String, String>(); + @Test(expected = NullPointerException.class) + public void queryByModel_Timed() throws AAIException { + List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); + Map<String, Object> map = new HashMap<String, Object>(); + map.put("test", new Object()); + startNodeFilterArrayOfHashes.add(map); + List<ResultSet> result = processor.queryByModel_Timed("test", "test", + "test", "test", "test", + "test", startNodeFilterArrayOfHashes, + "test"); + assertEquals("result has -local tacked on the end as it should", 0, result.size()); + - // when(mockProcessor.getNodeUsingUniqueId(any(String.class),any(String.class),any(String.class),any(String.class),any(String.class))).thenReturn(vertex); - when(mockProcessor.runDeleteByModel(any(String.class), - any(String.class), any(String.class), - any(String.class), anyMapOf(String.class, Object.class), any(String.class), any(String.class)) - ).thenReturn(resultMock); - Map<String, String> result = processor.runDeleteByModel("test", "test", - "test", "test", startNodeFilterHash, - "test", - "test"); - assertEquals("result has -local tacked on the end as it should", result.size(), resultMock.size()); + } + @Mock + Map<String, Object> startNodeFilterHash; + + @Test(expected = NullPointerException.class) + public void runDeleteByModel() throws AAIException { + Map<String, String> resultMock = new HashMap<String, String>(); - } - - Optional<Vertex> vertext = Optional.empty(); - - @Test(expected = AAIException.class) - public void runDeleteByModelWithNullParams() throws AAIException { - Map<String, String> resultMock = new HashMap<String, String>(); - - - Map<String, String> result = processor.runDeleteByModel("test", "test", - null, null, null, - "test", - "test"); - - assertNotNull(result); - - } - - @Test(expected = NullPointerException.class) - public void runDeleteByModelWithNullParams1() throws AAIException { - - Map<String, String> result1 = processor.runDeleteByModel("test", "test", - null, "unknown", null, - "test", - "test"); - assertNotNull(result1); - - } - - - @Test(expected = NullPointerException.class) - public void runDeleteByModelWithNullParams2() throws AAIException { - - Map<String, String> result1 = processor.runDeleteByModel("test", "test", - null, "unknown", null, - "test", - "test"); - assertNotNull(result1); - - } - - @Test(expected = AAIException.class) - public void queryByNamedQuery() throws AAIException{ - String transId="test"; - String fromAppId="test"; - String namedQueryUuid="test"; - ArrayList <Map<String,Object>> startNodeFilterArrayOfHashes=new ArrayList<Map<String,Object>>(); - String apiVer="test"; - List<ResultSet> result=processor.queryByNamedQuery(transId,fromAppId,namedQueryUuid,startNodeFilterArrayOfHashes,apiVer); - assertNotNull(result); - } - - @Test(expected = AAIException.class) - public void queryByNamedQuery1() throws AAIException{ - String transId="teet"; - String fromAppId="test"; - String namedQueryUuid="test"; - String secondaryFilterCutPoint="test"; - List <Map<String,Object>> startNodeFilterArrayOfHashes=new ArrayList<Map<String,Object>>(); - String apiVer="test"; - Map<String,Object> secondaryFilterHash=new HashMap<String,Object>(); - List<ResultSet> result=processor.queryByNamedQuery(transId,fromAppId,namedQueryUuid,startNodeFilterArrayOfHashes,apiVer,secondaryFilterCutPoint,secondaryFilterHash); - assertNotNull(result); - } - - @Test - public void deleteAsNeededFromResultSet() throws AAIException { - Vertex vert = new BaseVertexLabel("Test"); - Map<String, String> resultMock = new HashMap<String, String>(); - ResultSet resultSet = new ResultSet(); - resultSet.setVert(null); - - Map<String, String> result = processor.deleteAsNeededFromResultSet("test", "test", - resultSet, "test", "test", - "test", - resultMock); - - assertEquals(result.size(), 0); - - resultSet.setVert(vert); - - Map<String, String> result1 = processor.deleteAsNeededFromResultSet("test", "test", - resultSet, "test", "test", - "test", - resultMock); - - assertEquals(result.size(), 0); - - - } - - @Test(expected = NullPointerException.class) - public void pruneResultSetTest() throws AAIException { - ResultSet rs = new ResultSet(); - Vertex v = new BaseVertexLabel(AAIProperties.NODE_TYPE); - rs.setVert(v); - List<ResultSet> rsList = new ArrayList<ResultSet>(); - ResultSet rs1 = new ResultSet(); - rsList.add(rs1); - rs.setSubResultSet(rsList); - Map<String, Object> map = new HashMap<String, Object>(); - map.put("test", new Object()); - ResultSet resultSet = processor.pruneResultSet(rs, "testr", map); - assertNotNull(resultSet); - - } - - @Test(expected = NullPointerException.class) - public void satisfiesFiltersTest() throws AAIException { - ResultSet rs = new ResultSet(); - Vertex v = new BaseVertexLabel(AAIProperties.NODE_TYPE); - rs.setVert(v); - rs.getVert().property(AAIProperties.NODE_TYPE); - List<ResultSet> rsList = new ArrayList<ResultSet>(); - ResultSet rs1 = new ResultSet(); - rsList.add(rs1); - rs.setSubResultSet(rsList); - Map<String, Object> map = new HashMap<String, Object>(); - - map.put("modern.vertex-id", new Object()); - - boolean result = processor.satisfiesFilters(rs, map); - assertEquals(result, true); - } - - @Test - public void satisfiesFiltersTest1() throws AAIException { - ResultSet rs = new ResultSet(); - Vertex v = new BaseVertexLabel(AAIProperties.NODE_TYPE); - rs.setVert(v); - List<ResultSet> rsList = new ArrayList<ResultSet>(); - ResultSet rs1 = new ResultSet(); - rsList.add(rs1); - rs.setSubResultSet(rsList); - Map<String, Object> map = new HashMap<String, Object>(); - //map.put("test.filter",new Object()); - - boolean result = processor.satisfiesFilters(rs, map); - assertEquals(result, false); - } - - @Test(expected = AAIException.class) - public void satisfiesFiltersTest2() throws AAIException { - ResultSet rs = new ResultSet(); - Vertex v = new BaseVertexLabel(AAIProperties.NODE_TYPE); - rs.setVert(v); - List<ResultSet> rsList = new ArrayList<ResultSet>(); - ResultSet rs1 = new ResultSet(); - rsList.add(rs1); - rs.setSubResultSet(rsList); - Map<String, Object> map = new HashMap<String, Object>(); - map.put("testfilter", new Object()); - - boolean result = processor.satisfiesFilters(rs, map); - assertEquals(result, false); - } - - @Test - public void collapseForDoNotOutputTest() throws AAIException { - ResultSet rs = new ResultSet(); - rs.setDoNotOutputFlag("true"); - List<ResultSet> rsList = new ArrayList<ResultSet>(); - ResultSet rs1 = new ResultSet(); - rsList.add(rs1); - rs.setSubResultSet(rsList); - List<ResultSet> result = processor.collapseForDoNotOutput(rs); - assertEquals(result.size(), 1); - } - - @Test(expected = NullPointerException.class) - public void collectInstanceDataTest() throws AAIException { - - BaseVertexLabel bs = new BaseVertexLabel("test"); - //bs.setId(80); - EmptyVertex ev = new EmptyVertex(); - //ev.setId(50l); - Vertex thisLevelElemVtx = ev; - - - Multimap<String, String> thisMap = ArrayListMultimap.create(); - List<String> vidsTraversed = new ArrayList<String>(); - // only applies when collecting data using the default model for delete - Multimap<String, String> validNextStepMap = ArrayListMultimap.create(); - Map<String, String> namedQueryElementHash = new HashMap<String, String>(); - namedQueryElementHash.put("test", "test"); - Map<String, String> delKeyHash = new HashMap<String, String>(); - - ResultSet rs = processor.collectInstanceData("test", "test", thisLevelElemVtx, "test", validNextStepMap, vidsTraversed, 1, delKeyHash, namedQueryElementHash, "test"); - } - - @Test(expected = NullPointerException.class) - public void genTopoMap4ModelVerTest() throws - AAIException { - Vertex vertext = new EmptyVertex(); - Multimap<String, String> map = processor.genTopoMap4ModelVer("test", "test", vertext, "test"); - assertNotEquals(map, null); - } - - @Test(expected = AAIException.class) - public void genTopoMap4ModelVerTestNull() throws - AAIException { - Vertex vertext = null; - Multimap<String, String> map = processor.genTopoMap4ModelVer("test", "test", vertext, "test"); - assertNotEquals(map, null); - } - - @Test - public void makeSureItsAnArrayListTest() { - String input = "model-versionId,modelTestID,modelTestid2;"; - List<String> result = processor.makeSureItsAnArrayList(input); - assertTrue(result.size() > 0); - } - - @Test(expected = AAIException.class) - public void getModConstraintHashTest() throws AAIException { - Vertex modelElementVtx = new EmptyVertex(); - //modelElementVtx.property(AAIProperties.NODE_TYPE,"Model"); - Vertex modelElementVtx1 = new EmptyVertex(); - Map<String, Vertex> currentHash = new HashMap<String, Vertex>(); - currentHash.put("constraint", modelElementVtx1); - Map<String, Vertex> result = processor.getModConstraintHash(modelElementVtx, currentHash); - assertTrue(result.size() > 0); - } - - @Test(expected = AAIException.class) - public void getModConstraintHashTestNull() throws AAIException { - Vertex modelElementVtx = null; - //modelElementVtx.property(AAIProperties.NODE_TYPE,"Model"); - Vertex modelElementVtx1 =null; - Map<String, Vertex> currentHash = new HashMap<String, Vertex>(); - currentHash.put("constraint", modelElementVtx1); - Map<String, Vertex> result = processor.getModConstraintHash(modelElementVtx, currentHash); - assertTrue(result.size() > 0); - } - - @Test(expected = NullPointerException.class) - public void getTopElementForSvcOrResModelVerTest() throws AAIException { - Vertex modelElementVtx = new EmptyVertex(); - //modelElementVtx.property(AAIProperties.NODE_TYPE,"Model"); - Vertex modelElementVtx1 = new EmptyVertex(); - Map<String, Vertex> currentHash = new HashMap<String, Vertex>(); - currentHash.put("constraint", modelElementVtx1); - Vertex result = processor.getTopElementForSvcOrResModelVer(modelElementVtx, "test"); - assertNotEquals(result, null); - } - - @Test - public void getNamedQueryPropOverRideTest() throws AAIException { - String transId = "test"; - String fromAppId = "test"; - Vertex namedQueryElementVertex = new EmptyVertex(); - Vertex instanceVertex = new EmptyVertex(); - String apiVer = "test"; - - namedQueryElementVertex.properties("property-collect-list", ""); - - Map<String, Object> result = processor.getNamedQueryPropOverRide(transId, fromAppId, namedQueryElementVertex, instanceVertex, apiVer); - assertNotEquals(result, null); - } - - @Test(expected = NullPointerException.class) - public void getNamedQueryPropOverRideTestNull() throws AAIException { - String transId = "test"; - String fromAppId = "test"; - Vertex namedQueryElementVertex = null; - Vertex instanceVertex = new EmptyVertex(); - String apiVer = "test"; - - namedQueryElementVertex.properties("property-collect-list", ""); - - Map<String, Object> result = processor.getNamedQueryPropOverRide(transId, fromAppId, namedQueryElementVertex, instanceVertex, apiVer); - assertNotEquals(result, null); - } - - @Test(expected = NullPointerException.class) - public void namedQueryConstraintSaysStopTest() throws AAIException { - String transId = "test"; - String fromAppId = "test"; - Vertex namedQueryElementVertex = new EmptyVertex(); - Vertex instanceVertex = new EmptyVertex(); - String apiVer = "test"; - - namedQueryElementVertex.properties("property-collect-list", ""); - - boolean result = processor.namedQueryConstraintSaysStop(transId, fromAppId, namedQueryElementVertex, instanceVertex, apiVer); - assertTrue(result); - } - - @Test(expected = NullPointerException.class) - public void namedQueryConstraintSaysStopTestNull() throws AAIException { - String transId = "test"; - String fromAppId = "test"; - Vertex namedQueryElementVertex = null; - Vertex instanceVertex = new EmptyVertex(); - String apiVer = "test"; - - namedQueryElementVertex.properties("property-collect-list", ""); - - boolean result = processor.namedQueryConstraintSaysStop(transId, fromAppId, namedQueryElementVertex, instanceVertex, apiVer); - assertTrue(result); - } - - @Test(expected = AAIException.class) - public void namedQuerynamedQueryElementVertexNullTest() throws AAIException { - String transId = "test"; - String fromAppId = "test"; - Vertex namedQueryElementVertex = null; - Vertex instanceVertex = null; - String apiVer = "test"; - - - boolean result = processor.namedQueryConstraintSaysStop(transId, fromAppId, namedQueryElementVertex, instanceVertex, apiVer); - assertTrue(result); - } - - @Test(expected = NullPointerException.class) - - public void getNamedQueryExtraDataLookupTest() throws Exception { - - String transId = "test"; - String fromAppId = "test"; - Vertex namedQueryElementVertex = new EmptyVertex(); - Vertex instanceVertex = new EmptyVertex(); - String apiVer = "test"; - - namedQueryElementVertex.properties("property-collect-list", ""); - - Map<String, Object> result = processor.getNamedQueryExtraDataLookup(transId, fromAppId, namedQueryElementVertex, instanceVertex, apiVer); - - assertTrue(result.size() > 0); - } - - @Test(expected = NullPointerException.class) - public void collectNQElementHash() throws AAIException { - String transId = "test"; - String fromAppId = "test"; - Vertex thisLevelElemVtx = new EmptyVertex(); - String incomingTrail = "test"; - Map<String, String> currentHash = new HashMap<String, String>(); - ArrayList<String> vidsTraversed = new ArrayList<String>(); - int levelCounter = 1; - - Map<String, String> result = processor.collectNQElementHash(transId, fromAppId, - thisLevelElemVtx, incomingTrail, currentHash, - vidsTraversed, levelCounter); - - assertNotEquals(result, null); - } - - @Test(expected = NullPointerException.class) - public void collectDeleteKeyHash() throws AAIException { - String transId = "test"; - String fromAppId = "test"; - Vertex thisLevelElemVtx = new EmptyVertex(); - String incomingTrail = "test"; - Map<String, String> currentHash = new HashMap<String, String>(); - ArrayList<String> vidsTraversed = new ArrayList<String>(); - int levelCounter = 1; - Map<String, Vertex> modConstraintHash = new HashMap<String, Vertex>(); - String overRideModelId = "test"; - String overRideModelVersionId = "test"; - - Map<String, String> result = processor.collectDeleteKeyHash(transId, fromAppId, - thisLevelElemVtx, incomingTrail, currentHash, - vidsTraversed, levelCounter, modConstraintHash, overRideModelId, overRideModelVersionId); - - assertNotEquals(result, null); - } - - @Test - public void getLinkageConnectNodeTypesTest() throws AAIException { - List<String> linkagePtList = new ArrayList<String>(); - linkagePtList.add("modern\\|testdata\\|"); - Set<String> result = processor.getLinkageConnectNodeTypes(linkagePtList); - assertNotEquals(result, null); - - } - - @Test(expected = AAIException.class) - public void getLinkageConnectNodeTypesTest1() throws AAIException { - - Set<String> result1 = processor.getLinkageConnectNodeTypes(null); - assertNotEquals(result1, null); - - List<String> linkagePtList = new ArrayList<String>(); - linkagePtList.add("moderntestdata"); - Set<String> result = processor.getLinkageConnectNodeTypes(linkagePtList); - assertNotEquals(result, null); - } - - @Test(expected = NullPointerException.class) - public void collectTopology4ModelVerTest() throws AAIException { - String transId = "test"; - String fromAppId = "test"; - Multimap<String, String> thisMap = ArrayListMultimap.create(); - Vertex thisLevelElemVtx = new EmptyVertex(); - String incomingTrail = "test"; - Map<String, Vertex> currentHash = new HashMap<String, Vertex>(); - List<String> vidsTraversed = new ArrayList<String>(); - int levelCounter = 1; - - Multimap<String, String> result = processor.collectTopology4ModelVer(transId, fromAppId, - thisLevelElemVtx, incomingTrail, thisMap, vidsTraversed, levelCounter, currentHash - , "test", "test"); - - assertNotEquals(result, null); - } - - @Test(expected = AAIException.class) - public void check4EdgeRuleTest() throws AAIException { - processor.check4EdgeRule("test", "test"); - } - - @Test(expected = AAIException.class) - public void collectTopology4LinkagePointTest() throws AAIException { - String transId = "test"; - String fromAppId = "test"; - String linkagePointStrVal = "test"; - String incomingTrail = "test"; - Multimap<String, String> currentMap = ArrayListMultimap.create(); - - Multimap<String, String> result = processor.collectTopology4LinkagePoint(transId, fromAppId, linkagePointStrVal, incomingTrail, currentMap); - assertNotEquals(result, null); - - } - - @Test(expected = AAIException.class) - public void getNextStepElementsFromSet() throws AAIException { - Vertex constrElemSetVtx = new EmptyVertex(); - constrElemSetVtx.<String>property(AAIProperties.NODE_TYPE); - Map<String, Object> result = processor.getNextStepElementsFromSet(constrElemSetVtx); - assertNotEquals(result, null); - } - - @Test(expected = NullPointerException.class) - public void genTopoMap4NamedQTest() throws AAIException { - String transId = "test"; - String fromAppId = "test"; - Vertex queryVertex = new EmptyVertex(); - String namedQueryUuid = "E44533334343"; - Multimap<String, String> result = processor.genTopoMap4NamedQ(transId, fromAppId, queryVertex, namedQueryUuid); - assertNotEquals(result, null); - } - - @Test(expected = NullPointerException.class) - public void collectTopology4NamedQTest() throws AAIException { - String transId = "test"; - String fromAppId = "test"; - Multimap<String, String> thisMap = ArrayListMultimap.create(); - Vertex thisLevelElemVtx = new EmptyVertex(); - String incomingTrail = "test"; - Map<String, Vertex> currentHash = new HashMap<String, Vertex>(); - List<String> vidsTraversed = new ArrayList<String>(); - int levelCounter = 1; - - Multimap<String, String> result = processor.collectTopology4NamedQ(transId, fromAppId, - thisLevelElemVtx, incomingTrail, thisMap, vidsTraversed, levelCounter); - assertNotEquals(result, null); - } - - @Test(expected = NullPointerException.class) - public void getModelThatNqElementRepresentsTest() throws AAIException { - Vertex thisLevelElemVtx = new EmptyVertex(); - String incomingTrail = "test"; - Vertex vertex = processor.getModelThatNqElementRepresents(thisLevelElemVtx, incomingTrail); - assertNotEquals(vertex, null); - } - - @Test(expected = NullPointerException.class) - public void getModelGivenModelVer() throws AAIException { - Vertex thisLevelElemVtx = new EmptyVertex(); - String incomingTrail = "test"; - Vertex vertex = processor.getModelGivenModelVer(thisLevelElemVtx, incomingTrail); - assertNotEquals(vertex, null); - } - - @Test(expected = AAIException.class) - public void getModelTypeFromModel() throws AAIException { - Vertex thisLevelElemVtx = new EmptyVertex(); - String incomingTrail = "test"; - String vertex = processor.getModelTypeFromModel(thisLevelElemVtx, incomingTrail); - assertNotEquals(vertex, null); - } - - @Test(expected = NullPointerException.class) - public void getModelTypeFromModelVer() throws AAIException { - Vertex thisLevelElemVtx = new EmptyVertex(); - String incomingTrail = "test"; - String vertex = processor.getModelTypeFromModelVer(thisLevelElemVtx, incomingTrail); - assertNotEquals(vertex, null); - } - - @Test(expected = NullPointerException.class) - public void getModelElementStepName() throws AAIException { - Vertex thisLevelElemVtx = new EmptyVertex(); - String incomingTrail = "test"; - String vertex = processor.getModelElementStepName(thisLevelElemVtx, incomingTrail); - assertNotEquals(vertex, null); - } - - @Test(expected = AAIException.class) - public void nodeTypeSupportsPersona() throws AAIException { - String incomingTrail = ""; - boolean vertex = processor.nodeTypeSupportsPersona(incomingTrail); - assertFalse(vertex); - - - incomingTrail = "test"; - boolean vertex1 = processor.nodeTypeSupportsPersona(incomingTrail); - assertTrue(vertex1); - } - - @Test(expected = NullPointerException.class) - public void getNqElementWidgetType() throws AAIException{ - String appId="test"; - String transID="test"; - Vertex thisLevelElemVtx = new EmptyVertex(); - String incomingTrail = "test"; - String vertex1 = processor.getNqElementWidgetType(appId,transID,thisLevelElemVtx,incomingTrail); - assertNotEquals(vertex1,null); - } - - - @Test(expected = NullPointerException.class) - public void getModElementWidgetType() throws AAIException{ - String appId="test"; - String transID="test"; - Vertex thisLevelElemVtx = new EmptyVertex(); - String incomingTrail = "test"; - String vertex1 = processor.getModElementWidgetType(thisLevelElemVtx,incomingTrail); - assertNotEquals(vertex1,null); - } - - @Test(expected = NullPointerException.class) - public void getNodeUsingUniqueId() throws AAIException{ - String appId="test"; - String transID="test"; - String nodeType = "generic-vnf"; - String idPropertyName = "test"; - String uniqueIdVal="test"; - Vertex vertex1 = processor.getNodeUsingUniqueId(transID,appId,nodeType,idPropertyName,uniqueIdVal); - assertNotEquals(vertex1,null); - } - - - @Test(expected = AAIException.class) - public void getNodeUsingUniqueIdNull() throws AAIException{ - String appId="test"; - String transID="test"; - String nodeType = "generic-vnf"; - String idPropertyName = "test"; - String uniqueIdVal=""; - Vertex vertex1 = null; - vertex1= processor.getNodeUsingUniqueId(transID,appId,nodeType,idPropertyName,uniqueIdVal); - assertNotEquals(vertex1,null); - - } - - - @Test(expected = AAIException.class) - public void getNodeUsingUniqueIdNull1() throws AAIException{ - String appId="test"; - String transID="test"; - String nodeType = "generic-vnf"; - String idPropertyName=""; - String uniqueIdVal="test"; - Vertex vertex1 = null; - vertex1= processor.getNodeUsingUniqueId(transID,appId,nodeType,idPropertyName,uniqueIdVal); - assertNotEquals(vertex1,null); - - - } - - - @Test(expected = AAIException.class) - public void getNodeUsingUniqueIdNull2() throws AAIException{ - String appId="test"; - String transID="test"; - String nodeType = ""; - String idPropertyName="test"; - String uniqueIdVal="test"; - Vertex vertex1 = null; - vertex1= processor.getNodeUsingUniqueId(transID,appId,nodeType,idPropertyName,uniqueIdVal); - assertNotEquals(vertex1,null); - - - } - - @Test(expected = NullPointerException.class) - public void getModelVersUsingName() throws AAIException{ - String appId="test"; - String transID="test"; - String modelName = "test"; - - List<Vertex> result= processor.getModelVersUsingName(transID,appId,modelName); - assertNotEquals(result,null); - } - - - @Test(expected = AAIException.class) - public void getModelVersUsingNameNull() throws AAIException{ - String appId="test"; - String transID="test"; - String modelName = ""; - - List<Vertex> result= processor.getModelVersUsingName(transID,appId,modelName); - assertNotEquals(result,null); - } - - - @Test(expected = NullPointerException.class) - public void getModVersUsingModelInvId() throws AAIException{ - String appId="test"; - String transID="test"; - String modelName = "test"; - - Iterator<Vertex> result= processor.getModVersUsingModelInvId(transID,appId,modelName); - assertNotEquals(result,null); - } - - @Test(expected = AAIException.class) - public void getModVersUsingModelInvIdNull() throws AAIException{ - String appId="test"; - String transID="test"; - String modelName = ""; - - Iterator<Vertex> result= processor.getModVersUsingModelInvId(transID,appId,modelName); - assertNotEquals(result,null); - } - - @Test(expected = NullPointerException.class) - public void getModVersUsingModel() throws AAIException{ - String appId="test"; - String transID="test"; - String modelName = "test"; - Vertex thisLevelElemVtx = new EmptyVertex(); - List<Vertex> result= processor.getModVersUsingModel(transID,appId,thisLevelElemVtx); - assertNotEquals(result,null); - } - - @Test(expected = AAIException.class) - public void getModVersUsingModel1() throws AAIException{ - String appId="test"; - String transID="test"; - - Vertex thisLevelElemVtx = null; - List<Vertex> result= processor.getModVersUsingModel(transID,appId,thisLevelElemVtx); - assertNotEquals(result,null); - } - - @Test(expected = NullPointerException.class) - public void getModelVerIdsUsingName() throws AAIException{ - String appId="test"; - String transID="test"; - - String modelName= "test"; - List<String> result= processor.getModelVerIdsUsingName(transID,appId,modelName); - assertNotEquals(result,null); - } - - @Test(expected = AAIException.class) - public void getModelVerIdsUsingName1() throws AAIException{ - String appId="test"; - String transID="test"; - - String modelName= ""; - List<String> result= processor.getModelVerIdsUsingName(transID,appId,modelName); - assertNotEquals(result,null); - } - - @Test(expected =NullPointerException.class) - public void validateModel() throws AAIException{ - String appId="test"; - String transID="test"; - - String modelVersionId= "test"; - String modelInvId= "test"; - String modelName= "test"; - processor.validateModel(transID,appId,modelName,modelVersionId); - - - } + // when(mockProcessor.getNodeUsingUniqueId(any(String.class),any(String.class),any(String.class),any(String.class),any(String.class))).thenReturn(vertex); + when(mockProcessor.runDeleteByModel(any(String.class), + any(String.class), any(String.class), + any(String.class), anyMapOf(String.class, Object.class), any(String.class), any(String.class)) + ).thenReturn(resultMock); + Map<String, String> result = processor.runDeleteByModel("test", "test", + "test", "test", startNodeFilterHash, + "test", + "test"); + assertEquals("result has -local tacked on the end as it should", result.size(), resultMock.size()); + } + + Optional<Vertex> vertext = Optional.empty(); + + @Test(expected = AAIException.class) + public void runDeleteByModelWithNullParams() throws AAIException { + Map<String, String> resultMock = new HashMap<String, String>(); + + + Map<String, String> result = processor.runDeleteByModel("test", "test", + null, null, null, + "test", + "test"); + + assertNotNull(result); + + } + + @Test(expected = NullPointerException.class) + public void runDeleteByModelWithNullParams1() throws AAIException { + + Map<String, String> result1 = processor.runDeleteByModel("test", "test", + null, "unknown", null, + "test", + "test"); + assertNotNull(result1); + + } + + + @Test(expected = NullPointerException.class) + public void runDeleteByModelWithNullParams2() throws AAIException { + + Map<String, String> result1 = processor.runDeleteByModel("test", "test", + null, "unknown", null, + "test", + "test"); + assertNotNull(result1); + + } + + @Test(expected = AAIException.class) + public void queryByNamedQuery() throws AAIException { + String transId = "test"; + String fromAppId = "test"; + String namedQueryUuid = "test"; + ArrayList<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); + String apiVer = "test"; + List<ResultSet> result = processor.queryByNamedQuery(transId, fromAppId, namedQueryUuid, startNodeFilterArrayOfHashes, apiVer); + assertNotNull(result); + } + + @Test(expected = AAIException.class) + public void queryByNamedQuery1() throws AAIException { + String transId = "teet"; + String fromAppId = "test"; + String namedQueryUuid = "test"; + String secondaryFilterCutPoint = "test"; + List<Map<String, Object>> startNodeFilterArrayOfHashes = new ArrayList<Map<String, Object>>(); + String apiVer = "test"; + Map<String, Object> secondaryFilterHash = new HashMap<String, Object>(); + List<ResultSet> result = processor.queryByNamedQuery(transId, fromAppId, namedQueryUuid, startNodeFilterArrayOfHashes, apiVer, secondaryFilterCutPoint, secondaryFilterHash); + assertNotNull(result); + } + + @Test + public void deleteAsNeededFromResultSet() throws AAIException { + Vertex vert = new BaseVertexLabel("Test"); + Map<String, String> resultMock = new HashMap<String, String>(); + ResultSet resultSet = new ResultSet(); + resultSet.setVert(null); + + Map<String, String> result = processor.deleteAsNeededFromResultSet("test", "test", + resultSet, "test", "test", + "test", + resultMock); + + assertEquals(result.size(), 0); + + resultSet.setVert(vert); + + Map<String, String> result1 = processor.deleteAsNeededFromResultSet("test", "test", + resultSet, "test", "test", + "test", + resultMock); + + assertEquals(result.size(), 0); + + + } + + @Test(expected = NullPointerException.class) + public void pruneResultSetTest() throws AAIException { + ResultSet rs = new ResultSet(); + Vertex v = new BaseVertexLabel(AAIProperties.NODE_TYPE); + rs.setVert(v); + List<ResultSet> rsList = new ArrayList<ResultSet>(); + ResultSet rs1 = new ResultSet(); + rsList.add(rs1); + rs.setSubResultSet(rsList); + Map<String, Object> map = new HashMap<String, Object>(); + map.put("test", new Object()); + ResultSet resultSet = processor.pruneResultSet(rs, "testr", map); + assertNotNull(resultSet); + + } + + @Test(expected = NullPointerException.class) + public void satisfiesFiltersTest() throws AAIException { + ResultSet rs = new ResultSet(); + Vertex v = new BaseVertexLabel(AAIProperties.NODE_TYPE); + rs.setVert(v); + rs.getVert().property(AAIProperties.NODE_TYPE); + List<ResultSet> rsList = new ArrayList<ResultSet>(); + ResultSet rs1 = new ResultSet(); + rsList.add(rs1); + rs.setSubResultSet(rsList); + Map<String, Object> map = new HashMap<String, Object>(); + + map.put("modern.vertex-id", new Object()); + + boolean result = processor.satisfiesFilters(rs, map); + assertEquals(result, true); + } + + @Test + public void satisfiesFiltersTest1() throws AAIException { + ResultSet rs = new ResultSet(); + Vertex v = new BaseVertexLabel(AAIProperties.NODE_TYPE); + rs.setVert(v); + List<ResultSet> rsList = new ArrayList<ResultSet>(); + ResultSet rs1 = new ResultSet(); + rsList.add(rs1); + rs.setSubResultSet(rsList); + Map<String, Object> map = new HashMap<String, Object>(); + //map.put("test.filter",new Object()); + + boolean result = processor.satisfiesFilters(rs, map); + assertEquals(result, false); + } + + @Test(expected = AAIException.class) + public void satisfiesFiltersTest2() throws AAIException { + ResultSet rs = new ResultSet(); + Vertex v = new BaseVertexLabel(AAIProperties.NODE_TYPE); + rs.setVert(v); + List<ResultSet> rsList = new ArrayList<ResultSet>(); + ResultSet rs1 = new ResultSet(); + rsList.add(rs1); + rs.setSubResultSet(rsList); + Map<String, Object> map = new HashMap<String, Object>(); + map.put("testfilter", new Object()); + + boolean result = processor.satisfiesFilters(rs, map); + assertEquals(result, false); + } + + @Test + public void collapseForDoNotOutputTest() throws AAIException { + ResultSet rs = new ResultSet(); + rs.setDoNotOutputFlag("true"); + List<ResultSet> rsList = new ArrayList<ResultSet>(); + ResultSet rs1 = new ResultSet(); + rsList.add(rs1); + rs.setSubResultSet(rsList); + List<ResultSet> result = processor.collapseForDoNotOutput(rs); + assertEquals(result.size(), 1); + } + + @Test(expected = NullPointerException.class) + public void collectInstanceDataTest() throws AAIException { + + BaseVertexLabel bs = new BaseVertexLabel("test"); + //bs.setId(80); + EmptyVertex ev = new EmptyVertex(); + //ev.setId(50l); + Vertex thisLevelElemVtx = ev; + + + Multimap<String, String> thisMap = ArrayListMultimap.create(); + List<String> vidsTraversed = new ArrayList<String>(); + // only applies when collecting data using the default model for delete + Multimap<String, String> validNextStepMap = ArrayListMultimap.create(); + Map<String, String> namedQueryElementHash = new HashMap<String, String>(); + namedQueryElementHash.put("test", "test"); + Map<String, String> delKeyHash = new HashMap<String, String>(); + + ResultSet rs = processor.collectInstanceData("test", "test", thisLevelElemVtx, "test", validNextStepMap, vidsTraversed, 1, delKeyHash, namedQueryElementHash, "test"); + } + + @Test(expected = NullPointerException.class) + public void genTopoMap4ModelVerTest() throws + AAIException { + Vertex vertext = new EmptyVertex(); + Multimap<String, String> map = processor.genTopoMap4ModelVer("test", "test", vertext, "test"); + assertNotEquals(map, null); + } + + @Test(expected = AAIException.class) + public void genTopoMap4ModelVerTestNull() throws + AAIException { + Vertex vertext = null; + Multimap<String, String> map = processor.genTopoMap4ModelVer("test", "test", vertext, "test"); + assertNotEquals(map, null); + } + + @Test + public void makeSureItsAnArrayListTest() { + String input = "model-versionId,modelTestID,modelTestid2;"; + List<String> result = processor.makeSureItsAnArrayList(input); + assertTrue(result.size() > 0); + } + + @Test(expected = AAIException.class) + public void getModConstraintHashTest() throws AAIException { + Vertex modelElementVtx = new EmptyVertex(); + //modelElementVtx.property(AAIProperties.NODE_TYPE,"Model"); + Vertex modelElementVtx1 = new EmptyVertex(); + Map<String, Vertex> currentHash = new HashMap<String, Vertex>(); + currentHash.put("constraint", modelElementVtx1); + Map<String, Vertex> result = processor.getModConstraintHash(modelElementVtx, currentHash); + assertTrue(result.size() > 0); + } + + @Test(expected = AAIException.class) + public void getModConstraintHashTestNull() throws AAIException { + Vertex modelElementVtx = null; + //modelElementVtx.property(AAIProperties.NODE_TYPE,"Model"); + Vertex modelElementVtx1 = null; + Map<String, Vertex> currentHash = new HashMap<String, Vertex>(); + currentHash.put("constraint", modelElementVtx1); + Map<String, Vertex> result = processor.getModConstraintHash(modelElementVtx, currentHash); + assertTrue(result.size() > 0); + } + + @Test(expected = NullPointerException.class) + public void getTopElementForSvcOrResModelVerTest() throws AAIException { + Vertex modelElementVtx = new EmptyVertex(); + //modelElementVtx.property(AAIProperties.NODE_TYPE,"Model"); + Vertex modelElementVtx1 = new EmptyVertex(); + Map<String, Vertex> currentHash = new HashMap<String, Vertex>(); + currentHash.put("constraint", modelElementVtx1); + Vertex result = processor.getTopElementForSvcOrResModelVer(modelElementVtx, "test"); + assertNotEquals(result, null); + } + + @Test + public void getNamedQueryPropOverRideTest() throws AAIException { + String transId = "test"; + String fromAppId = "test"; + Vertex namedQueryElementVertex = new EmptyVertex(); + Vertex instanceVertex = new EmptyVertex(); + String apiVer = "test"; + + namedQueryElementVertex.properties("property-collect-list", ""); + + Map<String, Object> result = processor.getNamedQueryPropOverRide(transId, fromAppId, namedQueryElementVertex, instanceVertex, apiVer); + assertNotEquals(result, null); + } + + @Test(expected = NullPointerException.class) + public void getNamedQueryPropOverRideTestNull() throws AAIException { + String transId = "test"; + String fromAppId = "test"; + Vertex namedQueryElementVertex = null; + Vertex instanceVertex = new EmptyVertex(); + String apiVer = "test"; + + namedQueryElementVertex.properties("property-collect-list", ""); + + Map<String, Object> result = processor.getNamedQueryPropOverRide(transId, fromAppId, namedQueryElementVertex, instanceVertex, apiVer); + assertNotEquals(result, null); + } + + @Test(expected = NullPointerException.class) + public void namedQueryConstraintSaysStopTest() throws AAIException { + String transId = "test"; + String fromAppId = "test"; + Vertex namedQueryElementVertex = new EmptyVertex(); + Vertex instanceVertex = new EmptyVertex(); + String apiVer = "test"; + + namedQueryElementVertex.properties("property-collect-list", ""); + + boolean result = processor.namedQueryConstraintSaysStop(transId, fromAppId, namedQueryElementVertex, instanceVertex, apiVer); + assertTrue(result); + } + + @Test(expected = NullPointerException.class) + public void namedQueryConstraintSaysStopTestNull() throws AAIException { + String transId = "test"; + String fromAppId = "test"; + Vertex namedQueryElementVertex = null; + Vertex instanceVertex = new EmptyVertex(); + String apiVer = "test"; + + namedQueryElementVertex.properties("property-collect-list", ""); + + boolean result = processor.namedQueryConstraintSaysStop(transId, fromAppId, namedQueryElementVertex, instanceVertex, apiVer); + assertTrue(result); + } + + @Test(expected = AAIException.class) + public void namedQuerynamedQueryElementVertexNullTest() throws AAIException { + String transId = "test"; + String fromAppId = "test"; + Vertex namedQueryElementVertex = null; + Vertex instanceVertex = null; + String apiVer = "test"; + + + boolean result = processor.namedQueryConstraintSaysStop(transId, fromAppId, namedQueryElementVertex, instanceVertex, apiVer); + assertTrue(result); + } + + @Test(expected = NullPointerException.class) + + public void getNamedQueryExtraDataLookupTest() throws Exception { + + String transId = "test"; + String fromAppId = "test"; + Vertex namedQueryElementVertex = new EmptyVertex(); + Vertex instanceVertex = new EmptyVertex(); + String apiVer = "test"; + + namedQueryElementVertex.properties("property-collect-list", ""); + + Map<String, Object> result = processor.getNamedQueryExtraDataLookup(transId, fromAppId, namedQueryElementVertex, instanceVertex, apiVer); + + assertTrue(result.size() > 0); + } + + @Test(expected = NullPointerException.class) + public void collectNQElementHash() throws AAIException { + String transId = "test"; + String fromAppId = "test"; + Vertex thisLevelElemVtx = new EmptyVertex(); + String incomingTrail = "test"; + Map<String, String> currentHash = new HashMap<String, String>(); + ArrayList<String> vidsTraversed = new ArrayList<String>(); + int levelCounter = 1; + + Map<String, String> result = processor.collectNQElementHash(transId, fromAppId, + thisLevelElemVtx, incomingTrail, currentHash, + vidsTraversed, levelCounter); + + assertNotEquals(result, null); + } + + @Test(expected = NullPointerException.class) + public void collectDeleteKeyHash() throws AAIException { + String transId = "test"; + String fromAppId = "test"; + Vertex thisLevelElemVtx = new EmptyVertex(); + String incomingTrail = "test"; + Map<String, String> currentHash = new HashMap<String, String>(); + ArrayList<String> vidsTraversed = new ArrayList<String>(); + int levelCounter = 1; + Map<String, Vertex> modConstraintHash = new HashMap<String, Vertex>(); + String overRideModelId = "test"; + String overRideModelVersionId = "test"; + + Map<String, String> result = processor.collectDeleteKeyHash(transId, fromAppId, + thisLevelElemVtx, incomingTrail, currentHash, + vidsTraversed, levelCounter, modConstraintHash, overRideModelId, overRideModelVersionId); + + assertNotEquals(result, null); + } + + @Test + public void getLinkageConnectNodeTypesTest() throws AAIException { + List<String> linkagePtList = new ArrayList<String>(); + linkagePtList.add("modern\\|testdata\\|"); + Set<String> result = processor.getLinkageConnectNodeTypes(linkagePtList); + assertNotEquals(result, null); + + } + + @Test(expected = AAIException.class) + public void getLinkageConnectNodeTypesTest1() throws AAIException { + + Set<String> result1 = processor.getLinkageConnectNodeTypes(null); + assertNotEquals(result1, null); + + List<String> linkagePtList = new ArrayList<String>(); + linkagePtList.add("moderntestdata"); + Set<String> result = processor.getLinkageConnectNodeTypes(linkagePtList); + assertNotEquals(result, null); + } + + @Test(expected = NullPointerException.class) + public void collectTopology4ModelVerTest() throws AAIException { + String transId = "test"; + String fromAppId = "test"; + Multimap<String, String> thisMap = ArrayListMultimap.create(); + Vertex thisLevelElemVtx = new EmptyVertex(); + String incomingTrail = "test"; + Map<String, Vertex> currentHash = new HashMap<String, Vertex>(); + List<String> vidsTraversed = new ArrayList<String>(); + int levelCounter = 1; + + Multimap<String, String> result = processor.collectTopology4ModelVer(transId, fromAppId, + thisLevelElemVtx, incomingTrail, thisMap, vidsTraversed, levelCounter, currentHash + , "test", "test"); + + assertNotEquals(result, null); + } + + @Test(expected = AAIException.class) + public void check4EdgeRuleTest() throws AAIException { + processor.check4EdgeRule("test", "test"); + } + + @Test(expected = AAIException.class) + public void collectTopology4LinkagePointTest() throws AAIException { + String transId = "test"; + String fromAppId = "test"; + String linkagePointStrVal = "test"; + String incomingTrail = "test"; + Multimap<String, String> currentMap = ArrayListMultimap.create(); + + Multimap<String, String> result = processor.collectTopology4LinkagePoint(transId, fromAppId, linkagePointStrVal, incomingTrail, currentMap); + assertNotEquals(result, null); + + } + + @Test(expected = AAIException.class) + public void getNextStepElementsFromSet() throws AAIException { + Vertex constrElemSetVtx = new EmptyVertex(); + constrElemSetVtx.<String>property(AAIProperties.NODE_TYPE); + Map<String, Object> result = processor.getNextStepElementsFromSet(constrElemSetVtx); + assertNotEquals(result, null); + } + + @Test(expected = NullPointerException.class) + public void genTopoMap4NamedQTest() throws AAIException { + String transId = "test"; + String fromAppId = "test"; + Vertex queryVertex = new EmptyVertex(); + String namedQueryUuid = "E44533334343"; + Multimap<String, String> result = processor.genTopoMap4NamedQ(transId, fromAppId, queryVertex, namedQueryUuid); + assertNotEquals(result, null); + } + + @Test(expected = NullPointerException.class) + public void collectTopology4NamedQTest() throws AAIException { + String transId = "test"; + String fromAppId = "test"; + Multimap<String, String> thisMap = ArrayListMultimap.create(); + Vertex thisLevelElemVtx = new EmptyVertex(); + String incomingTrail = "test"; + Map<String, Vertex> currentHash = new HashMap<String, Vertex>(); + List<String> vidsTraversed = new ArrayList<String>(); + int levelCounter = 1; + + Multimap<String, String> result = processor.collectTopology4NamedQ(transId, fromAppId, + thisLevelElemVtx, incomingTrail, thisMap, vidsTraversed, levelCounter); + assertNotEquals(result, null); + } + + @Test(expected = NullPointerException.class) + public void getModelThatNqElementRepresentsTest() throws AAIException { + Vertex thisLevelElemVtx = new EmptyVertex(); + String incomingTrail = "test"; + Vertex vertex = processor.getModelThatNqElementRepresents(thisLevelElemVtx, incomingTrail); + assertNotEquals(vertex, null); + } + + @Test(expected = NullPointerException.class) + public void getModelGivenModelVer() throws AAIException { + Vertex thisLevelElemVtx = new EmptyVertex(); + String incomingTrail = "test"; + Vertex vertex = processor.getModelGivenModelVer(thisLevelElemVtx, incomingTrail); + assertNotEquals(vertex, null); + } + + @Test(expected = AAIException.class) + public void getModelTypeFromModel() throws AAIException { + Vertex thisLevelElemVtx = new EmptyVertex(); + String incomingTrail = "test"; + String vertex = processor.getModelTypeFromModel(thisLevelElemVtx, incomingTrail); + assertNotEquals(vertex, null); + } + + @Test(expected = NullPointerException.class) + public void getModelTypeFromModelVer() throws AAIException { + Vertex thisLevelElemVtx = new EmptyVertex(); + String incomingTrail = "test"; + String vertex = processor.getModelTypeFromModelVer(thisLevelElemVtx, incomingTrail); + assertNotEquals(vertex, null); + } + + @Test(expected = NullPointerException.class) + public void getModelElementStepName() throws AAIException { + Vertex thisLevelElemVtx = new EmptyVertex(); + String incomingTrail = "test"; + String vertex = processor.getModelElementStepName(thisLevelElemVtx, incomingTrail); + assertNotEquals(vertex, null); + } + + @Test(expected = AAIException.class) + public void nodeTypeSupportsPersona() throws AAIException { + String incomingTrail = ""; + boolean vertex = processor.nodeTypeSupportsPersona(incomingTrail); + assertFalse(vertex); + + + incomingTrail = "test"; + boolean vertex1 = processor.nodeTypeSupportsPersona(incomingTrail); + assertTrue(vertex1); + } + + @Test(expected = NullPointerException.class) + public void getNqElementWidgetType() throws AAIException { + String appId = "test"; + String transID = "test"; + Vertex thisLevelElemVtx = new EmptyVertex(); + String incomingTrail = "test"; + String vertex1 = processor.getNqElementWidgetType(appId, transID, thisLevelElemVtx, incomingTrail); + assertNotEquals(vertex1, null); + } + + + @Test(expected = NullPointerException.class) + public void getModElementWidgetType() throws AAIException { + String appId = "test"; + String transID = "test"; + Vertex thisLevelElemVtx = new EmptyVertex(); + String incomingTrail = "test"; + String vertex1 = processor.getModElementWidgetType(thisLevelElemVtx, incomingTrail); + assertNotEquals(vertex1, null); + } + + @Test(expected = NullPointerException.class) + public void getNodeUsingUniqueId() throws AAIException { + String appId = "test"; + String transID = "test"; + String nodeType = "generic-vnf"; + String idPropertyName = "test"; + String uniqueIdVal = "test"; + Vertex vertex1 = processor.getNodeUsingUniqueId(transID, appId, nodeType, idPropertyName, uniqueIdVal); + assertNotEquals(vertex1, null); + } + + + @Test(expected = AAIException.class) + public void getNodeUsingUniqueIdNull() throws AAIException { + String appId = "test"; + String transID = "test"; + String nodeType = "generic-vnf"; + String idPropertyName = "test"; + String uniqueIdVal = ""; + Vertex vertex1 = null; + vertex1 = processor.getNodeUsingUniqueId(transID, appId, nodeType, idPropertyName, uniqueIdVal); + assertNotEquals(vertex1, null); + + } + + + @Test(expected = AAIException.class) + public void getNodeUsingUniqueIdNull1() throws AAIException { + String appId = "test"; + String transID = "test"; + String nodeType = "generic-vnf"; + String idPropertyName = ""; + String uniqueIdVal = "test"; + Vertex vertex1 = null; + vertex1 = processor.getNodeUsingUniqueId(transID, appId, nodeType, idPropertyName, uniqueIdVal); + assertNotEquals(vertex1, null); + + + } + + + @Test(expected = AAIException.class) + public void getNodeUsingUniqueIdNull2() throws AAIException { + String appId = "test"; + String transID = "test"; + String nodeType = ""; + String idPropertyName = "test"; + String uniqueIdVal = "test"; + Vertex vertex1 = null; + vertex1 = processor.getNodeUsingUniqueId(transID, appId, nodeType, idPropertyName, uniqueIdVal); + assertNotEquals(vertex1, null); + + + } + + @Test(expected = NullPointerException.class) + public void getModelVersUsingName() throws AAIException { + String appId = "test"; + String transID = "test"; + String modelName = "test"; + + List<Vertex> result = processor.getModelVersUsingName(transID, appId, modelName); + assertNotEquals(result, null); + } + + + @Test(expected = AAIException.class) + public void getModelVersUsingNameNull() throws AAIException { + String appId = "test"; + String transID = "test"; + String modelName = ""; + + List<Vertex> result = processor.getModelVersUsingName(transID, appId, modelName); + assertNotEquals(result, null); + } + + + @Test(expected = NullPointerException.class) + public void getModVersUsingModelInvId() throws AAIException { + String appId = "test"; + String transID = "test"; + String modelName = "test"; + + Iterator<Vertex> result = processor.getModVersUsingModelInvId(transID, appId, modelName); + assertNotEquals(result, null); + } + + @Test(expected = AAIException.class) + public void getModVersUsingModelInvIdNull() throws AAIException { + String appId = "test"; + String transID = "test"; + String modelName = ""; + + Iterator<Vertex> result = processor.getModVersUsingModelInvId(transID, appId, modelName); + assertNotEquals(result, null); + } + + @Test(expected = NullPointerException.class) + public void getModVersUsingModel() throws AAIException { + String appId = "test"; + String transID = "test"; + String modelName = "test"; + Vertex thisLevelElemVtx = new EmptyVertex(); + List<Vertex> result = processor.getModVersUsingModel(transID, appId, thisLevelElemVtx); + assertNotEquals(result, null); + } + + @Test(expected = AAIException.class) + public void getModVersUsingModel1() throws AAIException { + String appId = "test"; + String transID = "test"; + + Vertex thisLevelElemVtx = null; + List<Vertex> result = processor.getModVersUsingModel(transID, appId, thisLevelElemVtx); + assertNotEquals(result, null); + } + + @Test(expected = NullPointerException.class) + public void getModelVerIdsUsingName() throws AAIException { + String appId = "test"; + String transID = "test"; + + String modelName = "test"; + List<String> result = processor.getModelVerIdsUsingName(transID, appId, modelName); + assertNotEquals(result, null); + } + + @Test(expected = AAIException.class) + public void getModelVerIdsUsingName1() throws AAIException { + String appId = "test"; + String transID = "test"; + + String modelName = ""; + List<String> result = processor.getModelVerIdsUsingName(transID, appId, modelName); + assertNotEquals(result, null); + } + + @Test(expected = NullPointerException.class) + public void validateModel() throws AAIException { + String appId = "test"; + String transID = "test"; + + String modelVersionId = "test"; + String modelInvId = "test"; + String modelName = "test"; + processor.validateModel(transID, appId, modelName, modelVersionId); + + + } + } diff --git a/aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingTest.java b/aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingTest.java index afb9b17..1f05785 100644 --- a/aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/dbgraphgen/ModelBasedProcessingTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * Copyright © 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. @@ -16,13 +16,14 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.onap.aai.dbgraphgen; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.T; @@ -33,28 +34,25 @@ import org.junit.BeforeClass; import org.junit.Test; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.onap.aai.AAISetup; import org.onap.aai.db.props.AAIProperties; import org.onap.aai.dbmap.DBConnectionType; import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.Loader; -import org.onap.aai.introspection.LoaderFactory; import org.onap.aai.introspection.ModelType; -import org.onap.aai.introspection.Version; import org.onap.aai.parsers.exceptions.AAIIdentityMapParseException; import org.onap.aai.serialization.db.DBSerializer; -import org.onap.aai.serialization.db.EdgeRules; -import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.QueryStyle; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.TransactionalGraphEngine; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; +import org.onap.aai.setup.SchemaVersion; -public class ModelBasedProcessingTest { +public class ModelBasedProcessingTest extends AAISetup{ - private static final Version version = Version.getLatest(); + private SchemaVersion version; private static final ModelType introspectorFactoryType = ModelType.MOXY; private static final QueryStyle queryStyle = QueryStyle.TRAVERSAL; private static final DBConnectionType type = DBConnectionType.REALTIME; @@ -81,7 +79,6 @@ public class ModelBasedProcessingTest { private static TransactionalGraphEngine.Admin admin; DBSerializer serializer; private static Loader loader; - EdgeRules rules; ModelBasedProcessing modelBasedProcessor; @@ -106,8 +103,9 @@ public class ModelBasedProcessingTest { @Before public void init() throws AAIException { MockitoAnnotations.initMocks(this); - rules = EdgeRules.getInstance(); - loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, AAIProperties.LATEST); + version = schemaVersions.getDefaultVersion(); + //rules = EdgeRules.getInstance(); + loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version); TransactionalGraphEngine newDbEngine = new JanusGraphDBEngine(queryStyle, type, loader); dbEngine = Mockito.spy(newDbEngine); serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); @@ -135,17 +133,17 @@ public class ModelBasedProcessingTest { "new-data-del-flag", "F"); GraphTraversalSource g = graph.traversal(); - rules.addTreeEdge(g, model, modelVersion); - rules.addTreeEdge(g, modelElement, modelConstraint); - rules.addTreeEdge(g, constrainedElementSet, modelConstraint); - rules.addTreeEdge(g, modelVersion, modelElement); - rules.addTreeEdge(g, modelElement, constrainedElementSet); - rules.addTreeEdge(g, constrainedElementSet, elementChoiceSet); - rules.addTreeEdge(g, modelElement, elementChoiceSet); - rules.addTreeEdge(g, namedQuery, namedQueryElement); - rules.addTreeEdge(g, namedQueryElement, namedQueryElement); - rules.addEdge(g, modelVersion, modelElement); - rules.addEdge(g, model, namedQueryElement); + edgeSer.addTreeEdge(g, model, modelVersion); + edgeSer.addTreeEdge(g, modelElement, modelConstraint); + edgeSer.addTreeEdge(g, constrainedElementSet, modelConstraint); + edgeSer.addTreeEdge(g, modelVersion, modelElement); + edgeSer.addTreeEdge(g, modelElement, constrainedElementSet); + edgeSer.addTreeEdge(g, constrainedElementSet, elementChoiceSet); + edgeSer.addTreeEdge(g, modelElement, elementChoiceSet); + edgeSer.addTreeEdge(g, namedQuery, namedQueryElement); + edgeSer.addTreeEdge(g, namedQueryElement, namedQueryElement); + edgeSer.addEdge(g, modelVersion, modelElement); + edgeSer.addEdge(g, model, namedQueryElement); return g; } @@ -438,10 +436,10 @@ public class ModelBasedProcessingTest { Vertex modelElementV = graph.addVertex(T.label, "model-element", T.id, "22", AAI_NODE_TYPE, "model-element"); GraphTraversalSource gts = serviceGraph.traversal(); - EdgeRules rules4Service = EdgeRules.getInstance(); - rules4Service.addTreeEdge(gts, modelV, modelVerV); - rules4Service.addTreeEdge(gts, modelElementV, modelVerV); - rules4Service.addEdge(gts, modelElementV, modelVerV); + //EdgeRules rules4Service = EdgeRules.getInstance(); + edgeSer.addTreeEdge(gts, modelV, modelVerV); + edgeSer.addTreeEdge(gts, modelElementV, modelVerV); + edgeSer.addEdge(gts, modelElementV, modelVerV); Mockito.when(dbEngine.asAdmin()).thenReturn(admin); Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); modelBasedProcessor.genTopoMap4ModelVer(TRANSACTION_ID, FROM_APP_ID, modelVerV, MODEL_VERSION_ID_VALUE); @@ -517,8 +515,7 @@ public class ModelBasedProcessingTest { Vertex instanceVertexV = graph.addVertex(T.label, "instance-vertex", T.id, "32", AAI_NODE_TYPE, "instance-vertex", "property-name", "property-name"); GraphTraversalSource gts = serviceGraph.traversal(); - EdgeRules rules4Service = EdgeRules.getInstance(); - rules4Service.addTreeEdge(gts, namedQueryElementV, propertyContraintV); + edgeSer.addTreeEdge(gts, namedQueryElementV, propertyContraintV); Mockito.when(dbEngine.asAdmin()).thenReturn(admin); Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); @@ -536,8 +533,8 @@ public class ModelBasedProcessingTest { Vertex instanceVertexV = graph.addVertex(T.label, "instance-vertex", T.id, "35", AAI_NODE_TYPE, "instance-vertex", "property-name", "property-name"); GraphTraversalSource gts = serviceGraph.traversal(); - EdgeRules rules4Service = EdgeRules.getInstance(); - rules4Service.addTreeEdge(gts, namedQueryElementV, propertyContraintV); + //EdgeRules rules4Service = EdgeRules.getInstance(); + edgeSer.addTreeEdge(gts, namedQueryElementV, propertyContraintV); Mockito.when(dbEngine.asAdmin()).thenReturn(admin); Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); @@ -556,8 +553,7 @@ public class ModelBasedProcessingTest { Vertex instanceVertexV = graph.addVertex(T.label, "instance-vertex", T.id, "38", AAI_NODE_TYPE, "instance-vertex", "property-name", "property-name"); GraphTraversalSource gts = serviceGraph.traversal(); - EdgeRules rules4Service = EdgeRules.getInstance(); - rules4Service.addTreeEdge(gts, namedQueryElementV, propertyContraintV); + edgeSer.addTreeEdge(gts, namedQueryElementV, propertyContraintV); Mockito.when(dbEngine.asAdmin()).thenReturn(admin); Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); @@ -576,8 +572,7 @@ public class ModelBasedProcessingTest { Vertex instanceVertexV = graph.addVertex(T.label, "instance-vertex", T.id, "41", AAI_NODE_TYPE, "instance-vertex", "property-name", "property-name"); GraphTraversalSource gts = serviceGraph.traversal(); - EdgeRules rules4Service = EdgeRules.getInstance(); - rules4Service.addTreeEdge(gts, namedQueryElementV, propertyContraintV); + edgeSer.addTreeEdge(gts, namedQueryElementV, propertyContraintV); Mockito.when(dbEngine.asAdmin()).thenReturn(admin); Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); @@ -596,8 +591,7 @@ public class ModelBasedProcessingTest { Vertex instanceVertexV = graph.addVertex(T.label, "instance-vertex", T.id, "44", AAI_NODE_TYPE, "instance-vertex", "property-name", "property-name"); GraphTraversalSource gts = serviceGraph.traversal(); - EdgeRules rules4Service = EdgeRules.getInstance(); - rules4Service.addTreeEdge(gts, namedQueryElementV, propertyContraintV); + edgeSer.addTreeEdge(gts, namedQueryElementV, propertyContraintV); Mockito.when(dbEngine.asAdmin()).thenReturn(admin); Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); @@ -615,8 +609,7 @@ public class ModelBasedProcessingTest { "source-node-property", "source-node-property", "source-node-type", "generic-vnf"); Vertex instanceVertexV = graph.addVertex(T.label, "instance-vertex", T.id, "47", AAI_NODE_TYPE, "instance-vertex", "property-name", "property-name"); GraphTraversalSource gts = serviceGraph.traversal(); - EdgeRules rules4Service = EdgeRules.getInstance(); - rules4Service.addTreeEdge(gts, namedQueryElementV, relatedLookUpV); + edgeSer.addTreeEdge(gts, namedQueryElementV, relatedLookUpV); Mockito.when(dbEngine.asAdmin()).thenReturn(admin); Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); @@ -635,8 +628,7 @@ public class ModelBasedProcessingTest { "target-node-property", "generic-vnf", "property-collect-list", "property-collect-list"); Vertex instanceVertexV = graph.addVertex(T.label, "instance-vertex", T.id, "53", AAI_NODE_TYPE, "instance-vertex", "property-name", "property-name"); GraphTraversalSource gts = serviceGraph.traversal(); - EdgeRules rules4Service = EdgeRules.getInstance(); - rules4Service.addTreeEdge(gts, namedQueryElementV, relatedLookUpV); + edgeSer.addTreeEdge(gts, namedQueryElementV, relatedLookUpV); Mockito.when(dbEngine.asAdmin()).thenReturn(admin); Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); @@ -654,8 +646,7 @@ public class ModelBasedProcessingTest { "source-node-property", "source-node-property", "source-node-type", "generic-vnf", "target-node-type", "generic-vnf", "target-node-property", "generic-vnf"); Vertex instanceVertexV = graph.addVertex(T.label, "instance-vertex", T.id, "56", AAI_NODE_TYPE, "instance-vertex", "source-node-property", "source-node-property"); GraphTraversalSource gts = serviceGraph.traversal(); - EdgeRules rules4Service = EdgeRules.getInstance(); - rules4Service.addTreeEdge(gts, namedQueryElementV, relatedLookUpV); + edgeSer.addTreeEdge(gts, namedQueryElementV, relatedLookUpV); Mockito.when(dbEngine.asAdmin()).thenReturn(admin); Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); @@ -737,10 +728,9 @@ public class ModelBasedProcessingTest { Vertex modelElementV = graph.addVertex(T.label, "model-element", T.id, "59", AAI_NODE_TYPE, "model-element"); GraphTraversalSource gts = serviceGraph.traversal(); - EdgeRules rules4Service = EdgeRules.getInstance(); - rules4Service.addTreeEdge(gts, modelV, modelVerV); - rules4Service.addTreeEdge(gts, modelElementV, modelVerV); - rules4Service.addEdge(gts, modelElementV, modelVerV); + edgeSer.addTreeEdge(gts, modelV, modelVerV); + edgeSer.addTreeEdge(gts, modelElementV, modelVerV); + edgeSer.addEdge(gts, modelElementV, modelVerV); Mockito.when(dbEngine.asAdmin()).thenReturn(admin); Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); modelBasedProcessor.getModelVerTopWidgetType(modelVerV, ""); @@ -755,10 +745,9 @@ public class ModelBasedProcessingTest { Vertex modelElementV = graph.addVertex(T.label, "model-element", T.id, "62", AAI_NODE_TYPE, "model-element"); GraphTraversalSource gts = serviceGraph.traversal(); - EdgeRules rules4Service = EdgeRules.getInstance(); - rules4Service.addTreeEdge(gts, modelV, modelVerV); - rules4Service.addTreeEdge(gts, modelElementV, modelVerV); - rules4Service.addEdge(gts, modelElementV, modelVerV); + edgeSer.addTreeEdge(gts, modelV, modelVerV); + edgeSer.addTreeEdge(gts, modelElementV, modelVerV); + edgeSer.addEdge(gts, modelElementV, modelVerV); Mockito.when(dbEngine.asAdmin()).thenReturn(admin); Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); modelBasedProcessor.getModelElementStepName(modelElementV, ""); @@ -801,10 +790,9 @@ public class ModelBasedProcessingTest { Vertex modelElementV = graph.addVertex(T.label, "model-element", T.id, "65", AAI_NODE_TYPE, "model-element"); GraphTraversalSource gts = serviceGraph.traversal(); - EdgeRules rules4Service = EdgeRules.getInstance(); - rules4Service.addTreeEdge(gts, modelV, modelVerV); - rules4Service.addTreeEdge(gts, modelElementV, modelVerV); - rules4Service.addEdge(gts, modelElementV, modelVerV); + edgeSer.addTreeEdge(gts, modelV, modelVerV); + edgeSer.addTreeEdge(gts, modelElementV, modelVerV); + edgeSer.addEdge(gts, modelElementV, modelVerV); Mockito.when(dbEngine.asAdmin()).thenReturn(admin); Mockito.when(admin.getReadOnlyTraversalSource()).thenReturn(gts); @@ -891,8 +879,7 @@ public class ModelBasedProcessingTest { //Vertex modelElementV = graph.addVertex(T.label, "model-element", T.id, "68", AAI_NODE_TYPE, "model-element"); GraphTraversalSource gts = serviceGraph.traversal(); - EdgeRules rules4Service = EdgeRules.getInstance(); - rules4Service.addTreeEdge(gts, modelV, modelVerV); + edgeSer.addTreeEdge(gts, modelV, modelVerV); //rules4Service.addTreeEdge(gts, modelElementV, modelVerV); //rules4Service.addEdge(gts, modelElementV, modelVerV); Mockito.when(dbEngine.asAdmin()).thenReturn(admin); diff --git a/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphEdgeRuleTest.java b/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphEdgeRuleTest.java index 92f4960..9d3a615 100644 --- a/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphEdgeRuleTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphEdgeRuleTest.java @@ -25,17 +25,20 @@ import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; - +import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException; import org.onap.aai.exceptions.AAIException; +import org.springframework.beans.factory.annotation.Autowired; @Ignore public class SearchGraphEdgeRuleTest { @Rule public ExpectedException expectedEx = ExpectedException.none(); + @Autowired + SearchGraph searchGraph; @Test - public void getEdgeLabelTest() throws AAIException { - String[] label = SearchGraph.getEdgeLabel("customer", "service-subscription"); + public void getEdgeLabelTest() throws AAIException, EdgeRuleNotFoundException { + String[] label = searchGraph.getEdgeLabel("customer", "service-subscription"); assertEquals("subscribesTo", label[0]); } @@ -46,7 +49,7 @@ public class SearchGraphEdgeRuleTest { String nodeTypeB = "service"; expectedEx.expect(AAIException.class); expectedEx.expectMessage("No EdgeRule found for passed nodeTypes: complex, service."); - SearchGraph.getEdgeLabel(nodeTypeA, nodeTypeB); + searchGraph.getEdgeLabel(nodeTypeA, nodeTypeB); } @Test @@ -55,6 +58,6 @@ public class SearchGraphEdgeRuleTest { String nodeTypeB = "B"; expectedEx.expect(AAIException.class); expectedEx.expectMessage("No EdgeRule found for passed nodeTypes: A, B."); - SearchGraph.getEdgeLabel(nodeTypeA, nodeTypeB); + searchGraph.getEdgeLabel(nodeTypeA, nodeTypeB); } } diff --git a/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphNamedQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphNamedQueryTest.java index ea0fdaa..243fc6e 100644 --- a/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphNamedQueryTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphNamedQueryTest.java @@ -22,7 +22,6 @@ package org.onap.aai.dbgraphmap; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import org.apache.commons.io.IOUtils; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; @@ -33,7 +32,7 @@ import org.onap.aai.exceptions.AAIException; import org.onap.aai.extensions.AAIExtensionMap; import org.onap.aai.introspection.*; import org.onap.aai.serialization.engines.QueryStyle; -import org.onap.aai.util.AAIApiVersion; +import org.onap.aai.setup.SchemaVersion; import org.onap.aai.util.AAIConstants; import javax.servlet.http.HttpServletRequest; @@ -41,31 +40,23 @@ import javax.ws.rs.core.*; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.*; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.anyObject; import static org.mockito.Mockito.*; +import org.onap.aai.AAISetup; -public class SearchGraphNamedQueryTest { - - private SearchGraph searchGraph; +public class SearchGraphNamedQueryTest extends AAISetup{ protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); private static final Set<Integer> VALID_HTTP_STATUS_CODES = new HashSet<>(); - private final static Version version = Version.getLatest(); - private final static ModelType introspectorFactoryType = ModelType.MOXY; - private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL; - private final static DBConnectionType type = DBConnectionType.REALTIME; - static { VALID_HTTP_STATUS_CODES.add(200); VALID_HTTP_STATUS_CODES.add(201); @@ -141,7 +132,7 @@ public class SearchGraphNamedQueryTest { } private String addVersionToUri(String uri ) { - return "/aai/" + Version.getLatest() + "/" + uri; + return "/aai/" + schemaVersions.getDefaultVersion() + "/" + uri; } @Before @@ -149,12 +140,7 @@ public class SearchGraphNamedQueryTest { httpTestUtil = new HttpTestUtil(); - System.setProperty("AJSC_HOME", "."); - System.setProperty("BUNDLECONFIG_DIR", "src/main/resources"); - - searchGraph = new SearchGraph(); - httpHeaders = mock(HttpHeaders.class); headersMultiMap = new MultivaluedHashMap<>(); @@ -211,10 +197,10 @@ public class SearchGraphNamedQueryTest { Mockito.when(request.getContentType()).thenReturn("application/json"); aaiExtMap.setUri("/search/named-query"); - aaiExtMap.setApiVersion(AAIApiVersion.get()); + aaiExtMap.setApiVersion(schemaVersions.getDefaultVersion().toString()); aaiExtMap.setServletRequest(request); - SearchGraph searchGraph = new SearchGraph(); + response = searchGraph.runNamedQuery("JUNIT", "JUNIT", queryParameters, DBConnectionType.REALTIME, aaiExtMap); System.out.println("response was\n" + response.getEntity().toString()); assertEquals("Expected success from query", 200, response.getStatus()); @@ -245,10 +231,10 @@ public class SearchGraphNamedQueryTest { Mockito.when(request.getContentType()).thenReturn("application/json"); aaiExtMap.setUri("/search/named-query"); - aaiExtMap.setApiVersion(AAIApiVersion.get()); + aaiExtMap.setApiVersion(schemaVersions.getDefaultVersion().toString()); aaiExtMap.setServletRequest(request); - SearchGraph searchGraph = new SearchGraph(); + response = searchGraph.runNamedQuery("JUNIT", "JUNIT", queryParameters, DBConnectionType.REALTIME, aaiExtMap); assertEquals("Expected success from query", 200, response.getStatus()); boolean hasModelName = response.getEntity().toString().indexOf("junit-model-name") > 0 ? true : false; @@ -326,10 +312,10 @@ public class SearchGraphNamedQueryTest { Mockito.when(request.getContentType()).thenReturn("application/json"); aaiExtMap.setUri("/search/named-query"); - aaiExtMap.setApiVersion(AAIApiVersion.get()); + aaiExtMap.setApiVersion(schemaVersions.getDefaultVersion().toString()); aaiExtMap.setServletRequest(request); - SearchGraph searchGraph = new SearchGraph(); + response = searchGraph.runNamedQuery("JUNIT", "JUNIT", queryParameters, DBConnectionType.REALTIME, aaiExtMap); assertEquals("Expected success from query", 200, response.getStatus()); boolean hasModelName = response.getEntity().toString().indexOf("example-model-name-val-closed-loop") > 0 ? true : false; @@ -392,10 +378,10 @@ public class SearchGraphNamedQueryTest { Mockito.when(request.getContentType()).thenReturn("application/json"); aaiExtMap.setUri("/search/named-query"); - aaiExtMap.setApiVersion(AAIApiVersion.get()); + aaiExtMap.setApiVersion(schemaVersions.getDefaultVersion().toString()); aaiExtMap.setServletRequest(request); - SearchGraph searchGraph = new SearchGraph(); + response = searchGraph.runNamedQuery("JUNIT", "JUNIT", queryParameters, DBConnectionType.REALTIME, aaiExtMap); assertEquals("Expected success from query", 200, response.getStatus()); boolean hasModelName = response.getEntity().toString().indexOf("example-model-name-val-component-list") > 0 ? true : false; diff --git a/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphTest.java b/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphTest.java index 87ebb8f..a048ffc 100644 --- a/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/dbgraphmap/SearchGraphTest.java @@ -24,15 +24,12 @@ import org.janusgraph.graphdb.types.system.EmptyVertex; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.apache.tinkerpop.gremlin.structure.VertexProperty; import org.eclipse.persistence.dynamic.DynamicEntity; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; import org.mockito.Mockito; -import org.onap.aai.dbgraphgen.ModelBasedProcessing; +import org.onap.aai.AAISetup; import org.onap.aai.dbmap.DBConnectionType; import org.onap.aai.exceptions.AAIException; import org.onap.aai.extensions.AAIExtensionMap; @@ -43,27 +40,27 @@ import org.onap.aai.serialization.engines.QueryStyle; import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import org.onap.aai.serialization.queryformats.utils.UrlBuilder; +import org.onap.aai.setup.SchemaVersion; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.*; import java.net.URI; -import java.sql.ResultSet; import java.util.*; import java.util.stream.Stream; import static org.mockito.Matchers.anyObject; import static org.mockito.Mockito.*; -public class SearchGraphTest { +public class SearchGraphTest extends AAISetup{ - private SearchGraph searchGraph; + protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); private static final Set<Integer> VALID_HTTP_STATUS_CODES = new HashSet<>(); - private final static Version version = Version.getLatest(); + private SchemaVersion version; private final static ModelType introspectorFactoryType = ModelType.MOXY; private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL; private final static DBConnectionType type = DBConnectionType.REALTIME; @@ -96,11 +93,7 @@ public class SearchGraphTest { @Before public void setup(){ - System.setProperty("AJSC_HOME", "."); - System.setProperty("BUNDLECONFIG_DIR", "src/main/resources"); - - searchGraph = new SearchGraph(); - + version = schemaVersions.getDefaultVersion(); httpHeaders = mock(HttpHeaders.class); uriInfo = mock(UriInfo.class); @@ -134,24 +127,24 @@ public class SearchGraphTest { Mockito.doReturn(null).when(queryParameters).remove(anyObject()); when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); - loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); + loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version); dbEngine = new JanusGraphDBEngine( queryStyle, type, loader); } -@Test(expected = AAIException.class) + @Test(expected = AAIException.class) public void runNodesQuery() throws AAIException{ DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); - UrlBuilder urlBuilder = new UrlBuilder(version, serializer); + UrlBuilder urlBuilder = new UrlBuilder(version, serializer, schemaVersions, basePath); searchGraph.runNodesQuery(httpHeaders,"",null, null,dbEngine,loader,urlBuilder); } @Test(expected = AAIException.class) public void runNodesQueryNull() throws AAIException{ DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); - UrlBuilder urlBuilder = new UrlBuilder(version, serializer); + UrlBuilder urlBuilder = new UrlBuilder(version, serializer, schemaVersions, basePath); searchGraph.runNodesQuery(httpHeaders,"nnn",null, null,dbEngine,loader,urlBuilder); } @@ -165,7 +158,7 @@ public class SearchGraphTest { includeStrings.add("cloud-region"); DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); - UrlBuilder urlBuilder = new UrlBuilder(version, serializer); + UrlBuilder urlBuilder = new UrlBuilder(version, serializer, schemaVersions, basePath); Response response = searchGraph.runGenericQuery(httpHeaders, "service-instance", keys, includeStrings, 1, dbEngine, loader, urlBuilder); System.out.println(response); } @@ -181,7 +174,7 @@ public class SearchGraphTest { includeStrings.add("cloud-region"); DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); - UrlBuilder urlBuilder = new UrlBuilder(version, serializer); + UrlBuilder urlBuilder = new UrlBuilder(version, serializer, schemaVersions, basePath); Response response = searchGraph.runGenericQuery(httpHeaders, null, keys, includeStrings, 1, dbEngine, loader, urlBuilder); System.out.println(response); } @@ -196,7 +189,7 @@ public class SearchGraphTest { includeStrings.add("cloud-region"); DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); - UrlBuilder urlBuilder = new UrlBuilder(version, serializer); + UrlBuilder urlBuilder = new UrlBuilder(version, serializer, schemaVersions, basePath); Response response = searchGraph.runGenericQuery(httpHeaders, "", null, includeStrings, 1, dbEngine, loader, urlBuilder); System.out.println(response); } @@ -211,7 +204,7 @@ public class SearchGraphTest { includeStrings.add("cloud-region"); DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); - UrlBuilder urlBuilder = new UrlBuilder(version, serializer); + UrlBuilder urlBuilder = new UrlBuilder(version, serializer, schemaVersions, basePath); Response response = searchGraph.runGenericQuery(httpHeaders, "", keys, null, 1, dbEngine, loader, urlBuilder); System.out.println(response); } diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/AbstractSpringRestTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/AbstractSpringRestTest.java new file mode 100644 index 0000000..7235fa3 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/AbstractSpringRestTest.java @@ -0,0 +1,135 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; +import org.apache.tinkerpop.gremlin.process.traversal.P; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.JanusGraphTransaction; +import org.junit.*; +import org.onap.aai.TraversalApp; +import org.onap.aai.TraversalTestConfiguration; +import org.onap.aai.config.PropertyPasswordConfiguration; +import org.onap.aai.dbmap.AAIGraph; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.nodes.NodeIngestor; +import org.onap.aai.util.AAIConfig; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.rules.SpringClassRule; +import org.springframework.test.context.junit4.rules.SpringMethodRule; +import org.springframework.web.client.RestTemplate; + +import java.io.UnsupportedEncodingException; +import java.util.Base64; +import java.util.Collections; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TraversalApp.class) +@TestPropertySource(locations = "classpath:application-test.properties") +@ContextConfiguration(initializers = PropertyPasswordConfiguration.class) +@Import(TraversalTestConfiguration.class) +public abstract class AbstractSpringRestTest { + + @ClassRule + public static final SpringClassRule springClassRule = new SpringClassRule(); + + @Rule + public final SpringMethodRule springMethodRule = new SpringMethodRule(); + + @Autowired + protected RestTemplate restTemplate; + + @Autowired + protected NodeIngestor nodeIngestor; + + @LocalServerPort + protected int randomPort; + + protected HttpEntity httpEntity; + + protected String baseUrl; + protected HttpHeaders headers ; + + @BeforeClass + public static void setupConfig() throws AAIException { + System.setProperty("AJSC_HOME", "./"); + System.setProperty("BUNDLECONFIG_DIR", "src/main/resources/"); + } + + @Before + public void setup() throws AAIException, UnsupportedEncodingException { + + AAIConfig.init(); + AAIGraph.getInstance(); + + createTestGraph(); + headers = new HttpHeaders(); + + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.add("Real-Time", "true"); + headers.add("X-FromAppId", "JUNIT"); + headers.add("X-TransactionId", "JUNIT"); + String authorization = Base64.getEncoder().encodeToString("AAI:AAI".getBytes("UTF-8")); + headers.add("Authorization", "Basic " + authorization); + httpEntity = new HttpEntity(headers); + baseUrl = "https://localhost:" + randomPort; + } + + /* + * Inheritors please override this one + */ + public void createTestGraph(){ + + } + @After + public void tearDown(){ + + JanusGraph janusGraph = AAIGraph.getInstance().getGraph(); + JanusGraphTransaction transaction = janusGraph.newTransaction(); + + boolean success = true; + + try { + GraphTraversalSource g = transaction.traversal(); + g.V().has("source-of-truth", P.within("JUNIT", "AAI-EXTENSIONS")) + .toList() + .stream() + .forEach(v -> v.remove()); + } catch(Exception ex){ + success = false; + } finally { + if(success){ + transaction.commit(); + } else { + transaction.rollback(); + } + } + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/BadQueryFormatTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/BadQueryFormatTest.java new file mode 100644 index 0000000..a566499 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/BadQueryFormatTest.java @@ -0,0 +1,109 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.HttpTestUtil; +import org.onap.aai.PayloadUtil; +import org.onap.aai.TraversalApp; +import org.onap.aai.TraversalTestConfiguration; +import org.onap.aai.config.PropertyPasswordConfiguration; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.http.*; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.client.RestTemplate; + +import java.util.Base64; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.junit.MatcherAssert.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TraversalApp.class) +@TestPropertySource(locations = "classpath:application-test.properties") +@ContextConfiguration(initializers = PropertyPasswordConfiguration.class) +@Import(TraversalTestConfiguration.class) +public class BadQueryFormatTest { + + private HttpTestUtil httpTestUtil; + + private String pserverUri; + + private String hostname; + + @Autowired + RestTemplate restTemplate; + + @LocalServerPort + int randomPort; + + private HttpEntity httpEntity; + + private HttpHeaders headers; + + private String baseUrl; + + @Before + public void setup() throws Exception { + + headers = new HttpHeaders(); + + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.add("Real-Time", "true"); + headers.add("X-FromAppId", "JUNIT"); + headers.add("X-TransactionId", "JUNIT"); + String authorization = Base64.getEncoder().encodeToString("AAI:AAI".getBytes("UTF-8")); + headers.add("Authorization", "Basic " + authorization); + + baseUrl = "https://localhost:" + randomPort; + } + + @Test + public void testPserverCount() throws Exception { + Map<String, String> gremlinQueryMap = new HashMap<>(); + gremlinQueryMap.put("gremlin-query", "g.V().has('hostname', '" + hostname + "').count()"); + + String payload = PayloadUtil.getTemplatePayload("gremlin-query.json", gremlinQueryMap); + + ResponseEntity responseEntity = null; + + String endpoint = "/aai/v11/query?format=hello"; + + httpEntity = new HttpEntity(payload, headers); + responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + + System.out.println(responseEntity.getBody()); + assertThat(responseEntity.getStatusCode(), is(HttpStatus.BAD_REQUEST)); + assertThat(responseEntity.getBody().toString(), containsString("Bad Parameter Passed:Unsupported format query parameter hello in request")); + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/DslConsumerTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/DslConsumerTest.java new file mode 100644 index 0000000..0e539ba --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/DslConsumerTest.java @@ -0,0 +1,113 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.junit.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.janusgraph.core.JanusGraphTransaction; +import org.junit.Before; +import org.junit.Test; +import org.onap.aai.PayloadUtil; +import org.onap.aai.dbmap.AAIGraph; +import org.onap.aai.util.AAIConfig; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.util.UriComponentsBuilder; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.jayway.jsonpath.JsonPath; + +public class DslConsumerTest extends AbstractSpringRestTest { + + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(DslConsumerTest.class); + + @Override + public void createTestGraph() { + JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction(); + boolean success = true; + try { + GraphTraversalSource g = transaction.traversal(); + g.addV().property("aai-node-type", "pserver").property("hostname", "test-pserver-dsl") + .property("in-maint", false).property("source-of-truth", "JUNIT") + .property("aai-uri", "/cloud-infrastructure/pservers/pserver/test-pserver").next(); + } catch (Exception ex) { + success = false; + } finally { + if (success) { + transaction.commit(); + } else { + transaction.rollback(); + fail("Unable to setup the graph"); + } + } + } + + @Test + public void testDslQuery() throws Exception { + + String endpoint = "/aai/v14/dsl?format=console"; + Map<String, String> dslQueryMap = new HashMap<>(); + dslQueryMap.put("dsl-query", "pserver*('hostname','test-pserver-dsl')"); + String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQueryMap); + httpEntity = new HttpEntity(payload, headers); + ResponseEntity responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, + String.class); + LOGGER.debug("Response for PUT request with uri {} : {}", baseUrl + endpoint, responseEntity.getBody()); + System.out.println(responseEntity.getBody()); + assertNotNull("Response from /aai/v14/dsl is not null", responseEntity); + assertEquals("Expected the response to be 500", HttpStatus.OK, responseEntity.getStatusCode()); + } + + @Test + public void testDslQueryException() throws Exception { + Map<String, String> dslQuerymap = new HashMap<>(); + dslQuerymap.put("dsl-query", "xserver"); + + String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQuerymap); + + ResponseEntity responseEntity = null; + + String endpoint = "/aai/v11/dsl?format=console"; + + httpEntity = new HttpEntity(payload, headers); + responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class); + assertEquals("Expected the response to be 400", HttpStatus.INTERNAL_SERVER_ERROR, + responseEntity.getStatusCode()); + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/GfpVserverDataStoredQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/GfpVserverDataStoredQueryTest.java index d5b695a..841b18e 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/GfpVserverDataStoredQueryTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/GfpVserverDataStoredQueryTest.java @@ -27,13 +27,13 @@ import org.janusgraph.core.JanusGraphTransaction; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.mockito.Mockito; +import org.onap.aai.AAISetup; import org.onap.aai.HttpTestUtil; import org.onap.aai.PayloadUtil; import org.onap.aai.dbmap.AAIGraph; -import org.onap.aai.introspection.Version; +import org.onap.aai.setup.SchemaVersion; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.*; @@ -47,7 +47,7 @@ import static org.mockito.Matchers.anyObject; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class GfpVserverDataStoredQueryTest { +public class GfpVserverDataStoredQueryTest extends AAISetup{ private static final EELFLogger logger = EELFManager.getInstance().getLogger(GfpVserverDataStoredQueryTest.class); @@ -66,13 +66,17 @@ public class GfpVserverDataStoredQueryTest { private QueryConsumer queryConsumer; - private static final Version VERSION = Version.v11; - private static final String CLOUD_REGION_URI = "/aai/" + VERSION.toString() - + "/cloud-infrastructure/cloud-regions/" - + "cloud-region/testOwner1/testRegion1"; + private SchemaVersion version; + private String cloudRegionUri; @Before public void setup() throws Exception { + + version = schemaVersions.getDefaultVersion(); + + cloudRegionUri = "/aai/" + version.toString() + + "/cloud-infrastructure/cloud-regions/" + + "cloud-region/testOwner1/testRegion1"; httpTestUtil = new HttpTestUtil(); Map<String, String> templateValues = new HashMap<>(); @@ -91,14 +95,14 @@ public class GfpVserverDataStoredQueryTest { String cloudRegionPayload = PayloadUtil. getTemplatePayload("cloud-region-with-linterface.json", templateValues); - Response response = httpTestUtil.doPut(CLOUD_REGION_URI, cloudRegionPayload); + Response response = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload); logger.info("Response status received {}", response.getEntity()); assertNotNull("Expected the response to be not null", response); assertEquals("Expecting the cloud region to be created", 201, response.getStatus()); logger.info("Successfully created the cloud region with linterface"); - queryConsumer = new QueryConsumer(); + queryConsumer = new QueryConsumer(traversalUriHttpEntry, schemaVersions, gremlinServerSingleton, basePath); httpHeaders = mock(HttpHeaders.class); @@ -128,14 +132,14 @@ public class GfpVserverDataStoredQueryTest { when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); } - @Ignore("This is more of a performance test to ensure no failure when too many starting vertexes") @Test public void testStoredQueryVerifyDoesNotThrowMethodTooLargeWhenLargeNumberOfStartingVertexes() throws Exception { // Add hundred thousand vserver vertexes to properly // test the scenario where the application was // failing with method too large - addVservers(1000000); + String vservers = System.getProperty("perf.vservers.count", "1000"); + addVservers(Integer.parseInt(vservers)); Map<String, String> templateValues = new HashMap<>(); @@ -148,7 +152,7 @@ public class GfpVserverDataStoredQueryTest { templateValues.put("query", "gfp-vserver-data"); String payload = PayloadUtil.getTemplatePayload("custom-query.json", templateValues); - String query = String.format("/aai/%s/query?format=resource_and_url", VERSION.toString()); + String query = String.format("/aai/%s/query?format=resource_and_url", version.toString()); UriInfo uriInfo = Mockito.mock(UriInfo.class); HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class); @@ -159,7 +163,7 @@ public class GfpVserverDataStoredQueryTest { Response response = queryConsumer.executeQuery( payload, - VERSION.toString(), + version.toString(), query, "resource_and_url", "" + "no_op", @@ -185,7 +189,7 @@ public class GfpVserverDataStoredQueryTest { templateValues.put("query", "fake-query"); String payload = PayloadUtil.getTemplatePayload("custom-query.json", templateValues); - String query = String.format("/aai/%s/query?format=resource_and_url", VERSION.toString()); + String query = String.format("/aai/%s/query?format=resource_and_url", version.toString()); UriInfo uriInfo = Mockito.mock(UriInfo.class); HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class); @@ -196,7 +200,7 @@ public class GfpVserverDataStoredQueryTest { Response response = queryConsumer.executeQuery( payload, - VERSION.toString(), + version.toString(), query, "resource_and_url", "" + "no_op", @@ -223,7 +227,7 @@ public class GfpVserverDataStoredQueryTest { templateValues.put("query", "gfp-vserver-data"); String payload = PayloadUtil.getTemplatePayload("custom-query.json", templateValues); - String query = String.format("/aai/%s/query?format=resource_and_url", VERSION.toString()); + String query = String.format("/aai/%s/query?format=resource_and_url", version.toString()); UriInfo uriInfo = Mockito.mock(UriInfo.class); HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class); @@ -234,7 +238,7 @@ public class GfpVserverDataStoredQueryTest { Response response = queryConsumer.executeQuery( payload, - VERSION.toString(), + version.toString(), query, "resource_and_url", "" + "no_op", @@ -245,10 +249,10 @@ public class GfpVserverDataStoredQueryTest { String entity = response.getEntity().toString(); - assertEquals("Expected the response to be 500 but got this returned: " + entity, - 500, response.getStatus()); + assertEquals("Expected the response to be 404 but got this returned: " + entity, + 404, response.getStatus()); - assertThat(entity, containsString("Internal Error:groovy.lang.MissingPropertyException")); + assertThat(entity, containsString("Start URI returned no vertexes, please check the start URI")); } @After diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/RecentApiTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/RecentApiTest.java new file mode 100644 index 0000000..ff2c98f --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/RecentApiTest.java @@ -0,0 +1,95 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.util.UriComponentsBuilder; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class RecentApiTest extends AbstractSpringRestTest { + + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(RecentApiTest.class); + + @Test + public void testRecentsQuery() { + + String endpoint = "/aai/recents/v14/pserver"; + httpEntity = new HttpEntity(headers); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUrl + endpoint).queryParam("hours", "190"); + ResponseEntity responseEntity = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, httpEntity, + String.class); + LOGGER.debug("Response for PUT request with uri {} : {}", builder.toUriString(), responseEntity.getBody()); + assertNotNull("Response from /aai/recents/v14/pserver is null", responseEntity); + assertEquals("Expected the response to be 400", HttpStatus.OK, responseEntity.getStatusCode()); + + } + + @Test + public void testRecentsQueryException() { + String endpoint = "/aai/recents/v14/xserver"; + httpEntity = new HttpEntity(headers); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUrl + endpoint).queryParam("hours", "190"); + ResponseEntity responseEntity = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, httpEntity, + String.class); + + LOGGER.debug("Response for PUT request with uri {} : {}", builder.toUriString(), responseEntity.getBody()); + assertNotNull("Response from /aai/recents/v14/pserver is null", responseEntity); + assertEquals("Expected the response to be 400", HttpStatus.BAD_REQUEST, responseEntity.getStatusCode()); + } + + @Test + public void testRecentsQueryExceptionHours() { + String endpoint = "/aai/recents/v14/pserver"; + httpEntity = new HttpEntity(headers); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUrl + endpoint).queryParam("hours", "200"); + + ResponseEntity responseEntity = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, httpEntity, + String.class); + LOGGER.debug("Response for PUT request with uri {} : {}", builder.toUriString(), responseEntity.getBody()); + assertNotNull("Response from /aai/recents/v14/pserver is null", responseEntity); + assertEquals("Expected the response to be 400", HttpStatus.BAD_REQUEST, + responseEntity.getStatusCode()); + + } + + @Test + public void testRecentsQueryExceptionDateTime() { + String endpoint = "/aai/recents/v14/pserver"; + httpEntity = new HttpEntity(headers); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUrl + endpoint).queryParam("date-time", + "200"); + + ResponseEntity responseEntity = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, httpEntity, + String.class); + LOGGER.debug("Response for PUT request with uri {} : {}", builder.toUriString(), responseEntity.getBody()); + assertNotNull("Response from /aai/recents/v14/pserver is null", responseEntity); + assertEquals("Expected the response to be 400", HttpStatus.BAD_REQUEST, + responseEntity.getStatusCode()); + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/SearchProviderRestTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/SearchProviderRestTest.java new file mode 100644 index 0000000..d53fa56 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/SearchProviderRestTest.java @@ -0,0 +1,102 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.junit.Test; +import org.springframework.http.*; +import org.springframework.web.util.UriComponentsBuilder; + +import java.util.Collections; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class SearchProviderRestTest extends AbstractSpringRestTest { + + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(SearchProviderRestTest.class); + + @Test + public void testNodesQueryInvalidData() { + + String endpoint = "/aai/latest/search/nodes-query"; + + httpEntity = new HttpEntity(headers); + + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUrl + endpoint) + .queryParam("key", "cloud-region.cloud-owner:test-aic") + .queryParam("include", "cloud-region"); + + ResponseEntity responseEntity = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, httpEntity, String.class); + + LOGGER.debug("Response for GET request with uri {} : {}", builder.toUriString(), responseEntity.getBody()); + + assertNotNull("Response from /aai/latest/search is null", responseEntity); + assertEquals("Expected the response to be 400", HttpStatus.BAD_REQUEST, responseEntity.getStatusCode()); + } + + @Test + public void testGenericQueryInvalidData() { + + String endpoint = "/aai/latest/search/generic-query"; + + httpEntity = new HttpEntity(headers); + + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUrl + endpoint) + .queryParam("key", "cloud-region.cloud-owner:test-aic") + .queryParam("include", "cloud-region"); + + ResponseEntity responseEntity = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, httpEntity, String.class); + + LOGGER.debug("Response for GET request with uri {} : {}", builder.toUriString(), responseEntity.getBody()); + + assertNotNull("Response from /aai/latest/search is null", responseEntity); + assertEquals("Expected the response to be 400", HttpStatus.BAD_REQUEST, responseEntity.getStatusCode()); + } + + @Test + public void testGenericQueryBypassTimeout(){ + headers = new HttpHeaders(); + + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.add("Real-Time", "true"); + headers.add("X-TransactionId", "JUNIT"); + + httpEntity = new HttpEntity(headers); + String endpoint = "/aai/latest/search/generic-query"; + + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUrl + endpoint) + .queryParam("key", "cloud-region.cloud-owner:test-aic") + .queryParam("include", "cloud-region") + .queryParam("start-node-type", "cloud-region"); + + ResponseEntity responseEntity = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, httpEntity, String.class); + + LOGGER.debug("Response for GET request with uri {} : {}", builder.toUriString(), responseEntity.getBody()); + + assertNotNull("Response from /aai/latest/search is null", responseEntity); + assertEquals("Expected the response to be 400", HttpStatus.BAD_REQUEST, responseEntity.getStatusCode()); + assertThat(responseEntity.getBody().toString(), containsString("4009")); + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/dsl/DslQueryProcessorTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/dsl/DslQueryProcessorTest.java index cd20266..abd98e9 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/dsl/DslQueryProcessorTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/dsl/DslQueryProcessorTest.java @@ -26,29 +26,28 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.onap.aai.AAISetup; import org.onap.aai.exceptions.AAIException; /** * The Class DslMain. */ -public class DslQueryProcessorTest { - - +public class DslQueryProcessorTest extends AAISetup { + + @Test public void cloudRegion1Test() throws AAIException { - DslQueryProcessor dslTest = new DslQueryProcessor(); + String aaiQuery = "cloud-region* !('cloud-owner','coid')('cloud-region-id','cr id') LIMIT 10"; - String aaiQuery = "cloud-region* !('cloud-owner','coid')('cloud-region-id','crid') LIMIT 10"; String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesExcludeByProperty('cloud-owner','coid')" - + ".getVerticesByProperty('cloud-region-id','crid').store('x').cap('x').unfold().dedup().limit(10)"; + + ".getVerticesByProperty('cloud-region-id','cr id').store('x').cap('x').unfold().dedup().limit(10)"; - String query = dslTest.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(aaiQuery); assertEquals(dslQuery, query); } @Test public void cloudRegion_entitlementTest() throws AAIException { - DslQueryProcessor dslTest = new DslQueryProcessor(); String aaiQuery = "generic-vnf (> vserver > tenant > cloud-region*('cloud-region-id','One')) > entitlement*"; String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'generic-vnf').where(" @@ -58,16 +57,15 @@ public class DslQueryProcessorTest { + ".getVerticesByProperty('cloud-region-id','One').store('x'))" + ".createEdgeTraversal(EdgeType.TREE, 'generic-vnf','entitlement').store('x').cap('x').unfold().dedup()"; - String query = dslTest.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(aaiQuery); assertEquals(dslQuery, query); } @Test public void complex_az_fromComplexTest() throws AAIException { - DslQueryProcessor dslTest = new DslQueryProcessor(); String aaiQuery = "cloud-region('cloud-owner','coid')('cloud-region-id','crid') > [ availability-zone* , complex*]"; - String query = dslTest.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(aaiQuery); String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region')" + ".getVerticesByProperty('cloud-owner','coid').getVerticesByProperty('cloud-region-id','crid')" + ".union(builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'cloud-region','availability-zone').store('x')" @@ -75,35 +73,32 @@ public class DslQueryProcessorTest { assertEquals(dslQuery, query); } - + @Test public void cloudRegion_fromComplex1Test() throws AAIException { - DslQueryProcessor dslTest = new DslQueryProcessor(); String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'complex').getVerticesByProperty('country','count-name')" + ".createEdgeTraversal(EdgeType.COUSIN, 'complex','cloud-region').store('x').cap('x').unfold().dedup()"; String aaiQuery = "complex('country','count-name') > cloud-region*"; - String query = dslTest.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(aaiQuery); assertEquals(builderQuery, query); } - + @Test public void cloudRegion_fromComplex2Test() throws AAIException { - DslQueryProcessor dslTest = new DslQueryProcessor(); String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'complex').getVerticesByProperty('country','count-name')" + ".createEdgeTraversal(EdgeType.COUSIN, 'complex','cloud-region').getVerticesByProperty('cloud-region-version','crv')" + ".store('x').cap('x').unfold().dedup()"; String aaiQuery = "complex('country','count-name') > cloud-region*('cloud-region-version','crv')"; - String query = dslTest.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(aaiQuery); assertEquals(builderQuery, query); } - + @Test public void cloudRegion_fromNfTypeTest() throws AAIException { - DslQueryProcessor dslTest = new DslQueryProcessor(); String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'image').getVerticesByProperty('application-vendor','F5')" + ".createEdgeTraversal(EdgeType.COUSIN, 'image','vserver')" @@ -112,13 +107,12 @@ public class DslQueryProcessorTest { + ".store('x').cap('x').unfold().dedup()"; String aaiQuery = "image('application-vendor','F5') > vserver (>generic-vnf('vnf-name','ZALL1MMSC03')) > tenant > cloud-region*"; - String query = dslTest.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(aaiQuery); assertEquals(builderQuery, query); } - + @Test public void cloudRegion_fromNfTypeVendorVersionTest() throws AAIException { - DslQueryProcessor dslTest = new DslQueryProcessor(); String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'image').getVerticesByProperty('application-vendor','vendor')" + ".createEdgeTraversal(EdgeType.COUSIN, 'image','vserver').where(" @@ -128,14 +122,13 @@ public class DslQueryProcessorTest { String aaiQuery = "image('application-vendor','vendor') > vserver( >generic-vnf('nf-type', 'nfType') ) > tenant > cloud-region*"; - String query = dslTest.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(aaiQuery); assertEquals(builderQuery, query); } @Test public void cloud_region_fromVnfTest() throws AAIException { - DslQueryProcessor dslTest = new DslQueryProcessor(); String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'generic-vnf').getVerticesByProperty('vnf-id','vnfId')" + ".createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','vnfc').store('x')" @@ -146,14 +139,13 @@ public class DslQueryProcessorTest { String aaiQuery = "generic-vnf('vnf-id','vnfId') > vnfc* > vserver* > tenant* > cloud-region*"; - String query = dslTest.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(aaiQuery); assertEquals(builderQuery, query); } - + @Test public void cloud_region_sitesTest() throws AAIException { - DslQueryProcessor dslTest = new DslQueryProcessor(); String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region')." + "getVerticesByProperty('cloud-owner','co').store('x').createEdgeTraversal(EdgeType.COUSIN, " @@ -161,14 +153,13 @@ public class DslQueryProcessorTest { String aaiQuery = "cloud-region*('cloud-owner','co') > complex*"; - String query = dslTest.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(aaiQuery); assertEquals(builderQuery, query); } - + @Test public void complex_fromVnf2Test() throws AAIException { - DslQueryProcessor dslTest = new DslQueryProcessor(); String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'generic-vnf').getVerticesByProperty('vnf-Id','vnfId').store('x').union(" + "builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','pserver').store('x')" @@ -181,15 +172,14 @@ public class DslQueryProcessorTest { String aaiQuery = "generic-vnf*('vnf-Id','vnfId') > " + "[ pserver* > complex*, " + " vserver > pserver* > complex* " + "]"; - String query = dslTest.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(aaiQuery); assertEquals(builderQuery, query); } - + @Test public void complex_fromVnfTest() throws AAIException { - DslQueryProcessor dslTest = new DslQueryProcessor(); - + String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'generic-vnf').getVerticesByProperty('vnf-Id','vnfId').store('x').union(" + "builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','pserver').store('x')" + ".createEdgeTraversal(EdgeType.COUSIN, 'pserver','complex').store('x')," @@ -201,17 +191,16 @@ public class DslQueryProcessorTest { String aaiQuery = "generic-vnf*('vnf-Id','vnfId') > " + "[ pserver* > complex*, " + " vserver > pserver* > complex* " + "]"; - String query = dslTest.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(aaiQuery); assertEquals(builderQuery, query); } @Test public void fn_topology1Test() throws AAIException { - DslQueryProcessor dslTest = new DslQueryProcessor(); String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'business')" - + ".createEdgeTraversal(EdgeType.COUSIN, 'business','customer').getVerticesByProperty('customer-id','a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb')" + + ".getVerticesByProperty('customer-id','a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb')" + ".createEdgeTraversal(EdgeType.TREE, 'customer','service-subscription').getVerticesByProperty('service-subscription-id','Nimbus')" + ".createEdgeTraversal(EdgeType.TREE, 'service-subscription','service-instance').getVerticesByProperty('service-instance-id','sid')" + ".createEdgeTraversal(EdgeType.COUSIN, 'service-instance','generic-vnf').store('x')" @@ -224,9 +213,68 @@ public class DslQueryProcessorTest { + " > service-instance('service-instance-id','sid') > generic-vnf* " + " > [ vnfc* , vserver*, pserver* , pnf* ]"; - String query = dslTest.parseAaiQuery(aaiQuery); + String query = dslQueryProcessor.parseAaiQuery(aaiQuery); assertEquals(builderQuery, query); } + @Test + public void vnf_Dsl() throws AAIException { + + String builderQuery = "builder.getVerticesByProperty('aai-node-type', 'generic-vnf').where(builder.newInstance().union(builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','pserver')" + + ".getVerticesByProperty('hostname','hostname1'),builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf','vserver')" + + ".createEdgeTraversal(EdgeType.COUSIN, 'vserver','pserver').getVerticesByProperty('hostname','hostname1'))).store('x').cap('x').unfold().dedup()"; + + String aaiQuery = "generic-vnf* (> [pserver('hostname','hostname1'), " + + "vserver > pserver('hostname','hostname1')])"; + String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + + assertEquals(builderQuery, query); + } + + @Test + public void hasPropertyTest() throws AAIException { + String aaiQuery = "cloud-region* ('cloud-owner')"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesByProperty('cloud-owner').store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + assertEquals(dslQuery, query); + } + + @Test + public void hasPropertyValuesTest() throws AAIException { + String aaiQuery = "cloud-region* ('cloud-owner','cloud-owner1','cloud-owner2')"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesByProperty('cloud-owner', new ArrayList<>(Arrays.asList('cloud-owner1','cloud-owner2'))).store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + assertEquals(dslQuery, query); + } + + @Test + public void hasNotPropertyValuesTest() throws AAIException { + String aaiQuery = "cloud-region* !('cloud-owner','cloud-owner1','cloud-owner2')"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesExcludeByProperty('cloud-owner', new ArrayList<>(Arrays.asList('cloud-owner1','cloud-owner2'))).store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + assertEquals(dslQuery, query); + } + + @Test + public void hasNotPropertyNullValuesTest() throws AAIException { + String aaiQuery = "cloud-region* !('cloud-owner',' ',' null ')"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesExcludeByProperty('cloud-owner', new ArrayList<>(Arrays.asList('','null'))).store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + assertEquals(dslQuery, query); + } + + @Test + public void hasNotPropertyTest() throws AAIException { + String aaiQuery = "cloud-region* !('cloud-owner')"; + String dslQuery = "builder.getVerticesByProperty('aai-node-type', 'cloud-region').getVerticesExcludeByProperty('cloud-owner').store('x').cap('x').unfold().dedup()"; + + String query = dslQueryProcessor.parseAaiQuery(aaiQuery); + assertEquals(dslQuery, query); + } + } diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/retired/RetiredConsumerSpringTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/retired/RetiredConsumerSpringTest.java new file mode 100644 index 0000000..6664465 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/retired/RetiredConsumerSpringTest.java @@ -0,0 +1,65 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.retired; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.junit.Test; +import org.onap.aai.rest.AbstractSpringRestTest; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + +public class RetiredConsumerSpringTest extends AbstractSpringRestTest { + + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(RetiredConsumerSpringTest.class); + + private Map<String, HttpStatus> httpStatusMap; + + @Test + public void testOldVersionsEndpointReturnRetired(){ + setupOldVersions(); + executeRestCalls(); + } + + protected void executeRestCalls() { + httpStatusMap.forEach((url, status) -> { + ResponseEntity responseEntity; + responseEntity = restTemplate.exchange(baseUrl + url, HttpMethod.GET, httpEntity, String.class); + LOGGER.debug("For url {} expected status {} actual status {} and body {}", url, status, responseEntity.getStatusCodeValue(), responseEntity.getBody()); + assertEquals(status, responseEntity.getStatusCode()); + }); + } + + private void setupOldVersions() { + httpStatusMap = new HashMap<>(); + + httpStatusMap.put("/aai/v2/search/generic-query", HttpStatus.GONE); + httpStatusMap.put("/aai/v3/search/generic-query", HttpStatus.GONE); + httpStatusMap.put("/aai/v4/search/generic-query", HttpStatus.GONE); + httpStatusMap.put("/aai/v5/search/generic-query", HttpStatus.GONE); + httpStatusMap.put("/aai/v6/search/generic-query", HttpStatus.GONE); + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/CloudRegionAndSourceFromConfigurationQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/CloudRegionAndSourceFromConfigurationQueryTest.java new file mode 100644 index 0000000..87e421d --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/CloudRegionAndSourceFromConfigurationQueryTest.java @@ -0,0 +1,102 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class CloudRegionAndSourceFromConfigurationQueryTest extends QueryTest { + + public CloudRegionAndSourceFromConfigurationQueryTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void test() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + //Set up the test graph + Vertex config = graph.addVertex(T.label, "configuration", T.id, "0", "aai-node-type", "configuration", "configuration-id", "configuration"); + Vertex logicalLink = graph.addVertex(T.label, "l", T.id, "1", "aai-node-type", "logical-link", "link-name", "link-name-0"); + Vertex lInterface = graph.addVertex(T.label, "l-interface", T.id, "2", "aai-node-type", "l-interface", "interface-name", "interface-name-0"); + Vertex vserver = graph.addVertex(T.label, "vserver", T.id, "3", "aai-node-type", "vserver", "vserver-id", "vserver-id-0", "vserver-name", "vserver-name-0"); + Vertex tenant = graph.addVertex(T.label, "tenant", T.id, "4", "aai-node-type", "tenant", "tenant-id", "tenantid01", "tenant-name", "tenantName01"); + Vertex cloudregion = graph.addVertex(T.label, "cloud-region", T.id, "5", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region-id-0", "cloud-region-owner", "cloud-owner-name-0","cloud-region-version","cloud-region-version-0"); + + Vertex vfmodule = graph.addVertex(T.label, "vf-module", T.id, "6", "aai-node-type", "vf-module", "vf-module-id", "vf-module-id-0", "vf-module-name", "vf-module-name0"); + Vertex gnvf = graph.addVertex(T.label, "generic-vnf", T.id, "7", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-0", "vnf-name", "vnf-name-0"); + + + Vertex lInterface1 = graph.addVertex(T.label, "l-interface", T.id, "12", "aai-node-type", "l-interface", "interface-name", "interface-name-1"); + Vertex vserver1 = graph.addVertex(T.label, "vserver", T.id, "13", "aai-node-type", "vserver", "vserver-id", "vserver-id-1", "vserver-name", "vserver-name-1"); + Vertex tenant1 = graph.addVertex(T.label, "tenant", T.id, "14", "aai-node-type", "tenant", "tenant-id", "tenantid11", "tenant-name", "tenantName11"); + Vertex cloudregion1 = graph.addVertex(T.label, "cloud-region", T.id, "15", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region-id-1", "cloud-region-owner", "cloud-owner-name-1","cloud-region-version","cloud-region-version-1"); + + Vertex vfmodule1 = graph.addVertex(T.label, "vf-module", T.id, "16", "aai-node-type", "vf-module", "vf-module-id", "vf-module-id-1", "vf-module-name", "vf-module-name1"); + Vertex gnvf1 = graph.addVertex(T.label, "generic-vnf", T.id, "17", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-1", "vnf-name", "vnf-name-1"); + + + GraphTraversalSource g = graph.traversal(); + rules.addEdge(g, config, logicalLink); + rules.addEdge(g, logicalLink, lInterface,"org.onap.relationships.inventory.Source"); + rules.addTreeEdge(g, lInterface, vserver); + rules.addTreeEdge(g, vserver, tenant); + rules.addTreeEdge(g, tenant, cloudregion); + rules.addEdge(g, vserver, vfmodule); + rules.addTreeEdge(g, vfmodule, gnvf); + + rules.addEdge(g, logicalLink, lInterface1,"tosca.relationships.network.LinksTo");//false + rules.addTreeEdge(g, lInterface1, vserver1);//false + rules.addTreeEdge(g, vserver1, tenant1);//false + rules.addTreeEdge(g, tenant1, cloudregion1);//false + rules.addEdge(g, vserver1, vfmodule1);//false + rules.addTreeEdge(g, vfmodule1, gnvf1);//false + + + expectedResult.add(cloudregion); + expectedResult.add(gnvf); + } + + @Override + protected String getQueryName() { + return "cloud-region-and-source-FromConfiguration"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "configuration").has("configuration-id", "configuration"); + } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/CloudRegionFromVnfTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/CloudRegionFromVnfTest.java index e23f416..d364f34 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/CloudRegionFromVnfTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/CloudRegionFromVnfTest.java @@ -51,17 +51,34 @@ public class CloudRegionFromVnfTest extends QueryTest { "vserver-id", "vservId", "vserver-name", "vservName", "vserver-selflink", "me/self"); Vertex cr = graph.addVertex(T.id, "30", "aai-node-type", "cloud-region", "cloud-owner", "some guy", "cloud-region-id", "crId"); Vertex tenant = graph.addVertex(T.id, "40", "aai-node-type", "tenant", "tenant-id", "ten1", "tenant-name", "tenName"); + Vertex pserv = graph.addVertex(T.id, "50", "aai-node-type", "pserver", "hostname", "hostname1", "in-maint", "false"); + Vertex vserv2 = graph.addVertex(T.id, "60", "aai-node-type", "vserver", + "vserver-id", "vservId2", "vserver-name", "vservName2", "vserver-selflink", "me/self"); + Vertex pserv2 = graph.addVertex(T.id, "70", "aai-node-type", "pserver", "hostname", "hostname2", "in-maint", "false"); + Vertex tenant2 = graph.addVertex(T.id, "80", "aai-node-type", "tenant", "tenant-id", "ten2", "tenant-name", "tenName2"); + Vertex cr2 = graph.addVertex(T.id, "90", "aai-node-type", "cloud-region", "cloud-owner", "some guy2", "cloud-region-id", "crId2"); GraphTraversalSource g = graph.traversal(); rules.addEdge(g, gv, vnfc); rules.addEdge(g, vnfc, vserv); + rules.addEdge(g, vserv, pserv); rules.addTreeEdge(g, cr, tenant); rules.addTreeEdge(g, tenant, vserv); + rules.addEdge(g, gv, vserv2); + rules.addEdge(g, vserv2, pserv2); + rules.addTreeEdge(g, vserv2, tenant2); + rules.addTreeEdge(g, tenant2, cr2); + expectedResult.add(gv); expectedResult.add(cr); expectedResult.add(tenant); expectedResult.add(vnfc); expectedResult.add(vserv); + expectedResult.add(pserv); + expectedResult.add(cr2); + expectedResult.add(tenant2); + expectedResult.add(vserv2); + expectedResult.add(pserv2); } @Override diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/ContainmentPathQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/ContainmentPathQueryTest.java index 01ba701..1a7edb4 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/ContainmentPathQueryTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/ContainmentPathQueryTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * Copyright © 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. @@ -16,8 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.onap.aai.rest.search; diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/DestinationFromConfigurationQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/DestinationFromConfigurationQueryTest.java new file mode 100644 index 0000000..47c7d84 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/DestinationFromConfigurationQueryTest.java @@ -0,0 +1,100 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class DestinationFromConfigurationQueryTest extends QueryTest { + + public DestinationFromConfigurationQueryTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void test() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + //Set up the test graph + Vertex config = graph.addVertex(T.label, "configuration", T.id, "0", "aai-node-type", "configuration", "configuration-id", "configuration"); + Vertex logicalLink = graph.addVertex(T.label, "l", T.id, "1", "aai-node-type", "logical-link", "link-name", "link-name-0"); + Vertex lInterface = graph.addVertex(T.label, "l-interface", T.id, "2", "aai-node-type", "l-interface", "interface-name", "interface-name-0"); + Vertex vserver = graph.addVertex(T.label, "vserver", T.id, "3", "aai-node-type", "vserver", "vserver-id", "vserver-id-0", "vserver-name", "vserver-name-0"); + Vertex vfmodule = graph.addVertex(T.label, "vf-module", T.id, "4", "aai-node-type", "vf-module", "vf-module-id", "vf-module-id-0", "vf-module-name", "vf-module-name0"); + + Vertex gnvf = graph.addVertex(T.label, "generic-vnf", T.id, "5", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-0", "vnf-name", "vnf-name-0"); + + Vertex logicalLink1 = graph.addVertex(T.label, "l", T.id, "11", "aai-node-type", "logical-link", "link-name", "link-name-1"); + Vertex lInterface1 = graph.addVertex(T.label, "l-interface", T.id, "12", "aai-node-type", "l-interface", "interface-name", "interface-name-1"); + Vertex vserver1 = graph.addVertex(T.label, "vserver", T.id, "13", "aai-node-type", "vserver", "vserver-id", "vserver-id-1", "vserver-name", "vserver-name-1"); + Vertex vfmodule1 = graph.addVertex(T.label, "vf-module", T.id, "14", "aai-node-type", "vf-module", "vf-module-id", "vf-module-id-1", "vf-module-name", "vf-module-name1"); + + Vertex gnvf1 = graph.addVertex(T.label, "generic-vnf", T.id, "15", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-1", "vnf-name", "vnf-name-1"); + Vertex pnf1 = graph.addVertex(T.label, "pnf", T.id, "16", "aai-node-type", "pnf", "pnf-name", "pnfname-1"); + + + GraphTraversalSource g = graph.traversal(); + rules.addEdge(g, config, logicalLink); + rules.addEdge(g, logicalLink, lInterface,"org.onap.relationships.inventory.Destination"); + rules.addTreeEdge(g, lInterface, vserver); + rules.addEdge(g, vserver, vfmodule); + rules.addTreeEdge(g, vfmodule, gnvf); + + rules.addEdge(g, logicalLink, lInterface1,"tosca.relationships.network.LinksTo");//false + rules.addTreeEdge(g, lInterface1, vserver1);//false + rules.addEdge(g, vserver1, vfmodule1);//false + rules.addTreeEdge(g, vfmodule1, gnvf1);//false + + rules.addEdge(g, config, logicalLink1); + rules.addEdge(g, logicalLink1, gnvf1); + rules.addEdge(g, gnvf1, pnf1); + + + expectedResult.add(gnvf); + expectedResult.add(pnf1); + } + + @Override + protected String getQueryName() { + return "destination-FromConfiguration"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "configuration").has("configuration-id", "configuration"); + } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GetClfiRoadmTailSummaryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetClfiRoadmTailSummaryTest.java new file mode 100644 index 0000000..9ddd2e3 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetClfiRoadmTailSummaryTest.java @@ -0,0 +1,105 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class GetClfiRoadmTailSummaryTest extends QueryTest { + + public GetClfiRoadmTailSummaryTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + Vertex serviceInstance = graph.addVertex(T.label, "service-instance", T.id, "1", "aai-node-type", "service-instance", + "service-instance-id", "service-instance-id-1", "service-instance-name", "service-instance-name-1"); + Vertex serviceSubscription = graph.addVertex(T.label, "service-subscription", T.id, "2", "aai-node-type", "service-subscription", + "service-type", "service-subcription-1"); + Vertex customer = graph.addVertex(T.label, "customer", T.id, "3", "aai-node-type", "customer", "" + + "global-customer-id", "customer-id-1", "subscriber-name", "customer-name1", "subscriber-type", "customer-type1"); + Vertex logicalLink1 = graph.addVertex(T.label, "logical-link", T.id, "4", "aai-node-type", "logical-link", "link-name", "logical-link-1"); + Vertex logicalLink2 = graph.addVertex(T.label, "logical-link", T.id, "5", "aai-node-type", "logical-link", "link-name", "logical-link-2"); + Vertex pInterface1 = graph.addVertex(T.label, "p-interface", T.id, "6", "aai-node-type", "p-interface", "interface-name", "p-interface-1"); + Vertex pInterface2 = graph.addVertex(T.label, "p-interface", T.id, "7", "aai-node-type", "p-interface", "interface-name", "p-interface-2"); + Vertex pInterface3 = graph.addVertex(T.label, "p-interface", T.id, "8", "aai-node-type", "p-interface", "interface-name", "p-interface-3"); + Vertex pnf1 = graph.addVertex(T.label, "pnf", T.id, "9", "aai-node-type", "pnf", "pnf-name", "pnf1name"); + Vertex pnf2 = graph.addVertex(T.label, "pnf", T.id, "10", "aai-node-type", "pnf", "pnf-name", "pnf2name"); + + Vertex lInterface1 = graph.addVertex(T.label, "l-interface", T.id, "11", "aai-node-type", "l-interface", "interface-name", "l-interface-1"); + + GraphTraversalSource g = graph.traversal(); + rules.addTreeEdge(g, customer, serviceSubscription); + rules.addTreeEdge(g, serviceSubscription, serviceInstance); + + rules.addEdge(g, serviceInstance, logicalLink1); + rules.addEdge(g, logicalLink2, logicalLink1); + rules.addEdge(g, logicalLink2, pInterface1); + rules.addEdge(g, logicalLink2, pInterface2); + rules.addEdge(g, logicalLink2, pInterface3); + + rules.addTreeEdge(g, pnf1, pInterface1); + rules.addTreeEdge(g, pnf2, pInterface2); + rules.addTreeEdge(g, pnf2, pInterface3); + + rules.addEdge(g, logicalLink1, lInterface1);//false + + expectedResult.add(logicalLink1); + expectedResult.add(pInterface1); + expectedResult.add(pnf1); + expectedResult.add(pInterface2); + expectedResult.add(pInterface3); + expectedResult.add(pnf2); + expectedResult.add(logicalLink2); + expectedResult.add(serviceInstance); + expectedResult.add(serviceSubscription); + expectedResult.add(customer); + } + + @Override + protected String getQueryName() { + return "getClfiRoadmTailSummary"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "logical-link").has("link-name", "logical-link-2"); + } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } + + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GetComplexByPnfNameQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetComplexByPnfNameQueryTest.java new file mode 100644 index 0000000..1d79466 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetComplexByPnfNameQueryTest.java @@ -0,0 +1,75 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +import java.util.Map; + +public class GetComplexByPnfNameQueryTest extends QueryTest { + public GetComplexByPnfNameQueryTest () throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + + // Set up the test graph + Vertex pnf1 = graph.addVertex(T.label, "pnf", T.id, "0", "aai-node-type", "pnf", "pnf-name", "pnf1name", "equip-vendor", "equip-vendor1", "equip-model","equip-model1"); + Vertex complex1 = graph.addVertex(T.label, "complex", T.id, "1", "aai-node-type", "complex", "physical-location-id", "physical-location-id-1"); + + // adding extra vertices and edges which shouldn't be picked. + Vertex pnf2 = graph.addVertex(T.label, "pnf", T.id, "2", "aai-node-type", "pnf", "pnf-name", "pnf2name", "equip-vendor", "equip-vendor2", "equip-model","equip-model2"); + Vertex complex2 = graph.addVertex(T.label, "complex", T.id, "3", "aai-node-type", "complex", "physical-location-id", "physical-location-id-2"); + + GraphTraversalSource g = graph.traversal(); + rules.addEdge(g, pnf1, complex1); + rules.addEdge(g, pnf2, complex2); + + expectedResult.add(pnf1); + expectedResult.add(complex1); + } + + @Override + protected String getQueryName() { + return "getComplexByPnfName"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "pnf").has("pnf-name", "pnf1name"); + } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GetComplexFromHostnameQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetComplexFromHostnameQueryTest.java new file mode 100644 index 0000000..694b1c5 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetComplexFromHostnameQueryTest.java @@ -0,0 +1,77 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +import java.util.Map; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class GetComplexFromHostnameQueryTest extends TreeQueryTest { + public GetComplexFromHostnameQueryTest () throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @SuppressWarnings("rawtypes") + @Test + public void run() { + super.run(); + Tree tree = treeList.get(0); + Vertex pserver1 = graph.traversal().V().has("aai-node-type","pserver").has("hostname","pserver-name-1").next(); + Vertex pserver2 = graph.traversal().V().has("aai-node-type","pserver").has("hostname","pserver-name-2").next(); + Vertex complex1 = graph.traversal().V().has("aai-node-type", "complex").has( "physical-location-id", "physical-location-id-1").next(); + assertTrue(tree.containsKey(pserver1)); + assertTrue(((Tree) tree.get(pserver1)).containsKey(complex1)); + assertFalse(tree.containsKey(pserver2)); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + + // Set up the test graph + Vertex pserver1 = graph.addVertex(T.label, "pserver", T.id, "0", "aai-node-type", "pserver", "hostname", "pserver-name-1"); + Vertex pserver2 = graph.addVertex(T.label, "pserver", T.id, "4", "aai-node-type", "pserver", "hostname", "pserver-name-2"); + Vertex complex1 = graph.addVertex(T.label, "complex", T.id, "1", "aai-node-type", "complex", "physical-location-id", "physical-location-id-1"); + rules.addEdge(gts, pserver1, complex1); + rules.addEdge(gts, pserver2, complex1); + } + + @Override + protected String getQueryName() { + return "getComplexFromHostname"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "pserver").has("hostname", "pserver-name-1"); + } + + @Override + protected void addParam(Map<String, Object> params) { + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GetDHVLogicalLinkTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetDHVLogicalLinkTest.java new file mode 100644 index 0000000..6659d20 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetDHVLogicalLinkTest.java @@ -0,0 +1,116 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +import static org.junit.Assert.*; + +public class GetDHVLogicalLinkTest extends TreeQueryTest { + public GetDHVLogicalLinkTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + + Tree tree = treeList.get(0); + Vertex gvnf1 = graph.traversal().V().has("aai-node-type", "generic-vnf").has("vnfname", "vnfname1").next(); + Vertex linterface1 = graph.traversal().V().has("aai-node-type", "l-interface").has("network-name", "networkName1").next(); + Vertex vlan1 = graph.traversal().V().has("aai-node-type", "vlan").has("vlan-interface", "vlan-interface1").next(); + Vertex logicalLink1 = graph.traversal().V().has("aai-node-type", "logical-link").has("link-type", "linkType1").next(); + + Vertex gvnf2 = graph.traversal().V().has("aai-node-type", "generic-vnf").has("vnfname", "vnfname2").next(); + + assertTrue(tree.containsKey(gvnf1)); + assertTrue(((Tree) tree.get(gvnf1)).containsKey(linterface1)); + assertTrue(((Tree)(((Tree) tree.get(gvnf1)).get(linterface1))).containsKey(vlan1)); + assertTrue(((Tree)((Tree)(((Tree) tree.get(gvnf1)).get(linterface1))).get(vlan1)).containsKey(logicalLink1)); + + assertFalse(tree.containsKey(gvnf2)); + } + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + + + //Set up the test graph + Vertex gvnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "0", "aai-node-type", "generic-vnf", "vnfname", "vnfname1", "vnf-name", "vnfname1", "vnf-type", "vnftype1"); + + + Vertex linterface1 = graph.addVertex(T.label, "l-interface", T.id, "1", "aai-node-type", "l-interface", + "l-interface-id", "l-interface-id0", "l-interface-name", "l-interface-name1","network-name","networkName1"); + + Vertex vlan1 = graph.addVertex(T.label, "vlan", T.id, "2", "aai-node-type", "vlan", "vlan-interface", "vlan-interface1"); + + Vertex logicalLink1 = graph.addVertex(T.label, "logical-link", T.id, "3", "aai-node-type", "logical-link", + "link-name", "linkName1", "in-maint", "false", "link-type","linkType1"); + + //Set up the test graph for false test cases + Vertex gvnf2 = graph.addVertex(T.label, "generic-vnf", T.id, "4", "aai-node-type", "generic-vnf", "vnfname", "vnfname2", "vnf-name", "vnfname2", "vnf-type", "vnftype2"); + + + Vertex linterface2 = graph.addVertex(T.label, "l-interface", T.id, "5", "aai-node-type", "l-interface", + "l-interface-id", "l-interface-id2", "l-interface-name", "l-interface-name2","network-name","networkName2"); + + Vertex vlan2 = graph.addVertex(T.label, "vlan", T.id, "6", "aai-node-type", "vlan", "vlan-interface", "vlan-interface2"); + + Vertex logicalLink2 = graph.addVertex(T.label, "logical-link", T.id, "7", "aai-node-type", "logical-link", + "link-name", "linkName2", "in-maint", "false", "link-type","linkType2"); + + + //GraphTraversalSource g = graph.traversal(); + + rules.addTreeEdge(gts, gvnf1, linterface1); // true + rules.addTreeEdge(gts, linterface1, vlan1); // true + rules.addEdge(gts, vlan1, logicalLink1); // true + + rules.addTreeEdge(gts, gvnf2, linterface2); // false + rules.addTreeEdge(gts, linterface2, vlan2); // false + rules.addEdge(gts, vlan2, logicalLink2); // false + + expectedResult.add(gvnf1); + expectedResult.add(linterface1); + expectedResult.add(vlan1); + expectedResult.add(logicalLink1); + + } + @Override + protected String getQueryName() { + return "getDHVLogicalLink"; + } + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "generic-vnf").has("vnfname", "vnfname1"); } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GetL3networkCloudRegionByNetworkRoleQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetL3networkCloudRegionByNetworkRoleQueryTest.java new file mode 100644 index 0000000..a9fedcd --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetL3networkCloudRegionByNetworkRoleQueryTest.java @@ -0,0 +1,91 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +import java.util.Map; + +public class GetL3networkCloudRegionByNetworkRoleQueryTest extends QueryTest { + public GetL3networkCloudRegionByNetworkRoleQueryTest () throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + + // Set up the test graph + Vertex l3Network1 = graph.addVertex(T.label, "l3-network", T.id, "0", "aai-node-type", "l3-network", "network-id", "networkId1", "network-name", "networkName1", "network-role","networkRole1"); + Vertex genericVnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "1", "aai-node-type", "generic-vnf", "vnf-id", "vnfId1", "vnf-name", "vnfName1", "vnf-type", "vnfType1"); + Vertex vserver1 = graph.addVertex(T.label, "vserver", T.id, "2", "aai-node-type", "vserver", "vserver-id", "vserverId1", "vserver-name", "vserverName1", "vserver-selflink", "vserverSelfLink1"); + Vertex tenant1 = graph.addVertex(T.label, "tenant", T.id, "3", "aai-node-type", "tenant", "tenant-id", "tenantId1", "tenant-name" ,"tenantName1"); + Vertex cloudRegion1 = graph.addVertex(T.label, "cloud-region", T.id, "4", "aai-node-type", "cloud-region", "cloud-owner", "cloudOwner1", "cloud-region-id", "cloudRegionId1"); + + // adding extra vertices and edges which shouldn't be picked. + Vertex l3Network2 = graph.addVertex(T.label, "l3-network", T.id, "5", "aai-node-type", "l3-network", "network-id", "networkId2", "network-name", "networkName2", "network-role","networkRole2"); + Vertex genericVnf2 = graph.addVertex(T.label, "generic-vnf", T.id, "6", "aai-node-type", "generic-vnf", "vnf-id", "vnfId2", "vnf-name", "vnfName2", "vnf-type", "vnfType2"); + Vertex vserver2 = graph.addVertex(T.label, "vserver", T.id, "7", "aai-node-type", "vserver", "vserver-id", "vserverId2", "vserver-name", "vserverName2", "vserver-selflink", "vserverSelfLink2"); + Vertex tenant2 = graph.addVertex(T.label, "tenant", T.id, "8", "aai-node-type", "tenant", "tenant-id", "tenantId2", "tenant-name" ,"tenantName2"); + Vertex cloudRegion2 = graph.addVertex(T.label, "cloud-region", T.id, "9", "aai-node-type", "cloud-region", "cloud-owner", "cloudOwner2", "cloud-region-id", "cloudRegionId2"); + + GraphTraversalSource g = graph.traversal(); + rules.addEdge(g, l3Network1, genericVnf1); + rules.addEdge(g, genericVnf1, vserver1); + rules.addTreeEdge(g, vserver1, tenant1); + rules.addTreeEdge(g, tenant1, cloudRegion1); + + rules.addEdge(g, l3Network2, genericVnf2); + rules.addEdge(g, genericVnf2, vserver2); + rules.addTreeEdge(g, vserver2, tenant2); + rules.addTreeEdge(g, tenant2, cloudRegion2); + + expectedResult.add(l3Network1); + expectedResult.add(genericVnf1); + expectedResult.add(vserver1); + expectedResult.add(tenant1); + expectedResult.add(cloudRegion1); + } + + @Override + protected String getQueryName() { + return "getL3networkCloudRegionByNetworkRole"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "l3-network").has("network-id", "networkId1").has("network-role", "networkRole1"); + } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GetLinterfaceFromNewvceTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetLinterfaceFromNewvceTest.java new file mode 100644 index 0000000..fbb77b8 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetLinterfaceFromNewvceTest.java @@ -0,0 +1,121 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +import java.util.Map; + +public class GetLinterfaceFromNewvceTest extends QueryTest { + public GetLinterfaceFromNewvceTest () throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + + // Set up the test graph + Vertex newvce = graph.addVertex(T.label, "newvce", T.id, "0", "aai-node-type", "newvce", "vnf-id2", "vnfId2-1", "vnf-name", "vnfName-1", "vnf-type", "vnfType-1"); + Vertex linterfaceNewvce1 = graph.addVertex(T.label, "l-interface", T.id, "1", "aai-node-type", "l-interface", "l-interface-id", "lInterfaceId-10", + "l-interface-name", "lInterfaceName-1", "interface-role", "UPLINK"); + Vertex linterfaceNewvce2 = graph.addVertex(T.label, "l-interface", T.id, "2", "aai-node-type", "l-interface", "l-interface-id", "lInterfaceId-20", + "l-interface-name", "lInterfaceName-1", "interface-role", "CUSTOMER"); + Vertex linterfaceNewvce3 = graph.addVertex(T.label, "l-interface", T.id, "3", "aai-node-type", "l-interface", "l-interface-id", "lInterfaceId-30", + "l-interface-name", "lInterfaceName-3", "interface-role", "CUSTOMER-UPLINK"); + + Vertex logicalLink1 = graph.addVertex(T.label, "logical-link", T.id, "4", "aai-node-type", "logical-link", "link-name", "linkName-1", "in-maint", "false", "link-type","linkType-1"); + + // 1 generic-vnf with 2 lags each has 1 linterface + Vertex genericvnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "5", "aai-node-type", "generic-vnf", "vnf-id", "vnfId-1","vnf-name", "vnfName-1"); + Vertex lagint1 = graph.addVertex(T.label, "lag-interface", T.id, "6", "aai-node-type", "lag-interface","interface-name", "lagIntName-1"); + Vertex linterface1 = graph.addVertex(T.label, "l-interface", T.id, "7", "aai-node-type", "l-interface", "l-interface-id", "lInterfaceId-1", + "l-interface-name", "lInterfaceName-1", "interface-role", "CUSTOMER"); + + Vertex linterface2 = graph.addVertex(T.label, "l-interface", T.id, "9", "aai-node-type", "l-interface", "l-interface-id", "lInterfaceId-2", + "l-interface-name", "lInterfaceName-2", "interface-role", "CUSTOMER-UPLINK"); + Vertex linterface3 = graph.addVertex(T.label, "l-interface", T.id, "10", "aai-node-type", "l-interface", "l-interface-id", "lInterfaceId-3", + "l-interface-name", "lInterfaceName-3", "interface-role", "UPLINK"); + Vertex linterface4 = graph.addVertex(T.label, "l-interface", T.id, "11", "aai-node-type", "l-interface", "l-interface-id", "lInterfaceId-4", "l-interface-name", "lInterfaceName-4", "interface-role", "CUSTOMER-UPLINK"); + + Vertex lagint2 = graph.addVertex(T.label, "lag-interface", T.id, "8", "aai-node-type", "lag-interface","interface-name", "lagIntName-2"); + Vertex linterface21 = graph.addVertex(T.label, "l-interface", T.id, "20", "aai-node-type", "l-interface", "l-interface-id", "lInterfaceId-21", + "l-interface-name", "lInterfaceName-2", "interface-role", "CUSTOMER-UPLINK"); + + Vertex genericvnf2 = graph.addVertex(T.label, "generic-vnf", T.id, "12", "aai-node-type", "generic-vnf", "vnf-id", "vnfId-2","vnf-name", "vnfName-2"); + Vertex linterface31 = graph.addVertex(T.label, "l-interface", T.id, "13", "aai-node-type", "l-interface", "l-interface-id", "lInterfaceId-21", "l-interface-name", "lInterfaceName-21", "interface-role", "CUSTOMER-UPLINK"); + Vertex lagint3 = graph.addVertex(T.label, "lag-interface", T.id, "14", "aai-node-type", "lag-interface","interface-name", "lagIntName-22"); + + + GraphTraversalSource g = graph.traversal(); + rules.addTreeEdge(g, newvce, linterfaceNewvce1); // true + rules.addTreeEdge(g, newvce, linterfaceNewvce2); + rules.addTreeEdge(g, newvce, linterfaceNewvce3); + rules.addEdge(g, linterfaceNewvce1, logicalLink1); // true + rules.addEdge(g, linterfaceNewvce2, logicalLink1); + + rules.addTreeEdge(g, genericvnf1, lagint1); + rules.addTreeEdge(g, lagint1, linterface1); + + rules.addTreeEdge(g, lagint1, linterface2); // true + rules.addTreeEdge(g, lagint1, linterface3); + rules.addTreeEdge(g, lagint1, linterface4); // true + rules.addTreeEdge(g, lagint2, linterface21); + + rules.addEdge(g, linterface2, logicalLink1); // true + rules.addEdge(g, linterface4, logicalLink1); // true + rules.addEdge(g, linterface21, logicalLink1); // true + + rules.addTreeEdge(g, genericvnf2, lagint3); + rules.addTreeEdge(g, lagint2, linterface31); + + + expectedResult.add(linterface2); + expectedResult.add(linterface4); + expectedResult.add(linterface21); + + } + + @Override + protected String getQueryName() { + return "getLinterface-fromNewvce"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "newvce").has("vnf-id2", "vnfId2-1"); + } + + @Override + protected void addParam(Map<String, Object> params) { + params.put("interfaceRole1", "UPLINK"); + params.put("interfaceRole2", "CUSTOMER-UPLINK"); + } +}
\ No newline at end of file diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GetNetworksTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetNetworksTest.java new file mode 100644 index 0000000..8e34236 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetNetworksTest.java @@ -0,0 +1,92 @@ +package org.onap.aai.rest.search; +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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========================================================= + */ + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class GetNetworksTest extends QueryTest { + + public GetNetworksTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void test() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + //Set up the test graph + Vertex owningentity = graph.addVertex(T.label, "owning-entity", T.id, "1", "aai-node-type", "owning-entity", "owning-entity-id", "owning-entity-id-0", "owning-entity-name", "owning-entity-name-0"); + Vertex serviceinstance = graph.addVertex(T.label, "service-instance", T.id, "2", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-0"); + Vertex l3network = graph.addVertex(T.label, "l3-network", T.id, "3", "aai-node-type", "l3-network", "network-id", "network-id-0", "network-role", "network-role-0", "is-bound-to-vpn", "false", "is-provider-network", "false", "is-shared-network", "false", "is-external-network", "false"); + Vertex cloudregion = graph.addVertex(T.label, "cloud-region", T.id, "10", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region-id-0", "cloud-region-owner", "cloud-owner-name-0","cloud-region-version","cloud-region-version-0"); + Vertex l3network2 = graph.addVertex(T.label, "l3-network", T.id, "8", "aai-node-type", "l3-network", "network-id", "network-id-2", "network-role", "network-role-2", "is-bound-to-vpn", "false", "is-provider-network", "false", "is-shared-network", "false", "is-external-network", "false"); + Vertex l3network3 = graph.addVertex(T.label, "l3-network", T.id, "9", "aai-node-type", "l3-network", "network-id", "network-id-0", "network-role", "network-role-3", "is-bound-to-vpn", "false", "is-provider-network", "false", "is-shared-network", "false", "is-external-network", "false"); + Vertex cloudregion2 = graph.addVertex(T.label, "cloud-region", T.id, "11", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region-id-2", "cloud-region-owner", "cloud-owner-name-0","cloud-region-version","cloud-region-version-0"); + + Vertex owningentity1 = graph.addVertex(T.label, "owning-entity", T.id, "4", "aai-node-type", "owning-entity", "owning-entity-id", "owning-entity-id-1", "owning-entity-name", "owning-entity-name-1"); + Vertex serviceinstance1 = graph.addVertex(T.label, "service-instance", T.id, "5", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-1"); + Vertex l3network1 = graph.addVertex(T.label, "l3-network", T.id, "6", "aai-node-type", "l3-network", "network-id", "network-id-1", "is-bound-to-vpn", "false", "is-provider-network", "false", "is-shared-network", "false", "is-external-network", "false"); + Vertex cloudregion1 = graph.addVertex(T.label, "cloud-region", T.id, "7", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region-id-1", "cloud-region-owner", "cloud-owner-name-1","cloud-region-version","cloud-region-version-1"); + + + GraphTraversalSource g = graph.traversal(); + rules.addEdge(g, owningentity, serviceinstance); + rules.addEdge(g, serviceinstance, l3network); + rules.addEdge(g, l3network, cloudregion); + rules.addEdge(g, serviceinstance, l3network2); + rules.addEdge(g, l3network2, cloudregion); + rules.addEdge(g, l3network3, cloudregion2); + rules.addEdge(g, serviceinstance, l3network3); + + rules.addEdge(g, owningentity1, serviceinstance1); + rules.addEdge(g, serviceinstance1, l3network1); //false + rules.addEdge(g, l3network1, cloudregion1); + + expectedResult.add(l3network); + } + + @Override + protected String getQueryName() { + return "getNetworks"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "owning-entity").has("owning-entity-id", "owning-entity-id-0"); + } + + @Override + protected void addParam(Map<String, Object> params) { + params.put("networkRole", "network-role-0"); + params.put("cloudRegionId", "cloud-region-id-0"); + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GetPinterfacePhysicalLinkBySvcInstIdTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetPinterfacePhysicalLinkBySvcInstIdTest.java new file mode 100644 index 0000000..b271183 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetPinterfacePhysicalLinkBySvcInstIdTest.java @@ -0,0 +1,106 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class GetPinterfacePhysicalLinkBySvcInstIdTest extends QueryTest { + + public GetPinterfacePhysicalLinkBySvcInstIdTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void test() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + //Set up the test graph + Vertex serviceinstance = graph.addVertex(T.label, "service-instance", T.id, "0", "aai-node-type", "service-instance", "service-instance-id", "s-instance-id1"); + Vertex serviceinstance1 = graph.addVertex(T.label, "service-instance", T.id, "1", "aai-node-type", "service-instance", "service-instance-id", "s-instance-id2"); + + Vertex gnvf = graph.addVertex(T.label, "generic-vnf", T.id, "2", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-1", "vnf-name", "vnf-name-1"); + Vertex gnvf1 = graph.addVertex(T.label, "generic-vnf", T.id, "3", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-2", "vnf-name", "vnf-name-2"); + + Vertex pserver = graph.addVertex(T.label, "pserver", T.id, "4", "aai-node-type", "pserver", "hostname", "pservername1"); + Vertex pserver1 = graph.addVertex(T.label, "pserver", T.id, "5", "aai-node-type", "pserver", "hostname", "pservername2"); + + Vertex vserver = graph.addVertex(T.label, "vserver", T.id, "6", "aai-node-type", "vserver", "vserver-id", "vserverid1"); + Vertex vserver1 = graph.addVertex(T.label, "vserver", T.id, "7", "aai-node-type", "vserver", "vserver-id", "vserverid2"); + + Vertex pInterface = graph.addVertex(T.label, "p-interface", T.id, "8", "aai-node-type", "p-interface", "interface-name", "p-interface-1"); + Vertex pInterface1 = graph.addVertex(T.label, "p-interface", T.id, "9", "aai-node-type", "p-interface", "interface-name", "p-interface-2"); + + Vertex plink = graph.addVertex(T.label, "physical-link", T.id, "10", "aai-node-type", "physical-link", "link-name", "link-name-1" ); + Vertex plink1 = graph.addVertex(T.label, "physical-link", T.id, "11", "aai-node-type", "physical-link", "link-name", "link-name-2" ); + + + + GraphTraversalSource g = graph.traversal(); + + rules.addEdge(g, serviceinstance, gnvf); + rules.addEdge(g, gnvf, vserver); + rules.addEdge(g, vserver, pserver); + rules.addTreeEdge(g, pserver, pInterface); + rules.addEdge(g, pInterface, plink); + + rules.addEdge(g, serviceinstance1, gnvf1); + rules.addEdge(g, gnvf1, vserver1); + rules.addEdge(g, vserver1, pserver1); + rules.addTreeEdge(g, pserver1, pInterface1); + rules.addEdge(g, pInterface1, plink1); + + expectedResult.add(serviceinstance); + expectedResult.add(gnvf); + expectedResult.add(vserver); + expectedResult.add(pserver); + expectedResult.add(pInterface); + expectedResult.add(plink); + + + } + + @Override + protected String getQueryName() { + return "getPinterfacePhysicalLinkBySvcInstId"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "service-instance").has("service-instance-id", "s-instance-id1"); + } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GetRouterRoadmTailSummaryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetRouterRoadmTailSummaryTest.java new file mode 100644 index 0000000..dc6d148 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetRouterRoadmTailSummaryTest.java @@ -0,0 +1,104 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class GetRouterRoadmTailSummaryTest extends QueryTest{ + + public GetRouterRoadmTailSummaryTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + Vertex serviceInstance = graph.addVertex(T.label, "service-instance", T.id, "1", "aai-node-type", "service-instance", + "service-instance-id", "service-instance-id-1", "service-instance-name", "service-instance-name-1"); + Vertex serviceSubscription = graph.addVertex(T.label, "service-subscription", T.id, "2", "aai-node-type", "service-subscription", + "service-type", "service-subcription-1"); + Vertex customer = graph.addVertex(T.label, "customer", T.id, "3", "aai-node-type", "customer", "" + + "global-customer-id", "customer-id-1", "subscriber-name", "customer-name1", "subscriber-type", "customer-type1"); + Vertex logicalLink1 = graph.addVertex(T.label, "logical-link", T.id, "4", "aai-node-type", "logical-link", "link-name", "logical-link-1"); + Vertex logicalLink2 = graph.addVertex(T.label, "logical-link", T.id, "5", "aai-node-type", "logical-link", "link-name", "logical-link-2"); + Vertex pInterface1 = graph.addVertex(T.label, "p-interface", T.id, "6", "aai-node-type", "p-interface", "interface-name", "p-interface-1"); + Vertex pInterface2 = graph.addVertex(T.label, "p-interface", T.id, "7", "aai-node-type", "p-interface", "interface-name", "p-interface-2"); + Vertex pInterface3 = graph.addVertex(T.label, "p-interface", T.id, "8", "aai-node-type", "p-interface", "interface-name", "p-interface-3"); + Vertex pnf1 = graph.addVertex(T.label, "pnf", T.id, "9", "aai-node-type", "pnf", "pnf-name", "pnf1name"); + Vertex pnf2 = graph.addVertex(T.label, "pnf", T.id, "10", "aai-node-type", "pnf", "pnf-name", "pnf2name"); + + Vertex lInterface1 = graph.addVertex(T.label, "l-interface", T.id, "11", "aai-node-type", "l-interface", "interface-name", "l-interface-1"); + + GraphTraversalSource g = graph.traversal(); + rules.addTreeEdge(g, customer, serviceSubscription); + rules.addTreeEdge(g, serviceSubscription, serviceInstance); + + rules.addEdge(g, serviceInstance, logicalLink1); + rules.addEdge(g, logicalLink2, logicalLink1); + rules.addEdge(g, logicalLink2, pInterface1); + rules.addEdge(g, logicalLink2, pInterface2); + rules.addEdge(g, logicalLink2, pInterface3); + + rules.addTreeEdge(g, pInterface1, pnf1); + rules.addTreeEdge(g, pInterface2, pnf2); + rules.addTreeEdge(g, pInterface3, pnf2); + + rules.addEdge(g, logicalLink2, lInterface1);//false + + expectedResult.add(pnf1); + expectedResult.add(pInterface1); + expectedResult.add(logicalLink1); + expectedResult.add(pInterface2); + expectedResult.add(pInterface3); + expectedResult.add(pnf2); + expectedResult.add(logicalLink2); + expectedResult.add(serviceInstance); + expectedResult.add(serviceSubscription); + expectedResult.add(customer); + } + + @Override + protected String getQueryName() { + return "getRouterRoadmTailSummary"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "pnf").has("pnf-name", "pnf1name"); + } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GetServiceTopologyTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetServiceTopologyTest.java new file mode 100644 index 0000000..5475ea8 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GetServiceTopologyTest.java @@ -0,0 +1,220 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class GetServiceTopologyTest extends TreeQueryTest { + + public GetServiceTopologyTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + //Set up the test graph + + + + Vertex customer = graph.addVertex(T.label, "customer", T.id, "1", "aai-node-type", "customer", "global-customer-id", "customer-id-1", "subscriber-name", "customer-name1", "subscriber-type", "customer-type1"); + Vertex serviceSubscription = graph.addVertex(T.label, "service-subscription", T.id, "2", "aai-node-type", "service-subscription", "service-type", "service-subcription-1"); + + Vertex serviceInstanceOne = graph.addVertex(T.label, "service-instance", T.id, "3", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-1", "service-instance-name", "service-instance-name-1"); + Vertex genericVnfOne = graph.addVertex(T.label, "generic-vnf", T.id, "4", "aai-node-type", "generic-vnf", "vnf-name", "vnf-name", "vnf-type", "test", "vnf-id", "vnf-test=1"); + Vertex lInterfaceOne = graph.addVertex(T.label, "l-interface", T.id, "5", "aai-node-type", "l-interface", "interface-name", "test-l-interface-one"); + Vertex l3Ipv4AddressListOne = graph.addVertex(T.label, "l3-interface-ipv4-address-list", T.id, "6", "aai-node-type", "l3-interface-ipv4-address-list", "l3-interface-ipv4-address", "test1"); + Vertex l3Ipv6AddressListOne = graph.addVertex(T.label, "l3-interface-ipv6-address-list", T.id, "7", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address", "test2"); + + Vertex vlanOne = graph.addVertex(T.label, "vlan", T.id, "8", "aai-node-type", "vlan", "vlan-interface", "test-vlan-one"); + Vertex l3Ipv4AddressListTwo = graph.addVertex(T.label, "l3-interface-ipv4-address-list", T.id, "9", "aai-node-type", "l3-interface-ipv4-address-list", "l3-interface-ipv4-address", "test3"); + Vertex l3Ipv6AddressListTwo = graph.addVertex(T.label, "l3-interface-ipv6-address-list", T.id, "10", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address", "test4"); + + Vertex vserverOne = graph.addVertex(T.label, "vserver", T.id, "11", "aai-node-type", "vserver", "vserver-id-one", "test-vserver", "vserver-selflink", "test", "vserver-name", "test-vserver"); + Vertex lInterfaceTwo = graph.addVertex(T.label, "l-interface", T.id, "12", "aai-node-type", "l-interface", "interface-name", "test-l-interface-two"); + Vertex l3Ipv4AddressListThree = graph.addVertex(T.label, "l3-interface-ipv4-address-list", T.id, "13", "aai-node-type", "l3-interface-ipv4-address-list", "l3-interface-ipv4-address", "test5"); + Vertex l3Ipv6AddressListThree = graph.addVertex(T.label, "l3-interface-ipv6-address-list", T.id, "14", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address", "test6"); + + Vertex vlanTwo = graph.addVertex(T.label, "vlan", T.id, "15", "aai-node-type", "vlan", "vlan-interface", "test-vlan-two"); + Vertex l3Ipv4AddressListFour = graph.addVertex(T.label, "l3-interface-ipv4-address-list", T.id, "16", "aai-node-type", "l3-interface-ipv4-address-list", "l3-interface-ipv4-address", "test7"); + Vertex l3Ipv6AddressListFour = graph.addVertex(T.label, "l3-interface-ipv6-address-list", T.id, "17", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address", "test8"); + + Vertex pserver = graph.addVertex(T.label, "pserver", T.id, "18", "aai-node-type", "pserver", "hostname", "test-pserver"); + Vertex complex = graph.addVertex(T.label, "complex", T.id, "19", "aai-node-type", "complex", "physical-location-id", "test-complex"); + + Vertex allottedResource = graph.addVertex(T.label, "allotted-resource", T.id, "20", "aai-node-type", "allotted-resource", "id", "test-resource"); + Vertex serviceInstanceTwo = graph.addVertex(T.label, "service-instance", T.id, "21", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-2", "service-instance-name", "service-instance-name-1"); + Vertex genericVnfTwo = graph.addVertex(T.label, "generic-vnf", T.id, "22", "aai-node-type", "generic-vnf", "vnf-name", "vnf-name", "vnf-type", "test", "vnf-id", "vnf-test-2"); + Vertex lInterfaceThree = graph.addVertex(T.label, "l-interface", T.id, "23", "aai-node-type", "l-interface", "interface-name", "test-l-interface-three"); + Vertex l3Ipv4AddressListFive = graph.addVertex(T.label, "l3-interface-ipv4-address-list", T.id, "24", "aai-node-type", "l3-interface-ipv4-address-list", "l3-interface-ipv4-address", "test9"); + Vertex l3Ipv6AddressListFive = graph.addVertex(T.label, "l3-interface-ipv6-address-list", T.id, "25", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address", "test10"); + + Vertex vlanThree = graph.addVertex(T.label, "vlan", T.id, "26", "aai-node-type", "vlan", "vlan-interface", "test-vlan-three"); + Vertex l3Ipv4AddressListSix = graph.addVertex(T.label, "l3-interface-ipv4-address-list", T.id, "27", "aai-node-type", "l3-interface-ipv4-address-list", "l3-interface-ipv4-address", "test11"); + Vertex l3Ipv6AddressListSix = graph.addVertex(T.label, "l3-interface-ipv6-address-list", T.id, "28", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address", "test12"); + + Vertex vserverTwo = graph.addVertex(T.label, "vserver", T.id, "29", "aai-node-type", "vserver", "vserver-id", "test-vserver", "vserver-selflink", "test", "vserver-name", "test-vserver=two"); + Vertex lInterfaceFour = graph.addVertex(T.label, "l-interface", T.id, "30", "aai-node-type", "l-interface", "interface-name", "test-l-interface-four"); + Vertex l3Ipv4AddressListSeven = graph.addVertex(T.label, "l3-interface-ipv4-address-list", T.id, "31", "aai-node-type", "l3-interface-ipv4-address-list", "l3-interface-ipv4-address", "test13"); + Vertex l3Ipv6AddressListSeven = graph.addVertex(T.label, "l3-interface-ipv6-address-list", T.id, "32", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address", "test14"); + + Vertex vlanFour = graph.addVertex(T.label, "vlan", T.id, "33", "aai-node-type", "vlan", "vlan-interface", "test-vlan-four"); + Vertex l3Ipv4AddressListEight = graph.addVertex(T.label, "l3-interface-ipv4-address-list", T.id, "34", "aai-node-type", "l3-interface-ipv4-address-list", "l3-interface-ipv4-address", "test15"); + Vertex l3Ipv6AddressListEight = graph.addVertex(T.label, "l3-interface-ipv6-address-list", T.id, "35", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address", "test16"); + + + GraphTraversalSource g = graph.traversal(); + + + rules.addTreeEdge(g, customer, serviceSubscription); + rules.addTreeEdge(g, serviceSubscription, serviceInstanceOne); + + rules.addEdge(g, serviceInstanceOne, genericVnfOne); + rules.addTreeEdge(g, genericVnfOne, lInterfaceOne); + rules.addTreeEdge(g, lInterfaceOne, l3Ipv4AddressListOne); + rules.addTreeEdge(g, lInterfaceOne, l3Ipv6AddressListOne); + + rules.addTreeEdge(g, lInterfaceOne, vlanOne); + rules.addTreeEdge(g, vlanOne, l3Ipv4AddressListTwo); + rules.addTreeEdge(g, vlanOne, l3Ipv6AddressListTwo); + + rules.addEdge(g, genericVnfOne, vserverOne); + rules.addTreeEdge(g, vserverOne, lInterfaceTwo); + rules.addTreeEdge(g, lInterfaceTwo, l3Ipv4AddressListThree); + rules.addTreeEdge(g, lInterfaceTwo, l3Ipv6AddressListThree); + rules.addTreeEdge(g, lInterfaceTwo, vlanTwo); + rules.addTreeEdge(g, vlanTwo, l3Ipv4AddressListFour); + rules.addTreeEdge(g, vlanTwo, l3Ipv6AddressListFour); + rules.addEdge(g, vserverOne, pserver); + rules.addEdge(g, pserver, complex); + + rules.addEdge(g, serviceInstanceOne, allottedResource); + rules.addTreeEdge(g, allottedResource, serviceInstanceTwo); + + rules.addEdge(g, serviceInstanceTwo, genericVnfTwo); + rules.addTreeEdge(g, genericVnfTwo, lInterfaceThree); + rules.addTreeEdge(g, lInterfaceThree, l3Ipv4AddressListFive); + rules.addTreeEdge(g, lInterfaceThree, l3Ipv6AddressListFive); + + rules.addTreeEdge(g, lInterfaceThree, vlanThree); + rules.addTreeEdge(g, vlanThree, l3Ipv4AddressListSix); + rules.addTreeEdge(g, vlanThree, l3Ipv6AddressListSix); + + rules.addEdge(g, genericVnfTwo, vserverTwo); + rules.addTreeEdge(g, vserverTwo, lInterfaceFour); + rules.addTreeEdge(g, lInterfaceFour, l3Ipv4AddressListSeven); + rules.addTreeEdge(g, lInterfaceFour, l3Ipv6AddressListSeven); + rules.addTreeEdge(g, lInterfaceFour, vlanFour); + rules.addTreeEdge(g, vlanFour, l3Ipv4AddressListEight); + rules.addTreeEdge(g, vlanFour, l3Ipv6AddressListEight); + + + + + expectedResult.add(serviceInstanceOne); + expectedResult.add(genericVnfOne); + expectedResult.add(lInterfaceOne); + expectedResult.add(l3Ipv4AddressListOne); + expectedResult.add(l3Ipv6AddressListOne); + expectedResult.add(vlanOne); + expectedResult.add(l3Ipv4AddressListTwo); + expectedResult.add(l3Ipv6AddressListTwo); + + + expectedResult.add(vserverOne); + expectedResult.add(lInterfaceTwo); + expectedResult.add(l3Ipv4AddressListThree); + expectedResult.add(l3Ipv6AddressListThree); + + expectedResult.add(vlanTwo); + expectedResult.add(l3Ipv4AddressListFour); + expectedResult.add(l3Ipv6AddressListFour); + + expectedResult.add(pserver); + expectedResult.add(complex); + + expectedResult.add(allottedResource); + expectedResult.add(serviceInstanceTwo); + expectedResult.add(genericVnfTwo); + expectedResult.add(lInterfaceThree); + expectedResult.add(l3Ipv4AddressListFive); + expectedResult.add(l3Ipv6AddressListFive); + + expectedResult.add(vlanThree); + expectedResult.add(l3Ipv4AddressListSix); + expectedResult.add(l3Ipv6AddressListSix); + + expectedResult.add(vserverTwo); + expectedResult.add(lInterfaceFour); + expectedResult.add(l3Ipv4AddressListSeven); + expectedResult.add(l3Ipv6AddressListSeven); + expectedResult.add(vlanFour); + expectedResult.add(l3Ipv4AddressListEight); + expectedResult.add(l3Ipv6AddressListEight); + + } + + @Test + public void run() { + super.run(); + Tree tree = treeList.get(0); + ArrayList<Vertex> actualResult = new ArrayList<Vertex>(); + int i = 1; + do { + actualResult.addAll(tree.getObjectsAtDepth(i)); + i++; + } while(!tree.getObjectsAtDepth(i).isEmpty()); + + assertEquals("result has expected number of values", actualResult.size(), expectedResult.size()); + int size = actualResult.size() == expectedResult.size() ? expectedResult.size() : 0; + for(i = 0; i < size; i++) { + assertTrue("result has node " + expectedResult.get(i), actualResult.contains(expectedResult.get(i))); + } + + } + + @Override + protected String getQueryName() { + return "getServiceTopology"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "service-instance").has("service-instance-id", "service-instance-id-1"); + } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GfpVserverDataQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GfpVserverDataQueryTest.java index 77cd524..8724785 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/GfpVserverDataQueryTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GfpVserverDataQueryTest.java @@ -53,6 +53,7 @@ public class GfpVserverDataQueryTest extends QueryTest { GraphTraversalSource g = graph.traversal(); + rules.addTreeEdge(g, tenant, cloudregion); rules.addTreeEdge(g, vserver, tenant); rules.addEdge(g, genericvnf, vserver); diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GfpVserverQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GfpVserverQueryTest.java new file mode 100644 index 0000000..286319f --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GfpVserverQueryTest.java @@ -0,0 +1,69 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; + +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class GfpVserverQueryTest extends QueryTest { + public GfpVserverQueryTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + @Test + public void run() { + super.run(); + } + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + //set up test graph + Vertex cloudregion = graph.addVertex(T.label, "cloud-region", T.id, "1", "aai-node-type", "cloud-region", "cloud-region-id", "regionid0", "cloud-owner", "cloudOwnername0"); + Vertex tenant = graph.addVertex(T.label, "tenant", T.id, "2", "aai-node-type", "tenant", "tenant-id", "tenantid0", "tenant-name", "tenantName0"); + Vertex vserver = graph.addVertex(T.label, "vserver", T.id, "3", "aai-node-type", "vserver", "vserver-id", "vserverid0"); + Vertex linterface = graph.addVertex(T.label, "l-interface", T.id, "4", "aai-node-type", "l-interface", "l-interface-id", "l-interface-id0", "l-interface-name", "l-interface-name0"); + GraphTraversalSource g = graph.traversal(); + + rules.addTreeEdge(g, tenant, cloudregion); + rules.addTreeEdge(g, vserver, tenant); + rules.addTreeEdge(g, linterface, vserver); + + expectedResult.add(vserver); + } + @Override + protected String getQueryName() { + return "gfp-vserver"; + } + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "vserver"); + } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } +}
\ No newline at end of file diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GremlinServerImplTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GremlinServerImplTest.java deleted file mode 100644 index 1391bbf..0000000 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/GremlinServerImplTest.java +++ /dev/null @@ -1,161 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 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.aai.rest.search; - -import org.janusgraph.core.JanusGraph; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; -import org.apache.tinkerpop.gremlin.structure.Graph; -import org.apache.tinkerpop.gremlin.structure.T; -import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.onap.aai.dbmap.DBConnectionType; -import org.onap.aai.exceptions.AAIException; -import org.onap.aai.introspection.Loader; -import org.onap.aai.introspection.LoaderFactory; -import org.onap.aai.introspection.ModelType; -import org.onap.aai.introspection.Version; -import org.onap.aai.serialization.engines.QueryStyle; -import org.onap.aai.serialization.engines.JanusGraphDBEngine; -import org.onap.aai.serialization.engines.TransactionalGraphEngine; -import org.onap.aai.serialization.queryformats.SubGraphStyle; - -import javax.ws.rs.core.*; -import java.net.URI; -import java.util.*; - -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class GremlinServerImplTest { - - GremlinServerImpl gremlinServerImpl; - - protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); - - private static final Set<Integer> VALID_HTTP_STATUS_CODES = new HashSet<>(); - - private final static Version version = Version.getLatest(); - private final static ModelType introspectorFactoryType = ModelType.MOXY; - private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL; - private final static DBConnectionType type = DBConnectionType.REALTIME; - - static { - VALID_HTTP_STATUS_CODES.add(200); - VALID_HTTP_STATUS_CODES.add(201); - VALID_HTTP_STATUS_CODES.add(204); - } - - private GenericQueryProcessor genericQueryProcessor; - private HttpHeaders httpHeaders; - - private UriInfo uriInfo; - - private MultivaluedMap<String, String> headersMultiMap; - private MultivaluedMap<String, String> queryParameters; - - private List<String> aaiRequestContextList; - - private List<MediaType> outputMediaTypes; - - private Loader loader; - private JanusGraph graph; - - private Graph tx; - - private GraphTraversalSource g; - private TransactionalGraphEngine dbEngine; - - - -@Before - public void setup()throws AAIException{ - - httpHeaders = mock(HttpHeaders.class); - uriInfo = mock(UriInfo.class); - - headersMultiMap = new MultivaluedHashMap<>(); - queryParameters = Mockito.spy(new MultivaluedHashMap<>()); - - headersMultiMap.add("X-FromAppId", "JUNIT"); - headersMultiMap.add("X-TransactionId", UUID.randomUUID().toString()); - headersMultiMap.add("Real-Time", "true"); - headersMultiMap.add("Accept", "application/json"); - headersMultiMap.add("aai-request-context", ""); - - outputMediaTypes = new ArrayList<>(); - outputMediaTypes.add(APPLICATION_JSON); - - aaiRequestContextList = new ArrayList<>(); - aaiRequestContextList.add(""); - - when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); - when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); - when(httpHeaders.getRequestHeader("X-FromAppId")).thenReturn(Arrays.asList("JUNIT")); - when(httpHeaders.getRequestHeader("X-TransactionId")).thenReturn(Arrays.asList("JUNIT")); - - when(httpHeaders.getRequestHeader("aai-request-context")).thenReturn(aaiRequestContextList); - - - when(uriInfo.getQueryParameters()).thenReturn(queryParameters); - when(uriInfo.getQueryParameters(false)).thenReturn(queryParameters); - - // TODO - Check if this is valid since RemoveDME2QueryParameters seems to be very unreasonable - Mockito.doReturn(null).when(queryParameters).remove(anyObject()); - - when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); - loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); - dbEngine = new JanusGraphDBEngine( - queryStyle, - type, - loader); - GenericQueryProcessor.Builder builder=new GenericQueryProcessor.Builder(dbEngine); -builder.queryFrom(URI.create("te")); -builder.queryFrom("te", "gremlin"); -builder.create(); -builder.processWith(QueryProcessorType.GREMLIN_SERVER); - builder.processWith(QueryProcessorType.LOCAL_GROOVY); - - gremlinServerImpl= new GremlinServerImpl(builder); - } - - @Test(expected = NullPointerException.class) - public void processSubGraphTest() throws Exception{ - GraphTraversal<Vertex, Vertex> g=Mockito.mock(GraphTraversal.class); - g.has("cloud-region-id", "cloud-region-id-1"); - gremlinServerImpl.processSubGraph(SubGraphStyle.prune,g); -} - - @Test(expected = RuntimeException.class) - public void executeTest() throws Exception{ - GraphTraversal<Vertex, Vertex> g=Mockito.mock(GraphTraversal.class); - g.has("cloud-region-id", "cloud-region-id-1"); - //Mockito.when(etPath()).thenReturn("testpath"); - List<Object> re= gremlinServerImpl.execute(SubGraphStyle.prune); - Assert.assertNotNull(re); - } - - - -} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/GroovyShellImplTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/GroovyShellImplTest.java index 0bbb04f..97045df 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/GroovyShellImplTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/GroovyShellImplTest.java @@ -19,26 +19,20 @@ */ package org.onap.aai.rest.search; -import org.janusgraph.core.JanusGraph; import groovy.lang.MissingPropertyException; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; -import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; +import org.onap.aai.AAISetup; import org.onap.aai.dbmap.DBConnectionType; -import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.Loader; -import org.onap.aai.introspection.LoaderFactory; import org.onap.aai.introspection.ModelType; -import org.onap.aai.introspection.Version; -import org.onap.aai.serialization.engines.QueryStyle; import org.onap.aai.serialization.engines.JanusGraphDBEngine; +import org.onap.aai.serialization.engines.QueryStyle; import org.onap.aai.serialization.engines.TransactionalGraphEngine; -import org.onap.aai.serialization.queryformats.SubGraphStyle; +import org.onap.aai.setup.SchemaVersion; import javax.ws.rs.core.*; import java.net.URI; @@ -48,7 +42,7 @@ import static org.mockito.Matchers.anyObject; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class GroovyShellImplTest { +public class GroovyShellImplTest extends AAISetup{ GroovyShellImpl groovyShellImpl ; @@ -56,18 +50,19 @@ public class GroovyShellImplTest { private static final Set<Integer> VALID_HTTP_STATUS_CODES = new HashSet<>(); - private final static Version version = Version.getLatest(); + private SchemaVersion version; + private final static ModelType introspectorFactoryType = ModelType.MOXY; private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL; private final static DBConnectionType type = DBConnectionType.REALTIME; + static { VALID_HTTP_STATUS_CODES.add(200); VALID_HTTP_STATUS_CODES.add(201); VALID_HTTP_STATUS_CODES.add(204); } - private GenericQueryProcessor genericQueryProcessor; private HttpHeaders httpHeaders; private UriInfo uriInfo; @@ -80,18 +75,12 @@ public class GroovyShellImplTest { private List<MediaType> outputMediaTypes; private Loader loader; - private JanusGraph graph; - - private Graph tx; - - private GraphTraversalSource g; private TransactionalGraphEngine dbEngine; + @Before + public void setup() { - -@Before - public void setup()throws AAIException{ - + version = schemaVersions.getDefaultVersion(); httpHeaders = mock(HttpHeaders.class); uriInfo = mock(UriInfo.class); @@ -125,31 +114,27 @@ public class GroovyShellImplTest { Mockito.doReturn(null).when(queryParameters).remove(anyObject()); when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); - loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); + loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version); dbEngine = new JanusGraphDBEngine( queryStyle, type, loader); - GenericQueryProcessor.Builder builder=new GenericQueryProcessor.Builder(dbEngine); -builder.queryFrom(URI.create("te")); -builder.queryFrom("te", "gremlin"); -builder.create(); -builder.processWith(QueryProcessorType.GREMLIN_SERVER); - builder.processWith(QueryProcessorType.LOCAL_GROOVY); - - groovyShellImpl= new GroovyShellImpl(builder); + GenericQueryProcessor.Builder builder = new GenericQueryProcessor.Builder(dbEngine, gremlinServerSingleton); + builder.queryFrom(URI.create("te")); + builder.queryFrom("te", "gremlin"); + builder.create(); + builder.processWith(QueryProcessorType.GREMLIN_SERVER); + builder.processWith(QueryProcessorType.LOCAL_GROOVY); + + groovyShellImpl = new GroovyShellImpl(builder); } @Test(expected = MissingPropertyException.class) - public void processSubGraphTest() throws Exception{ - GraphTraversal<Vertex, Vertex> g=Mockito.mock(GraphTraversal.class); + public void processSubGraphTest() throws Exception { + GraphTraversal<Vertex, Vertex> g = Mockito.mock(GraphTraversal.class); g.has("cloud-region-id", "cloud-region-id-1"); Map<String, Object> params = new HashMap<>(); - groovyShellImpl.runQuery("vnfs-fromServiceInstance",params); -} - - - - + groovyShellImpl.runQuery("vnfs-fromServiceInstance", params); + } } diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/InstanceGroupsByCloudRegionQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/InstanceGroupsByCloudRegionQueryTest.java new file mode 100644 index 0000000..0dbb911 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/InstanceGroupsByCloudRegionQueryTest.java @@ -0,0 +1,78 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class InstanceGroupsByCloudRegionQueryTest extends QueryTest { + + public InstanceGroupsByCloudRegionQueryTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void test() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + //Set up the test graph + Vertex cloudregion = graph.addVertex(T.label, "cloud-region", T.id, "1", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region-id-0", "cloud-region-owner", "cloud-owner-name-0","cloud-region-version","cloud-region-version-0"); + Vertex instancegroup = graph.addVertex(T.label, "instance-group", T.id, "2", "aai-node-type", "instance-group", "id", "id-0", "instance-group-type", "instance-group-type-0","instance-group-role","instance-group-role-0","instance-group-function","instance-group-function-0","instance-group-description","instance-group-description-0"); + + Vertex cloudregion1 = graph.addVertex(T.label, "cloud-region", T.id, "3", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region-id-1", "cloud-region-owner", "cloud-owner-name-1","cloud-region-version","cloud-region-version-1"); + Vertex instancegroup1 = graph.addVertex(T.label, "instance-group", T.id, "4", "aai-node-type", "instance-group", "id", "id-1", "instance-group-type", "instance-group-type-1","instance-group-role","instance-group-role-1","instance-group-function","instance-group-function-1","instance-group-description","instance-group-description-1"); + + + GraphTraversalSource g = graph.traversal(); + rules.addEdge(g, cloudregion, instancegroup); + + rules.addEdge(g, cloudregion1, instancegroup1); //false + + expectedResult.add(instancegroup); + } + + @Override + protected String getQueryName() { + return "instance-groups-byCloudRegion"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "cloud-region").has("cloud-region-owner", "cloud-owner-name-0").has("cloud-region-id", "cloud-region-id-0"); + } + + @Override + protected void addParam(Map<String, Object> params) { + params.put("role", "instance-group-role-0"); + params.put("type", "instance-group-type-0"); + params.put("function", "instance-group-function-0"); + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/LinkedDevices_NewvceVserverTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/LinkedDevices_NewvceVserverTest.java index 8d6ef91..c828c67 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/LinkedDevices_NewvceVserverTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/LinkedDevices_NewvceVserverTest.java @@ -68,7 +68,7 @@ public class LinkedDevices_NewvceVserverTest extends QueryTest { "interface-name", "lint3", "is-port-mirrored", "true", "in-maint", "true", "is-ip-unnumbered", "false"); Vertex cloudregion = graph.addVertex(T.label, "cloud-region", T.id, "50", "aai-node-type", "cloud-region", - "cloud-owner", "onap", "cloud-region-id", "crId"); + "cloud-owner", "att", "cloud-region-id", "crId"); Vertex tenant = graph.addVertex(T.label, "tenant", T.id, "60", "aai-node-type", "tenant", "tenant-id", "tenId", "tenant-name", "verity"); Vertex vserver = graph.addVertex(T.label, "vserver", T.id, "30", "aai-node-type", "vserver", diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/LogicalLinkByCloudRegionIdTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/LogicalLinkByCloudRegionIdTest.java new file mode 100644 index 0000000..a231ccd --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/LogicalLinkByCloudRegionIdTest.java @@ -0,0 +1,75 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +import java.util.Map; + +public class LogicalLinkByCloudRegionIdTest extends QueryTest { + public LogicalLinkByCloudRegionIdTest () throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + + // Set up the test graph + Vertex cloudRegion1 = graph.addVertex(T.label, "cloud-region", T.id, "0", "aai-node-type", "cloud-region", "cloud-owner", "cloudOwner1", "cloud-region-id", "cloudRegionId1"); + Vertex logicalLink1 = graph.addVertex(T.label, "logical-link", T.id, "1", "aai-node-type", "logical-link", "link-name", "linkName1", "in-maint", "false", "link-type","linkType1"); + + // adding extra vertices and edges which shouldn't be picked. + Vertex cloudRegion2 = graph.addVertex(T.label, "cloud-region", T.id, "2", "aai-node-type", "cloud-region", "cloud-owner", "cloudOwner2", "cloud-region-id", "cloudRegionId3"); + Vertex logicalLink2 = graph.addVertex(T.label, "logical-link", T.id, "3", "aai-node-type", "logical-link", "link-name", "linkName2", "in-maint", "false", "link-type","linkType4"); + + GraphTraversalSource g = graph.traversal(); + rules.addEdge(g, cloudRegion1, logicalLink1); + rules.addEdge(g, cloudRegion2, logicalLink2); + + expectedResult.add(cloudRegion1); + expectedResult.add(logicalLink1); + } + + @Override + protected String getQueryName() { + return "getLogicalLinkByCloudRegionId"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "cloud-region").has("cloud-region-id", "cloudRegionId1"); + } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } +}
\ No newline at end of file diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/ModelAndNamedQueryRestProviderTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/ModelAndNamedQueryRestProviderTest.java index 793723e..1fc8bbd 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/ModelAndNamedQueryRestProviderTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/ModelAndNamedQueryRestProviderTest.java @@ -23,18 +23,19 @@ import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import org.apache.commons.io.IOUtils; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.mockito.Mockito; +import org.onap.aai.AAISetup; import org.onap.aai.dbmap.DBConnectionType; import org.onap.aai.introspection.Loader; -import org.onap.aai.introspection.LoaderFactory; import org.onap.aai.introspection.ModelType; -import org.onap.aai.introspection.Version; import org.onap.aai.serialization.db.DBSerializer; import org.onap.aai.serialization.engines.QueryStyle; import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import org.onap.aai.serialization.queryformats.utils.UrlBuilder; +import org.onap.aai.setup.SchemaVersion; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.*; @@ -48,13 +49,13 @@ import static org.mockito.Matchers.anyObject; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class ModelAndNamedQueryRestProviderTest { +public class ModelAndNamedQueryRestProviderTest extends AAISetup{ protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); private static final Set<Integer> VALID_HTTP_STATUS_CODES = new HashSet<>(); - private static final Version version = Version.getLatest(); + private SchemaVersion version; private static final ModelType introspectorFactoryType = ModelType.MOXY; private static final QueryStyle queryStyle = QueryStyle.TRAVERSAL; private static final DBConnectionType type = DBConnectionType.REALTIME; @@ -85,11 +86,10 @@ public class ModelAndNamedQueryRestProviderTest { @Before public void setup(){ + version = schemaVersions.getDefaultVersion(); logger.info("Starting the setup for the integration tests of Rest Endpoints"); - System.setProperty("AJSC_HOME", "."); - System.setProperty("BUNDLECONFIG_DIR", "src/main/resources"); - - modelAndNamedQueryRestProvider = new ModelAndNamedQueryRestProvider(); + + modelAndNamedQueryRestProvider = new ModelAndNamedQueryRestProvider(searchGraph, schemaVersions); httpHeaders = mock(HttpHeaders.class); uriInfo = mock(UriInfo.class); @@ -125,7 +125,7 @@ public class ModelAndNamedQueryRestProviderTest { Mockito.doReturn(null).when(queryParameters).remove(anyObject()); when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); - loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); + loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version); dbEngine = new JanusGraphDBEngine( queryStyle, type, @@ -159,9 +159,6 @@ public class ModelAndNamedQueryRestProviderTest { when(httpHeaders.getRequestHeader("X-FromAppId")).thenThrow(IllegalArgumentException.class); when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); - DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); - UrlBuilder urlBuilder = new UrlBuilder(version, serializer); - Response response = modelAndNamedQueryRestProvider.getNamedQueryResponse( httpHeaders, null, @@ -173,6 +170,7 @@ public class ModelAndNamedQueryRestProviderTest { assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); } + @Ignore("This test is too dependent on the cpu time to timeout and will fail randomly") @Test public void testNamedQueryCallTimeoutThrown() throws Exception { diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/NetworkCollectionByServiceInstanceTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/NetworkCollectionByServiceInstanceTest.java new file mode 100644 index 0000000..bb44704 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/NetworkCollectionByServiceInstanceTest.java @@ -0,0 +1,103 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class NetworkCollectionByServiceInstanceTest extends QueryTest{ + public NetworkCollectionByServiceInstanceTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + + + //Set up the test graph + Vertex serviceinstance1 = graph.addVertex(T.label, "service-instance", T.id, "0", "aai-node-type", + "service-instance", "service-instance-id", "service-instance-id-1", "service-instance-name", + "service-instance-name-1"); + + Vertex collection1 = graph.addVertex(T.label, "collection", T.id, "1", "aai-node-type", "collection"); + + Vertex instancegroup1 = graph.addVertex(T.label, "instance-group", T.id, "2", "aai-node-type", "instance-group", + "id", "id-0", "instance-group-type", "instance-group-type-0","instance-group-role","instance-group-role-0", + "instance-group-function","instance-group-function-0","instance-group-description","instance-group-description-0"); + + Vertex l3network1 = graph.addVertex(T.label, "l3-network", T.id, "3", "aai-node-type", "l3-network"); + + + + Vertex serviceinstance2 = graph.addVertex(T.label, "service-instance", T.id, "4", "aai-node-type", + "service-instance", "service-instance-id", "service-instance-id-2", "service-instance-name", + "service-instance-name-1"); + + Vertex collection2 = graph.addVertex(T.label, "collection", T.id, "5", "aai-node-type", "collection"); + + Vertex instancegroup2 = graph.addVertex(T.label, "instance-group", T.id, "6", "aai-node-type", "instance-group", + "id", "id-0", "instance-group-type", "instance-group-type-0","instance-group-role","instance-group-role-0", + "instance-group-function","instance-group-function-0","instance-group-description","instance-group-description-0"); + + Vertex l3network2 = graph.addVertex(T.label, "l3-network", T.id, "7", "aai-node-type", "l3-network"); + + GraphTraversalSource g = graph.traversal(); + + rules.addEdge(g, serviceinstance1, collection1); // True + rules.addEdge(g, collection1, instancegroup1); // True + rules.addEdge(g, instancegroup1, l3network1); // True + + rules.addEdge(g, serviceinstance2, collection2); // False + rules.addEdge(g, collection2, instancegroup2); // False + rules.addEdge(g, instancegroup2, l3network2);// False + + expectedResult.add(serviceinstance1); + expectedResult.add(collection1); + expectedResult.add(instancegroup1); + expectedResult.add(l3network1); + + } + @Override + protected String getQueryName() { + return "network-collection-ByServiceInstance"; + } + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "service-instance").has("service-instance-id", "service-instance-id-1"); + } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } +} + + diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/PathQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/PathQueryTest.java index 5e1b729..84d7a59 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/PathQueryTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/PathQueryTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * Copyright © 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. @@ -16,8 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.onap.aai.rest.search; diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/PendingTopologyDetailTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/PendingTopologyDetailTest.java index bb73030..9de2607 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/PendingTopologyDetailTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/PendingTopologyDetailTest.java @@ -50,6 +50,7 @@ public class PendingTopologyDetailTest extends QueryTest { Vertex servinst = graph.addVertex(T.label, "service-instance", T.id, "4", "aai-node-type", "service-instance", "service-instance-id", "servInstId0", "service-type", "servType0"); Vertex owningentity = graph.addVertex(T.label, "owning-entity", T.id, "5", "aai-node-type", "owning-entity", "owning-entity-id", "entityId0", "owning-entity-name", "entityName0"); Vertex project = graph.addVertex(T.label, "project", T.id, "6", "aai-node-type", "project", "project-name", "project0"); + Vertex vfmodule = graph.addVertex(T.label, "vf-module", T.id, "38", "aai-node-type", "vf-module", "vf-module-id", "1"); Vertex vnfc = graph.addVertex(T.label, "vnfc", T.id, "7", "aai-node-type", "vnfc", "vnfc-name", "vnfc0", "nfc-naming-code", "namingCode0", "nfc-function", "function0"); Vertex vserver = graph.addVertex(T.label, "vserver", T.id, "8", "aai-node-type", "vserver", "vserver-id", "vserverid0"); Vertex linterface = graph.addVertex(T.label, "l-interface", T.id, "9", "aai-node-type", "l-interface", "l-interface-id", "l-interface-id0", "l-interface-name", "l-interface-name0"); @@ -69,7 +70,8 @@ public class PendingTopologyDetailTest extends QueryTest { Vertex genericvnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "40", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-1", "vnf-name", "vnf-name-1"); Vertex platform1 = graph.addVertex(T.label, "platform", T.id, "41", "aai-node-type", "platform", "platform-name", "platform1"); - + + Vertex vfmodule2 = graph.addVertex(T.label, "vf-module", T.id, "39", "aai-node-type", "vf-module", "vf-module-id", "2"); Vertex genericvnf2 = graph.addVertex(T.label, "generic-vnf", T.id, "30", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-2", "vnf-name", "vnf-name2"); Vertex vnfc2 = graph.addVertex(T.label, "vnfc", T.id, "31", "aai-node-type", "vnfc", "vnfc-name", "vnfc2", "nfc-naming-code", "namingCode2", "nfc-function", "function2"); Vertex vipipv4addresslist2 = graph.addVertex(T.label, "vip-ipv4-address-list", T.id, "32", "aai-node-type", "vip-ipv4-address-list", "vip-ipv4-addres", "vip-ipv4-address2"); @@ -85,7 +87,9 @@ public class PendingTopologyDetailTest extends QueryTest { rules.addEdge(g, genericvnf, servinst); rules.addEdge(g, owningentity, servinst); rules.addEdge(g, project, servinst); - rules.addEdge(g, genericvnf, vnfc); + rules.addTreeEdge(g, genericvnf, vfmodule); + rules.addEdge(g, vfmodule, vnfc); + //rules.addEdge(g, genericvnf, vnfc); rules.addEdge(g, vnfc, vserver); rules.addTreeEdge(g, vserver, tenant); rules.addTreeEdge(g, tenant, cloudregion); @@ -111,7 +115,8 @@ public class PendingTopologyDetailTest extends QueryTest { // false - rules.addEdge(g, genericvnf2, vnfc2); + rules.addTreeEdge(g, genericvnf2, vfmodule2); + rules.addEdge(g, vfmodule2, vnfc2); rules.addTreeEdge(g, vipipv4addresslist2, cloudregion); rules.addTreeEdge(g, vipipv6addresslist2, cloudregion); rules.addEdge(g, vnfc2, vipipv4addresslist2); @@ -129,6 +134,7 @@ public class PendingTopologyDetailTest extends QueryTest { expectedResult.add(lineofbusiness); expectedResult.add(owningentity); expectedResult.add(project); + expectedResult.add(vfmodule); expectedResult.add(vnfc); expectedResult.add(l3inter1ipv4addresslist); expectedResult.add(subnet4); diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/PserverFromFqdnFirstTokenTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/PserverFromFqdnFirstTokenTest.java new file mode 100644 index 0000000..6b3fcb2 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/PserverFromFqdnFirstTokenTest.java @@ -0,0 +1,74 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class PserverFromFqdnFirstTokenTest extends QueryTest { + + public PserverFromFqdnFirstTokenTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void test() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + //Set up the test graph + Vertex pserver1 = graph.addVertex(T.label, "pserver", T.id, "1", "aai-node-type", "pserver", "hostname", "hostname-10", "fqdn", "fqdn-1.abc.com", "source-of-truth", "RCT"); + Vertex pserver2 = graph.addVertex(T.label, "pserver", T.id, "5", "aai-node-type", "pserver", "hostname", "hostname-20", "fqdn", "fqdn-2.abc.com", "source-of-truth", "RCT"); + Vertex pserver3 = graph.addVertex(T.label, "pserver", T.id, "6", "aai-node-type", "pserver", "hostname", "hostname-30", "fqdn", "fqdn-13.abc.com", "source-of-truth", "AAIRctFeed"); + Vertex pserver4 = graph.addVertex(T.label, "pserver", T.id, "7", "aai-node-type", "pserver", "hostname", "hostname-40", "fqdn", "fqdn-12.abc.com", "source-of-truth", "RO"); + Vertex pserver5 = graph.addVertex(T.label, "pserver", T.id, "8", "aai-node-type", "pserver", "hostname", "hostname-50", "fqdn", "fqdn-20.abc.com", "source-of-truth", "RO"); + + expectedResult.add(pserver1); + expectedResult.add(pserver3); + + } + + @Override + protected String getQueryName() { + return "pserver-fromFqdnFirstToken"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type","pserver"); + } + + @Override + protected void addParam(Map<String, Object> params) { + params.put("fqdnFirstToken", "fqdn-1"); + params.put("sourcesOfTruth", "RCT', 'AAIRctFeed"); //placement of single quotes is intentional, values between the first and last values must be in single quotes + + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/PserverFromHostnameFirstTokenTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/PserverFromHostnameFirstTokenTest.java new file mode 100644 index 0000000..9fe290b --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/PserverFromHostnameFirstTokenTest.java @@ -0,0 +1,75 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class PserverFromHostnameFirstTokenTest extends QueryTest { + + public PserverFromHostnameFirstTokenTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void test() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + //Set up the test graph + Vertex pserver1 = graph.addVertex(T.label, "pserver", T.id, "1", "aai-node-type", "pserver", "hostname", "hostname-1.abc.com", "source-of-truth", "RO"); + Vertex pserver2 = graph.addVertex(T.label, "pserver", T.id, "5", "aai-node-type", "pserver", "hostname", "hostname-2.abc.com", "source-of-truth", "RO"); + Vertex pserver3 = graph.addVertex(T.label, "pserver", T.id, "6", "aai-node-type", "pserver", "hostname", "hostname-13.abc.com", "source-of-truth", "AAI-EXTENSIONS"); + Vertex pserver4 = graph.addVertex(T.label, "pserver", T.id, "7", "aai-node-type", "pserver", "hostname", "hostname-12.abc.com", "source-of-truth", "RCT"); + Vertex pserver5 = graph.addVertex(T.label, "pserver", T.id, "8", "aai-node-type", "pserver", "hostname", "hostname-20.abc.com", "source-of-truth", "RO"); + + + expectedResult.add(pserver1); + expectedResult.add(pserver3); + + } + + @Override + protected String getQueryName() { + return "pserver-fromHostnameFirstToken"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type","pserver"); + } + + @Override + protected void addParam(Map<String, Object> params) { + params.put("hostnameFirstToken", "hostname-1"); + params.put("sourcesOfTruth", "RO', 'AAI-EXTENSIONS"); //placement of single quotes is intentional, values between the first and last values must be in single quotes + + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/PserverfromConfigurationFilterInterfaceIdTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/PserverfromConfigurationFilterInterfaceIdTest.java index e77b479..eb0fd25 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/PserverfromConfigurationFilterInterfaceIdTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/PserverfromConfigurationFilterInterfaceIdTest.java @@ -53,6 +53,8 @@ public class PserverfromConfigurationFilterInterfaceIdTest extends QueryTest { "in-maint", "true", "is-ip-unnumbered", "false", "interface-id", "interface-id1"); Vertex pnf1 = graph.addVertex(T.label, "pnf", T.id, "17", "aai-node-type", "pnf", "pnf-name", "pnf1name", "equip-vendor", "equip-vendor1", "equip-model", "equip-model1"); + + Vertex vserver1 = graph.addVertex(T.label, "vserver", T.id, "22", "aai-node-type", "vserver", "vserver-id", "vserver-id-1", "vserver-name", "vserver-name-1"); // Following are extra nodes that should not be picked up in // expectedResults @@ -69,7 +71,8 @@ public class PserverfromConfigurationFilterInterfaceIdTest extends QueryTest { rules.addEdge(g, config1, loglink2); rules.addEdge(g, lint1, loglink1); rules.addEdge(g, lint2, loglink1); - rules.addEdge(g, loglink1, pserver1); + rules.addTreeEdge(g, vserver1,lint1); + rules.addEdge(g, vserver1, pserver1); rules.addEdge(g, loglink1, gvnf1); rules.addEdge(g, gvnf1, pnf1); diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/PserverfromConfigurationTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/PserverfromConfigurationTest.java index b3fbab1..8a39e1d 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/PserverfromConfigurationTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/PserverfromConfigurationTest.java @@ -53,6 +53,7 @@ public class PserverfromConfigurationTest extends QueryTest { "in-maint", "true", "is-ip-unnumbered", "false", "interface-id", "interface-id1"); Vertex pnf1 = graph.addVertex(T.label, "pnf", T.id, "17", "aai-node-type", "pnf", "pnf-name", "pnf1name", "equip-vendor", "equip-vendor1", "equip-model", "equip-model1"); + Vertex vserver1 = graph.addVertex(T.label, "vserver", T.id, "22", "aai-node-type", "vserver", "vserver-id", "vserver-id-1", "vserver-name", "vserver-name-1"); // Following are extra nodes that should not be picked up in // expectedResults @@ -70,7 +71,8 @@ public class PserverfromConfigurationTest extends QueryTest { rules.addEdge(g, config1, loglink1); rules.addEdge(g, lint1, loglink1); rules.addEdge(g, lint2, loglink1); - rules.addEdge(g, loglink1, pserver1); + rules.addTreeEdge(g, vserver1,lint1); + rules.addEdge(g, vserver1, pserver1); rules.addEdge(g, loglink1, gvnf1); rules.addEdge(g, gvnf1, pnf1); diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/QueryCountTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/QueryCountTest.java index 13e3953..9ab2284 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/QueryCountTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/QueryCountTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * Copyright © 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. @@ -16,8 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.onap.aai.rest.search; diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/QueryPnfFromModelTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/QueryPnfFromModelTest.java new file mode 100644 index 0000000..95290fb --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/QueryPnfFromModelTest.java @@ -0,0 +1,81 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +import java.util.Map; + +public class QueryPnfFromModelTest extends QueryTest { + public QueryPnfFromModelTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + + + Vertex serviceInst1 = graph.addVertex(T.label, "service-instance", T.id, "1", "aai-node-type", "service-instance", "service-instance-id", + "service-instance1", "model-invariant-id", "miid1", "model-version-id", "mvid1"); + Vertex pnf1 = graph.addVertex(T.label, "pnf", T.id, "2", "aai-node-type", "pnf", "pnf-name", "pnf1name", "equip-vendor", "equip-vendor1", "equip-model", + "equip-model1"); + + Vertex serviceInst2 = graph.addVertex(T.label, "service-instance", T.id, "3", "aai-node-type", "service-instance", "service-instance-id", + "service-instance2", "model-invariant-id", "miid2", "model-version-id", "mvid2"); + Vertex pnf2 = graph.addVertex(T.label, "pnf", T.id, "4", "aai-node-type", "pnf", "pnf-name", "pnf2name", "equip-vendor", "equip-vendor2", "equip-model", + "equip-model2"); + + + GraphTraversalSource g = graph.traversal(); + rules.addEdge(g, serviceInst1, pnf1); + + rules.addEdge(g, serviceInst2, pnf2);//false + + + expectedResult.add(pnf1); + } + + @Override + protected String getQueryName() { + return "pnf-from-model"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("model-invariant-id", "miid1").has("model-version-id", "mvid1"); + } + + @Override + protected void addParam(Map<String, Object> params) { + params.put("equipVendor", "equip-vendor1"); + params.put("equipModel", "equip-model1"); + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/QueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/QueryTest.java index f9e467c..29cd505 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/QueryTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/QueryTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * Copyright © 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. @@ -16,8 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.onap.aai.rest.search; @@ -28,16 +26,37 @@ import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSo import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.onap.aai.config.IntrospectionConfig; +import org.onap.aai.config.SpringContextAware; +import org.onap.aai.edges.EdgeIngestor; +import org.onap.aai.edges.exceptions.AmbiguousRuleChoiceException; +import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException; import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.Loader; import org.onap.aai.introspection.LoaderFactory; import org.onap.aai.introspection.ModelType; -import org.onap.aai.introspection.Version; +import org.onap.aai.nodes.NodeIngestor; +import org.onap.aai.setup.AAIConfigTranslator; +import org.onap.aai.setup.SchemaLocationsBean; +import org.onap.aai.setup.SchemaVersion; +import org.onap.aai.setup.SchemaVersions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.rules.SpringClassRule; +import org.springframework.test.context.junit4.rules.SpringMethodRule; import org.onap.aai.query.builder.GremlinTraversal; import org.onap.aai.restcore.search.GremlinGroovyShellSingleton; -import org.onap.aai.serialization.db.EdgeRules; +import org.onap.aai.restcore.search.GroovyQueryBuilderSingleton; +import org.onap.aai.serialization.db.EdgeSerializer; import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; import org.onap.aai.serialization.engines.QueryStyle; import org.onap.aai.serialization.engines.TransactionalGraphEngine; @@ -49,39 +68,92 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Mockito.when; +@RunWith(Parameterized.class) +@ContextConfiguration(classes = { + SchemaLocationsBean.class, + SchemaVersions.class, + AAIConfigTranslator.class, + EdgeIngestor.class, + EdgeSerializer.class, + NodeIngestor.class, + SpringContextAware.class, + GremlinServerSingleton.class, + IntrospectionConfig.class +}) +@TestPropertySource(properties = { + "schema.uri.base.path = /aai", + "schema.ingest.file = src/test/resources/application-test.properties" +}) public abstract class QueryTest { + @ClassRule + public static final SpringClassRule springClassRule = new SpringClassRule(); + + @Rule + public final SpringMethodRule springMethodRule = new SpringMethodRule(); + protected EELFLogger logger; protected Graph graph; - protected GremlinServerSingleton gremlinServerSingleton; protected GremlinGroovyShellSingleton shell; @Mock protected TransactionalGraphEngine dbEngine; protected final List<Vertex> expectedResult = new ArrayList<>(); - protected final EdgeRules rules = EdgeRules.getInstance(); + + @Autowired + protected EdgeIngestor edgeRules; + + @Autowired + protected EdgeSerializer rules; + + @Autowired + protected LoaderFactory loaderFactory; + + @Autowired + protected SchemaVersions schemaVersions; + + @Autowired + protected GremlinServerSingleton gremlinServerSingleton; + protected Loader loader; protected GraphTraversalSource gts; + @Parameterized.Parameter(value = 0) + public SchemaVersion version; + + @Parameterized.Parameters(name = "Version.{0}") + public static Collection<Object[]> data() { + return Arrays.asList(new Object[][]{ + {new SchemaVersion("v11")}, + {new SchemaVersion("v12")}, + {new SchemaVersion("v13")}, + {new SchemaVersion("v14")} + }); + } + protected String query; + LinkedHashMap <String, Object> params; - public QueryTest() throws AAIException, NoEdgeRuleFoundException { - setUp(); - logger = EELFManager.getInstance().getLogger(getClass()); - setUpQuery(); + @BeforeClass + public static void setupBundleconfig() { + System.setProperty("AJSC_HOME", "./"); + System.setProperty("BUNDLECONFIG_DIR", "src/main/resources/"); } - protected void setUp() throws AAIException, NoEdgeRuleFoundException { + @Before + public void setUp() throws AAIException, NoEdgeRuleFoundException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException { System.setProperty("AJSC_HOME", "."); System.setProperty("BUNDLECONFIG_DIR", "src/main/resources"); + logger = EELFManager.getInstance().getLogger(getClass()); MockitoAnnotations.initMocks(this); graph = TinkerGraph.open(); gts = graph.traversal(); createGraph(); - gremlinServerSingleton = GremlinServerSingleton.getInstance(); shell = GremlinGroovyShellSingleton.getInstance(); - loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.getLatest()); + loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, version); + setUpQuery(); } + protected void setUpQuery() { query = gremlinServerSingleton.getStoredQueryFromConfig(getQueryName()); params = new LinkedHashMap <>(); @@ -128,12 +200,12 @@ public abstract class QueryTest { .collect(Collectors.joining(",")); } - protected abstract void createGraph() throws AAIException, NoEdgeRuleFoundException; - + protected abstract void createGraph() throws AAIException, NoEdgeRuleFoundException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException; + protected abstract String getQueryName(); - + protected abstract void addStartNode(GraphTraversal<Vertex, Vertex> g); - + protected abstract void addParam(Map<String, Object> params); } diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/RelatedToBothCousinAndTreeCustomQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/RelatedToBothCousinAndTreeCustomQueryTest.java new file mode 100644 index 0000000..85f4e3b --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/RelatedToBothCousinAndTreeCustomQueryTest.java @@ -0,0 +1,88 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +import java.util.Map; + +public class RelatedToBothCousinAndTreeCustomQueryTest extends QueryTest{ + + public RelatedToBothCousinAndTreeCustomQueryTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + + Vertex lagInterface1 = graph.addVertex(T.label, "lag-interface", T.id, "1", "aai-node-type", "lag-interface", "interface-name", "lag-int1"); + + Vertex lInterface1 = graph.addVertex(T.label, "l-interface", T.id, "2", "aai-node-type", "l-interface", "interface-name", "l-interfaceid01"); + Vertex lInterface2 = graph.addVertex(T.label, "l-interface", T.id, "3", "aai-node-type", "l-interface", "interface-name", "l-interfaceid02"); + Vertex lInterface3 = graph.addVertex(T.label, "l-interface", T.id, "4", "aai-node-type", "l-interface", "interface-name", "l-interfaceid03"); + Vertex lInterface4 = graph.addVertex(T.label, "l-interface", T.id, "5", "aai-node-type", "l-interface", "interface-name", "l-interfaceid04"); + Vertex lInterface5 = graph.addVertex(T.label, "l-interface", T.id, "6", "aai-node-type", "l-interface", "interface-name", "l-interfaceid05"); + Vertex lInterface6 = graph.addVertex(T.label, "l-interface", T.id, "7", "aai-node-type", "l-interface", "interface-name", "l-interfaceid06"); + + GraphTraversalSource g = graph.traversal(); + rules.addEdge(g, lagInterface1, lInterface1); + rules.addEdge(g, lagInterface1, lInterface2); + rules.addEdge(g, lagInterface1, lInterface3); + rules.addTreeEdge(g, lagInterface1, lInterface4); + rules.addTreeEdge(g, lagInterface1, lInterface5); + rules.addTreeEdge(g, lagInterface1, lInterface6); + + expectedResult.add(lInterface1); + expectedResult.add(lInterface2); + expectedResult.add(lInterface3); + expectedResult.add(lInterface4); + expectedResult.add(lInterface5); + expectedResult.add(lInterface6); + + } + + @Override + protected String getQueryName() { + return "related-to"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("interface-name", "lag-int1"); + } + + @Override + protected void addParam(Map<String, Object> params) { + params.put("startingNodeType", "lag-interface"); + params.put("relatedToNodeType", "l-interface"); + + + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/RelatedToCustomQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/RelatedToCustomQueryTest.java new file mode 100644 index 0000000..b8a8156 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/RelatedToCustomQueryTest.java @@ -0,0 +1,78 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +import java.util.Map; +public class RelatedToCustomQueryTest extends QueryTest{ + + public RelatedToCustomQueryTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + + Vertex genericvnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "1", "aai-node-type", "generic-vnf", "vnf-id", "genvnf1", "vnf-name", "genvnfname1", "nf-type", "sample-nf-type"); + + Vertex vserver1 = graph.addVertex(T.label, "vserver", T.id, "2", "aai-node-type", "vserver", "vserver-id", "vserverid01"); + Vertex vserver2 = graph.addVertex(T.label, "vserver", T.id, "3", "aai-node-type", "vserver", "vserver-id", "vserverid02"); + Vertex vserver3 = graph.addVertex(T.label, "vserver", T.id, "4", "aai-node-type", "vserver", "vserver-id", "vserverid03"); + + GraphTraversalSource g = graph.traversal(); + rules.addEdge(g, genericvnf1, vserver1); + rules.addEdge(g, genericvnf1, vserver2); + rules.addEdge(g, genericvnf1, vserver3); + + expectedResult.add(vserver1); + expectedResult.add(vserver2); + expectedResult.add(vserver3); + + } + + @Override + protected String getQueryName() { + return "related-to"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("vnf-id", "genvnf1"); + } + + @Override + protected void addParam(Map<String, Object> params) { + params.put("startingNodeType", "generic-vnf"); + params.put("relatedToNodeType", "vserver"); + + + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/RelatedToTreeCustomQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/RelatedToTreeCustomQueryTest.java new file mode 100644 index 0000000..8998b90 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/RelatedToTreeCustomQueryTest.java @@ -0,0 +1,77 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +import java.util.Map; + +public class RelatedToTreeCustomQueryTest extends QueryTest { + + public RelatedToTreeCustomQueryTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + + Vertex genericvnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "1", "aai-node-type", "generic-vnf", "vnf-id", "genvnf1", "vnf-name", "genvnfname1", "nf-type", "sample-nf-type"); + + Vertex entitlement1 = graph.addVertex(T.label, "entitlement", T.id, "2", "aai-node-type", "entitlement", "group-uuid", "entitlementid01", "resource-uuid", "rentitlementid01"); + Vertex entitlement2 = graph.addVertex(T.label, "entitlement", T.id, "3", "aai-node-type", "entitlement", "group-uuid", "entitlementid02", "resource-uuid", "rentitlementid02"); + Vertex entitlement3 = graph.addVertex(T.label, "entitlement", T.id, "4", "aai-node-type", "entitlement", "group-uuid", "entitlementid03", "resource-uuid", "rentitlementid03"); + + GraphTraversalSource g = graph.traversal(); + rules.addTreeEdge(g, genericvnf1, entitlement1); + rules.addTreeEdge(g, genericvnf1, entitlement2); + rules.addTreeEdge(g, genericvnf1, entitlement3); + + expectedResult.add(entitlement1); + expectedResult.add(entitlement2); + expectedResult.add(entitlement3); + + } + + @Override + protected String getQueryName() { + return "related-to"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("vnf-id", "genvnf1"); + } + + @Override + protected void addParam(Map<String, Object> params) { + params.put("startingNodeType", "generic-vnf"); + params.put("relatedToNodeType", "entitlement"); + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/SearchProviderTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/SearchProviderTest.java index 9b34d5f..b69f992 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/SearchProviderTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/SearchProviderTest.java @@ -25,33 +25,33 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.mockito.Mockito; +import org.onap.aai.AAISetup; import org.onap.aai.dbmap.DBConnectionType; import org.onap.aai.introspection.Loader; -import org.onap.aai.introspection.LoaderFactory; import org.onap.aai.introspection.ModelType; -import org.onap.aai.introspection.Version; -import org.onap.aai.serialization.db.DBSerializer; -import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.QueryStyle; +import org.onap.aai.serialization.engines.JanusGraphDBEngine; import org.onap.aai.serialization.engines.TransactionalGraphEngine; -import org.onap.aai.serialization.queryformats.utils.UrlBuilder; +import org.onap.aai.setup.SchemaVersion; import javax.ws.rs.core.*; import java.util.*; +import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; import static org.mockito.Matchers.anyObject; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class SearchProviderTest { +public class SearchProviderTest extends AAISetup{ protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); private static final Set<Integer> VALID_HTTP_STATUS_CODES = new HashSet<>(); - private static final Version version = Version.getLatest(); + private SchemaVersion version; private static final ModelType introspectorFactoryType = ModelType.MOXY; private static final QueryStyle queryStyle = QueryStyle.TRAVERSAL; private static final DBConnectionType type = DBConnectionType.REALTIME; @@ -83,10 +83,9 @@ public class SearchProviderTest { @Before public void setup(){ logger.info("Starting the setup for the integration tests of Rest Endpoints"); - System.setProperty("AJSC_HOME", "."); - System.setProperty("BUNDLECONFIG_DIR", "src/main/resources"); - - searchProvider = new SearchProvider(); + version = schemaVersions.getDefaultVersion(); + + searchProvider = new SearchProvider(loaderFactory, searchGraph, schemaVersions, basePath); httpHeaders = mock(HttpHeaders.class); uriInfo = mock(UriInfo.class); @@ -122,7 +121,7 @@ public class SearchProviderTest { Mockito.doReturn(null).when(queryParameters).remove(anyObject()); when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); - loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); + loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version); dbEngine = new JanusGraphDBEngine( queryStyle, type, @@ -130,45 +129,6 @@ public class SearchProviderTest { } @Test - public void testNodesQueryInvalidData() throws Exception { - - List<String> keys = new ArrayList<>(); - keys.add("cloud-region.cloud-owner:test-aic"); - - List<String> includeStrings = new ArrayList<>(); - includeStrings.add("cloud-region"); - - DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); - UrlBuilder urlBuilder = new UrlBuilder(version, serializer); - - Response response = searchProvider.getNodesQueryResponse( - httpHeaders, - null, - "cloud-region", - keys, - includeStrings, - version.toString(), - uriInfo - ); - - assertNotNull(response); - assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); - - response = searchProvider.getNodesQueryResponse( - httpHeaders, - null, - "cloud-region", - keys, - includeStrings, - "latest", - uriInfo - ); - - assertNotNull(response); - assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); - } - - @Test public void testNodesQueryInvalidHeaders() throws Exception { List<String> keys = new ArrayList<>(); @@ -182,9 +142,6 @@ public class SearchProviderTest { when(httpHeaders.getRequestHeader("X-FromAppId")).thenThrow(IllegalArgumentException.class); when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); - DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); - UrlBuilder urlBuilder = new UrlBuilder(version, serializer); - Response response = searchProvider.getNodesQueryResponse( httpHeaders, null, @@ -199,6 +156,8 @@ public class SearchProviderTest { assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); } + //TODO fix test + @Ignore("Test has a time dependency and fails based on system perf") @Test public void testNodesQueryTimeoutThrown() throws Exception { @@ -214,9 +173,6 @@ public class SearchProviderTest { when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); - DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); - UrlBuilder urlBuilder = new UrlBuilder(version, serializer); - Response response = searchProvider.getNodesQueryResponse( httpHeaders, null, @@ -229,7 +185,7 @@ public class SearchProviderTest { assertNotNull(response); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); - assertEquals(true, response.getEntity().toString().contains("7406")); + assertThat(response.getEntity().toString(), containsString("7406")); } @Test @@ -247,9 +203,6 @@ public class SearchProviderTest { when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); - DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); - UrlBuilder urlBuilder = new UrlBuilder(version, serializer); - Response response = searchProvider.getNodesQueryResponse( httpHeaders, null, @@ -262,83 +215,11 @@ public class SearchProviderTest { assertNotNull(response); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); - assertEquals(true, response.getEntity().toString().contains("4009")); + assertThat(response.getEntity().toString(), containsString("4009")); } - - @Test - public void testGenericQueryInvalidData() throws Exception { - - List<String> keys = new ArrayList<>(); - keys.add("cloud-region.cloud-owner:test-aic"); - - List<String> includeStrings = new ArrayList<>(); - includeStrings.add("cloud-region"); - - DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); - UrlBuilder urlBuilder = new UrlBuilder(version, serializer); - - Response response = searchProvider.getGenericQueryResponse( - httpHeaders, - null, - "cloud-region", - keys, - includeStrings, - 0, - version.toString(), - uriInfo - ); - - assertNotNull(response); - assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); - - response = searchProvider.getNodesQueryResponse( - httpHeaders, - null, - "cloud-region", - keys, - includeStrings, - "latest", - uriInfo - ); - - assertNotNull(response); - assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); - } - - @Test - public void testGenericQueryInvalidHeaders() throws Exception { - - List<String> keys = new ArrayList<>(); - keys.add("cloud-region.cloud-owner:test-aic"); - - List<String> includeStrings = new ArrayList<>(); - includeStrings.add("cloud-region"); - - httpHeaders = mock(HttpHeaders.class); - - when(httpHeaders.getRequestHeader("X-FromAppId")).thenThrow(IllegalArgumentException.class); - when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); - - DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); - UrlBuilder urlBuilder = new UrlBuilder(version, serializer); - - Response response = searchProvider.getGenericQueryResponse( - httpHeaders, - null, - "cloud-region", - keys, - includeStrings, - 0, - version.toString(), - uriInfo - ); - - assertNotNull(response); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); - } - - @Ignore("This test is very specific to the server vm specification") + //TODO fix test + @Ignore("Test has a time dependency and fails based on system perf") @Test public void testGenericQueryTimeoutThrown() throws Exception { @@ -355,8 +236,6 @@ public class SearchProviderTest { when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); - DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); - UrlBuilder urlBuilder = new UrlBuilder(version, serializer); Response response = searchProvider.getGenericQueryResponse( httpHeaders, @@ -371,41 +250,7 @@ public class SearchProviderTest { assertNotNull(response); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); - assertEquals(true, response.getEntity().toString().contains("7406")); + assertThat(response.getEntity().toString(), containsString("7406")); } - @Test - public void testGenericQueryBypassTimeout() throws Exception { - - List<String> keys = new ArrayList<>(); - keys.add("cloud-region.cloud-owner:test-aic"); - - List<String> includeStrings = new ArrayList<>(); - includeStrings.add("cloud-region"); - - httpHeaders = mock(HttpHeaders.class); - - headersMultiMap.putSingle("X-FromAppId", "JUNITTESTAPP2"); - when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); - - when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); - - DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, "JUNIT"); - UrlBuilder urlBuilder = new UrlBuilder(version, serializer); - - Response response = searchProvider.getGenericQueryResponse( - httpHeaders, - null, - "cloud-region", - keys, - includeStrings, - 0, - version.toString(), - uriInfo - ); - - assertNotNull(response); - assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); - assertEquals(true, response.getEntity().toString().contains("4009")); - } } diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/SimpleFormatTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/SimpleFormatTest.java index 531437f..d6ad59a 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/SimpleFormatTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/SimpleFormatTest.java @@ -19,46 +19,48 @@ */ package org.onap.aai.rest.search; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.List; - +import com.google.gson.JsonObject; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.T; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; +import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.onap.aai.AAISetup; import org.onap.aai.dbmap.DBConnectionType; import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.Loader; -import org.onap.aai.introspection.LoaderFactory; import org.onap.aai.introspection.ModelType; -import org.onap.aai.introspection.Version; import org.onap.aai.serialization.db.DBSerializer; -import org.onap.aai.serialization.db.EdgeRules; + import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; -import org.onap.aai.serialization.engines.QueryStyle; import org.onap.aai.serialization.engines.JanusGraphDBEngine; +import org.onap.aai.serialization.engines.QueryStyle; import org.onap.aai.serialization.engines.TransactionalGraphEngine; import org.onap.aai.serialization.queryformats.RawFormat; import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexException; import org.onap.aai.serialization.queryformats.utils.UrlBuilder; +import org.springframework.test.annotation.DirtiesContext; -import com.google.gson.JsonObject; +import java.util.ArrayList; +import java.util.List; -public class SimpleFormatTest { +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) +public class SimpleFormatTest extends AAISetup{ + protected Graph graph; private TransactionalGraphEngine dbEngine; protected final List<Vertex> expectedResult = new ArrayList<>(); - protected final EdgeRules rules = EdgeRules.getInstance(); + protected Loader loader; private DBSerializer serializer; @@ -68,16 +70,11 @@ public class SimpleFormatTest { Vertex vfmodule = null; - public SimpleFormatTest() throws AAIException, NoEdgeRuleFoundException { - setUp(); - } - + @Before public void setUp() throws AAIException, NoEdgeRuleFoundException { - System.setProperty("AJSC_HOME", "."); - System.setProperty("BUNDLECONFIG_DIR", "src/main/resources"); MockitoAnnotations.initMocks(this); graph = TinkerGraph.open(); - loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v10); + loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getRelatedLinkVersion()); vfmodule = graph.addVertex(T.label, "vf-module", T.id, "5", "aai-node-type", "vf-module", @@ -96,7 +93,7 @@ public class SimpleFormatTest { "contrail-service-instance-fqdn", "example-contrail-service-instance-fqdn-val-68205"); final ModelType factoryType = ModelType.MOXY; - Loader loader = LoaderFactory.createLoaderForVersion(factoryType, Version.v10); + Loader loader = loaderFactory.createLoaderForVersion(factoryType, schemaVersions.getRelatedLinkVersion()); dbEngine = spy(new JanusGraphDBEngine( QueryStyle.TRAVERSAL, DBConnectionType.CACHED, @@ -106,7 +103,7 @@ public class SimpleFormatTest { TransactionalGraphEngine.Admin spyAdmin = spy(dbEngine.asAdmin()); when(spyAdmin.getTraversalSource()).thenReturn(graph.traversal()); when(dbEngine.asAdmin()).thenReturn(spyAdmin); - serializer = new DBSerializer(Version.v10, dbEngine, factoryType, "Junit"); + serializer = new DBSerializer(schemaVersions.getRelatedLinkVersion(), dbEngine, factoryType, "Junit"); _simpleFormat = new RawFormat.Builder(loader, serializer, urlBuilder).modelDriven().build(); dbEngine.startTransaction(); } @@ -116,7 +113,7 @@ public class SimpleFormatTest { assertNotNull(dbEngine.tx()); System.out.println(dbEngine.tx()); assertNotNull(graph.traversal()); - JsonObject json = _simpleFormat.createPropertiesObject(vfmodule); + JsonObject json = _simpleFormat.createPropertiesObject(vfmodule).get(); json.entrySet().stream().forEach((System.out::println)); assertTrue(json.has("model-invariant-id")); diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/SriovTopologyFromVnfQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/SriovTopologyFromVnfQueryTest.java new file mode 100644 index 0000000..cceab09 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/SriovTopologyFromVnfQueryTest.java @@ -0,0 +1,109 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class SriovTopologyFromVnfQueryTest extends QueryTest { + public SriovTopologyFromVnfQueryTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + + + //Set up the test graph + Vertex gvnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "0", "aai-node-type", "generic-vnf", + "vnf-id", "gvnf1", "vnf-name", "genvnfname1", "nf-type", "sample-nf-type"); + Vertex vserver1 = graph.addVertex(T.label, "vserver", T.id, "1", "aai-node-type", "vserver","vserver-name", "vservername1"); + Vertex lint1 = graph.addVertex(T.label, "l-interface", T.id, "2", "aai-node-type", "l-interface", + "interface-name", "lint1", "is-port-mirrored", "true", "in-maint", "true", "is-ip-unnumbered", "false"); + + Vertex sriovVf1 = graph.addVertex(T.label, "sriov-vf", T.id, "3", "aai-node-type", "sriov-vf", "pci-id", "pcIid1"); + Vertex sriovPf1 = graph.addVertex(T.label, "sriov-pf", T.id, "4", "aai-node-type", "sriov-pf", "pf-pci-id", "pfPciId1"); + + Vertex pint1 = graph.addVertex(T.label, "p-interface", T.id, "5", "aai-node-type", "p-interface", "interface-name", "ge0/0/0"); + Vertex plink1 = graph.addVertex(T.label, "physical-link", T.id, "6", "aai-node-type", "physical-link", "link-name", "ge0/0/0-to-xe0/0/0"); + + + Vertex gvnf2 = graph.addVertex(T.label, "generic-vnf", T.id, "10", "aai-node-type", "generic-vnf", + "vnf-id", "gvnf2", "vnf-name", "genvnfname2", "nf-type", "sample-nf-type1"); + Vertex vserver2 = graph.addVertex(T.label, "vserver", T.id, "11", "aai-node-type", "vserver","vserver-name", "vservername2"); + Vertex lint2 = graph.addVertex(T.label, "l-interface", T.id, "12", "aai-node-type", "l-interface", + "interface-name", "lint2", "is-port-mirrored", "true", "in-maint", "true", "is-ip-unnumbered", "false"); + + Vertex sriovVf2 = graph.addVertex(T.label, "sriov-vf", T.id, "13", "aai-node-type", "sriov-vf", "pci-id", "pcIid2"); + Vertex sriovPf2 = graph.addVertex(T.label, "sriov-pf", T.id, "14", "aai-node-type", "sriov-pf", "pf-pci-id", "pfPciId2"); + + Vertex pint2 = graph.addVertex(T.label, "p-interface", T.id, "15", "aai-node-type", "p-interface", "interface-name", "ge0/0/1"); + Vertex plink2 = graph.addVertex(T.label, "physical-link", T.id, "16", "aai-node-type", "physical-link", "link-name", "ge0/0/0-to-xe0/0/1"); + + + + GraphTraversalSource g = graph.traversal(); + + rules.addEdge(g, gvnf1, vserver1); + rules.addTreeEdge(g, vserver1, lint1); + rules.addTreeEdge(g, lint1, sriovVf1); + rules.addEdge(g, sriovVf1, sriovPf1); + rules.addTreeEdge(g, sriovPf1, pint1); + rules.addEdge(g, pint1, plink1); + + rules.addEdge(g, gvnf2, vserver2);//false + rules.addTreeEdge(g, vserver2, lint2);//false + rules.addTreeEdge(g, lint2, sriovVf2);//false + rules.addEdge(g, sriovVf2, sriovPf2);//false + rules.addTreeEdge(g, sriovPf2, pint2);//false + rules.addEdge(g, pint2, plink2);//false + + + expectedResult.add(gvnf1); + expectedResult.add(vserver1); + expectedResult.add(sriovVf1); + expectedResult.add(plink1); + + } + @Override + protected String getQueryName() { + return "sriov-topology-fromVnf"; + } + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type","generic-vnf").has("vnf-id", "gvnf1").has("vnf-name", "genvnfname1"); + } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/TopologyDetailFromVnfQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/TopologyDetailFromVnfQueryTest.java new file mode 100644 index 0000000..c553d05 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/TopologyDetailFromVnfQueryTest.java @@ -0,0 +1,163 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; + +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class TopologyDetailFromVnfQueryTest extends QueryTest { + + public TopologyDetailFromVnfQueryTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + Vertex gnvf1 = graph.addVertex(T.label, "generic-vnf", T.id, "1", "aai-node-type", "generic-vnf", "vnf-id", "vnfuuid", "vnf-name", "vnf-name-1", "service-id", "service-id-1"); + Vertex gnvf2 = graph.addVertex(T.label, "generic-vnf", T.id, "2", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-2", "vnf-name", "vnf-name-2", "service-id", "service-id-wrong"); + + Vertex vserver1 = graph.addVertex(T.label, "vserver", T.id, "3", "aai-node-type", "vserver", "vserver-id", "vserver-id-1", "vserver-name", "vserver-name-1", "vserver-selflink", "vserver-selflink-1"); + Vertex vserver2 = graph.addVertex(T.label, "vserver", T.id, "4", "aai-node-type", "vserver", "vserver-id", "vserver-id-2", "vserver-name", "vserver-name-2", "vserver-selflink", "vserver-selflink-2"); + + Vertex vnfc1 = graph.addVertex(T.label, "vnfc", T.id, "5", "aai-node-type", "vnfc", "vnfc-name", "vnfc-name-1", "nfc-naming-code", "nfc-naming-code-1"); + Vertex vnfc2 = graph.addVertex(T.label, "vnfc", T.id, "6", "aai-node-type", "vnfc", "vnfc-name", "vnfc-name-2", "nfc-naming-code", "nfc-naming-code-2"); + + Vertex tenant1 = graph.addVertex(T.label, "tenant-id", T.id, "7", "aai-node-type", "tenant", "tenant-id", "TenantID", "tenant-name", "TenantName"); + Vertex tenant2 = graph.addVertex(T.label, "tenant-id", T.id, "8", "aai-node-type", "tenant", "tenant-id", "TenantID2", "tenant-name", "TenantName2"); + + Vertex flavor1 = graph.addVertex(T.label, "flavor", T.id, "9", "aai-node-type", "flavor", "flavor-id", "flavor-id-1", "flavor-name", "flavor-name-1", "flavor-selflink", "flavor-selflink-1"); + Vertex image1 = graph.addVertex(T.label, "image", T.id, "10", "aai-node-type", "image", "image-id", "image-id-1", "image-name", "image-name-1", "image-os-distro", "image-os-distro-1", "image-os-version", "image-os-version-1"); + + Vertex flavor2 = graph.addVertex(T.label, "flavor", T.id, "11", "aai-node-type", "flavor", "flavor-id", "flavor-id-2", "flavor-name", "flavor-name-2", "flavor-selflink", "flavor-selflink-2"); + Vertex image2 = graph.addVertex(T.label, "image", T.id, "12", "aai-node-type", "image", "image-id", "image-id-2", "image-name", "image-name-2", "image-os-distro", "image-os-distro-2", "image-os-version", "image-os-version-2"); + + Vertex linter1 = graph.addVertex(T.label, "l-interface", T.id, "13", "aai-node-type", "l-interface", "l-interface-id", "l-interface-id-1", "l-interface-name", "l-interface-name1"); + Vertex linter2 = graph.addVertex(T.label, "l-interface", T.id, "14", "aai-node-type", "l-interface", "l-interface-id", "l-interface-id-2", "l-interface-name", "l-interface-name2"); + + Vertex l3inter1ipv4addresslist = graph.addVertex(T.label, "interface-ipv4-address-list", T.id, "15", "aai-node-type", "l3-interface-ipv4-address-list", "l3-interface-ipv4-address", "l3-interface-ipv4-address-1"); + Vertex l3inter1ipv4addresslist2 = graph.addVertex(T.label, "interface-ipv4-address-list", T.id, "16", "aai-node-type", "l3-interface-ipv4-address-list", "l3-interface-ipv4-address", "l3-interface-ipv4-address-2"); + + Vertex l3inter1ipv6addresslist = graph.addVertex(T.label, "l3-interface-ipv6-address-list", T.id, "17", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address", "l3-interface-ipv6-address-1"); + Vertex l3inter1ipv6addresslist2 = graph.addVertex(T.label, "l3-interface-ipv6-address-list", T.id, "18", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address", "l3-interface-ipv6-address-2"); + + Vertex cloudRegion1 = graph.addVertex(T.label, "cloud-region", T.id, "19", "aai-node-type", "cloud-region", "cloud-owner", "CloudOwner1", "cloud-region-id", "CloudRegionId1"); + Vertex cloudRegion2 = graph.addVertex(T.label, "cloud-region", T.id, "20", "aai-node-type", "cloud-region", "cloud-owner", "CloudOwner2", "cloud-region-id", "CloudRegionId2"); + + Vertex availibityzone1 = graph.addVertex(T.label, "availability-zone", T.id, "21", "aai-node-type", "availability-zone", "availability-zone-name", "az-name-1", "hypervisor-type", "hypervisortype-1"); + + Vertex pserver1 = graph.addVertex(T.label, "pserver", T.id, "22", "aai-node-type", "pserver", "pserver-id", "PserverID1", "hostname", "PserverHostName1"); + Vertex pserver2 = graph.addVertex(T.label, "pserver", T.id, "23", "aai-node-type", "pserver", "pserver-id", "PserverID2", "hostname", "PserverHostName2"); //false + + Vertex serviceinstance1 = graph.addVertex(T.label, "service-instance", T.id, "24", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-1", "service-instance-name", "service-instance-name-1"); + Vertex serviceinstance2 = graph.addVertex(T.label, "service-instance", T.id, "25", "aai-node-type", "service-instance", "service-instance-id", "servInstId-2", "service-type", "servType-2", "service-role", "servRole-2"); + + Vertex vfmodule1 = graph.addVertex(T.label, "vf-module", T.id, "26", "aai-node-type", "vf-module", "vf-module-id", "vf-module-id-1", "vf-module-name", "vf-module-name1"); + Vertex vfmodule2 = graph.addVertex(T.label, "vf-module", T.id, "27", "aai-node-type", "vf-module", "vf-module-id", "vf-module-id-2", "vf-module-name", "vf-module-name2"); + + Vertex volumegroup1 = graph.addVertex(T.label, "volume-group", T.id, "28", "aai-node-type", "volume-group", "volume-group-id", "volume-group-id-1", "volume-group-name", "volume-group-name1"); + Vertex volumegroup2 = graph.addVertex(T.label, "volume-group", T.id, "29", "aai-node-type", "volume-group", "volume-group-id", "volume-group-id-2", "volume-group-name", "volume-group-name2"); + + Vertex complex = graph.addVertex(T.label, "complex", T.id, "30", "aai-node-type", "complex"); + + + GraphTraversalSource g = graph.traversal();//true + + rules.addEdge(g, gnvf1, vserver1);//true + + rules.addEdge(g, vserver1, vnfc1);//true + rules.addEdge(g, vserver2, vnfc1);//true + + rules.addTreeEdge(g, vserver1, tenant1);//true + rules.addTreeEdge(g, tenant1, cloudRegion1);//true + rules.addTreeEdge(g, cloudRegion1,availibityzone1 );//true + rules.addEdge(g, vserver1, image1);//true + rules.addEdge(g, vserver1, flavor1);//true + rules.addEdge(g, vserver1, pserver1);//true + rules.addEdge(g, vserver2, image1); + rules.addEdge(g, vserver2, flavor1); + rules.addEdge(g, pserver1, complex);//true + + rules.addTreeEdge(g, vserver1, linter1);//true + rules.addTreeEdge(g, linter1, l3inter1ipv4addresslist);//true + rules.addTreeEdge(g, linter1, l3inter1ipv6addresslist);//true + + rules.addEdge(g, gnvf1, serviceinstance1);//true + rules.addTreeEdge(g, gnvf1, vfmodule1);//true + rules.addEdge(g, vfmodule1, volumegroup1); + + //--------------------------------------------------- + + //rules.addTreeEdge(g, vserver1, tenant2);//false + //rules.addTreeEdge(g, vserver2, linter1);//false + //rules.addEdge(g, vserver1, vnfc2);//false + + + + expectedResult.add(gnvf1); + expectedResult.add(vnfc1); + expectedResult.add(vserver1); + expectedResult.add(tenant1); + expectedResult.add(cloudRegion1); + expectedResult.add(image1); + expectedResult.add(flavor1); + expectedResult.add(pserver1); + expectedResult.add(complex); + + expectedResult.add(serviceinstance1); + expectedResult.add(availibityzone1); + expectedResult.add(volumegroup1); + expectedResult.add(linter1); + expectedResult.add(l3inter1ipv4addresslist); + expectedResult.add(l3inter1ipv6addresslist); + + + } + + @Override + protected String getQueryName() { + return "topology-detail-fromVnf"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("vnf-id", "vnfuuid"); + + } + + @Override + protected void addParam(Map<String, Object> params) { + //return; + params.put("serviceId", "service-id-1"); + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/TopologyDetailFromVserverQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/TopologyDetailFromVserverQueryTest.java index 6d9dd6c..d9821d0 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/TopologyDetailFromVserverQueryTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/TopologyDetailFromVserverQueryTest.java @@ -61,28 +61,44 @@ public class TopologyDetailFromVserverQueryTest extends QueryTest { Vertex pserver = graph.addVertex(T.label, "pserver", T.id, "17", "aai-node-type", "pserver", "hostname", "pservername1"); Vertex complex = graph.addVertex(T.label, "pserver", T.id, "18", "aai-node-type", "complex", "physical-location-id", "locationId", "physical-location-type", "locationType", "physical-location-id", "locationId", "city", "cityName", "state", "stateName", "postal-code", "zip", "country", "countryName"); - + Vertex availabilityZone = graph.addVertex(T.label, "availability-zone", T.id, "19", "aai-node-type", "availability-zone", "availability-zone-name", "azName0", "hypervisor-type", "ht0"); + Vertex virtualDataCenter = graph.addVertex(T.label, "virtual-data-center", T.id, "20", "aai-node-type", "virtual-data-center", "vdc-id", "vdcId0", "vdc-name", "vdcName0"); + Vertex volumeGroup = graph.addVertex(T.label, "volume-group", T.id, "21", "aai-node-type", "volume-group", "volume-group-id", "vgId0", "volume-group-name", "vgName0", "vnf-type", "vnfType0"); + Vertex image = graph.addVertex(T.label, "image", T.id, "22", "aai-node-type", "image", "image-id", "imageId0", "image-name", "imageName0", "image-os-distro", "imageOsDistro0", "image-os-version", "imageOsVersion0", "image-selflink", "imageSl0"); + Vertex flavor = graph.addVertex(T.label, "flavor", T.id, "23", "aai-node-type", "flavor", "flavor-id", "flavorId0", "flavor-name", "flavorName0", "flavor-selflink", "flavorSl0"); + Vertex vfModule = graph.addVertex(T.label, "vf-module", T.id, "24", "aai-node-type", "vf-module", "vf-module-id", "vfmId0", "is-base-vf-module", "true"); + Vertex genericvnf2 = graph.addVertex(T.label, "generic-vnf", T.id, "25", "aai-node-type", "generic-vnf", "vnf-id", "vnfid1", "nf-type", "sample-nf-type"); + Vertex vfModule2 = graph.addVertex(T.label, "vf-module", T.id, "26", "aai-node-type", "vf-module", "vf-module-id", "vfmId1", "is-base-vf-module", "true"); + GraphTraversalSource g = graph.traversal(); rules.addTreeEdge(g, tenant, cloudregion); rules.addTreeEdge(g, vserver, tenant); rules.addEdge(g, pserver, vserver); rules.addEdge(g, complex, pserver); + rules.addEdge(g, availabilityZone, pserver); rules.addEdge(g, genericvnf, vserver); + rules.addTreeEdge(g, genericvnf, vfModule); // related to the genericvnf only, not the vserver rules.addEdge(g, genericvnf, platform); rules.addEdge(g, genericvnf, lineofbusiness); rules.addEdge(g, genericvnf, vnfc); rules.addEdge(g, genericvnf, servinst); + rules.addEdge(g, virtualDataCenter, genericvnf); + rules.addEdge(g, volumeGroup, genericvnf); rules.addEdge(g, owningentity, servinst); rules.addEdge(g, project, servinst); rules.addTreeEdge(g, linterface, vserver); rules.addTreeEdge(g, l3inter1ipv4addresslist, linterface); - rules.addEdge(g, l3inter1ipv4addresslist, subnet4); - rules.addTreeEdge(g, l3network4, subnet4); - rules.addTreeEdge(g, l3inter1ipv6addresslist, linterface); - rules.addEdge(g, l3inter1ipv6addresslist, subnet6); - rules.addTreeEdge(g, l3network6, subnet6); - + rules.addEdge(g, l3inter1ipv4addresslist, subnet4); + rules.addTreeEdge(g, l3network4, subnet4); + rules.addTreeEdge(g, l3inter1ipv6addresslist, linterface); + rules.addEdge(g, l3inter1ipv6addresslist, subnet6); + rules.addTreeEdge(g, l3network6, subnet6); + rules.addEdge(g, image, vserver); + rules.addEdge(g, flavor, vserver); + rules.addTreeEdge(g, genericvnf2, vfModule2); + rules.addEdge(g, vserver, vfModule2); + expectedResult.add(vserver); expectedResult.add(linterface); expectedResult.add(l3inter1ipv4addresslist); @@ -91,14 +107,23 @@ public class TopologyDetailFromVserverQueryTest extends QueryTest { expectedResult.add(l3inter1ipv6addresslist); expectedResult.add(subnet6); expectedResult.add(l3network6); + expectedResult.add(tenant); expectedResult.add(cloudregion); + expectedResult.add(pserver); expectedResult.add(complex); + expectedResult.add(availabilityZone); expectedResult.add(genericvnf); + expectedResult.add(vfModule); // related to the genericvnf only, not the vserver expectedResult.add(platform); expectedResult.add(lineofbusiness); + expectedResult.add(virtualDataCenter); + expectedResult.add(volumeGroup); expectedResult.add(owningentity); expectedResult.add(project); expectedResult.add(vnfc); + expectedResult.add(image); + expectedResult.add(flavor); + expectedResult.add(vfModule2); // related to the vserver } @Override protected String getQueryName() { diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/TopologySummaryFromCloudRegionQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/TopologySummaryFromCloudRegionQueryTest.java new file mode 100644 index 0000000..0377182 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/TopologySummaryFromCloudRegionQueryTest.java @@ -0,0 +1,118 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; + +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class TopologySummaryFromCloudRegionQueryTest extends QueryTest{ + + public TopologySummaryFromCloudRegionQueryTest() throws AAIException, NoEdgeRuleFoundException{ + super(); + } + + @Test + public void run() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + Vertex region = graph.addVertex(T.label, "cloud-region", T.id, "1", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region-id-1", + "cloud-region-owner", "cloud-region-owner-1","cloud-region-version","cloud-region-version-1"); + Vertex tenant = graph.addVertex(T.label, "tenant", T.id, "2", "aai-node-type", "tenant", "tenant-id", "tenant-id-1", + "tenant-name", "tenant-name-1"); + Vertex vserver = graph.addVertex(T.label, "vserver", T.id, "3", "aai-node-type", "vserver", "vserver-id", "vserver-id-1", + "vserver-name", "vserver-name-1"); + Vertex vnf = graph.addVertex(T.label, "generic-vnf", T.id, "4", "aai-node-type", "generic-vnf", "vnf-id", "vnf-uuid-1", + "vnf-name", "vnf-name=1"); + Vertex vnfc = graph.addVertex(T.label, "vnfc", T.id, "13", "aai-node-type", "vnfc", "vnfc-name", "VnfcName", "nfc-naming-code", + "NfcNamingCode", "nfc-function", "NfcFunction", "in-maint", "false", "is-closed-loop-disabled", "false"); + Vertex vnfc2 = graph.addVertex(T.label, "vnfc", T.id, "15", "aai-node-type", "vnfc", "vnfc-name", "VnfcName3", "nfc-naming-code", + "NfcNamingCode3", "nfc-function", "NfcFunction3", "in-maint", "false", "is-closed-loop-disabled", "false"); + Vertex pserver = graph.addVertex(T.label, "pserver", T.id, "5", "aai-node-type", "pserver", "hostname", "pserver-hostname-1"); + Vertex pserver2 = graph.addVertex(T.label, "pserver", T.id, "6", "aai-node-type", "pserver", "hostname", "pserver-hostname-2"); + + Vertex region_exclude = graph.addVertex(T.label, "cloud-region", T.id, "7", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region-id-2", + "cloud-region-owner", "cloud-region-owner-2","cloud-region-version","cloud-region-version-2"); + Vertex tenant_exclude = graph.addVertex(T.label, "tenant", T.id, "8", "aai-node-type", "tenant", "tenant-id", "tenant-id-2", + "tenant-name", "tenant-name-2"); + Vertex vserver_exclude = graph.addVertex(T.label, "vserver", T.id, "9", "aai-node-type", "vserver", "vserver-id", "vserver-id-2", + "vserver-name", "vserver-name-2"); + Vertex vnf_exclude = graph.addVertex(T.label, "generic-vnf", T.id, "10", "aai-node-type", "generic-vnf", "vnf-id", "vnf-uuid-2", + "vnf-name", "vnf-name=2"); + Vertex vnfc_exclude = graph.addVertex(T.label, "vnfc", T.id, "14", "aai-node-type", "vnfc", "vnfc-name", "VnfcName2", "nfc-naming-code", + "NfcNamingCode2", "nfc-function", "NfcFunction2", "in-maint", "false", "is-closed-loop-disabled", "false"); + Vertex vnfc_exclude2 = graph.addVertex(T.label, "vnfc", T.id, "16", "aai-node-type", "vnfc", "vnfc-name", "VnfcName4", "nfc-naming-code", + "NfcNamingCode4", "nfc-function", "NfcFunction4", "in-maint", "false", "is-closed-loop-disabled", "false"); + Vertex pserver_exclude = graph.addVertex(T.label, "pserver", T.id, "11", "aai-node-type", "pserver", "hostname", "pserver-hostname-2"); + Vertex pserver2_exclude = graph.addVertex(T.label, "pserver", T.id, "12", "aai-node-type", "pserver", "hostname", "pserver-hostname-3"); + + GraphTraversalSource g = graph.traversal(); + rules.addTreeEdge(g, region, tenant); + rules.addTreeEdge(g, tenant, vserver); + rules.addEdge(g, vserver, pserver); + rules.addEdge(g, vserver, vnf); + rules.addEdge(g, vnf, vnfc); + rules.addEdge(g, vserver, vnfc2); + rules.addEdge(g, region, pserver2); + + rules.addTreeEdge(g, region_exclude, tenant_exclude); + rules.addTreeEdge(g, tenant_exclude, vserver_exclude); + rules.addEdge(g, vserver_exclude, pserver_exclude); + rules.addEdge(g, vserver_exclude, vnf_exclude); + rules.addEdge(g, vnf_exclude, vnfc_exclude); + rules.addEdge(g, vserver_exclude, vnfc_exclude2); + rules.addEdge(g, region_exclude, pserver2_exclude); + + expectedResult.add(region); + expectedResult.add(tenant); + expectedResult.add(vserver); + expectedResult.add(pserver); + expectedResult.add(vnf); + expectedResult.add(vnfc); + expectedResult.add(vnfc2); + expectedResult.add(pserver2); + } + + @Override + protected String getQueryName() { + return "topology-summary-fromCloudRegion"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("cloud-region-id", "cloud-region-id-1").has("cloud-region-owner", "cloud-region-owner-1"); + } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/TopologySummaryFromTenantTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/TopologySummaryFromTenantTest.java new file mode 100644 index 0000000..36c7396 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/TopologySummaryFromTenantTest.java @@ -0,0 +1,93 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class TopologySummaryFromTenantTest extends QueryTest { + + public TopologySummaryFromTenantTest() throws AAIException,NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + Vertex tenant = graph.addVertex(T.label, "tenant-id", T.id, "0", "aai-node-type", "tenant", "tenant-id", "TenantID", "tenant-name", "TenantName"); + Vertex cloudRegion = graph.addVertex(T.label, "cloud-region", T.id, "1", "aai-node-type", "cloud-region", "cloud-owner", "CloudOwner", "cloud-region-id", "CloudRegionId"); + Vertex vserver = graph.addVertex(T.label, "vserver", T.id, "2", "aai-node-type", "vserver", "vserver-id", "vservId-1", "vserver-name", "vserv-name-1", "vserver-selflink", "me/self"); + Vertex genericVnf = graph.addVertex(T.label, "generic-vnf", T.id, "3", "aai-node-type", "generic-vnf", "vnf-id", "VnfID", "vnf-name", "VnfName", "vnf-type", "VnfType"); + Vertex pserver = graph.addVertex(T.label, "pserver", T.id, "4", "aai-node-type", "pserver", "pserver-id", "PserverID", "hostname", "PserverHostName"); + + Vertex tenant2 = graph.addVertex(T.label, "tenant-id2", T.id, "5", "aai-node-type", "tenant", "tenant-id", "TenantID2", "tenant-name", "TenantName2"); + Vertex cloudRegion2 = graph.addVertex(T.label, "cloud-region2", T.id, "6", "aai-node-type", "cloud-region", "cloud-owner", "CloudOwner2", "cloud-region-id", "CloudRegionId2"); + Vertex vserver2 = graph.addVertex(T.label, "vserver2", T.id, "7", "aai-node-type", "vserver", "vserver-id", "vservId-2", "vserver-name", "vserv-name-2", "vserver-selflink", "me/self"); //false + Vertex genericVnf2 = graph.addVertex(T.label, "generic-vnf2", T.id, "8", "aai-node-type", "generic-vnf", "vnf-id", "VnfID2", "vnf-name", "VnfName2", "vnf-type", "VnfType"); //false + Vertex pserver2 = graph.addVertex(T.label, "pserver2", T.id, "9", "aai-node-type", "pserver", "pserver-id", "PserverID2", "hostname", "PserverHostName2"); //false + + GraphTraversalSource g = graph.traversal(); + rules.addTreeEdge(g, tenant, cloudRegion); + rules.addTreeEdge(g, tenant, vserver); + rules.addEdge(g, vserver, genericVnf); + rules.addEdge(g, vserver, pserver); + + //tenant2 + rules.addTreeEdge(g, tenant2, cloudRegion2);//false + rules.addTreeEdge(g, tenant2, vserver2);//false + rules.addEdge(g, vserver2, genericVnf2); //false + rules.addEdge(g, vserver2, pserver2); //false + + + expectedResult.add(tenant); + expectedResult.add(cloudRegion); + expectedResult.add(vserver); + expectedResult.add(genericVnf); + expectedResult.add(pserver); + + } + + @Override + protected String getQueryName() { + return "topology-summary-fromTenant"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "tenant").has("tenant-id","TenantID"); + } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/TreeQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/TreeQueryTest.java index 1ec880c..109cfc1 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/TreeQueryTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/TreeQueryTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * Copyright © 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. @@ -16,8 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.onap.aai.rest.search; diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/UcpeTopologyQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/UcpeTopologyQueryTest.java index d4eac58..4503717 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/UcpeTopologyQueryTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/UcpeTopologyQueryTest.java @@ -53,9 +53,9 @@ public class UcpeTopologyQueryTest extends QueryTest { Vertex tenant = graph.addVertex(T.label, "tenant", T.id, "5", "aai-node-type", "tenant", "tenant-id", "tenantuuid", "tenant-name", "tenantname"); Vertex cloudregion = graph.addVertex(T.label, "cloud-region", T.id, "6", "aai-node-type", "cloud-region", "cloud-region-id", "clouduuid", "cloud-region-owner", "cloudOwnername"); Vertex vnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "7", "aai-node-type", "generic-vnf", "vnf-id", "vnf1uuid"); - Vertex vnf1image = graph.addVertex(T.label, "vnf-image", T.id, "8", "aai-node-type", "vnf-image", "vnf-image-uuid", "vnf1imageuuid"); + Vertex vnf1image = graph.addVertex(T.label, "vnf-image", T.id, "8", "aai-node-type", "vnf-image", "att-uuid", "vnf1imageuuid"); Vertex vnf2 = graph.addVertex(T.label, "generic-vnf", T.id, "9", "aai-node-type", "generic-vnf", "vnf-id", "vnf1uuid"); - Vertex vnf2image = graph.addVertex(T.label, "vnf-image", T.id, "10", "aai-node-type", "vnf-image", "vnf-image-uuid", "vnf2imageuuid"); + Vertex vnf2image = graph.addVertex(T.label, "vnf-image", T.id, "10", "aai-node-type", "vnf-image", "att-uuid", "vnf2imageuuid"); Vertex pnf = graph.addVertex(T.label, "pnf", T.id, "11", "aai-node-type", "pnf", "pnf-name", "pnf1name"); Vertex pnfint = graph.addVertex(T.label, "p-interface", T.id, "12", "aai-node-type", "p-interface", "interface-name", "ge0/0/0"); Vertex plink1 = graph.addVertex(T.label, "physical-link", T.id, "13", "aai-node-type", "physical-link", "link-name", "ge0/0/0-to-xe0/0/0"); diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/VfModuleFromServiceInstanceTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/VfModuleFromServiceInstanceTest.java new file mode 100644 index 0000000..0d2d11a --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/VfModuleFromServiceInstanceTest.java @@ -0,0 +1,84 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class VfModuleFromServiceInstanceTest extends QueryTest { + + public VfModuleFromServiceInstanceTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void test() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + //Set up the test graph + Vertex serviceinstance = graph.addVertex(T.label, "service-instance", T.id, "0", "aai-node-type", "service-instance", "service-instance-id", "s-instance-id1"); + Vertex vfmodule = graph.addVertex(T.label, "vf-module", T.id, "2", "aai-node-type", "vf-module", "vf-module-id", "vf-module-id-0", "vf-module-name", "vf-module-name0"); + + Vertex gnvf = graph.addVertex(T.label, "generic-vnf", T.id, "1", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-0", "vnf-name", "vnf-name-0"); + + + Vertex serviceinstance1 = graph.addVertex(T.label, "service-instance", T.id, "10", "aai-node-type", "service-instance", "service-instance-id", "s-instance-id11"); + Vertex vfmodule1 = graph.addVertex(T.label, "vf-module", T.id, "12", "aai-node-type", "vf-module", "vf-module-id", "vf-module-id-01", "vf-module-name", "vf-module-name01"); + + Vertex gnvf1 = graph.addVertex(T.label, "generic-vnf", T.id, "11", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-01", "vnf-name", "vnf-name-01"); + + GraphTraversalSource g = graph.traversal(); + rules.addEdge(g, serviceinstance, gnvf); + rules.addTreeEdge(g, gnvf, vfmodule); + + rules.addEdge(g, serviceinstance1, gnvf1); //false + rules.addTreeEdge(g, gnvf1, vfmodule1); //false + + expectedResult.add(vfmodule); + + } + + @Override + protected String getQueryName() { + return "vfModule-fromServiceInstance"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "service-instance").has("service-instance-id", "s-instance-id1"); + } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/VnfToServiceInstanceQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/VnfToServiceInstanceQueryTest.java new file mode 100644 index 0000000..dfd36b7 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/VnfToServiceInstanceQueryTest.java @@ -0,0 +1,75 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class VnfToServiceInstanceQueryTest extends QueryTest { + public VnfToServiceInstanceQueryTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + + + //Set up the test graph + Vertex serviceinstance1 = graph.addVertex(T.label, "service-instance", T.id, "1", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-1", "service-instance-name", "service-instance-name-1"); + Vertex serviceinstance2 = graph.addVertex(T.label, "service-instance", T.id, "2", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-2", "service-instance-name", "service-instance-name-2"); + + Vertex vnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "3", "aai-node-type", "generic-vnf", "vnf-id", "vnfid1", "vnf-name", "vnfname1", "vnf-type", "vnftype1"); + Vertex vnf2 = graph.addVertex(T.label, "generic-vnf", T.id, "4", "aai-node-type", "generic-vnf", "vnf-id", "vnfid2", "vnf-name", "vnfname2", "vnf-type", "vnftype1"); + + GraphTraversalSource g = graph.traversal(); + + rules.addEdge(g, vnf1, serviceinstance1);//true + rules.addEdge(g, vnf2, serviceinstance1); + + expectedResult.add(vnf1); + expectedResult.add(serviceinstance1); + expectedResult.add(vnf2); + + } + @Override + protected String getQueryName() { + return "vnf-to-service-instance"; + } + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "generic-vnf").has("vnf-id", "vnfid1"); + } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/VnfTopologyFromServiceInstanceTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/VnfTopologyFromServiceInstanceTest.java deleted file mode 100644 index 120f3ac..0000000 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/VnfTopologyFromServiceInstanceTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 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.aai.rest.search; - -import java.util.Map; - -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; -import org.apache.tinkerpop.gremlin.structure.T; -import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.junit.Test; -import org.onap.aai.exceptions.AAIException; -import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; - -public class VnfTopologyFromServiceInstanceTest extends QueryTest { - public VnfTopologyFromServiceInstanceTest() throws AAIException, NoEdgeRuleFoundException { - super(); - } - - @Test - public void run() { - super.run(); - } - - @Override - protected void createGraph() throws AAIException, NoEdgeRuleFoundException { - //Set up the test graph - Vertex gnvf1 = graph.addVertex(T.label, "generic-vnf", T.id, "0", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-1", "vnf-name", "vnf-name-1"); - Vertex serviceinstance = graph.addVertex(T.label, "service-instance", T.id, "1", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-1", "service-instance-name", "service-instance-name-1"); - Vertex servicesubscription = graph.addVertex(T.label, "service-subscription", T.id, "2", "aai-node-type", "service-subscription", "service-subscription-id", "service-subscription-id-1","service-subscription-name","service-subscription-name1"); - Vertex customer = graph.addVertex(T.label, "customer", T.id, "3", "aai-node-type", "customer", "customer-id", "customer-id-1", "customer-name", "customer-name1"); - Vertex allottedresource = graph.addVertex(T.label, "allotted-resource", T.id, "4", "aai-node-type", "allotted-resource", "allotted-resource-id", "allotted-resource-id-1", "allotted-resource-name", "allotted-resource-name1"); - Vertex vfmodule = graph.addVertex(T.label, "vf-module", T.id, "5", "aai-node-type", "vf-module", "vf-module-id", "vf-module-id-1", "vf-module-name", "vf-module-name1"); - Vertex volumegroup = graph.addVertex(T.label, "volume-group", T.id, "6", "aai-node-type", "volume-group", "volume-group-id", "volume-group-id-1", "volume-group-name", "volume-group-name1"); - Vertex linter1 = graph.addVertex(T.label, "l-interface", T.id, "7", "aai-node-type", "l-interface", "l-interface-id", "l-interface-id-1", "l-interface-name", "l-interface-name1"); - Vertex l3inter1ipv4addresslist = graph.addVertex(T.label, "interface-ipv4-address-list", T.id, "8", "aai-node-type", "l3-interface-ipv4-address-list", "l3-interface-ipv4-address-list-id", "l3-interface-ipv4-address-list-id-1", "l3-interface-ipv6-address-list-name", "l3-interface-ipv6-address-list-name1"); - Vertex l3network1 = graph.addVertex(T.label, "l3-network", T.id, "9", "aai-node-type", "l3-network", "ll3-network-id", "l3-network-id-1", "l3-network-name", "l3-network-name1"); - Vertex l3inter1ipv6addresslist = graph.addVertex(T.label, "l3-interface-ipv6-address-list", T.id, "10", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address-list-id", "l3-interface-ipv6-address-list-id-1", "l3-interface-ipv6-address-list-name", "l3-interface-ipv6-address-list-name1"); - Vertex vserver = graph.addVertex(T.label, "vserver", T.id, "11", "aai-node-type", "vserver", "vserver-name1", "vservername1"); - Vertex tenant = graph.addVertex(T.label, "tenant", T.id, "12", "aai-node-type", "tenant", "tenant-name1", "tenant-name-1","tenant-id", "tenant-id-1"); - Vertex region1 = graph.addVertex(T.label, "cloud-region", T.id, "13", "aai-node-type", "cloud-region", "cloud-owner", "cloudOwner1"); - Vertex pserver = graph.addVertex(T.label, "pserver", T.id, "14", "aai-node-type", "pserver", "hostname", "pservername"); - Vertex linter2 = graph.addVertex(T.label, "l-interface", T.id, "15", "aai-node-type", "l-interface", "l-interface-id", "l-interface-id-2", "l-interface-name", "l-interface-name2"); - Vertex l3inter2ipv4addresslist = graph.addVertex(T.label, "interface-ipv6-address-list", T.id, "16", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address-list-id", "l3-interface-ipv6-address-list-id-2", "l3-interface-ipv6-address-list-name", "l3-interface-ipv6-address-list-name2"); - Vertex l3network2 = graph.addVertex(T.label, "l3-network", T.id, "17", "aai-node-type", "l3-network", "ll3-network-id", "l3-network-id-2", "l3-network-name", "l3-network-name2"); - Vertex l3inter2ipv6addresslist = graph.addVertex(T.label, "l3-interface-ipv6-address-list", T.id, "18", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address-list-id", "l3-interface-ipv6-address-list-id-2", "l3-interface-ipv6-address-list-name", "l3-interface-ipv6-address-list-name2"); - Vertex l3network3 = graph.addVertex(T.label, "l3-network", T.id, "19", "aai-node-type", "l3-network", "ll3-network-id", "l3-network-id-3", "l3-network-name", "l3-network-name3"); - Vertex l3network4 = graph.addVertex(T.label, "l3-network", T.id, "20", "aai-node-type", "l3-network", "ll3-network-id", "l3-network-id-4", "l3-network-name", "l3-network-name4"); - - - - GraphTraversalSource g = graph.traversal(); - rules.addEdge(g, gnvf1, serviceinstance);//false - rules.addTreeEdge(g, serviceinstance, servicesubscription);//true - rules.addTreeEdge(g, servicesubscription, customer);//true - rules.addTreeEdge(g, serviceinstance, allottedresource);//true - rules.addTreeEdge(g, gnvf1, vfmodule);//true - rules.addEdge(g, gnvf1, volumegroup);//false - rules.addTreeEdge(g, gnvf1, linter1);//true - rules.addTreeEdge(g, linter1, l3inter1ipv4addresslist);//true - rules.addEdge(g, l3inter1ipv4addresslist, l3network1);//false - rules.addTreeEdge(g, linter1, l3inter1ipv6addresslist);//true - rules.addEdge(g, l3inter1ipv6addresslist, l3network2);//false - rules.addEdge(g, gnvf1, vserver);//false - rules.addTreeEdge(g, vserver, tenant);//true - rules.addTreeEdge(g, tenant, region1);//true - rules.addEdge(g, vserver, pserver);//false - rules.addTreeEdge(g, vserver, linter2);//false - rules.addTreeEdge(g, linter2, l3inter2ipv4addresslist);//false - rules.addEdge(g, l3inter2ipv4addresslist, l3network3);//false - rules.addTreeEdge(g, linter2, l3inter2ipv6addresslist);//true - rules.addEdge(g, l3inter2ipv6addresslist, l3network4);//true - - - expectedResult.add(gnvf1); - expectedResult.add(serviceinstance); - expectedResult.add(customer); - expectedResult.add(allottedresource); - expectedResult.add(vfmodule); - expectedResult.add(volumegroup); - expectedResult.add(l3inter1ipv4addresslist); - expectedResult.add(l3network1); - expectedResult.add(l3inter1ipv6addresslist); - expectedResult.add(l3network2); - expectedResult.add(vserver); - expectedResult.add(tenant); - expectedResult.add(region1); - expectedResult.add(pserver); - expectedResult.add(l3inter2ipv4addresslist); - expectedResult.add(l3network3); - expectedResult.add(l3inter2ipv6addresslist); - expectedResult.add(l3network4); - - } - - @Override - protected String getQueryName() { - return "vnf-topology-fromServiceInstance"; - } - @Override - protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { - g.has("service-instance-name", "service-instance-name-1"); - - } - @Override - protected void addParam(Map<String, Object> params) { - return; - } -} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/VnfTopologyFromVnfTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/VnfTopologyFromVnfTest.java index 235e217..4441d3f 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/VnfTopologyFromVnfTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/VnfTopologyFromVnfTest.java @@ -92,10 +92,12 @@ public class VnfTopologyFromVnfTest extends QueryTest { expectedResult.add(gnvf1); expectedResult.add(serviceinstance); + expectedResult.add(servicesubscription); expectedResult.add(customer); expectedResult.add(allottedresource); expectedResult.add(vfmodule); expectedResult.add(volumegroup); + expectedResult.add(linter1); expectedResult.add(l3inter1ipv4addresslist); expectedResult.add(l3network1); expectedResult.add(l3inter1ipv6addresslist); @@ -104,7 +106,7 @@ public class VnfTopologyFromVnfTest extends QueryTest { expectedResult.add(tenant); expectedResult.add(region1); expectedResult.add(pserver); - expectedResult.add(vserver); + expectedResult.add(linter2); expectedResult.add(l3inter2ipv4addresslist); expectedResult.add(l3network3); expectedResult.add(l3inter2ipv6addresslist); diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/VnfsVlansFromServiceInstanceTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/VnfsVlansFromServiceInstanceTest.java new file mode 100644 index 0000000..f7c517e --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/VnfsVlansFromServiceInstanceTest.java @@ -0,0 +1,103 @@ +package org.onap.aai.rest.search; /** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class VnfsVlansFromServiceInstanceTest extends QueryTest { + public VnfsVlansFromServiceInstanceTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + + + //Set up the test graph + Vertex serviceinstance1 = graph.addVertex(T.label, "service-instance", T.id, "0", "aai-node-type", + "service-instance", "service-instance-id", "service-instance-id-1", "service-instance-name", + "service-instance-name-1"); + + Vertex config1 = graph.addVertex(T.label, "configuration", T.id, "1", "aai-node-type", "configuration", "configuration-id", "configuration1"); + + Vertex gvnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "2", "aai-node-type", "generic-vnf", + "vnf-id", "gvnf1", "vnf-name", "genvnfname1", "nf-type", "sample-nf-type"); + + Vertex linterface1 = graph.addVertex(T.label, "l-interface", T.id, "3", "aai-node-type", "l-interface", "l-interface-id", "l-interface-id0", "l-interface-name", "l-interface-name0","network-name","networkName0"); + + Vertex vlan1 = graph.addVertex(T.label, "vlan", T.id, "4", "aai-node-type", "vlan", "vlan-interface", "vlan-interface1"); + + + Vertex serviceinstance2 = graph.addVertex(T.label, "service-instance", T.id, "5", "aai-node-type", + "service-instance", "service-instance-id", "service-instance-id-2", "service-instance-name", + "service-instance-name-1"); + + Vertex config2 = graph.addVertex(T.label, "configuration", T.id, "6", "aai-node-type", "configuration", "configuration-id", "configuration2"); + + Vertex gvnf2 = graph.addVertex(T.label, "generic-vnf", T.id, "7", "aai-node-type", "generic-vnf", + "vnf-id", "gvnf2", "vnf-name", "genvnfname2", "nf-type", "sample-nf-type"); + + Vertex linterface2 = graph.addVertex(T.label, "l-interface", T.id, "8", "aai-node-type", "l-interface", "l-interface-id", "l-interface-id2", "l-interface-name", "l-interface-name2","network-name","networkName1"); + + Vertex vlan2 = graph.addVertex(T.label, "vlan", T.id, "9", "aai-node-type", "vlan", "vlan-interface", "vlan-interface2"); + + GraphTraversalSource g = graph.traversal(); + + rules.addEdge(g, serviceinstance1, config1); // True + rules.addEdge(g, config1, gvnf1); // True + rules.addEdge(g, config1, linterface1); // True + rules.addTreeEdge(g, linterface1, vlan1); // True + + rules.addEdge(g, serviceinstance2, config2); // False + rules.addEdge(g, config2, gvnf2); // False + rules.addEdge(g, config2, linterface2);// False + rules.addTreeEdge(g, linterface2, vlan2); // False + + expectedResult.add(gvnf1); + expectedResult.add(vlan1); + + } + @Override + protected String getQueryName() { + return "vnfs-vlans-fromServiceInstance"; + } + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "service-instance").has("service-instance-id", "service-instance-id-1"); + } + + @Override + protected void addParam(Map<String, Object> params) { + return; + } +}*/
\ No newline at end of file diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/VserverFromPserverTreeTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/VserverFromPserverTreeTest.java new file mode 100644 index 0000000..79d070a --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/VserverFromPserverTreeTest.java @@ -0,0 +1,86 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +import java.util.Map; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class VserverFromPserverTreeTest extends TreeQueryTest { + + public VserverFromPserverTreeTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + Vertex p1 = graph.addVertex(T.label, "pserver", T.id, "0", "aai-node-type", "pserver", "hostname", "pserver-name-1"); + Vertex p2 = graph.addVertex(T.label, "pserver", T.id, "1", "aai-node-type", "pserver", "hostname", "pserver-name-2"); + Vertex v1 = graph.addVertex(T.label, "vserver", T.id, "2", "aai-node-type", "vserver", "vserver-id", "vservId-1", "vserver-name", "vserv-name-1", "vserver-selflink", "me/self"); + Vertex v2 = graph.addVertex(T.label, "vserver", T.id, "3", "aai-node-type", "vserver", "vserver-id", "vservId-2", "vserver-name", "vserv-name-2", "vserver-selflink", "me/self"); + Vertex v3 = graph.addVertex(T.label, "vserver", T.id, "4", "aai-node-type", "vserver", "vserver-id", "vservId-3", "vserver-name", "vserv-name-3", "vserver-selflink", "me/self"); + + rules.addEdge(gts, p1, v1); + rules.addEdge(gts, p1, v2); + rules.addEdge(gts, p1, v3); + } + + @Test + public void run() { + super.run(); + Tree tree = treeList.get(0); + + Vertex p1 = graph.traversal().V().has("aai-node-type","pserver").has("hostname","pserver-name-1").next(); + Vertex p2 = graph.traversal().V().has("aai-node-type","pserver").has("hostname","pserver-name-2").next(); + Vertex v1 = graph.traversal().V().has("aai-node-type", "vserver").has("vserver-id","vservId-1").next(); + Vertex v2 = graph.traversal().V().has("aai-node-type", "vserver").has("vserver-id","vservId-2").next(); + Vertex v3 = graph.traversal().V().has("aai-node-type", "vserver").has("vserver-id","vservId-3").next(); + + assertTrue(tree.containsKey(p1)); + assertTrue(((Tree) tree.get(p1)).containsKey(v1)); + assertTrue(((Tree) tree.get(p1)).containsKey(v2)); + assertTrue(((Tree) tree.get(p1)).containsKey(v3)); + assertFalse(tree.containsKey(p2)); + } + + @Override + protected String getQueryName() { + return "vservers-fromPserver-tree"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "pserver").has("hostname", "pserver-name-1"); + } + + @Override + protected void addParam(Map<String, Object> params) { + + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/VserverFromVnfQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/VserverFromVnfQueryTest.java index ae95c42..3dd7b25 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/search/VserverFromVnfQueryTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/VserverFromVnfQueryTest.java @@ -19,8 +19,6 @@ */ package org.onap.aai.rest.search; -import static org.junit.Assert.*; - import java.util.Map; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; @@ -53,6 +51,16 @@ public class VserverFromVnfQueryTest extends QueryTest { Vertex ipv4 = graph.addVertex(T.id, "40", "aai-node-type", "l3-interface-ipv4-address-list", "l3-interface-ipv4-address", "0.0.0.0"); Vertex ipv6 = graph.addVertex(T.id, "50", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address", "0.0.0.0"); + + Vertex gv1 = graph.addVertex(T.id, "60", "aai-node-type", "generic-vnf", "vnf-id", "gvId1", "vnf-name", "gvName1", "vnf-type", "some-type1"); + Vertex vnfc1 = graph.addVertex(T.id, "70", "aai-node-type", "vnfc", + "vnfc-name", "vnfcName11", "nfc-naming-code", "blue1", "nfc-function", "correct-function1"); + Vertex vserv1 = graph.addVertex(T.id, "80", "aai-node-type", "vserver", + "vserver-id", "vservId1", "vserver-name", "vservName1", "vserver-selflink", "me/self1"); + Vertex lint1 = graph.addVertex(T.id, "90", "aai-node-type", "l-interface", "interface-name", "lintName1"); + Vertex ipv41 = graph.addVertex(T.id, "1", "aai-node-type", "l3-interface-ipv4-address-list", "l3-interface-ipv4-address", "0.0.0.0.1"); + Vertex ipv61 = graph.addVertex(T.id, "2", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address", "0.0.0.0.1"); + GraphTraversalSource g = graph.traversal(); rules.addEdge(g, gv, vnfc); rules.addEdge(g, vserv, vnfc); @@ -60,6 +68,12 @@ public class VserverFromVnfQueryTest extends QueryTest { rules.addTreeEdge(g, lint, ipv4); rules.addTreeEdge(g, lint, ipv6); + rules.addEdge(g, gv1, vnfc1);//false + rules.addEdge(g, vserv1, vnfc1);//false + rules.addTreeEdge(g, vserv1, lint1);//false + rules.addTreeEdge(g, lint1, ipv41);//false + rules.addTreeEdge(g, lint1, ipv61);//false + expectedResult.add(vserv); expectedResult.add(lint); expectedResult.add(ipv4); @@ -79,7 +93,7 @@ public class VserverFromVnfQueryTest extends QueryTest { @Override protected void addParam(Map<String, Object> params) { - params.put("nfcFunction", "correct-function"); + params.put("nfcNamingCode", "blue"); } diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/VserverLinterfacesFromVnfcTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/VserverLinterfacesFromVnfcTest.java new file mode 100644 index 0000000..2c1a0ea --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/VserverLinterfacesFromVnfcTest.java @@ -0,0 +1,98 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import static org.junit.Assert.*; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class VserverLinterfacesFromVnfcTest extends QueryTest { + + public VserverLinterfacesFromVnfcTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + Vertex vnfc = graph.addVertex(T.label, "vnfc",T.id, "0", "aai-node-type", "vnfc", + "vnfc-name", "vnfcName1", "nfc-naming-code", "blue", "nfc-function", "correct-function"); + Vertex vserv = graph.addVertex(T.label, "vserver",T.id, "1", "aai-node-type", "vserver", + "vserver-id", "vservId", "vserver-name", "vservName", "vserver-selflink", "me/self"); + Vertex linterface = graph.addVertex(T.label, "l-interface", T.id, "2", "aai-node-type", "l-interface", "l-interface-id", "l-interface-id0", "l-interface-name", "l-interface-name0","network-name","networkName0"); + Vertex linterface1 = graph.addVertex(T.label, "l-interface", T.id, "3", "aai-node-type", "l-interface", "l-interface-id", "l-interface-id1", "l-interface-name", "l-interface-name1","network-name","networkName1"); + Vertex vlan = graph.addVertex(T.label, "vlan", T.id, "4", "aai-node-type", "vlan", "vlan-interface", "vlan-interface0"); + + + Vertex vnfc1 = graph.addVertex(T.label, "vnfc",T.id, "10", "aai-node-type", "vnfc", + "vnfc-name", "vnfcName2", "nfc-naming-code", "blue-1", "nfc-function", "correct-function-1"); + Vertex vserv1 = graph.addVertex(T.label, "vserver",T.id, "11", "aai-node-type", "vserver", + "vserver-id", "vservId1", "vserver-name", "vservName1", "vserver-selflink", "me/self-1"); + Vertex linterface2 = graph.addVertex(T.label, "l-interface", T.id, "12", "aai-node-type", "l-interface", "l-interface-id", "l-interface-id2", "l-interface-name", "l-interface-name2","network-name","networkName2"); + Vertex linterface21 = graph.addVertex(T.label, "l-interface", T.id, "13", "aai-node-type", "l-interface", "l-interface-id", "l-interface-id21", "l-interface-name", "l-interface-name21","network-name","networkName21"); + Vertex vlan1 = graph.addVertex(T.label, "vlan", T.id, "14", "aai-node-type", "vlan", "vlan-interface", "vlan-interface1"); + + + GraphTraversalSource g = graph.traversal(); + rules.addEdge(g, vnfc,vserv); + rules.addTreeEdge(g, vserv, linterface); + rules.addTreeEdge(g, linterface, linterface1); + rules.addTreeEdge(g, linterface1, vlan); + + rules.addEdge(g, vnfc1,vserv1);//false + rules.addTreeEdge(g, vserv1, linterface2);//false + rules.addTreeEdge(g, linterface2, linterface21);//false + rules.addTreeEdge(g, linterface21, vlan1);//false + + expectedResult.add(vserv); + expectedResult.add(linterface); + expectedResult.add(linterface1); + expectedResult.add(vlan); + } + + @Override + protected String getQueryName() { + return "vserver-l-interfaces-fromVnfc"; + } + + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "vnfc").has("vnfc-name", "vnfcName1"); + } + + @Override + protected void addParam(Map<String, Object> params) { + params.put("networkName", "networkName0"); + } + + +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/search/getSvcSubscriberModelInfoTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/search/getSvcSubscriberModelInfoTest.java new file mode 100644 index 0000000..c854f43 --- /dev/null +++ b/aai-traversal/src/test/java/org/onap/aai/rest/search/getSvcSubscriberModelInfoTest.java @@ -0,0 +1,76 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 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.aai.rest.search; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.edges.exceptions.AmbiguousRuleChoiceException; +import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +import java.util.Map; + +public class getSvcSubscriberModelInfoTest extends QueryTest { + + public getSvcSubscriberModelInfoTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + @Test + public void run() { + super.run(); + } + + + + @Override + protected void createGraph() throws AAIException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException { + + Vertex serviceInstance = graph.addVertex(T.label, "service-instance", T.id, "1", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-1", "service-instance-name", "service-instance-name-1"); + Vertex serviceSubscription = graph.addVertex(T.label, "service-subscription", T.id, "2", "aai-node-type", "service-subscription", "service-type", "service-subcription-1"); + Vertex modelver = graph.addVertex(T.label, "model-ver", T.id, "3", "aai-node-type", "model-ver"); + + GraphTraversalSource g = graph.traversal(); + rules.addTreeEdge(g, serviceInstance, serviceSubscription); + rules.addPrivateEdge(g, serviceInstance, modelver,null); + + expectedResult.add(serviceInstance); + expectedResult.add(serviceSubscription); + expectedResult.add(modelver); + + } + + + @Override + protected String getQueryName() { + return "getSvcSubscriberModelInfo"; + } + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("aai-node-type", "service-instance").has("service-instance-id", "service-instance-id-1"); + } + @Override + protected void addParam(Map<String, Object> params) { + return; + } +} diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/util/ValidateEncodingTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/util/ValidateEncodingTest.java index 3cfb775..bf7612b 100644 --- a/aai-traversal/src/test/java/org/onap/aai/rest/util/ValidateEncodingTest.java +++ b/aai-traversal/src/test/java/org/onap/aai/rest/util/ValidateEncodingTest.java @@ -76,6 +76,7 @@ public class ValidateEncodingTest { assertEquals(false, validator.validate(mockUriInfo)); } + @Test public void goodQueryParams() throws UnsupportedEncodingException { MultivaluedHashMap<String, String> map = new MultivaluedHashMap<String, String>(); @@ -88,7 +89,19 @@ public class ValidateEncodingTest { assertEquals(true, validator.validate(mockUriInfo)); } - + + @Test + public void testWhenQueryParameterHasPlusSignItShouldPass() throws UnsupportedEncodingException { + + MultivaluedHashMap<String, String> map = new MultivaluedHashMap<String, String>(); + map.putSingle("some-key", "test+one+two+three"); + UriInfo mockUriInfo = getMockUriInfo("", map); + + ValidateEncoding validator = ValidateEncoding.getInstance(); + + assertEquals(true, validator.validate(mockUriInfo)); + } + private UriInfo getMockUriInfo(String path, MultivaluedMap<String, String> map) { UriInfo mockUriInfo = Mockito.mock(UriInfo.class); Mockito.when(mockUriInfo.getPath(false)).thenReturn(path); diff --git a/aai-traversal/src/test/java/org/onap/aai/retiredcustomer/RetiredConsumerTest.java b/aai-traversal/src/test/java/org/onap/aai/retiredcustomer/RetiredConsumerTest.java deleted file mode 100644 index 6a3ae9f..0000000 --- a/aai-traversal/src/test/java/org/onap/aai/retiredcustomer/RetiredConsumerTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 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.aai.retiredcustomer; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.onap.aai.introspection.Version; -import org.onap.aai.rest.retired.RetiredConsumer; - -import javax.ws.rs.core.*; -import java.util.*; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.when; - -public abstract class RetiredConsumerTest { - - protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); - - private static final Set<Integer> VALID_HTTP_STATUS_CODES = new HashSet<>(); - - static { - VALID_HTTP_STATUS_CODES.add(200); - VALID_HTTP_STATUS_CODES.add(201); - VALID_HTTP_STATUS_CODES.add(204); - } - - protected RetiredConsumer retiredConsumer; - protected HttpHeaders httpHeaders; - protected UriInfo uriInfo; - - private MultivaluedMap<String, String> headersMultiMap; - private MultivaluedMap<String, String> queryParameters; - - private List<String> aaiRequestContextList; - - private List<MediaType> outputMediaTypes; - - private static final EELFLogger logger = EELFManager.getInstance().getLogger(RetiredConsumer.class.getName()); - - @Before - public void setup(){ - logger.info("Starting the setup for the integration tests of Rest Endpoints"); - - retiredConsumer = getRetiredConsumer(); - httpHeaders = Mockito.mock(HttpHeaders.class); - uriInfo = Mockito.mock(UriInfo.class); - - headersMultiMap = new MultivaluedHashMap<>(); - queryParameters = Mockito.spy(new MultivaluedHashMap<>()); - - headersMultiMap.add("X-FromAppId", "JUNIT"); - headersMultiMap.add("X-TransactionId", UUID.randomUUID().toString()); - headersMultiMap.add("Real-Time", "true"); - headersMultiMap.add("Accept", "application/json"); - headersMultiMap.add("aai-request-context", ""); - - outputMediaTypes = new ArrayList<>(); - outputMediaTypes.add(APPLICATION_JSON); - - aaiRequestContextList = new ArrayList<>(); - aaiRequestContextList.add(""); - - when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes); - when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap); - - when(httpHeaders.getRequestHeader("aai-request-context")).thenReturn(aaiRequestContextList); - - - when(uriInfo.getQueryParameters()).thenReturn(queryParameters); - when(uriInfo.getQueryParameters(false)).thenReturn(queryParameters); - - // TODO - Check if this is valid since RemoveDME2QueryParameters seems to be very unreasonable - Mockito.doReturn(null).when(queryParameters).remove(anyObject()); - - when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); - } - - @Test - public void testRetiredForAllEndPoints(){ - when(uriInfo.getPath()).thenReturn("/aai/v3/cloud-infrastructure/pservers/pserver/test-pserver1"); - - Response response = retiredConsumer.createMessageGet(Version.getLatest().toString(), httpHeaders, uriInfo, null); - assertNotNull(response); - assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus()); - - response = retiredConsumer.createMessagePost(Version.getLatest().toString(), httpHeaders, uriInfo, null); - assertNotNull(response); - assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus()); - - response = retiredConsumer.createMessagePatch(Version.getLatest().toString(), httpHeaders, uriInfo, null); - assertNotNull(response); - assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus()); - - response = retiredConsumer.createMessagePut(Version.getLatest().toString(), httpHeaders, uriInfo, null); - assertNotNull(response); - assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus()); - - response = retiredConsumer.createMessageDelete(Version.getLatest().toString(), httpHeaders, uriInfo, null); - assertNotNull(response); - assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus()); - } - - public abstract RetiredConsumer getRetiredConsumer(); -} diff --git a/aai-traversal/src/test/java/org/onap/aai/retiredcustomer/V3ThroughV7ConsumerTest.java b/aai-traversal/src/test/java/org/onap/aai/retiredcustomer/V3ThroughV7ConsumerTest.java deleted file mode 100644 index 8c3285a..0000000 --- a/aai-traversal/src/test/java/org/onap/aai/retiredcustomer/V3ThroughV7ConsumerTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 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.aai.retiredcustomer; - -import org.onap.aai.rest.retired.RetiredConsumer; -import org.onap.aai.rest.retired.V3ThroughV7Consumer; - - -public class V3ThroughV7ConsumerTest extends RetiredConsumerTest { - - @Override - public RetiredConsumer getRetiredConsumer() { - return new V3ThroughV7Consumer(); - } -} diff --git a/aai-traversal/src/test/java/org/onap/aai/retiredcustomer/V7V8NamedQueriesTest.java b/aai-traversal/src/test/java/org/onap/aai/retiredcustomer/V7V8NamedQueriesTest.java deleted file mode 100644 index 7ab10d2..0000000 --- a/aai-traversal/src/test/java/org/onap/aai/retiredcustomer/V7V8NamedQueriesTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 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.aai.retiredcustomer; - -import org.onap.aai.rest.retired.RetiredConsumer; -import org.onap.aai.rest.retired.V7V8NamedQueries; - -public class V7V8NamedQueriesTest extends RetiredConsumerTest { - - @Override - public RetiredConsumer getRetiredConsumer() { - return new V7V8NamedQueries(); - } -} |