Changes for checkstyle 8.32
[policy/apex-pdp.git] / auth / cli-editor / src / test / java / org / onap / policy / apex / auth / clieditor / LogicBlockTest.java
1 /*-
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
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
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.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.auth.clieditor;
22
23 import static org.junit.Assert.assertTrue;
24
25 import java.io.File;
26 import java.io.IOException;
27 import java.net.URL;
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;
35
36 // TODO: Auto-generated Javadoc
37 /**
38  * The Class TestLogicBlock.
39  */
40 public class LogicBlockTest {
41     private String[] logicBlockArgs;
42     private String[] avroSchemaArgs;
43
44     private File tempLogicModelFile;
45     private File tempAvroModelFile;
46
47     /**
48      * Creates the temp files.
49      *
50      * @throws IOException Signals that an I/O exception has occurred.
51      */
52     @Before
53     public void createTempFiles() throws IOException {
54         tempLogicModelFile = File.createTempFile("TestLogicPolicyModel", ".json");
55         tempAvroModelFile = File.createTempFile("TestAvroPolicyModel", ".json");
56
57         logicBlockArgs = new String[] {"-c", "src/test/resources/scripts/LogicBlock.apex", "-o",
58                 tempLogicModelFile.getCanonicalPath(), "-if", "true", "-nl"};
59
60         avroSchemaArgs = new String[] {"-c", "src/test/resources/scripts/AvroSchema.apex", "-o",
61                 tempAvroModelFile.getCanonicalPath(), "-nl"};
62     }
63
64     /**
65      * Removes the temp files.
66      */
67     @After
68     public void removeTempFiles() {
69         tempLogicModelFile.delete();
70         tempAvroModelFile.delete();
71     }
72
73     /**
74      * Test logic block.
75      *
76      * @throws IOException Signals that an I/O exception has occurred.
77      * @throws ApexModelException if there is an Apex error
78      */
79     @Test
80     public void testLogicBlock() throws IOException, ApexModelException {
81         new ApexCommandLineEditorMain(logicBlockArgs);
82
83         // Read the file from disk
84         final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class);
85         modelReader.setValidateFlag(false);
86
87         final URL writtenModelUrl = ResourceUtils.getLocalFile(tempLogicModelFile.getCanonicalPath());
88         final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream());
89
90         final URL compareModelUrl =
91                 ResourceUtils.getLocalFile("src/test/resources/compare/LogicBlockModel_Compare.json");
92         final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream());
93
94         // Ignore key info UUIDs
95         writtenModel.getKeyInformation().getKeyInfoMap().clear();
96         compareModel.getKeyInformation().getKeyInfoMap().clear();
97
98         assertTrue(writtenModel.equals(compareModel));
99     }
100
101     /**
102      * Test avro schema.
103      *
104      * @throws IOException Signals that an I/O exception has occurred.
105      * @throws ApexModelException if there is an Apex error
106      */
107     @Test
108     public void testAvroSchema() throws IOException, ApexModelException {
109         new ApexCommandLineEditorMain(avroSchemaArgs);
110
111         // Read the file from disk
112         final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class);
113         modelReader.setValidateFlag(false);
114
115         final URL writtenModelUrl = ResourceUtils.getLocalFile(tempAvroModelFile.getCanonicalPath());
116         final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream());
117
118         final URL compareModelUrl =
119                 ResourceUtils.getLocalFile("src/test/resources/compare/AvroSchemaModel_Compare.json");
120         final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream());
121
122         // Ignore key info UUIDs
123         writtenModel.getKeyInformation().getKeyInfoMap().clear();
124         compareModel.getKeyInformation().getKeyInfoMap().clear();
125
126         assertTrue(writtenModel.equals(compareModel));
127     }
128 }