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.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
28 import java.io.IOException;
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;
39 * The Class TestContextAlbums.
41 public class ContextAlbumsTest {
42 private String[] logicBlockArgs;
44 private File tempModelFile;
47 * Creates the temp files.
49 * @throws IOException Signals that an I/O exception has occurred.
52 public void createTempFiles() throws IOException {
53 tempModelFile = File.createTempFile("TestPolicyModel", ".json");
55 logicBlockArgs = new String[] {"-c", "src/test/resources/scripts/ContextAlbums.apex", "-o",
56 tempModelFile.getAbsolutePath(), "-nl"};
60 * Removes the generated models.
63 public void removeGeneratedModels() {
64 tempModelFile.delete();
70 * @throws IOException Signals that an I/O exception has occurred.
71 * @throws ApexModelException if there is an Apex error
74 public void testLogicBlock() throws IOException, ApexModelException {
75 final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(logicBlockArgs);
76 assertEquals(1, cliEditor.getErrorCount());
78 // Read the file from disk
79 final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class);
80 modelReader.setValidateFlag(false);
82 final URL writtenModelUrl = ResourceUtils.getLocalFile(tempModelFile.getCanonicalPath());
83 final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream());
84 assertNotNull(writtenModel);
86 final URL compareModelUrl =
87 ResourceUtils.getLocalFile("src/test/resources/compare/ContextAlbumsModel_Compare.json");
88 final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream());
90 // Ignore key info UUIDs
91 writtenModel.getKeyInformation().getKeyInfoMap().clear();
92 compareModel.getKeyInformation().getKeyInfoMap().clear();
94 assertTrue(writtenModel.equals(compareModel));