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;
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
35 import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;
36 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
37 import org.onap.policy.common.utils.resources.ResourceUtils;
40 * The Class TestContextAlbums.
42 public class ContextAlbumsTest {
43 private String[] logicBlockArgs;
45 private File tempModelFile;
48 * Creates the temp files.
50 * @throws IOException Signals that an I/O exception has occurred.
53 public void createTempFiles() throws IOException {
54 tempModelFile = File.createTempFile("TestPolicyModel", ".json");
56 logicBlockArgs = new String[] {"-c", "src/test/resources/scripts/ContextAlbums.apex", "-o",
57 tempModelFile.getAbsolutePath(), "-nl"};
61 * Removes the generated models.
64 public void removeGeneratedModels() {
65 tempModelFile.delete();
71 * @throws IOException Signals that an I/O exception has occurred.
72 * @throws ApexModelException if there is an Apex error
75 public void testLogicBlock() throws IOException, ApexModelException {
76 final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(logicBlockArgs);
77 assertEquals(1, cliEditor.getErrorCount());
79 // Read the file from disk
80 final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class);
81 modelReader.setValidateFlag(false);
83 final URL writtenModelUrl = ResourceUtils.getLocalFile(tempModelFile.getCanonicalPath());
84 final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream());
85 assertNotNull(writtenModel);
87 final URL compareModelUrl =
88 ResourceUtils.getLocalFile("src/test/resources/compare/ContextAlbumsModel_Compare.json");
89 final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream());
91 // Ignore key info UUIDs
92 writtenModel.getKeyInformation().getKeyInfoMap().clear();
93 compareModel.getKeyInformation().getKeyInfoMap().clear();
95 assertTrue(writtenModel.equals(compareModel));