2 * ============LICENSE_START=======================================================
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
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.dbmap;
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;
30 import org.onap.aai.AAISetup;
31 import org.onap.aai.util.AAIConstants;
33 import static org.hamcrest.CoreMatchers.containsString;
34 import static org.hamcrest.Matchers.matchesPattern;
35 import static org.junit.Assert.*;
37 public class AAIGraphTest extends AAISetup{
39 private static final String SERVICE_NAME = "JUNIT";
43 System.setProperty("aai.service.name", SERVICE_NAME);
44 AAIGraph.getInstance();
48 public void getRealtimeInstanceConnectionName() throws Exception {
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\\)$"));
59 public void getCachedInstanceConnectionName() throws Exception {
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\\)$"));
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\\)$"));