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.assertNotNull;
25 import static org.junit.Assert.fail;
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;
32 public class ModelFacadeTest {
35 public void testModelFacade() {
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());
43 final ApexModel apexModel = new ApexModelFactory().createApexModel(null, false);
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());
52 final Properties modelProperties = new Properties();
53 final ModelFacade mf = new ModelFacade(apexModel, modelProperties, false);
55 ApexApiResult result = mf.createModel(null, null, null, null);
56 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
58 result = mf.createModel("ModelName", null, null, null);
59 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
61 result = mf.createModel("ModelName", "0.0.1", null, null);
62 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
64 modelProperties.setProperty("DEFAULT_CONCEPT_VERSION", "");
65 result = mf.createModel("ModelName", null, null, null);
66 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
68 modelProperties.setProperty("DEFAULT_CONCEPT_VERSION", "£$£$£$");
69 result = mf.createModel("ModelName", null, null, null);
70 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
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());
80 result = mf.updateModel("ModelName", null, UUID.randomUUID().toString(), "New Description");
81 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
83 result = mf.updateModel("ModelName", "0.0.1", UUID.randomUUID().toString(), "New Description");
84 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
86 modelProperties.remove("DEFAULT_CONCEPT_VERSION");
87 result = mf.updateModel("ModelName", null, UUID.randomUUID().toString(), "New Description");
88 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
90 result = mf.updateModel(null, null, UUID.randomUUID().toString(), "New Description");
91 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
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());
98 result = mf.getModelKey();
99 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
101 result = mf.listModel();
102 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
103 assertEquals("AxPolicyModel:(AxPolicyModel:(key=AxArtifactKey:(n", result.getMessage().substring(0, 50));
105 result = mf.deleteModel();
106 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());