2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.aai.dbmap;
22 import org.janusgraph.core.JanusGraphFactory;
23 import org.janusgraph.core.JanusGraph;
24 import org.janusgraph.core.schema.JanusGraphManagement;
26 import org.onap.aai.AAISetup;
27 import org.onap.aai.util.AAIConstants;
30 import static org.hamcrest.CoreMatchers.containsString;
31 import static org.hamcrest.Matchers.matchesPattern;
32 import static org.junit.Assert.*;
34 import java.io.FileNotFoundException;
36 public class AAIGraphTest extends AAISetup{
39 AAIGraph.getInstance();
43 public void getRealtimeInstanceConnectionName() throws Exception {
45 JanusGraphManagement graphMgt = AAIGraph.getInstance().getGraph().openManagement();
46 String connectionInstanceName = graphMgt.getOpenInstances().stream().filter(c -> c.contains("current")).findFirst().get();
47 assertThat(connectionInstanceName, containsString(SERVICE_NAME));
48 assertThat(connectionInstanceName, containsString("realtime"));
49 assertThat(connectionInstanceName, matchesPattern("^\\d+_[\\w\\-\\d]+_" + SERVICE_NAME + "_realtime_\\d+\\(current\\)$"));
54 public void getCachedInstanceConnectionName() throws Exception {
56 JanusGraphManagement graphMgt = AAIGraph.getInstance().getGraph(DBConnectionType.CACHED).openManagement();
57 String connectionInstanceName = graphMgt.getOpenInstances().stream().filter(c -> c.contains("current")).findFirst().get();
58 assertThat(connectionInstanceName, containsString(SERVICE_NAME));
59 assertThat(connectionInstanceName, containsString("cached"));
60 assertThat(connectionInstanceName, matchesPattern("^\\d+_[\\w\\-\\d]+_" + SERVICE_NAME + "_cached_\\d+\\(current\\)$"));
65 public void JanusGraphOpenNameTest() throws Exception{
66 JanusGraph graph = JanusGraphFactory.open(new AAIGraphConfig.Builder(AAIConstants.REALTIME_DB_CONFIG).forService(SERVICE_NAME).withGraphType("graphType").buildConfiguration());
67 JanusGraphManagement graphMgt = graph.openManagement();
68 String connectionInstanceName = graphMgt.getOpenInstances().stream().filter(c -> c.contains("current")).findFirst().get();
69 assertThat(connectionInstanceName,matchesPattern("^\\d+_[\\w\\-\\d]+_" + SERVICE_NAME + "_graphType_\\d+\\(current\\)$"));
74 @Test (expected=FileNotFoundException.class)
75 public void JanusGraphOpenNameWithInvalidFilePathTest() throws Exception{
76 JanusGraph graph = JanusGraphFactory.open(new AAIGraphConfig.Builder("invalid").forService(SERVICE_NAME).withGraphType("graphType").buildConfiguration());
77 JanusGraphManagement graphMgt = graph.openManagement();
78 String connectionInstanceName = graphMgt.getOpenInstances().stream().filter(c -> c.contains("current")).findFirst().get();
79 assertThat(connectionInstanceName,matchesPattern("^\\d+_[\\w\\-\\d]+_" + SERVICE_NAME + "_graphType_\\d+\\(current\\)$"));