1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.common;
|
11
|
|
12
|
import static org.junit.Assert.assertNotNull;
|
13
|
|
14
|
import java.io.File;
|
15
|
import java.io.IOException;
|
16
|
import java.io.InputStream;
|
17
|
|
18
|
import org.apache.log4j.Level;
|
19
|
import org.apache.log4j.Logger;
|
20
|
import org.junit.After;
|
21
|
import org.junit.AfterClass;
|
22
|
import org.junit.Assert;
|
23
|
import org.junit.Before;
|
24
|
import org.junit.BeforeClass;
|
25
|
import org.junit.Test;
|
26
|
|
27
|
/**
|
28
|
* @author a.mueller
|
29
|
* @since 22.01.2008
|
30
|
*
|
31
|
*/
|
32
|
public class CdmUtilsTest {
|
33
|
private static final Logger logger = Logger.getLogger(CdmUtilsTest.class);
|
34
|
|
35
|
@BeforeClass
|
36
|
public static void setUpBeforeClass() throws Exception {
|
37
|
}
|
38
|
|
39
|
@AfterClass
|
40
|
public static void tearDownAfterClass() throws Exception {
|
41
|
}
|
42
|
|
43
|
@Before
|
44
|
public void setUp() throws Exception {
|
45
|
}
|
46
|
|
47
|
@After
|
48
|
public void tearDown() throws Exception {
|
49
|
}
|
50
|
|
51
|
/************************** TESTS ****************************************/
|
52
|
|
53
|
@Test
|
54
|
public void testGetReadableResourceStream() {
|
55
|
String resourceFileName = CdmUtils.MUST_EXIST_FILE;
|
56
|
try {
|
57
|
InputStream inputStream = CdmUtils.getReadableResourceStream(resourceFileName);
|
58
|
assertNotNull(inputStream);
|
59
|
} catch (IOException e) {
|
60
|
Assert.fail("IOException");
|
61
|
}
|
62
|
}
|
63
|
|
64
|
@Test
|
65
|
public void testGetFolderSeperator() {
|
66
|
Assert.assertEquals(File.separator, CdmUtils.getFolderSeperator());
|
67
|
}
|
68
|
|
69
|
@Test
|
70
|
public void testGetHomeDir() {
|
71
|
//Assert.assertEquals("", CdmUtils.getHomeDir());
|
72
|
}
|
73
|
|
74
|
@Test
|
75
|
public void testFindLibrary() {
|
76
|
if (logger.isEnabledFor(Level.DEBUG)) {logger.debug(CdmUtils.findLibrary(CdmUtils.class));}
|
77
|
|
78
|
String library = CdmUtils.findLibrary(CdmUtils.class);
|
79
|
String endOfLibrary = "target/classes/eu/etaxonomy/cdm/common/CdmUtils.class";
|
80
|
String libraryContains = "/cdmlib-commons/";
|
81
|
|
82
|
Assert.assertTrue(library.endsWith(endOfLibrary));
|
83
|
Assert.assertTrue(library.contains(libraryContains));
|
84
|
}
|
85
|
|
86
|
/**
|
87
|
* This is a default test for fast running any simple test. It can be overriden and ignored whenever needed.
|
88
|
*/
|
89
|
@Test
|
90
|
public void testAny(){
|
91
|
String str = "Noms vernaculaires:";
|
92
|
if (! str.matches("Nom(s)? vernaculaire(s)?\\:")){
|
93
|
System.out.println("NO");
|
94
|
}
|
95
|
}
|
96
|
|
97
|
@Test
|
98
|
public void testEqualsIgnoreWS(){
|
99
|
String str1 = null;
|
100
|
String str2 = null;
|
101
|
Assert.assertTrue(CdmUtils.equalsIgnoreWS(str1, str2));
|
102
|
|
103
|
str2 = "Any ";
|
104
|
Assert.assertFalse(CdmUtils.equalsIgnoreWS(str1, str2));
|
105
|
|
106
|
str1 = "Any ";
|
107
|
Assert.assertTrue(CdmUtils.equalsIgnoreWS(str1, str2));
|
108
|
|
109
|
str1 = "An y eer";
|
110
|
str2 = "A nye er";
|
111
|
Assert.assertTrue(CdmUtils.equalsIgnoreWS(str1, str2));
|
112
|
|
113
|
str1 = "An y eer";
|
114
|
str2 = "A nyfffe er";
|
115
|
Assert.assertFalse(CdmUtils.equalsIgnoreWS(str1, str2));
|
116
|
|
117
|
}
|
118
|
|
119
|
}
|