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;
33 * @author Liam Fallon (liam.fallon@ericsson.com)
35 public class TestBasicModelTest {
38 public void testNormalModelCreator() throws ApexException {
39 final TestApexModel<AxModel> testApexModel =
40 new TestApexModel<AxModel>(AxModel.class, new TestApexBasicModelCreator());
42 testApexModel.testApexModelValid();
44 testApexModel.testApexModelVaidateObservation();
45 fail("Test should throw an exception");
46 } catch (final Exception e) {
47 assertEquals("model should have observations", e.getMessage());
49 testApexModel.testApexModelVaidateWarning();
50 testApexModel.testApexModelVaidateInvalidModel();
51 testApexModel.testApexModelVaidateMalstructured();
53 testApexModel.testApexModelWriteReadJSON();
54 testApexModel.testApexModelWriteReadXML();
58 public void testModelCreator0() throws ApexException {
59 final TestApexModel<AxModel> testApexModel =
60 new TestApexModel<AxModel>(AxModel.class, new TestApexTestModelCreator0());
62 testApexModel.testApexModelValid();
64 testApexModel.testApexModelVaidateObservation();
65 fail("Test should throw an exception");
66 } catch (final Exception e) {
67 assertEquals("model should have observations", e.getMessage());
70 testApexModel.testApexModelVaidateWarning();
71 fail("Test should throw an exception");
72 } catch (final Exception e) {
73 assertEquals("model should have warnings", e.getMessage());
76 testApexModel.testApexModelVaidateInvalidModel();
77 fail("Test should throw an exception");
78 } catch (final Exception e) {
79 assertEquals("should not be valid ***validation of model successful***", e.getMessage());
82 testApexModel.testApexModelVaidateMalstructured();
83 fail("Test should throw an exception");
84 } catch (final Exception e) {
85 assertEquals("should not be valid ***validation of model successful***", e.getMessage());
90 public void testModelCreator1() throws ApexException {
91 final TestApexModel<AxModel> testApexModel =
92 new TestApexModel<AxModel>(AxModel.class, new TestApexTestModelCreator1());
95 testApexModel.testApexModelValid();
96 fail("Test should throw an exception");
97 } catch (final Exception e) {
98 assertTrue(e.getMessage().startsWith("model is invalid"));
101 testApexModel.testApexModelVaidateObservation();
102 fail("Test should throw an exception");
103 } catch (final Exception e) {
104 assertTrue(e.getMessage().startsWith("model is invalid"));
107 testApexModel.testApexModelVaidateWarning();
108 fail("Test should throw an exception");
109 } catch (final Exception e) {
110 assertTrue(e.getMessage().startsWith("model is invalid"));
112 testApexModel.testApexModelVaidateInvalidModel();
113 testApexModel.testApexModelVaidateMalstructured();
117 public void testModelCreator2() throws ApexException {
118 final TestApexModel<AxModel> testApexModel =
119 new TestApexModel<AxModel>(AxModel.class, new TestApexTestModelCreator2());
121 testApexModel.testApexModelValid();
122 testApexModel.testApexModelVaidateObservation();
124 testApexModel.testApexModelVaidateWarning();
125 fail("Test should throw an exception");
126 } catch (final Exception e) {
127 assertEquals("model should have warnings", e.getMessage());
132 public void testModelCreator1XMLJSON() throws ApexException {
133 final TestApexModel<AxModel> testApexModel =
134 new TestApexModel<AxModel>(AxModel.class, new TestApexTestModelCreator1());
137 testApexModel.testApexModelWriteReadJSON();
138 fail("Test should throw an exception");
139 } catch (final Exception e) {
140 assertTrue(e.getMessage().startsWith("error processing file"));
144 testApexModel.testApexModelWriteReadXML();
145 fail("Test should throw an exception");
146 } catch (final Exception e) {
147 assertTrue(e.getMessage().startsWith("error processing file"));