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 testModelCreator0() throws ApexException {
56 final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
57 new TestApexModelCreator0Test());
59 testApexModel.testApexModelValid();
61 testApexModel.testApexModelVaidateObservation();
62 fail("Test should throw an exception");
63 } catch (final Exception e) {
64 assertEquals("model should have observations", e.getMessage());
67 testApexModel.testApexModelVaidateWarning();
68 fail("Test should throw an exception");
69 } catch (final Exception e) {
70 assertEquals("model should have warnings", e.getMessage());
73 testApexModel.testApexModelVaidateInvalidModel();
74 fail("Test should throw an exception");
75 } catch (final Exception e) {
76 assertEquals("model should not be valid ***validation of model successful***", e.getMessage());
79 testApexModel.testApexModelVaidateMalstructured();
80 fail("Test should throw an exception");
81 } catch (final Exception e) {
82 assertEquals("model should not be valid ***validation of model successful***", e.getMessage());
87 public void testModelCreator1() throws ApexException {
88 final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
89 new TestApexModelCreator1Test());
92 testApexModel.testApexModelValid();
93 fail("Test should throw an exception");
94 } catch (final Exception e) {
95 assertTrue(e.getMessage().startsWith("model is invalid"));
98 testApexModel.testApexModelVaidateObservation();
99 fail("Test should throw an exception");
100 } catch (final Exception e) {
101 assertTrue(e.getMessage().startsWith("model is invalid"));
104 testApexModel.testApexModelVaidateWarning();
105 fail("Test should throw an exception");
106 } catch (final Exception e) {
107 assertTrue(e.getMessage().startsWith("model is invalid"));
109 testApexModel.testApexModelVaidateInvalidModel();
110 testApexModel.testApexModelVaidateMalstructured();
114 public void testModelCreator2() throws ApexException {
115 final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
116 new TestApexModelCreator2Test());
118 testApexModel.testApexModelValid();
119 testApexModel.testApexModelVaidateObservation();
121 testApexModel.testApexModelVaidateWarning();
122 fail("Test should throw an exception");
123 } catch (final Exception e) {
124 assertEquals("model should have warnings", e.getMessage());
129 public void testModelCreator1XmlJson() throws ApexException {
130 final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
131 new TestApexModelCreator1Test());
134 testApexModel.testApexModelWriteReadJson();
135 fail("Test should throw an exception");
136 } catch (final Exception e) {
137 assertTrue(e.getMessage().startsWith("error processing file"));
141 testApexModel.testApexModelWriteReadXml();
142 fail("Test should throw an exception");
143 } catch (final Exception e) {
144 assertTrue(e.getMessage().startsWith("error processing file"));