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;
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Test;
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.ResourceUtils;
37 // TODO: Auto-generated Javadoc
39 * The Class TestLogicBlock.
41 public class LogicBlockTest {
42 private String[] logicBlockArgs;
43 private String[] avroSchemaArgs;
45 private File tempLogicModelFile;
46 private File tempAvroModelFile;
49 * Creates the temp files.
51 * @throws IOException Signals that an I/O exception has occurred.
54 public void createTempFiles() throws IOException {
55 tempLogicModelFile = File.createTempFile("TestLogicPolicyModel", ".json");
56 tempAvroModelFile = File.createTempFile("TestAvroPolicyModel", ".json");
58 logicBlockArgs = new String[] {"-c", "src/test/resources/scripts/LogicBlock.apex", "-o",
59 tempLogicModelFile.getCanonicalPath(), "-if", "true", "-nl"};
61 avroSchemaArgs = new String[] {"-c", "src/test/resources/scripts/AvroSchema.apex", "-o",
62 tempAvroModelFile.getCanonicalPath(), "-nl"};
66 * Removes the temp files.
69 public void removeTempFiles() {
70 tempLogicModelFile.delete();
71 tempAvroModelFile.delete();
77 * @throws IOException Signals that an I/O exception has occurred.
78 * @throws ApexModelException if there is an Apex error
81 public void testLogicBlock() throws IOException, ApexModelException {
82 new ApexCommandLineEditorMain(logicBlockArgs);
84 // Read the file from disk
85 final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class);
86 modelReader.setValidateFlag(false);
88 final URL writtenModelUrl = ResourceUtils.getLocalFile(tempLogicModelFile.getCanonicalPath());
89 final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream());
91 final URL compareModelUrl =
92 ResourceUtils.getLocalFile("src/test/resources/compare/LogicBlockModel_Compare.json");
93 final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream());
95 // Ignore key info UUIDs
96 writtenModel.getKeyInformation().getKeyInfoMap().clear();
97 compareModel.getKeyInformation().getKeyInfoMap().clear();
99 assertTrue(writtenModel.equals(compareModel));
105 * @throws IOException Signals that an I/O exception has occurred.
106 * @throws ApexModelException if there is an Apex error
109 public void testAvroSchema() throws IOException, ApexModelException {
110 new ApexCommandLineEditorMain(avroSchemaArgs);
112 // Read the file from disk
113 final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class);
114 modelReader.setValidateFlag(false);
116 final URL writtenModelUrl = ResourceUtils.getLocalFile(tempAvroModelFile.getCanonicalPath());
117 final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream());
119 final URL compareModelUrl =
120 ResourceUtils.getLocalFile("src/test/resources/compare/AvroSchemaModel_Compare.json");
121 final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream());
123 // Ignore key info UUIDs
124 writtenModel.getKeyInformation().getKeyInfoMap().clear();
125 compareModel.getKeyInformation().getKeyInfoMap().clear();
127 assertTrue(writtenModel.equals(compareModel));