5915ce68010ac625dc17aa48230941eff4e680c0
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / dbmap / AAIGraphTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
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 package org.onap.aai.dbmap;
21
22 import org.janusgraph.core.JanusGraphFactory;
23 import org.janusgraph.core.JanusGraph;
24 import org.janusgraph.core.schema.JanusGraphManagement;
25 import org.junit.*;
26 import org.onap.aai.AAISetup;
27 import org.onap.aai.util.AAIConstants;
28
29
30 import static org.hamcrest.CoreMatchers.containsString;
31 import static org.hamcrest.Matchers.matchesPattern;
32 import static org.junit.Assert.*;
33
34 import java.io.FileNotFoundException;
35
36 public class AAIGraphTest extends AAISetup{
37         @Before
38         public void setup() {
39                 AAIGraph.getInstance();
40         }
41
42         @Test
43         public void getRealtimeInstanceConnectionName() throws Exception {
44
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\\)$"));
50                 graphMgt.rollback();
51         }
52
53         @Test
54         public void getCachedInstanceConnectionName() throws Exception {
55
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\\)$"));
61                 graphMgt.rollback();
62         }
63
64         @Test
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\\)$"));
70                 graphMgt.rollback();
71                 graph.close();
72         }
73         
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\\)$"));
80                 graphMgt.rollback();
81                 graph.close();
82         }
83
84 }