Sync the latest code changes
[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 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
23 package org.onap.aai.dbmap;
24
25 import com.thinkaurelius.titan.core.TitanFactory;
26 import com.thinkaurelius.titan.core.TitanGraph;
27 import com.thinkaurelius.titan.core.schema.TitanManagement;
28 import org.hamcrest.CoreMatchers;
29 import org.junit.*;
30 import org.onap.aai.AAISetup;
31 import org.onap.aai.util.AAIConstants;
32
33 import static org.hamcrest.CoreMatchers.containsString;
34 import static org.hamcrest.Matchers.matchesPattern;
35 import static org.junit.Assert.*;
36
37 public class AAIGraphTest extends AAISetup{
38
39         private static final String SERVICE_NAME = "JUNIT";
40
41         @Before
42         public void setup() {
43                 System.setProperty("aai.service.name", SERVICE_NAME);
44                 AAIGraph.getInstance();
45         }
46
47         @Test
48         public void getRealtimeInstanceConnectionName() throws Exception {
49
50                 TitanManagement graphMgt = AAIGraph.getInstance().getGraph().openManagement();
51                 String connectionInstanceName = graphMgt.getOpenInstances().stream().filter(c -> c.contains("current")).findFirst().get();
52                 assertThat(connectionInstanceName, containsString(SERVICE_NAME));
53                 assertThat(connectionInstanceName, containsString("realtime"));
54                 assertThat(connectionInstanceName, matchesPattern("^\\d+_[\\w\\-\\d]+_" + SERVICE_NAME + "_realtime_\\d+\\(current\\)$"));
55                 graphMgt.rollback();
56         }
57
58         @Test
59         public void getCachedInstanceConnectionName() throws Exception {
60
61                 TitanManagement graphMgt = AAIGraph.getInstance().getGraph(DBConnectionType.CACHED).openManagement();
62                 String connectionInstanceName = graphMgt.getOpenInstances().stream().filter(c -> c.contains("current")).findFirst().get();
63                 assertThat(connectionInstanceName, containsString(SERVICE_NAME));
64                 assertThat(connectionInstanceName, containsString("cached"));
65                 assertThat(connectionInstanceName, matchesPattern("^\\d+_[\\w\\-\\d]+_" + SERVICE_NAME + "_cached_\\d+\\(current\\)$"));
66                 graphMgt.rollback();
67         }
68
69         @Test
70         public void titanGraphOpenNameTest() throws Exception{
71                 TitanGraph graph = TitanFactory.open(new AAIGraphConfig.Builder(AAIConstants.REALTIME_DB_CONFIG).forService(SERVICE_NAME).withGraphType("graphType").buildConfiguration());
72                 TitanManagement graphMgt = graph.openManagement();
73                 String connectionInstanceName = graphMgt.getOpenInstances().stream().filter(c -> c.contains("current")).findFirst().get();
74                 assertThat(connectionInstanceName,matchesPattern("^\\d+_[\\w\\-\\d]+_" + SERVICE_NAME + "_graphType_\\d+\\(current\\)$"));
75                 graphMgt.rollback();
76                 graph.close();
77         }
78
79 }