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 TestFile2File {
38 public void testJsonFileEvents() throws MessagingException, ApexException, IOException {
39 final String[] args = {"src/test/resources/prodcons/File2FileJsonEvent.json"};
41 testFileEvents(args, "src/test/resources/events/EventsOut.json", 48956);
45 public void testXmlFileEvents() throws MessagingException, ApexException, IOException {
46 final String[] args = {"src/test/resources/prodcons/File2FileXmlEvent.json"};
48 testFileEvents(args, "src/test/resources/events/EventsOut.xmlfile", 106739);
51 private void testFileEvents(final String[] args, final String outFilePath, final long expectedFileSize)
52 throws MessagingException, ApexException, IOException {
53 final ApexMain apexMain = new ApexMain(args);
55 final File outFile = new File(outFilePath);
57 while (!outFile.exists()) {
58 ThreadUtilities.sleep(500);
61 // Wait for the file to be filled
64 final String fileString = TextFileUtils.getTextFileAsString(outFilePath).replaceAll("\\s+", "");
65 outFileSize = fileString.length();
66 if (outFileSize > 0 && outFileSize >= expectedFileSize) {
69 ThreadUtilities.sleep(500);
74 assertEquals(outFileSize, expectedFileSize);