-
Notifications
You must be signed in to change notification settings - Fork 664
Expand file tree
/
Copy pathFileUtilTest.java
More file actions
103 lines (90 loc) · 3.48 KB
/
Copy pathFileUtilTest.java
File metadata and controls
103 lines (90 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*******************************************************************************
* Copyright (c) quickfixengine.org All rights reserved.
*
* This file is part of the QuickFIX FIX Engine
*
* This file may be distributed under the terms of the quickfixengine.org
* license as defined by quickfixengine.org and appearing in the file
* LICENSE included in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* See http://www.quickfixengine.org/LICENSE for licensing information.
*
* Contact ask@quickfixengine.org if any conditions of this licensing
* are not clear to you.
******************************************************************************/
package quickfix;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.InputStream;
import java.net.Socket;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FileUtilTest {
private final Logger log = LoggerFactory.getLogger(getClass());
@Test
public void testFileLocation() throws Exception {
// Tests that FileUtil.open can find a file in parent directory
InputStream in = FileUtil.open(null, "../LICENSE");
assertNotNull("File not found", in);
in.close();
}
@Test
public void testClassResourceLocation() throws Exception {
InputStream in = FileUtil.open(Message.class, "FixVersions.class");
assertNotNull("Resource not found", in);
in.close();
}
@Test
public void testClassLoaderResourceLocation() throws Exception {
InputStream in = FileUtil.open(Message.class, "quickfix/test/acceptance/definitions/client/Normal.def");
assertNotNull("Resource not found", in);
in.close();
}
@Test
public void testURLLocation() throws Exception {
// Assumption: Internet access
if (isInternetAccessible()) {
InputStream in = FileUtil.open(Message.class, "http://www.quickfixj.org/");
if (in != null) {
in.close();
}
assertNotNull("Resource not found", in);
}
}
@Test
public void testJARURLLocation() throws Exception {
// just test that we don't run into a ClassCastException
InputStream in = FileUtil.open(Message.class, "jar:file:/foo.bar!/");
if (in != null) {
in.close();
}
}
@Test
// QFJ-775
public void testSessionIDFileName() {
SessionID sessionID = new SessionID(FixVersions.BEGINSTRING_FIX44, "SENDER???",
"bla_/--/#()_bla", "!!!TARGET", "foo::bar");
String sessionIdFileName = FileUtil.sessionIdFileName(sessionID);
assertEquals("FIX.4.4-SENDER____bla__--_____bla-___TARGET_foo__bar", sessionIdFileName);
assertTrue(sessionIdFileName.matches("[a-zA-Z0-9-._]*"));
sessionID = new SessionID(FixVersions.BEGINSTRING_FIX44, "SENDER", "TARGET");
sessionIdFileName = FileUtil.sessionIdFileName(sessionID);
assertEquals("FIX.4.4-SENDER-TARGET", sessionIdFileName);
}
private boolean isInternetAccessible() {
try {
Socket socket = new Socket("www.quickfixj.org", 80);
socket.close();
return true;
} catch (Exception e) {
log.warn("No internet access");
}
return false;
}
}