f033b3029d46f79133eac02b969d6be8e9af6db0
[aai/champ.git] / champ-lib / champ-core / src / test / java / org / onap / aai / champcore / core / ChampAPITest.java
1 /**
2  * ============LICENSE_START==========================================
3  * org.onap.aai
4  * ===================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017 Amdocs
7  * ===================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *        http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22 package org.onap.aai.champcore.core;
23
24 import org.junit.Test;
25 import org.onap.aai.champcore.ChampAPI;
26 import org.onap.aai.champcore.ChampGraph;
27 import org.onap.aai.champcore.graph.impl.ChampAPIImpl;
28 import org.onap.aai.champcore.graph.impl.InMemoryChampGraphImpl;
29 import org.onap.aai.champcore.model.ChampObjectConstraint;
30 import org.onap.aai.champcore.model.ChampRelationshipConstraint;
31
32 import static org.junit.Assert.assertTrue;
33
34 import java.util.Optional;
35
36 public class ChampAPITest {
37
38   @Test
39   public void testChampAPIMemoryInstantiation() {
40     testChampAPIInstantiation(new ChampAPIImpl("IN_MEMORY"), "IN_MEMORY");
41   }
42
43   public void testChampAPIInstantiation(ChampAPI api, String expectedType) {
44       assertTrue(api.getType() == expectedType);
45
46       api.getGraph("foo");
47       api.shutdown();
48
49       try {
50         api.getGraph("foo");
51         throw new AssertionError("Able to call getGraph(String name) after shutdown()");
52       } catch (IllegalStateException e) {
53         //Expected
54       }
55   }
56
57   @Test
58   public void testChampMemoryGraphInstantiation() throws Exception
59   {
60     testChampGraphInstantiation(new InMemoryChampGraphImpl.Builder().build());
61   }
62
63   public void testChampGraphInstantiation(ChampGraph graph) throws Exception {
64
65     graph.shutdown();
66
67     try {
68       graph.deleteObject(null, Optional.empty());
69       throw new AssertionError("Able to call API method after shutdown was initiated");
70     } catch (IllegalStateException e) {
71       //Expected
72     }
73
74     try {
75       graph.deleteObjectIndex(null);
76       throw new AssertionError("Able to call API method after shutdown was initiated");
77     } catch (IllegalStateException e) {
78       //Expected
79     }
80
81     try {
82       graph.deletePartition(null, Optional.empty());
83       throw new AssertionError("Able to call API method after shutdown was initiated");
84     } catch (IllegalStateException e) {
85       //Expected
86     }
87
88     try {
89       graph.deleteRelationship(null, Optional.empty());
90       throw new AssertionError("Able to call API method after shutdown was initiated");
91     } catch (IllegalStateException e) {
92       //Expected
93     }
94
95     try {
96       graph.deleteRelationshipIndex(null);
97       throw new AssertionError("Able to call API method after shutdown was initiated");
98     } catch (IllegalStateException e) {
99       //Expected
100     }
101
102     try {
103       graph.deleteSchema();
104       throw new AssertionError("Able to call API method after shutdown was initiated");
105     } catch (IllegalStateException e) {
106       //Expected
107     }
108
109     try {
110       graph.queryObjects(null, Optional.empty());
111       throw new AssertionError("Able to call API method after shutdown was initiated");
112     } catch (IllegalStateException e) {
113       //Expected
114     }
115
116     try {
117       graph.queryRelationships(null, Optional.empty());
118       throw new AssertionError("Able to call API method after shutdown was initiated");
119     } catch (IllegalStateException e) {
120       //Expected
121     }
122
123     try {
124       graph.retrieveObject(null, Optional.empty());
125       throw new AssertionError("Able to call API method after shutdown was initiated");
126     } catch (IllegalStateException e) {
127       //Expected
128     }
129
130     try {
131       graph.retrieveObjectIndex(null);
132       throw new AssertionError("Able to call API method after shutdown was initiated");
133     } catch (IllegalStateException e) {
134       //Expected
135     }
136
137     try {
138       graph.retrieveObjectIndices();
139       throw new AssertionError("Able to call API method after shutdown was initiated");
140     } catch (IllegalStateException e) {
141       //Expected
142     }
143
144     try {
145       graph.retrieveRelationship(null, Optional.empty());
146       throw new AssertionError("Able to call API method after shutdown was initiated");
147     } catch (IllegalStateException e) {
148       //Expected
149     }
150
151     try {
152       graph.retrieveRelationshipIndex(null);
153       throw new AssertionError("Able to call API method after shutdown was initiated");
154     } catch (IllegalStateException e) {
155       //Expected
156     }
157
158     try {
159       graph.retrieveRelationshipIndices();
160       throw new AssertionError("Able to call API method after shutdown was initiated");
161     } catch (IllegalStateException e) {
162       //Expected
163     }
164
165     try {
166       graph.retrieveRelationships(null, Optional.empty());
167       throw new AssertionError("Able to call API method after shutdown was initiated");
168     } catch (IllegalStateException e) {
169       //Expected
170     }
171
172     try {
173       graph.retrieveSchema();
174       throw new AssertionError("Able to call API method after shutdown was initiated");
175     } catch (IllegalStateException e) {
176       //Expected
177     }
178
179     try {
180       graph.storeObject(null, Optional.empty());
181       throw new AssertionError("Able to call API method after shutdown was initiated");
182     } catch (IllegalStateException e) {
183       //Expected
184     }
185
186     try {
187       graph.storeObjectIndex(null);
188       throw new AssertionError("Able to call API method after shutdown was initiated");
189     } catch (IllegalStateException e) {
190       //Expected
191     }
192
193     try {
194       graph.storePartition(null, Optional.empty());
195       throw new AssertionError("Able to call API method after shutdown was initiated");
196     } catch (IllegalStateException e) {
197       //Expected
198     }
199
200     try {
201       graph.storeRelationship(null, Optional.empty());
202       throw new AssertionError("Able to call API method after shutdown was initiated");
203     } catch (IllegalStateException e) {
204       //Expected
205     }
206
207     try {
208       graph.storeRelationshipIndex(null);
209       throw new AssertionError("Able to call API method after shutdown was initiated");
210     } catch (IllegalStateException e) {
211       //Expected
212     }
213
214     try {
215       graph.storeSchema(null);
216       throw new AssertionError("Able to call API method after shutdown was initiated");
217     } catch (IllegalStateException e) {
218       //Expected
219     }
220
221     try {
222       graph.updateSchema(new ChampObjectConstraint.Builder("").build());
223       throw new AssertionError("Able to call API method after shutdown was initiated");
224     } catch (IllegalStateException e) {
225       //Expected
226     }
227
228     try {
229       graph.updateSchema(new ChampRelationshipConstraint.Builder("").build());
230       throw new AssertionError("Able to call API method after shutdown was initiated");
231     } catch (IllegalStateException e) {
232       //Expected
233     }
234
235     try {
236       graph.shutdown();
237       throw new AssertionError("Able to call API method after shutdown was initiated");
238     } catch (IllegalStateException e) {
239       //Expected
240     }
241   }
242 }