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.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", "src/test/resources/events/Events0104Out.json"};
44 final long[] expectedFileSizes = {25949, 23007};
46 testFilteredFileEvents(args, outFilePaths, expectedFileSizes);
50 public void testJsonFilteredFileOutEvents() throws MessagingException, ApexException, IOException {
51 final String[] args = {"src/test/resources/prodcons/File2FileFilteredOutJsonEvent.json"};
53 final String[] outFilePaths =
54 {"src/test/resources/events/Events0004Out.json", "src/test/resources/events/Events0104Out.json"};
56 final long[] expectedFileSizes = {25949, 23007};
58 testFilteredFileEvents(args, outFilePaths, expectedFileSizes);
62 public void testJsonFilteredFileInEvents() throws MessagingException, ApexException, IOException {
63 final String[] args = {"src/test/resources/prodcons/File2FileFilteredInJsonEvent.json"};
65 final String[] outFilePaths = {"src/test/resources/events/Events0004Out.json"};
67 final long[] expectedFileSizes = {25949};
69 testFilteredFileEvents(args, outFilePaths, expectedFileSizes);
72 private void testFilteredFileEvents(final String[] args, final String[] outFilePaths,
73 final long[] expectedFileSizes) throws MessagingException, ApexException, IOException {
74 final ApexMain apexMain = new ApexMain(args);
76 final File outFile0 = new File(outFilePaths[0]);
78 while (!outFile0.exists()) {
79 ThreadUtilities.sleep(500);
82 // Wait for the file to be filled
83 long outFile0Size = 0;
84 for (int i = 0; i < 4; i++) {
85 final String fileString = TextFileUtils.getTextFileAsString(outFilePaths[0]).replaceAll("\\s+", "");
86 outFile0Size = fileString.length();
87 if (outFile0Size > 0 && outFile0Size >= expectedFileSizes[0]) {
90 ThreadUtilities.sleep(500);
93 ThreadUtilities.sleep(500);
96 final long[] actualFileSizes = new long[expectedFileSizes.length];
98 for (int i = 0; i < outFilePaths.length; i++) {
99 final String fileString = TextFileUtils.getTextFileAsString(outFilePaths[i]).replaceAll("\\s+", "");
100 actualFileSizes[i] = fileString.length();
101 new File(outFilePaths[i]).delete();
104 for (int i = 0; i < actualFileSizes.length; i++) {
105 assertEquals(actualFileSizes[i], expectedFileSizes[i]);