Changes for checkstyle 8.32
[policy/apex-pdp.git] / model / model-api / src / test / java / org / onap / policy / apex / model / modelapi / ModelFacadeTest.java
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.assertNotNull;
25 import static org.junit.Assert.fail;
26
27 import java.util.Properties;
28 import java.util.UUID;
29 import org.junit.Test;
30 import org.onap.policy.apex.model.modelapi.impl.ModelFacade;
31
32 public class ModelFacadeTest {
33
34     @Test
35     public void testModelFacade() {
36         try {
37             new ModelFacade(null, null, false);
38             fail("test should throw an exception here");
39         } catch (final Exception e) {
40             assertEquals("apexModel may not be null", e.getMessage());
41         }
42
43         final ApexModel apexModel = new ApexModelFactory().createApexModel(null, false);
44
45         try {
46             new ModelFacade(apexModel, null, false);
47             fail("test should throw an exception here");
48         } catch (final Exception e) {
49             assertEquals("apexProperties may not be null", e.getMessage());
50         }
51
52         final Properties modelProperties = new Properties();
53         final ModelFacade mf = new ModelFacade(apexModel, modelProperties, false);
54
55         ApexApiResult result = mf.createModel(null, null, null, null);
56         assertEquals(ApexApiResult.Result.FAILED, result.getResult());
57
58         result = mf.createModel("ModelName", null, null, null);
59         assertEquals(ApexApiResult.Result.FAILED, result.getResult());
60
61         result = mf.createModel("ModelName", "0.0.1", null, null);
62         assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
63
64         modelProperties.setProperty("DEFAULT_CONCEPT_VERSION", "");
65         result = mf.createModel("ModelName", null, null, null);
66         assertEquals(ApexApiResult.Result.FAILED, result.getResult());
67
68         modelProperties.setProperty("DEFAULT_CONCEPT_VERSION", "£$£$£$");
69         result = mf.createModel("ModelName", null, null, null);
70         assertEquals(ApexApiResult.Result.FAILED, result.getResult());
71
72         modelProperties.setProperty("DEFAULT_CONCEPT_VERSION", "0.0.1");
73         result = mf.createModel("ModelName", null, null, null);
74         assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
75         result = mf.deleteModel();
76         assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
77         result = mf.createModel("ModelName", null, null, null);
78         assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
79
80         result = mf.updateModel("ModelName", null, UUID.randomUUID().toString(), "New Description");
81         assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
82
83         result = mf.updateModel("ModelName", "0.0.1", UUID.randomUUID().toString(), "New Description");
84         assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
85
86         modelProperties.remove("DEFAULT_CONCEPT_VERSION");
87         result = mf.updateModel("ModelName", null, UUID.randomUUID().toString(), "New Description");
88         assertEquals(ApexApiResult.Result.FAILED, result.getResult());
89
90         result = mf.updateModel(null, null, UUID.randomUUID().toString(), "New Description");
91         assertEquals(ApexApiResult.Result.FAILED, result.getResult());
92
93         result = mf.deleteModel();
94         assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
95         result = mf.updateModel("name", "0.0.1", UUID.randomUUID().toString(), "New Description");
96         assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
97
98         result = mf.getModelKey();
99         assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
100
101         result = mf.listModel();
102         assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
103         assertEquals("AxPolicyModel:(AxPolicyModel:(key=AxArtifactKey:(n", result.getMessage().substring(0, 50));
104
105         result = mf.deleteModel();
106         assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
107         assertNotNull(mf);
108     }
109 }