/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= * * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.onap.aai.rest.search; import com.thinkaurelius.titan.core.TitanGraph; 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.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.TitanDBEngine; 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 GroovyShellImplTest { GroovyShellImpl groovyShellImpl ; protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); private static final Set 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 headersMultiMap; private MultivaluedMap queryParameters; private List aaiRequestContextList; private List outputMediaTypes; private Loader loader; private TitanGraph 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 TitanDBEngine( 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); } @Test(expected = MissingPropertyException.class) public void processSubGraphTest() throws Exception{ GraphTraversal g=Mockito.mock(GraphTraversal.class); g.has("cloud-region-id", "cloud-region-id-1"); Map params = new HashMap<>(); groovyShellImpl.runQuery("vnfs-fromServiceInstance",params); } }