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;
30 import org.junit.Test;
31 import org.onap.policy.apex.model.modelapi.impl.ModelFacade;
33 public class ModelFacadeTest {
36 public void testModelFacade() {
38 new ModelFacade(null, null, false);
39 fail("test should throw an exception here");
40 } catch (final Exception e) {
41 assertEquals("apexModel may not be null", e.getMessage());
44 final ApexModel apexModel = new ApexModelFactory().createApexModel(null, false);
47 new ModelFacade(apexModel, null, false);
48 fail("test should throw an exception here");
49 } catch (final Exception e) {
50 assertEquals("apexProperties may not be null", e.getMessage());
53 final Properties modelProperties = new Properties();
54 final ModelFacade mf = new ModelFacade(apexModel, modelProperties, false);
56 ApexApiResult result = mf.createModel(null, null, null, null);
57 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
59 result = mf.createModel("ModelName", null, null, null);
60 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
62 result = mf.createModel("ModelName", "0.0.1", null, null);
63 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
65 modelProperties.setProperty("DEFAULT_CONCEPT_VERSION", "");
66 result = mf.createModel("ModelName", null, null, null);
67 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
69 modelProperties.setProperty("DEFAULT_CONCEPT_VERSION", "£$£$£$");
70 result = mf.createModel("ModelName", null, null, null);
71 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
73 modelProperties.setProperty("DEFAULT_CONCEPT_VERSION", "0.0.1");
74 result = mf.createModel("ModelName", null, null, null);
75 assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
76 result = mf.deleteModel();
77 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
78 result = mf.createModel("ModelName", null, null, null);
79 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
81 result = mf.updateModel("ModelName", null, UUID.randomUUID().toString(), "New Description");
82 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
84 result = mf.updateModel("ModelName", "0.0.1", UUID.randomUUID().toString(), "New Description");
85 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
87 modelProperties.remove("DEFAULT_CONCEPT_VERSION");
88 result = mf.updateModel("ModelName", null, UUID.randomUUID().toString(), "New Description");
89 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
91 result = mf.updateModel(null, null, UUID.randomUUID().toString(), "New Description");
92 assertEquals(ApexApiResult.Result.FAILED, result.getResult());
94 result = mf.deleteModel();
95 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
96 result = mf.updateModel("name", "0.0.1", UUID.randomUUID().toString(), "New Description");
97 assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
99 result = mf.getModelKey();
100 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
102 result = mf.listModel();
103 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
104 assertEquals("AxPolicyModel:(AxPolicyModel:(key=AxArtifactKey:(n", result.getMessage().substring(0, 50));
106 result = mf.deleteModel();
107 assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());