Commit e8360311 authored by daryl herzmann's avatar daryl herzmann

Merge pull request #368 from sco0ter/test

Tests should retrieve resources from the classpath rather than files.
parents e46cda93 56367f03
...@@ -83,6 +83,7 @@ ...@@ -83,6 +83,7 @@
<property name="test.dest.dir" value="${work.dir}/test"/> <property name="test.dest.dir" value="${work.dir}/test"/>
<property name="test.classes.dest.dir" value="${test.dest.dir}/classes"/> <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="test.results.dest.dir" value="${test.dest.dir}/results"/>
<property name="plugin.src.dir" value="${src.dir}/plugins"/> <property name="plugin.src.dir" value="${src.dir}/plugins"/>
...@@ -662,6 +663,7 @@ ...@@ -662,6 +663,7 @@
<path refid="test.dependencies"/> <path refid="test.dependencies"/>
<pathelement path="${test.dest.dir}"/> <pathelement path="${test.dest.dir}"/>
<pathelement path="${test.classes.dest.dir}"/> <pathelement path="${test.classes.dest.dir}"/>
<pathelement path="${test.resources.dest.dir}"/>
</classpath> </classpath>
<formatter type="xml"/> <formatter type="xml"/>
......
...@@ -8,11 +8,9 @@ ...@@ -8,11 +8,9 @@
package org.jivesoftware.util; package org.jivesoftware.util;
import java.io.FileInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator;
import org.dom4j.Element; import org.dom4j.Element;
import org.jivesoftware.admin.AdminConsole; import org.jivesoftware.admin.AdminConsole;
...@@ -47,11 +45,9 @@ public class AdminConsoleTest { ...@@ -47,11 +45,9 @@ public class AdminConsoleTest {
@Test @Test
public void testModifyGlobalProps() throws Exception { public void testModifyGlobalProps() throws Exception {
// Add a new stream to the AdminConsole: // Add a new stream to the AdminConsole:
String filename = TestUtils.prepareFilename( try (InputStream in = getClass().getResourceAsStream("/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-01.xml")) {
"./resources/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-01.xml"); AdminConsole.addModel("test1", in);
InputStream in = new FileInputStream(filename); }
AdminConsole.addModel("test1", in);
in.close();
String name = AdminConsole.getAppName(); String name = AdminConsole.getAppName();
assertEquals("Foo Bar", name); assertEquals("Foo Bar", name);
String img = AdminConsole.getLogoImage(); String img = AdminConsole.getLogoImage();
...@@ -61,11 +57,9 @@ public class AdminConsoleTest { ...@@ -61,11 +57,9 @@ public class AdminConsoleTest {
@Test @Test
public void testNewTabs() throws Exception { public void testNewTabs() throws Exception {
// Add a new stream to the AdminConsole: // Add a new stream to the AdminConsole:
String filename = TestUtils.prepareFilename( try (InputStream in = getClass().getResourceAsStream("/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-02.xml")) {
"./resources/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-02.xml"); AdminConsole.addModel("test2", in);
InputStream in = new FileInputStream(filename); }
AdminConsole.addModel("test2", in);
in.close();
Collection tabs = AdminConsole.getModel().selectNodes("//tab"); Collection tabs = AdminConsole.getModel().selectNodes("//tab");
assertNotNull(tabs); assertNotNull(tabs);
assertTrue(tabs.size() > 0); assertTrue(tabs.size() > 0);
...@@ -86,11 +80,9 @@ public class AdminConsoleTest { ...@@ -86,11 +80,9 @@ public class AdminConsoleTest {
@Test @Test
public void testTabOverwrite() throws Exception { public void testTabOverwrite() throws Exception {
// Add a new stream to the AdminConsole: // Add a new stream to the AdminConsole:
String filename = TestUtils.prepareFilename( try (InputStream in = getClass().getResourceAsStream("/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-03.xml")) {
"./resources/org/jivesoftware/admin/AdminConsoleTest.admin-sidebar-03.xml"); AdminConsole.addModel("test3", in);
InputStream in = new FileInputStream(filename); }
AdminConsole.addModel("test3", in);
in.close();
boolean found = false; boolean found = false;
for (Object o : AdminConsole.getModel().selectNodes("//tab")) { for (Object o : AdminConsole.getModel().selectNodes("//tab")) {
Element tab = (Element) o; 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 { ...@@ -41,8 +41,7 @@ public class XMLPropertiesTest {
@Test @Test
public void testGetProperty() throws Exception { public void testGetProperty() throws Exception {
XMLProperties props = new XMLProperties( XMLProperties props = new XMLProperties(getClass().getResourceAsStream("XMLProperties.test01.xml"));
"./resources/org/jivesoftware/util/XMLProperties.test01.xml");
assertEquals("123", props.getProperty("foo.bar")); assertEquals("123", props.getProperty("foo.bar"));
assertEquals("456", props.getProperty("foo.bar.baz")); assertEquals("456", props.getProperty("foo.bar.baz"));
assertNull(props.getProperty("foo")); assertNull(props.getProperty("foo"));
...@@ -51,8 +50,7 @@ public class XMLPropertiesTest { ...@@ -51,8 +50,7 @@ public class XMLPropertiesTest {
@Test @Test
public void testGetChildPropertiesIterator() throws Exception { public void testGetChildPropertiesIterator() throws Exception {
XMLProperties props = new XMLProperties( XMLProperties props = new XMLProperties(getClass().getResourceAsStream("XMLProperties.test02.xml"));
"./resources/org/jivesoftware/util/XMLProperties.test02.xml");
String[] names = {"a","b","c","d"}; String[] names = {"a","b","c","d"};
String[] values = {"1","2","3","4"}; String[] values = {"1","2","3","4"};
String[] children = props.getChildrenProperties("foo.bar"); 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