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.apex.model.utilities.ResourceUtils;
39 public class TestContextAlbums {
40 private String[] logicBlockArgs;
42 private File tempModelFile;
45 public void createTempFiles() throws IOException {
46 tempModelFile = File.createTempFile("TestPolicyModel", ".json");
48 logicBlockArgs = new String[] {
50 "src/test/resources/scripts/ContextAlbums.apex",
52 tempModelFile.getAbsolutePath(),
58 * Removes the generated models.
61 public void removeGeneratedModels() {
62 tempModelFile.delete();
68 * @throws IOException Signals that an I/O exception has occurred.
69 * @throws ApexModelException if there is an Apex error
72 public void testLogicBlock() throws IOException, ApexModelException {
73 final ApexCLIEditorMain cliEditor = new ApexCLIEditorMain(logicBlockArgs);
74 assertEquals(1, cliEditor.getErrorCount());
76 // Read the file from disk
77 final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class);
78 modelReader.setValidateFlag(false);
80 final URL writtenModelURL = ResourceUtils.getLocalFile(tempModelFile.getCanonicalPath());
81 final AxPolicyModel writtenModel = modelReader.read(writtenModelURL.openStream());
82 assertNotNull(writtenModel);
84 final URL compareModelURL = ResourceUtils.getLocalFile("src/test/resources/compare/ContextAlbumsModel_Compare.json");
85 final AxPolicyModel compareModel = modelReader.read(compareModelURL.openStream());
87 // Ignore key info UUIDs
88 writtenModel.getKeyInformation().getKeyInfoMap().clear();
89 compareModel.getKeyInformation().getKeyInfoMap().clear();
91 assertTrue(writtenModel.equals(compareModel));