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.testsuites.integration.uservice.adapt.file;
23 import static org.junit.Assert.assertEquals;
26 import java.io.IOException;
28 import org.junit.Test;
29 import org.onap.policy.apex.core.infrastructure.messaging.MessagingException;
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.utilities.TextFileUtils;
33 import org.onap.policy.apex.service.engine.main.ApexMain;
35 public class TestFile2FileFiltered {
38 public void testJsonFilteredFileInOutEvents() throws MessagingException, ApexException, IOException {
39 final String[] args = {"src/test/resources/prodcons/File2FileFilteredInOutJsonEvent.json"};
41 final String[] outFilePaths = {
42 "src/test/resources/events/Events0004Out.json",
43 "src/test/resources/events/Events0104Out.json"
46 final long[] expectedFileSizes = {25949, 23007};
48 testFilteredFileEvents(args, outFilePaths, expectedFileSizes);
52 public void testJsonFilteredFileOutEvents() throws MessagingException, ApexException, IOException {
53 final String[] args = {"src/test/resources/prodcons/File2FileFilteredOutJsonEvent.json"};
55 final String[] outFilePaths = {
56 "src/test/resources/events/Events0004Out.json",
57 "src/test/resources/events/Events0104Out.json"
60 final long[] expectedFileSizes = {25949, 23007};
62 testFilteredFileEvents(args, outFilePaths, expectedFileSizes);
66 public void testJsonFilteredFileInEvents() throws MessagingException, ApexException, IOException {
67 final String[] args = {"src/test/resources/prodcons/File2FileFilteredInJsonEvent.json"};
69 final String[] outFilePaths = {"src/test/resources/events/Events0004Out.json"};
71 final long[] expectedFileSizes = {25949};
73 testFilteredFileEvents(args, outFilePaths, expectedFileSizes);
76 private void testFilteredFileEvents(final String[] args, final String[] outFilePaths,
77 final long[] expectedFileSizes) throws MessagingException, ApexException, IOException {
78 final ApexMain apexMain = new ApexMain(args);
80 final File outFile0 = new File(outFilePaths[0]);
82 while (!outFile0.exists()) {
83 ThreadUtilities.sleep(500);
86 // Wait for the file to be filled
87 long outFile0Size = 0;
88 for (int i = 0; i < 4; i++) {
89 final String fileString = TextFileUtils.getTextFileAsString(outFilePaths[0]).replaceAll("\\s+", "");
90 outFile0Size = fileString.length();
91 if (outFile0Size > 0 && outFile0Size >= expectedFileSizes[0]) {
94 ThreadUtilities.sleep(500);
97 ThreadUtilities.sleep(500);
100 final long[] actualFileSizes = new long[expectedFileSizes.length];
102 for (int i = 0; i < outFilePaths.length; i++) {
103 final String fileString = TextFileUtils.getTextFileAsString(outFilePaths[i]).replaceAll("\\s+", "");
104 actualFileSizes[i] = fileString.length();
105 new File(outFilePaths[i]).delete();
108 for (int i = 0; i < actualFileSizes.length; i++) {
109 assertEquals(actualFileSizes[i], expectedFileSizes[i]);