523197090e77453cb6024327440cd6fd3b9f8f2c
[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 public class AAIGraphTest extends AAISetup{
35         @Before
36         public void setup() {
37                 AAIGraph.getInstance();
38         }
39
40         @Test
41         public void getRealtimeInstanceConnectionName() throws Exception {
42
43                 JanusGraphManagement graphMgt = AAIGraph.getInstance().getGraph().openManagement();
44                 String connectionInstanceName = graphMgt.getOpenInstances().stream().filter(c -> c.contains("current")).findFirst().get();
45                 assertThat(connectionInstanceName, containsString(SERVICE_NAME));
46                 assertThat(connectionInstanceName, containsString("realtime"));
47                 assertThat(connectionInstanceName, matchesPattern("^\\d+_[\\w\\-\\d]+_" + SERVICE_NAME + "_realtime_\\d+\\(current\\)$"));
48                 graphMgt.rollback();
49         }
50
51         @Test
52         public void getCachedInstanceConnectionName() throws Exception {
53
54                 JanusGraphManagement graphMgt = AAIGraph.getInstance().getGraph(DBConnectionType.CACHED).openManagement();
55                 String connectionInstanceName = graphMgt.getOpenInstances().stream().filter(c -> c.contains("current")).findFirst().get();
56                 assertThat(connectionInstanceName, containsString(SERVICE_NAME));
57                 assertThat(connectionInstanceName, containsString("cached"));
58                 assertThat(connectionInstanceName, matchesPattern("^\\d+_[\\w\\-\\d]+_" + SERVICE_NAME + "_cached_\\d+\\(current\\)$"));
59                 graphMgt.rollback();
60         }
61
62         @Test
63         public void JanusGraphOpenNameTest() throws Exception{
64                 JanusGraph graph = JanusGraphFactory.open(new AAIGraphConfig.Builder(AAIConstants.REALTIME_DB_CONFIG).forService(SERVICE_NAME).withGraphType("graphType").buildConfiguration());
65                 JanusGraphManagement graphMgt = graph.openManagement();
66                 String connectionInstanceName = graphMgt.getOpenInstances().stream().filter(c -> c.contains("current")).findFirst().get();
67                 assertThat(connectionInstanceName,matchesPattern("^\\d+_[\\w\\-\\d]+_" + SERVICE_NAME + "_graphType_\\d+\\(current\\)$"));
68                 graphMgt.rollback();
69                 graph.close();
70         }
71
72 }