17ddfc51c3c882e99a5a89df430a3dd309c1b12b
[aai/traversal.git] / aai-traversal / src / test / java / org / onap / aai / rest / search / SimpleFormatTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  *
20  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22 package org.onap.aai.rest.search;
23
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
26 import static org.mockito.Mockito.spy;
27 import static org.mockito.Mockito.when;
28
29 import java.util.ArrayList;
30 import java.util.List;
31
32 import org.apache.tinkerpop.gremlin.structure.Graph;
33 import org.apache.tinkerpop.gremlin.structure.T;
34 import org.apache.tinkerpop.gremlin.structure.Vertex;
35 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
36 import org.junit.Test;
37 import org.mockito.Mock;
38 import org.mockito.MockitoAnnotations;
39 import org.onap.aai.dbmap.DBConnectionType;
40 import org.onap.aai.exceptions.AAIException;
41 import org.onap.aai.introspection.Loader;
42 import org.onap.aai.introspection.LoaderFactory;
43 import org.onap.aai.introspection.ModelType;
44 import org.onap.aai.introspection.Version;
45 import org.onap.aai.serialization.db.DBSerializer;
46 import org.onap.aai.serialization.db.EdgeRules;
47 import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException;
48 import org.onap.aai.serialization.engines.QueryStyle;
49 import org.onap.aai.serialization.engines.TitanDBEngine;
50 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
51 import org.onap.aai.serialization.queryformats.RawFormat;
52 import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexException;
53 import org.onap.aai.serialization.queryformats.utils.UrlBuilder;
54
55 import com.google.gson.JsonObject;
56
57 public class SimpleFormatTest {
58
59         protected Graph graph;
60         private TransactionalGraphEngine dbEngine;
61
62         protected final List<Vertex> expectedResult = new ArrayList<>();
63         protected final EdgeRules rules = EdgeRules.getInstance();
64         protected Loader loader;
65         private DBSerializer serializer;
66
67         @Mock
68         private UrlBuilder urlBuilder;
69         private RawFormat _simpleFormat;
70
71         Vertex vfmodule = null;
72
73         public SimpleFormatTest() throws AAIException, NoEdgeRuleFoundException {
74                 setUp();
75         }
76
77         public void setUp() throws AAIException, NoEdgeRuleFoundException {
78                 System.setProperty("AJSC_HOME", ".");
79                 System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
80                 MockitoAnnotations.initMocks(this);
81                 graph = TinkerGraph.open();
82                 loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v10);
83                 vfmodule = graph.addVertex(T.label, "vf-module",
84                                 T.id, "5",
85                                 "aai-node-type", "vf-module",
86                                 "vf-module-id", "vf-module-id-val-68205",
87                                 "vf-module-name", "example-vf-module-name-val-68205",
88                                 "heat-stack-id", "example-heat-stack-id-val-68205",
89                                 "orchestration-status", "example-orchestration-status-val-68205",
90                                 "is-base-vf-module", "true",
91                                 "resource-version", "1498166571906",
92                                 "model-invariant-id", "fe8aac07-ce6c-4f9f-aa0d-b561c77da9e8",
93                                 "model-invariant-id-local", "fe8aac07-ce6c-4f9f-aa0d-b561c77da9e8",
94                                 "model-version-id", "0d23052d-8ffe-433e-a25d-da5da027bb7c",
95                                 "model-version-id-local", "0d23052d-8ffe-433e-a25d-da5da027bb7c",
96                                 "widget-model-id", "example-widget-model-id-val-68205",
97                                 "widget-model-version", "example-widget--model-version-val-68205",
98                                 "contrail-service-instance-fqdn", "example-contrail-service-instance-fqdn-val-68205");
99
100                 final ModelType factoryType = ModelType.MOXY;
101                 Loader loader = LoaderFactory.createLoaderForVersion(factoryType, Version.v10);
102                 dbEngine = spy(new TitanDBEngine(
103                                 QueryStyle.TRAVERSAL,
104                                 DBConnectionType.CACHED,
105                                 loader));
106
107                 when(dbEngine.tx()).thenReturn(graph);
108                 TransactionalGraphEngine.Admin spyAdmin = spy(dbEngine.asAdmin());
109                 when(spyAdmin.getTraversalSource()).thenReturn(graph.traversal());
110                 when(dbEngine.asAdmin()).thenReturn(spyAdmin);
111                 serializer = new DBSerializer(Version.v10, dbEngine, factoryType, "Junit");
112                 _simpleFormat = new RawFormat.Builder(loader, serializer, urlBuilder).modelDriven().build();
113                 dbEngine.startTransaction();
114         }
115
116         @Test
117         public void run() throws AAIFormatVertexException {
118                 assertNotNull(dbEngine.tx());
119                 System.out.println(dbEngine.tx());
120                 assertNotNull(graph.traversal());
121                 JsonObject json = _simpleFormat.createPropertiesObject(vfmodule);
122                 json.entrySet().stream().forEach((System.out::println));
123                 assertTrue(json.has("model-invariant-id"));
124
125         }
126
127 }