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;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 import org.onap.policy.apex.auth.clieditor.ApexCommandLineEditorMain;
32 import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
33 import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;
34 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
35 import org.onap.policy.common.utils.resources.TextFileUtils;
38 * Test MyFirstPolicyModel CLI.
40 public class MfpModelCliTest {
41 private static AxPolicyModel testApexModel1;
42 private static AxPolicyModel testApexModel2;
47 * @throws Exception if there is an error
50 public static void setup() throws Exception {
51 testApexModel1 = new TestMfpModelCreator.TestMfp1ModelCreator().getModel();
52 testApexModel2 = new TestMfpModelCreator.TestMfp2ModelCreator().getModel();
58 * @throws IOException Signals that an I/O exception has occurred.
59 * @throws ApexModelException ifd there is an Apex Error
62 public void testCliPolicy() throws IOException, ApexModelException {
64 final File tempLogFile1 = File.createTempFile("TestMyFirstPolicy1CLI", ".log");
65 final File tempModelFile1 = File.createTempFile("TestMyFirstPolicy1CLI", ".json");
66 final File tempLogFile2 = File.createTempFile("TestMyFirstPolicy2CLI", ".log");
67 final File tempModelFile2 = File.createTempFile("TestMyFirstPolicy2CLI", ".json");
69 final String[] testApexModel1CliArgs = {
71 "src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModelMvel_0.0.1.apex",
73 tempLogFile1.getAbsolutePath(),
75 tempModelFile1.getAbsolutePath()
77 final String[] testApexModel2CliArgs = {
79 "src/main/resources/examples/models/MyFirstPolicy/2/MyFirstPolicyModel_0.0.1.apex",
81 tempLogFile2.getAbsolutePath(),
83 tempModelFile2.getAbsolutePath()
87 new ApexCommandLineEditorMain(testApexModel1CliArgs);
88 new ApexCommandLineEditorMain(testApexModel2CliArgs);
90 final ApexModelReader<AxPolicyModel> reader = new ApexModelReader<>(AxPolicyModel.class);
91 AxPolicyModel generatedmodel = reader.read(TextFileUtils.getTextFileAsString(tempModelFile1.getAbsolutePath()));
93 assertEquals("Model generated from the CLI (" + testApexModel1CliArgs[1] + ") into file "
94 + tempModelFile1.getAbsolutePath() + " is not the same as the test Model for "
95 + testApexModel1.getKey(), testApexModel1, generatedmodel);
97 tempLogFile1.delete();
98 tempModelFile1.delete();
100 generatedmodel = reader.read(TextFileUtils.getTextFileAsString(tempModelFile2.getAbsolutePath()));
101 assertEquals("Model generated from the CLI (" + testApexModel2CliArgs[1] + ") into file "
102 + tempModelFile2.getAbsolutePath() + " is not the same as the test Model for "
103 + testApexModel2.getKey(), testApexModel2, generatedmodel);
105 tempLogFile2.delete();
106 tempModelFile2.delete();