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.basicmodel.handling;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
27 import org.junit.Test;
28 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
29 import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
30 import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
32 public class SupportBasicModelTester {
35 public void testNormalModelCreator() throws ApexException {
36 final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
37 new DummyApexBasicModelCreator());
39 testApexModel.testApexModelValid();
41 testApexModel.testApexModelVaidateObservation();
42 fail("Test should throw an exception");
43 } catch (final Exception e) {
44 assertEquals("model should have observations", e.getMessage());
46 testApexModel.testApexModelVaidateWarning();
47 testApexModel.testApexModelVaidateInvalidModel();
48 testApexModel.testApexModelVaidateMalstructured();
50 testApexModel.testApexModelWriteReadJson();
51 testApexModel.testApexModelWriteReadXml();
55 public void testModelsUnequal() throws ApexException {
56 final TestApexModel<AxModel> testApexModel0 = new TestApexModel<AxModel>(AxModel.class,
57 new DummyApexBasicModelCreator());
58 final TestApexModel<AxModel> testApexModel1 = new TestApexModel<AxModel>(AxModel.class,
59 new DummyApexBasicModelCreator());
61 testApexModel1.getModel().getKey().setVersion("0.0.2");
64 testApexModel0.checkModelEquality(testApexModel0.getModel(), testApexModel1.getModel(),
65 "Models are not equal");
66 fail("test should throw an exception here");
67 } catch (ApexException ae) {
68 assertEquals("Models are not equal", ae.getMessage());
73 public void testModelCreator0() throws ApexException {
74 final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
75 new SupportApexModelCreator0());
77 testApexModel.testApexModelValid();
79 testApexModel.testApexModelVaidateObservation();
80 fail("Test should throw an exception");
81 } catch (final Exception e) {
82 assertEquals("model should have observations", e.getMessage());
85 testApexModel.testApexModelVaidateWarning();
86 fail("Test should throw an exception");
87 } catch (final Exception e) {
88 assertEquals("model should have warnings", e.getMessage());
91 testApexModel.testApexModelVaidateInvalidModel();
92 fail("Test should throw an exception");
93 } catch (final Exception e) {
94 assertEquals("model should not be valid ***validation of model successful***", e.getMessage());
97 testApexModel.testApexModelVaidateMalstructured();
98 fail("Test should throw an exception");
99 } catch (final Exception e) {
100 assertEquals("model should not be valid ***validation of model successful***", e.getMessage());
105 public void testModelCreator1() throws ApexException {
106 final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
107 new SupportApexModelCreator1());
110 testApexModel.testApexModelValid();
111 fail("Test should throw an exception");
112 } catch (final Exception e) {
113 assertTrue(e.getMessage().startsWith("model is invalid"));
116 testApexModel.testApexModelVaidateObservation();
117 fail("Test should throw an exception");
118 } catch (final Exception e) {
119 assertTrue(e.getMessage().startsWith("model is invalid"));
122 testApexModel.testApexModelVaidateWarning();
123 fail("Test should throw an exception");
124 } catch (final Exception e) {
125 assertTrue(e.getMessage().startsWith("model is invalid"));
127 testApexModel.testApexModelVaidateInvalidModel();
128 testApexModel.testApexModelVaidateMalstructured();
132 public void testModelCreator2() throws ApexException {
133 final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
134 new SupportApexModelCreator2());
136 testApexModel.testApexModelValid();
137 testApexModel.testApexModelVaidateObservation();
139 testApexModel.testApexModelVaidateWarning();
140 fail("Test should throw an exception");
141 } catch (final Exception e) {
142 assertEquals("model should have warnings", e.getMessage());
147 public void testModelCreator1XmlJson() throws ApexException {
148 final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
149 new SupportApexModelCreator1());
152 testApexModel.testApexModelWriteReadJson();
153 fail("Test should throw an exception");
154 } catch (final Exception e) {
155 assertTrue(e.getMessage().startsWith("error processing file"));
159 testApexModel.testApexModelWriteReadXml();
160 fail("Test should throw an exception");
161 } catch (final Exception e) {
162 assertTrue(e.getMessage().startsWith("error processing file"));