Update license date and text
[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-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 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  */
21 package org.onap.aai.champcore.core;
22
23 import org.junit.Test;
24 import org.onap.aai.champcore.ChampAPI;
25 import org.onap.aai.champcore.ChampGraph;
26 import org.onap.aai.champcore.graph.impl.ChampAPIImpl;
27 import org.onap.aai.champcore.graph.impl.InMemoryChampGraphImpl;
28 import org.onap.aai.champcore.model.ChampObjectConstraint;
29 import org.onap.aai.champcore.model.ChampRelationshipConstraint;
30
31 import static org.junit.Assert.assertTrue;
32
33 import java.util.Optional;
34
35 public class ChampAPITest {
36
37   @Test
38   public void testChampAPIMemoryInstantiation() {
39     testChampAPIInstantiation(new ChampAPIImpl("IN_MEMORY"), "IN_MEMORY");
40   }
41
42   public void testChampAPIInstantiation(ChampAPI api, String expectedType) {
43       assertTrue(api.getType() == expectedType);
44
45       api.getGraph("foo");
46       api.shutdown();
47
48       try {
49         api.getGraph("foo");
50         throw new AssertionError("Able to call getGraph(String name) after shutdown()");
51       } catch (IllegalStateException e) {
52         //Expected
53       }
54   }
55
56   @Test
57   public void testChampMemoryGraphInstantiation() throws Exception
58   {
59     testChampGraphInstantiation(new InMemoryChampGraphImpl.Builder().build());
60   }
61
62   public void testChampGraphInstantiation(ChampGraph graph) throws Exception {
63
64     graph.shutdown();
65
66     try {
67       graph.deleteObject(null, Optional.empty());
68       throw new AssertionError("Able to call API method after shutdown was initiated");
69     } catch (IllegalStateException e) {
70       //Expected
71     }
72
73     try {
74       graph.deleteObjectIndex(null);
75       throw new AssertionError("Able to call API method after shutdown was initiated");
76     } catch (IllegalStateException e) {
77       //Expected
78     }
79
80     try {
81       graph.deletePartition(null, Optional.empty());
82       throw new AssertionError("Able to call API method after shutdown was initiated");
83     } catch (IllegalStateException e) {
84       //Expected
85     }
86
87     try {
88       graph.deleteRelationship(null, Optional.empty());
89       throw new AssertionError("Able to call API method after shutdown was initiated");
90     } catch (IllegalStateException e) {
91       //Expected
92     }
93
94     try {
95       graph.deleteRelationshipIndex(null);
96       throw new AssertionError("Able to call API method after shutdown was initiated");
97     } catch (IllegalStateException e) {
98       //Expected
99     }
100
101     try {
102       graph.deleteSchema();
103       throw new AssertionError("Able to call API method after shutdown was initiated");
104     } catch (IllegalStateException e) {
105       //Expected
106     }
107
108     try {
109       graph.queryObjects(null, Optional.empty());
110       throw new AssertionError("Able to call API method after shutdown was initiated");
111     } catch (IllegalStateException e) {
112       //Expected
113     }
114
115     try {
116       graph.queryRelationships(null, Optional.empty());
117       throw new AssertionError("Able to call API method after shutdown was initiated");
118     } catch (IllegalStateException e) {
119       //Expected
120     }
121
122     try {
123       graph.retrieveObject(null, Optional.empty());
124       throw new AssertionError("Able to call API method after shutdown was initiated");
125     } catch (IllegalStateException e) {
126       //Expected
127     }
128
129     try {
130       graph.retrieveObjectIndex(null);
131       throw new AssertionError("Able to call API method after shutdown was initiated");
132     } catch (IllegalStateException e) {
133       //Expected
134     }
135
136     try {
137       graph.retrieveObjectIndices();
138       throw new AssertionError("Able to call API method after shutdown was initiated");
139     } catch (IllegalStateException e) {
140       //Expected
141     }
142
143     try {
144       graph.retrieveRelationship(null, Optional.empty());
145       throw new AssertionError("Able to call API method after shutdown was initiated");
146     } catch (IllegalStateException e) {
147       //Expected
148     }
149
150     try {
151       graph.retrieveRelationshipIndex(null);
152       throw new AssertionError("Able to call API method after shutdown was initiated");
153     } catch (IllegalStateException e) {
154       //Expected
155     }
156
157     try {
158       graph.retrieveRelationshipIndices();
159       throw new AssertionError("Able to call API method after shutdown was initiated");
160     } catch (IllegalStateException e) {
161       //Expected
162     }
163
164     try {
165       graph.retrieveRelationships(null, Optional.empty());
166       throw new AssertionError("Able to call API method after shutdown was initiated");
167     } catch (IllegalStateException e) {
168       //Expected
169     }
170
171     try {
172       graph.retrieveSchema();
173       throw new AssertionError("Able to call API method after shutdown was initiated");
174     } catch (IllegalStateException e) {
175       //Expected
176     }
177
178     try {
179       graph.storeObject(null, Optional.empty());
180       throw new AssertionError("Able to call API method after shutdown was initiated");
181     } catch (IllegalStateException e) {
182       //Expected
183     }
184
185     try {
186       graph.storeObjectIndex(null);
187       throw new AssertionError("Able to call API method after shutdown was initiated");
188     } catch (IllegalStateException e) {
189       //Expected
190     }
191
192     try {
193       graph.storePartition(null, Optional.empty());
194       throw new AssertionError("Able to call API method after shutdown was initiated");
195     } catch (IllegalStateException e) {
196       //Expected
197     }
198
199     try {
200       graph.storeRelationship(null, Optional.empty());
201       throw new AssertionError("Able to call API method after shutdown was initiated");
202     } catch (IllegalStateException e) {
203       //Expected
204     }
205
206     try {
207       graph.storeRelationshipIndex(null);
208       throw new AssertionError("Able to call API method after shutdown was initiated");
209     } catch (IllegalStateException e) {
210       //Expected
211     }
212
213     try {
214       graph.storeSchema(null);
215       throw new AssertionError("Able to call API method after shutdown was initiated");
216     } catch (IllegalStateException e) {
217       //Expected
218     }
219
220     try {
221       graph.updateSchema(new ChampObjectConstraint.Builder("").build());
222       throw new AssertionError("Able to call API method after shutdown was initiated");
223     } catch (IllegalStateException e) {
224       //Expected
225     }
226
227     try {
228       graph.updateSchema(new ChampRelationshipConstraint.Builder("").build());
229       throw new AssertionError("Able to call API method after shutdown was initiated");
230     } catch (IllegalStateException e) {
231       //Expected
232     }
233
234     try {
235       graph.shutdown();
236       throw new AssertionError("Able to call API method after shutdown was initiated");
237     } catch (IllegalStateException e) {
238       //Expected
239     }
240   }
241 }