Remove try/catch blocks with assertj - apex-pdp
[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  *  Modifications Copyright (C) 2020 Nordix Foundation
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.model.modelapi;
23
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
27
28 import java.util.Properties;
29 import java.util.UUID;
30 import org.junit.Test;
31 import org.onap.policy.apex.model.modelapi.impl.ModelFacade;
32
33 public class ModelFacadeTest {
34
35     @Test
36     public void testModelFacade() {
37         assertThatThrownBy(() -> new ModelFacade(null, null, false))
38             .hasMessage("apexModel may not be null");
39         final ApexModel apexModel = new ApexModelFactory().createApexModel(null, false);
40
41         assertThatThrownBy(() -> new ModelFacade(apexModel, null, false))
42             .hasMessage("apexProperties may not be null");
43         final Properties modelProperties = new Properties();
44         final ModelFacade mf = new ModelFacade(apexModel, modelProperties, false);
45
46         ApexApiResult result = mf.createModel(null, null, null, null);
47         assertEquals(ApexApiResult.Result.FAILED, result.getResult());
48
49         result = mf.createModel("ModelName", null, null, null);
50         assertEquals(ApexApiResult.Result.FAILED, result.getResult());
51
52         result = mf.createModel("ModelName", "0.0.1", null, null);
53         assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
54
55         modelProperties.setProperty("DEFAULT_CONCEPT_VERSION", "");
56         result = mf.createModel("ModelName", null, null, null);
57         assertEquals(ApexApiResult.Result.FAILED, result.getResult());
58
59         modelProperties.setProperty("DEFAULT_CONCEPT_VERSION", "£$£$£$");
60         result = mf.createModel("ModelName", null, null, null);
61         assertEquals(ApexApiResult.Result.FAILED, result.getResult());
62
63         modelProperties.setProperty("DEFAULT_CONCEPT_VERSION", "0.0.1");
64         result = mf.createModel("ModelName", null, null, null);
65         assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
66         result = mf.deleteModel();
67         assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
68         result = mf.createModel("ModelName", null, null, null);
69         assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
70
71         result = mf.updateModel("ModelName", null, UUID.randomUUID().toString(), "New Description");
72         assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
73
74         result = mf.updateModel("ModelName", "0.0.1", UUID.randomUUID().toString(), "New Description");
75         assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
76
77         modelProperties.remove("DEFAULT_CONCEPT_VERSION");
78         result = mf.updateModel("ModelName", null, UUID.randomUUID().toString(), "New Description");
79         assertEquals(ApexApiResult.Result.FAILED, result.getResult());
80
81         result = mf.updateModel(null, null, UUID.randomUUID().toString(), "New Description");
82         assertEquals(ApexApiResult.Result.FAILED, result.getResult());
83
84         result = mf.deleteModel();
85         assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
86         result = mf.updateModel("name", "0.0.1", UUID.randomUUID().toString(), "New Description");
87         assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
88
89         result = mf.getModelKey();
90         assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
91
92         result = mf.listModel();
93         assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
94         assertEquals("AxPolicyModel:(AxPolicyModel:(key=AxArtifactKey:(n", result.getMessage().substring(0, 50));
95
96         result = mf.deleteModel();
97         assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
98         assertNotNull(mf);
99     }
100 }