Changes for checkstyle 8.32
[policy/apex-pdp.git] / auth / cli-editor / src / test / java / org / onap / policy / apex / auth / clieditor / ContextAlbumsTest.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.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
26
27 import java.io.File;
28 import java.io.IOException;
29 import java.net.URL;
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
34 import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;
35 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
36 import org.onap.policy.common.utils.resources.ResourceUtils;
37
38 /**
39  * The Class TestContextAlbums.
40  */
41 public class ContextAlbumsTest {
42     private String[] logicBlockArgs;
43
44     private File tempModelFile;
45
46     /**
47      * Creates the temp files.
48      *
49      * @throws IOException Signals that an I/O exception has occurred.
50      */
51     @Before
52     public void createTempFiles() throws IOException {
53         tempModelFile = File.createTempFile("TestPolicyModel", ".json");
54
55         logicBlockArgs = new String[] {"-c", "src/test/resources/scripts/ContextAlbums.apex", "-o",
56                 tempModelFile.getAbsolutePath(), "-nl"};
57     }
58
59     /**
60      * Removes the generated models.
61      */
62     @After
63     public void removeGeneratedModels() {
64         tempModelFile.delete();
65     }
66
67     /**
68      * Test logic block.
69      *
70      * @throws IOException Signals that an I/O exception has occurred.
71      * @throws ApexModelException if there is an Apex error
72      */
73     @Test
74     public void testLogicBlock() throws IOException, ApexModelException {
75         final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(logicBlockArgs);
76         assertEquals(1, cliEditor.getErrorCount());
77
78         // Read the file from disk
79         final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class);
80         modelReader.setValidateFlag(false);
81
82         final URL writtenModelUrl = ResourceUtils.getLocalFile(tempModelFile.getCanonicalPath());
83         final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream());
84         assertNotNull(writtenModel);
85
86         final URL compareModelUrl =
87                 ResourceUtils.getLocalFile("src/test/resources/compare/ContextAlbumsModel_Compare.json");
88         final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream());
89
90         // Ignore key info UUIDs
91         writtenModel.getKeyInformation().getKeyInfoMap().clear();
92         compareModel.getKeyInformation().getKeyInfoMap().clear();
93
94         assertTrue(writtenModel.equals(compareModel));
95     }
96 }