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