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.auth.clieditor;
23 import static org.junit.Assert.assertTrue;
26 import java.io.IOException;
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
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.ResourceUtils;
36 // TODO: Auto-generated Javadoc
38 * The Class TestLogicBlock.
40 public class LogicBlockTest {
41 private String[] logicBlockArgs;
42 private String[] avroSchemaArgs;
44 private File tempLogicModelFile;
45 private File tempAvroModelFile;
48 * Creates the temp files.
50 * @throws IOException Signals that an I/O exception has occurred.
53 public void createTempFiles() throws IOException {
54 tempLogicModelFile = File.createTempFile("TestLogicPolicyModel", ".json");
55 tempAvroModelFile = File.createTempFile("TestAvroPolicyModel", ".json");
57 logicBlockArgs = new String[] {"-c", "src/test/resources/scripts/LogicBlock.apex", "-o",
58 tempLogicModelFile.getCanonicalPath(), "-if", "true", "-nl"};
60 avroSchemaArgs = new String[] {"-c", "src/test/resources/scripts/AvroSchema.apex", "-o",
61 tempAvroModelFile.getCanonicalPath(), "-nl"};
65 * Removes the temp files.
68 public void removeTempFiles() {
69 tempLogicModelFile.delete();
70 tempAvroModelFile.delete();
76 * @throws IOException Signals that an I/O exception has occurred.
77 * @throws ApexModelException if there is an Apex error
80 public void testLogicBlock() throws IOException, ApexModelException {
81 new ApexCommandLineEditorMain(logicBlockArgs);
83 // Read the file from disk
84 final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class);
85 modelReader.setValidateFlag(false);
87 final URL writtenModelUrl = ResourceUtils.getLocalFile(tempLogicModelFile.getCanonicalPath());
88 final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream());
90 final URL compareModelUrl =
91 ResourceUtils.getLocalFile("src/test/resources/compare/LogicBlockModel_Compare.json");
92 final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream());
94 // Ignore key info UUIDs
95 writtenModel.getKeyInformation().getKeyInfoMap().clear();
96 compareModel.getKeyInformation().getKeyInfoMap().clear();
98 assertTrue(writtenModel.equals(compareModel));
104 * @throws IOException Signals that an I/O exception has occurred.
105 * @throws ApexModelException if there is an Apex error
108 public void testAvroSchema() throws IOException, ApexModelException {
109 new ApexCommandLineEditorMain(avroSchemaArgs);
111 // Read the file from disk
112 final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class);
113 modelReader.setValidateFlag(false);
115 final URL writtenModelUrl = ResourceUtils.getLocalFile(tempAvroModelFile.getCanonicalPath());
116 final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream());
118 final URL compareModelUrl =
119 ResourceUtils.getLocalFile("src/test/resources/compare/AvroSchemaModel_Compare.json");
120 final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream());
122 // Ignore key info UUIDs
123 writtenModel.getKeyInformation().getKeyInfoMap().clear();
124 compareModel.getKeyInformation().getKeyInfoMap().clear();
126 assertTrue(writtenModel.equals(compareModel));