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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.model.modelapi;
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
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;
33 public class ModelFacadeTest {
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);
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);
46 ApexApiResult result = mf.createModel(null, null, null, null);
47 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
49 result = mf.createModel("ModelName", null, null, null);
50 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
52 result = mf.createModel("ModelName", "0.0.1", null, null);
53 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
55 modelProperties.setProperty("DEFAULT_CONCEPT_VERSION", "");
56 result = mf.createModel("ModelName", null, null, null);
57 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
59 modelProperties.setProperty("DEFAULT_CONCEPT_VERSION", "£$£$£$");
60 result = mf.createModel("ModelName", null, null, null);
61 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
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());
71 result = mf.updateModel("ModelName", null, UUID.randomUUID().toString(), "New Description");
72 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
74 result = mf.updateModel("ModelName", "0.0.1", UUID.randomUUID().toString(), "New Description");
75 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
77 modelProperties.remove("DEFAULT_CONCEPT_VERSION");
78 result = mf.updateModel("ModelName", null, UUID.randomUUID().toString(), "New Description");
79 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
81 result = mf.updateModel(null, null, UUID.randomUUID().toString(), "New Description");
82 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
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());
89 result = mf.getModelKey();
90 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
92 result = mf.listModel();
93 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
94 assertEquals("AxPolicyModel:(AxPolicyModel:(key=AxArtifactKey:(n", result.getMessage().substring(0, 50));
96 result = mf.deleteModel();
97 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());