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.apps.uservice.test.context;
23 import static org.junit.Assert.assertEquals;
26 import java.io.IOException;
28 import org.junit.Test;
29 import org.onap.policy.apex.auth.clieditor.ApexCLIEditorMain;
30 import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
31 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
32 import org.onap.policy.apex.model.basicmodel.service.ModelService;
33 import org.onap.policy.apex.model.basicmodel.service.ParameterService;
34 import org.onap.policy.apex.model.utilities.ResourceUtils;
35 import org.onap.policy.apex.model.utilities.TextFileUtils;
36 import org.onap.policy.apex.service.engine.main.ApexMain;
38 public class JavaEventAlbumContextTest {
40 public void testJavaEventAlbumContextTest() throws IOException, ApexException {
41 final File tempCommandFile = File.createTempFile("TestPolicyJavaEventContext", ".apex");
42 final File tempLogFile = File.createTempFile("TestPolicyJavaEventContext", ".log");
43 final File tempModelFile = File.createTempFile("TestPolicyJavaEventContext", ".json");
45 final String javaEventContextString =
46 ResourceUtils.getResourceAsString("examples/scripts/TestPolicyJavaEventContext.apex");
47 TextFileUtils.putStringAsFile(javaEventContextString, tempCommandFile);
49 final String[] cliArgs = new String[] {"-c", tempCommandFile.getCanonicalPath(), "-l",
50 tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath()};
54 new ApexCLIEditorMain(cliArgs);
56 tempCommandFile.delete();
61 final String[] args = new String[] {"-m", tempModelFile.getAbsolutePath(), "-c",
62 "src/test/resources/prodcons/Context_JavaEventAlbum_file2file.json"};
63 final ApexMain apexMain = new ApexMain(args);
64 ThreadUtilities.sleep(1000);
66 ParameterService.clear();
68 // The output event is in this file
69 final File outputEventFile = new File("src/test/resources/events/Context_JavaEventAlbum_EventOut.json");
70 final String actualFileContent = TextFileUtils.getTextFileAsString(outputEventFile.getCanonicalPath());
71 final String outputEventString = actualFileContent.replaceAll("\\s+", "");
73 // We compare the output to what we expect to get
74 final String expectedFileContent = TextFileUtils
75 .getTextFileAsString("src/test/resources/events/Context_JavaEventAlbum_EventOutCompare.json");
76 final String outputEventCompareString = expectedFileContent.replaceAll("\\s+", "");
78 assertEquals(outputEventCompareString, outputEventString);
80 tempModelFile.delete();
81 outputEventFile.delete();