2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2020 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.examples.myfirstpolicy;
24 import static org.junit.Assert.assertEquals;
27 import java.io.IOException;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.onap.policy.apex.auth.clieditor.ApexCommandLineEditorMain;
31 import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
32 import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;
33 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
34 import org.onap.policy.common.utils.resources.TextFileUtils;
37 * Test MyFirstPolicyModel CLI.
39 public class MfpModelCliTest {
40 private static AxPolicyModel testApexModel1;
41 private static AxPolicyModel testApexModel2;
46 * @throws Exception if there is an error
49 public static void setup() throws Exception {
50 testApexModel1 = new TestMfpModelCreator.TestMfp1ModelCreator().getModel();
51 testApexModel2 = new TestMfpModelCreator.TestMfp2ModelCreator().getModel();
57 * @throws IOException Signals that an I/O exception has occurred.
58 * @throws ApexModelException ifd there is an Apex Error
61 public void testCliPolicy() throws IOException, ApexModelException {
63 final File tempLogFile1 = File.createTempFile("TestMyFirstPolicy1CLI", ".log");
64 final File tempModelFile1 = File.createTempFile("TestMyFirstPolicy1CLI", ".json");
65 final File tempLogFile2 = File.createTempFile("TestMyFirstPolicy2CLI", ".log");
66 final File tempModelFile2 = File.createTempFile("TestMyFirstPolicy2CLI", ".json");
68 final String[] testApexModel1CliArgs = {
70 "src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModelMvel_0.0.1.apex",
72 tempLogFile1.getAbsolutePath(),
74 tempModelFile1.getAbsolutePath()
76 final String[] testApexModel2CliArgs = {
78 "src/main/resources/examples/models/MyFirstPolicy/2/MyFirstPolicyModel_0.0.1.apex",
80 tempLogFile2.getAbsolutePath(),
82 tempModelFile2.getAbsolutePath()
86 new ApexCommandLineEditorMain(testApexModel1CliArgs);
87 new ApexCommandLineEditorMain(testApexModel2CliArgs);
89 final ApexModelReader<AxPolicyModel> reader = new ApexModelReader<>(AxPolicyModel.class);
90 AxPolicyModel generatedmodel = reader.read(TextFileUtils.getTextFileAsString(tempModelFile1.getAbsolutePath()));
92 assertEquals("Model generated from the CLI (" + testApexModel1CliArgs[1] + ") into file "
93 + tempModelFile1.getAbsolutePath() + " is not the same as the test Model for "
94 + testApexModel1.getKey(), testApexModel1, generatedmodel);
96 tempLogFile1.delete();
97 tempModelFile1.delete();
99 generatedmodel = reader.read(TextFileUtils.getTextFileAsString(tempModelFile2.getAbsolutePath()));
100 assertEquals("Model generated from the CLI (" + testApexModel2CliArgs[1] + ") into file "
101 + tempModelFile2.getAbsolutePath() + " is not the same as the test Model for "
102 + testApexModel2.getKey(), testApexModel2, generatedmodel);
104 tempLogFile2.delete();
105 tempModelFile2.delete();