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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.model.modelapi;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
26 import org.junit.Test;
29 * Context schema for API tests.
30 * @author Liam Fallon (liam.fallon@ericsson.com)
32 public class TestApexEditorApiContextSchema {
34 public void testContextSchemaCrud() {
35 final ApexModel apexModel = new ApexModelFactory().createApexModel(null, false);
37 ApexApiResult result = apexModel.validateContextSchemas(null, null);
38 assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
40 result = apexModel.validateContextSchemas("%%%$£", null);
41 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
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));
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));
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));
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));
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));
84 result = apexModel.validateContextSchemas(null, null);
85 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
87 result = apexModel.updateContextSchema(null, null, null, null, null, null);
88 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
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));
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));
101 result = apexModel.listContextSchemas("@£%%$", null);
102 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
104 result = apexModel.listContextSchemas("Hello", "0.1.2");
105 assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
106 assertTrue(result.getMessages().size() == 2);
108 result = apexModel.listContextSchemas("Hello", null);
109 assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
110 assertTrue(result.getMessages().size() == 4);
112 result = apexModel.listContextSchemas(null, null);
113 assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
114 assertTrue(result.getMessages().size() == 9);
116 result = apexModel.deleteContextSchema("@£%%$", null);
117 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
119 result = apexModel.deleteContextSchema("Hello", "0.1.1");
120 assertTrue(result.getResult().equals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST));
122 result = apexModel.deleteContextSchema("Hellooooo", null);
123 assertTrue(result.getResult().equals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST));
125 result = apexModel.listContextSchemas("Hello", null);
126 assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
127 assertTrue(result.getMessages().size() == 4);
129 result = apexModel.deleteContextSchema("Hello", "0.1.2");
130 assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
132 result = apexModel.listContextSchemas("Hello", null);
133 assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
134 assertTrue(result.getMessages().size() == 3);
136 result = apexModel.deleteContextSchema("Hello", null);
137 assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
139 result = apexModel.listContextSchemas("Hello", null);
140 assertTrue(result.getResult().equals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST));
142 result = apexModel.listContextSchemas(null, null);
143 assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
145 result = apexModel.deleteContextSchema(null, null);
146 assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
147 assertEquals(5, result.getMessages().size());
149 result = apexModel.listContextSchemas(null, null);
150 assertTrue(result.getResult().equals(ApexApiResult.Result.SUCCESS));
151 assertEquals(0, result.getMessages().size());