/
AbstractITCase.java
105 lines (87 loc) · 3.64 KB
/
AbstractITCase.java
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
104
105
/*
* R Service Bus
*
* Copyright (c) Copyright of OpenAnalytics BVBA, 2010-2014
*
* ===========================================================================
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.openanalytics.rsb;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.custommonkey.xmlunit.NamespaceContext;
import org.custommonkey.xmlunit.SimpleNamespaceContext;
import org.custommonkey.xmlunit.XMLUnit;
import org.junit.Before;
import eu.openanalytics.rsb.config.Configuration;
/**
* @author "OpenAnalytics <rsb.development@openanalytics.eu>"
*/
public abstract class AbstractITCase {
protected static final String TEST_APPLICATION_NAME_PREFIX = "rsb_it_";
protected final static String RSB_BASE_URI = "http://localhost:8888/rsb";
@Before
public void setupXmlNameSpaces() {
final Map<String, String> m = new HashMap<String, String>();
m.put("rsb", "http://rest.rsb.openanalytics.eu/types");
final NamespaceContext ctx = new SimpleNamespaceContext(m);
XMLUnit.setXpathNamespaceContext(ctx);
}
protected Configuration getConfiguration() {
return SuiteITCase.configuration;
}
protected Properties getRawMessages() {
return SuiteITCase.rawMessages;
}
public static InputStream getTestData(final String payloadResourceFile) {
return Thread.currentThread().getContextClassLoader().getResourceAsStream("data/" + payloadResourceFile);
}
public static File getTestFile(final String payloadResourceFile) {
try {
return new File(Thread.currentThread().getContextClassLoader().getResource("data/" + payloadResourceFile).toURI());
} catch (final URISyntaxException urise) {
throw new RuntimeException(urise);
}
}
public static void validateZipResult(final InputStream responseStream) throws IOException {
final ZipInputStream result = new ZipInputStream(responseStream);
ZipEntry ze = null;
while ((ze = result.getNextEntry()) != null) {
if (ze.getName().endsWith(".pdf")) {
return;
}
}
fail("No PDF file found in Zip result");
}
public static void validateErrorResult(final InputStream responseStream) throws IOException {
final String response = IOUtils.toString(responseStream);
assertTrue(response + " should contain 'error'", StringUtils.containsIgnoreCase(response, "error"));
}
protected String newTestApplicationName() {
return TEST_APPLICATION_NAME_PREFIX + RandomStringUtils.randomAlphanumeric(20);
}
}