Commit 56367f03 authored by Christian Schudt's avatar Christian Schudt

Tests should retrieve resources from the classpath rather than files.

These tests otherwise may throw FileNotFoundException and are harder to make them run.

Also delete TestUtils.java because it's not needed now anymore.
parent 1c992ebd
......@@ -83,6 +83,7 @@
<property name="test.dest.dir" value="${work.dir}/test"/>
<property name="test.classes.dest.dir" value="${test.dest.dir}/classes"/>
<property name="test.resources.dest.dir" value="${test.dest.dir}/resources"/>
<property name="test.results.dest.dir" value="${test.dest.dir}/results"/>
<property name="plugin.src.dir" value="${src.dir}/plugins"/>
......@@ -662,6 +663,7 @@
<path refid="test.dependencies"/>
<pathelement path="${test.dest.dir}"/>
<pathelement path="${test.classes.dest.dir}"/>
<pathelement path="${test.resources.dest.dir}"/>
</classpath>
<formatter type="xml"/>
......
......@@ -8,11 +8,9 @@
package org.jivesoftware.util;
import java.io.FileInputStream;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Iterator;
import org.dom4j.Element;
import org.jivesoftware.admin.AdminConsole;
......@@ -47,11 +45,9 @@ public class AdminConsoleTest {
@Test
public void testModifyGlobalProps() throws Exception {
// Add a new stream to the AdminConsole:
String filename = TestUtils.prepareFilename(
"./resources/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-01.xml");
InputStream in = new FileInputStream(filename);
AdminConsole.addModel("test1", in);
in.close();
try (InputStream in = getClass().getResourceAsStream("/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-01.xml")) {
AdminConsole.addModel("test1", in);
}
String name = AdminConsole.getAppName();
assertEquals("Foo Bar", name);
String img = AdminConsole.getLogoImage();
......@@ -61,11 +57,9 @@ public class AdminConsoleTest {
@Test
public void testNewTabs() throws Exception {
// Add a new stream to the AdminConsole:
String filename = TestUtils.prepareFilename(
"./resources/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-02.xml");
InputStream in = new FileInputStream(filename);
AdminConsole.addModel("test2", in);
in.close();
try (InputStream in = getClass().getResourceAsStream("/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-02.xml")) {
AdminConsole.addModel("test2", in);
}
Collection tabs = AdminConsole.getModel().selectNodes("//tab");
assertNotNull(tabs);
assertTrue(tabs.size() > 0);
......@@ -86,11 +80,9 @@ public class AdminConsoleTest {
@Test
public void testTabOverwrite() throws Exception {
// Add a new stream to the AdminConsole:
String filename = TestUtils.prepareFilename(
"./resources/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-03.xml");
InputStream in = new FileInputStream(filename);
AdminConsole.addModel("test3", in);
in.close();
try (InputStream in = getClass().getResourceAsStream("/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-03.xml")) {
AdminConsole.addModel("test3", in);
}
boolean found = false;
for (Object o : AdminConsole.getModel().selectNodes("//tab")) {
Element tab = (Element) o;
......
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004-2008 Jive Software. All rights reserved.
*/
package org.jivesoftware.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
/**
* A collection of utilities for test writers. <p>
*
* File methods:
*
* <ul><li>{@link #createTempFile()}</li>
* <li>{@link #createTempFile(String, String)}</li>
* <li>{@link #getAsString(java.io.File)}</li></ul>
*/
public class TestUtils {
/**
* Creates a temp file.
* @see java.io.File#createTempFile(String, String)
*/
public static File createTempFile() throws Exception {
return createTempFile("test", ".test");
}
/**
* Creates a temp file with the given filename suffix and prefix.
* @see java.io.File#createTempFile(String, String)
*/
public static File createTempFile(String prefix, String suffix) throws Exception {
return File.createTempFile(prefix, suffix);
}
/**
* Returns the contents of the given file as a String.
*/
public static String getAsString(File file) throws Exception {
try (BufferedReader in = new BufferedReader(new FileReader(file))) {
StringBuffer xml = new StringBuffer();
String lineSeparator = System.getProperty("line.separator");
if (lineSeparator == null) {
lineSeparator = "\n";
}
String line = null;
while ((line = in.readLine()) != null) {
xml.append(line).append(lineSeparator);
}
return xml.toString();
}
}
public static String prepareFilename(String filename) {
return filename.replace('/', File.separatorChar);
}
}
......@@ -41,8 +41,7 @@ public class XMLPropertiesTest {
@Test
public void testGetProperty() throws Exception {
XMLProperties props = new XMLProperties(
"./resources/org/jivesoftware/util/XMLProperties.test01.xml");
XMLProperties props = new XMLProperties(getClass().getResourceAsStream("XMLProperties.test01.xml"));
assertEquals("123", props.getProperty("foo.bar"));
assertEquals("456", props.getProperty("foo.bar.baz"));
assertNull(props.getProperty("foo"));
......@@ -51,8 +50,7 @@ public class XMLPropertiesTest {
@Test
public void testGetChildPropertiesIterator() throws Exception {
XMLProperties props = new XMLProperties(
"./resources/org/jivesoftware/util/XMLProperties.test02.xml");
XMLProperties props = new XMLProperties(getClass().getResourceAsStream("XMLProperties.test02.xml"));
String[] names = {"a","b","c","d"};
String[] values = {"1","2","3","4"};
String[] children = props.getChildrenProperties("foo.bar");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment