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