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;
39 * The Class AvroEventAlbumContextTest.
41 public class AvroEventAlbumContextTest {
44 * Test avro event fields, by starting an engine, send event in, test event out.
46 * @throws IOException Signals that an I/O exception has occurred.
47 * @throws ApexException the apex exception
50 public void testAvroEventAlbumContextTest() throws IOException, ApexException {
51 final File tempCommandFile = File.createTempFile("TestPolicyAvroEventContext", ".apex");
52 final File tempLogFile = File.createTempFile("TestPolicyAvroEventContext", ".log");
53 final File tempModelFile = File.createTempFile("TestPolicyAvroEventContext", ".json");
55 final String javaEventContextString =
56 ResourceUtils.getResourceAsString("examples/scripts/TestPolicyAvroEventContext.apex");
57 TextFileUtils.putStringAsFile(javaEventContextString, tempCommandFile);
59 final String[] cliArgs = new String[] {"-c", tempCommandFile.getCanonicalPath(), "-l",
60 tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath()};
64 new ApexCLIEditorMain(cliArgs);
66 tempCommandFile.delete();
71 final String[] args = new String[] {"-m", tempModelFile.getAbsolutePath(), "-c",
72 "src/test/resources/prodcons/Context_AvroEventAlbum_file2file.json"};
73 final ApexMain apexMain = new ApexMain(args);
74 ThreadUtilities.sleep(1000);
77 ParameterService.clear();
78 // The output event is in this file
79 final File outputEventFile = new File("src/test/resources/events/Context_AvroEventAlbum_EventOut.json");
80 final String outputEventString =
81 TextFileUtils.getTextFileAsString(outputEventFile.getCanonicalPath()).replaceAll("\\s+", "");
83 // We compare the output to what we expect to get
84 final String outputEventCompareString = TextFileUtils
85 .getTextFileAsString("src/test/resources/events/Context_AvroEventAlbum_EventOutCompare.json")
86 .replaceAll("\\s+", "");
88 // Check what we got is what we expected to get
89 assertEquals(outputEventCompareString, outputEventString);
92 tempModelFile.delete();
93 outputEventFile.delete();