c952d73b5365b220b19f85da88ef40630c5546cd
[policy/apex-pdp.git] /
1 /*-
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
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
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.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.apps.uservice.test.adapt.file;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.io.File;
26 import java.io.IOException;
27
28 import org.onap.policy.apex.core.infrastructure.messaging.MessagingException;
29 import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
30 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
31 import org.onap.policy.apex.model.utilities.TextFileUtils;
32 import org.onap.policy.apex.service.engine.main.ApexMain;
33
34 public class TestFile2FileIgnore {
35
36     // This test is used just to bring up an instance of Apex for manual testing and demonstrations
37     // It should always be ignored in automated testing because it holds Apex up for a very long
38     // time
39     public static void main(final String[] args) throws MessagingException, ApexException, IOException {
40         final String[] apexArgs = {"src/test/resources/prodcons/File2FileJsonEvent.json"};
41
42         testFileEvents(apexArgs, "src/test/resources/events/EventsOut.json", 48656);
43     }
44
45     private static void testFileEvents(final String[] args, final String outFilePath, final long expectedFileSize)
46             throws MessagingException, ApexException, IOException {
47         final ApexMain apexMain = new ApexMain(args);
48
49         final File outFile = new File(outFilePath);
50
51         while (!outFile.exists()) {
52             ThreadUtilities.sleep(500);
53         }
54
55         // Wait for the file to be filled
56         long outFileSize = 0;
57         while (true) {
58             final String fileString = TextFileUtils.getTextFileAsString(outFilePath).replaceAll("\\s+", "");
59             outFileSize = fileString.length();
60             if (outFileSize > 0 && outFileSize >= expectedFileSize) {
61                 break;
62             }
63             ThreadUtilities.sleep(500);
64         }
65
66         // Here's the long time I was talking about above!
67         ThreadUtilities.sleep(100000000);
68
69         apexMain.shutdown();
70         outFile.delete();
71         assertEquals(outFileSize, expectedFileSize);
72     }
73 }
74
75