diff options
Diffstat (limited to 'aai-traversal/src/test/java/org/onap/aai/rest/search/GremlinServerImplTest.java')
-rw-r--r-- | aai-traversal/src/test/java/org/onap/aai/rest/search/GremlinServerImplTest.java | 161 |
1 files changed, 0 insertions, 161 deletions
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); - } - - - -} |