25ab6df6bb1d18c877b93a776b5f3fab78bbea0e
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.model.modelapi;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
25
26 import org.junit.Test;
27
28 /**
29  * Context schema for API tests.
30  * @author Liam Fallon (liam.fallon@ericsson.com)
31  */
32 public class TestApexEditorApiContextSchema {
33     @Test
34     public void testContextSchemaCrud() {
35         final ApexModel apexModel = new ApexModelFactory().createApexModel(null, false);
36
37         ApexApiResult result = apexModel.validateContextSchemas(null, null);
38         assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
39
40         result = apexModel.validateContextSchemas("%%%$£", null);
41         assertEquals(ApexApiResult.Result.FAILED, result.getResult());
42
43         result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json");
44         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
45         result = apexModel.listContextSchemas(null, null);
46         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
47
48         result = apexModel.createContextSchema("Hello", "0.0.2", "Java", "java.lang.String",
49                 "1fa2e430-f2b2-11e6-bc64-92361f002671", "A description of hello");
50         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
51         result = apexModel.createContextSchema("Hello", "0.1.2", "Java", "java.lang.String",
52                 "1fa2e430-f2b2-11e6-bc64-92361f002672", "A description of hola");
53         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
54         result = apexModel.createContextSchema("Hello", "0.1.4", "Java", "java.lang.String",
55                 "1fa2e430-f2b2-11e6-bc64-92361f002672", "A description of connichi wa");
56         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
57         result = apexModel.createContextSchema("Hello", null, "Java", "java.lang.String", null, null);
58         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
59         result = apexModel.createContextSchema("Hello", null, "Java", "java.lang.String", null, null);
60         assertTrue(result.getResult().equals(ApexApiResult.Result.CONCEPT_EXISTS));
61         result = apexModel.deleteContextSchema("Hello", "0.1.4");
62         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
63         result = apexModel.createContextSchema("Hello", "0.1.4", "Java", "java.lang.String",
64                 "1fa2e430-f2b2-11e6-bc64-92361f002672", "A description of connichi wa");
65         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
66
67         result = apexModel.createContextSchema("Hello2", null, null, "java.lang.String", null, null);
68         assertTrue(result.getResult().equals(ApexApiResult.Result.FAILED));
69         result = apexModel.createContextSchema("Hello2", null, null, null, null, null);
70         assertTrue(result.getResult().equals(ApexApiResult.Result.FAILED));
71         result = apexModel.createContextSchema("Hello2", null, "Java", "java.lang.String", null, null);
72         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
73
74         result = apexModel.createContextSchema("Hello", "0.1.2", "Java", "java.lang.Float",
75                 "1fa2e430-f2b2-11e6-bc64-92361f002672", "A description of hola");
76         assertTrue(result.getResult().equals(ApexApiResult.Result.CONCEPT_EXISTS));
77
78         result = apexModel.deleteContextSchema("Hello", "0.1.4");
79         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
80         result = apexModel.createContextSchema("Hello", "0.1.4", "Java", "java.lang.String",
81                 "1fa2e430-f2b2-11e6-bc64-92361f002672", "A description of connichi wa");
82         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
83
84         result = apexModel.validateContextSchemas(null, null);
85         assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
86
87         result = apexModel.updateContextSchema(null, null, null, null, null, null);
88         assertEquals(ApexApiResult.Result.FAILED, result.getResult());
89
90         result = apexModel.updateContextSchema("Hello", "0.0.2", null, null, null, "An updated description of hello");
91         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
92         result = apexModel.updateContextSchema("Hello", "0.0.2", null, null, null, null);
93         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
94         result = apexModel.updateContextSchema("Hello", "0.1.2", "Java", "java.lang.Integer",
95                 "1fa2e430-f2b2-11e6-bc64-92361f002673", "A further updated description of hola");
96         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
97
98         result = apexModel.updateContextSchema("Hello2", "0.0.2", null, null, null, "An updated description of hello");
99         assertTrue(result.getResult().equals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST));
100
101         result = apexModel.listContextSchemas("@£%%$", null);
102         assertEquals(ApexApiResult.Result.FAILED, result.getResult());
103
104         result = apexModel.listContextSchemas("Hello", "0.1.2");
105         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
106         assertTrue(result.getMessages().size() == 2);
107
108         result = apexModel.listContextSchemas("Hello", null);
109         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
110         assertTrue(result.getMessages().size() == 4);
111
112         result = apexModel.listContextSchemas(null, null);
113         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
114         assertTrue(result.getMessages().size() == 9);
115
116         result = apexModel.deleteContextSchema("@£%%$", null);
117         assertEquals(ApexApiResult.Result.FAILED, result.getResult());
118
119         result = apexModel.deleteContextSchema("Hello", "0.1.1");
120         assertTrue(result.getResult().equals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST));
121
122         result = apexModel.deleteContextSchema("Hellooooo", null);
123         assertTrue(result.getResult().equals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST));
124
125         result = apexModel.listContextSchemas("Hello", null);
126         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
127         assertTrue(result.getMessages().size() == 4);
128
129         result = apexModel.deleteContextSchema("Hello", "0.1.2");
130         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
131
132         result = apexModel.listContextSchemas("Hello", null);
133         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
134         assertTrue(result.getMessages().size() == 3);
135
136         result = apexModel.deleteContextSchema("Hello", null);
137         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
138
139         result = apexModel.listContextSchemas("Hello", null);
140         assertTrue(result.getResult().equals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST));
141
142         result = apexModel.listContextSchemas(null, null);
143         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
144
145         result = apexModel.deleteContextSchema(null, null);
146         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
147         assertEquals(5, result.getMessages().size());
148
149         result = apexModel.listContextSchemas(null, null);
150         assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
151         assertEquals(0, result.getMessages().size());
152     }
153 }