Commit c5ffbaee authored by Sven Bunge's avatar Sven Bunge

Migrate junit tests from 3.x to 4.x:

* Use annotations
* Use org.junit.* instead of junit.framework.*
* Small code cleanups
parent 92a75372
package org.jivesoftware.openfire.plugin;
import junit.framework.TestCase;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.XPPReader;
import org.xmlpull.v1.XmlPullParserException;
import org.xmpp.packet.Message;
import org.xmpp.packet.Presence;
import java.io.IOException;
import java.io.StringReader;
import java.util.regex.PatternSyntaxException;
/**
* Basic unit tests for ContentFilter.
*
* @author chayes
*/
public class ContentFilterTest extends TestCase {
private ContentFilter filter;
public static void main(String[] args) {
junit.textui.TestRunner.run(ContentFilterTest.class);
}
/*
* @see TestCase#setUp()
*/
protected void setUp() throws Exception {
filter = new ContentFilter();
}
/*
* @see TestCase#tearDown()
*/
protected void tearDown() throws Exception {
filter.clearMask();
filter.clearPatterns();
filter = null;
}
public void testSetInvalidPatterns() {
try {
filter.setPatterns("$*[");
fail("expected PatternSyntaxException");
} catch (PatternSyntaxException e) {
}
}
public void testSetContentMask() {
assertFalse(filter.isMaskingContent());
filter.setMask("dummy");
assertTrue(filter.isMaskingContent());
filter.clearMask();
assertFalse(filter.isMaskingContent());
}
public void testFilterWithEmptyMessage() {
Message message = new Message();
boolean matched = filter.filter(message);
// no matches should be found
assertFalse(matched);
// message should not have changed
assertEquals(new Message().toXML(), message.toXML());
}
public void testFilterMessageSubject() {
// filter on the word fox
filter.setPatterns("fox");
// test message
Message message = new Message();
message.setSubject("the quick brown fox jumped over the lazy dog");
boolean matched = filter.filter(message);
// matches should be found
assertTrue(matched);
// content has not changed as there is no content mask
assertEquals("the quick brown fox jumped over the lazy dog", message
.getSubject());
assertNull(message.getBody());
}
public void testFilterMessageSubjectWithMask() {
// filter on the word fox
filter.setPatterns("fox");
// set a content mask
filter.setMask("**");
// test message
Message message = new Message();
message.setSubject("the quick brown fox jumped over the lazy dog");
boolean matched = filter.filter(message);
// matches should be found
assertTrue(matched);
// content has changed
assertEquals("the quick brown ** jumped over the lazy dog", message
.getSubject());
assertNull(message.getBody());
}
public void testFilterMessageBody() {
// filter on the word fox
filter.setPatterns("fox");
// test message
Message message = new Message();
message.setBody("the quick brown fox jumped over the lazy dog");
boolean matched = filter.filter(message);
// matches should be found
assertTrue(matched);
// content has not changed as there is no content mask
assertEquals("the quick brown fox jumped over the lazy dog", message
.getBody());
assertNull(message.getSubject());
}
public void testFilterMessageBodyWithMask() {
// filter on the word "fox" and "dog"
filter.setPatterns("fox,dog");
filter.setMask("**");
// test message
Message message = new Message();
message.setBody("the quick brown fox jumped over the lazy dog");
boolean matched = filter.filter(message);
// matches should not be found
assertTrue(matched);
// content has changed
assertEquals("the quick brown ** jumped over the lazy **", message
.getBody());
assertNull(message.getSubject());
}
public void testFilterWholeWords() {
filter.setPatterns("at"); //match every instance of "at" in string
filter.setMask("**");
Message message = new Message();
message.setBody("At noon the fat cats ate lunch at Rizzos");
boolean matched = filter.filter(message);
assertTrue(matched);
assertEquals("At noon the f** c**s **e lunch ** Rizzos", message.getBody());
filter.setPatterns("(?i)\\bat\\b"); //match only whole word instances of "at" ignoring case
message.setBody("At noon the fat cats ate lunch at Rizzos");
matched = filter.filter(message);
assertTrue(matched);
assertEquals("** noon the fat cats ate lunch ** Rizzos", message.getBody());
}
public void testFilterChatMessage() throws DocumentException, IOException, XmlPullParserException {
String chatXML =
"<message to=\"doe@127.0.0.1/Adium\" type=\"chat\" id=\"iChat_E8B5ED64\" from=\"bob@127.0.0.1/frodo\">" +
"<body>fox</body>" +
"<html xmlns=\"http://jabber.org/protocol/xhtml-im\">" +
"<body xmlns=\"http://www.w3.org/1999/xhtml\" style=\"background-color:#E8A630;color:#000000\">fox</body>" +
"</html>" +
"<x xmlns=\"jabber:x:event\">" +
"<composing/>" +
"</x>" +
"</message>";
XPPReader packetReader = new XPPReader();
Document doc = packetReader.read(new StringReader(chatXML));
Message m = new Message(doc.getRootElement());
// filter on the word "fox" and "dog"
filter.setPatterns("fox,dog,message");
filter.setMask("**");
String expectedXML = chatXML.replaceAll("fox", filter.getMask());
// do filter
boolean matched = filter.filter(m);
assertTrue(matched);
assertEquals(expectedXML, expectedXML, m.toXML());
}
public void testFilterAvailablePresence() throws Exception {
// setup available presence
Presence presence = new Presence();
presence.setStatus("fox is now online!");
System.out.println(presence.toXML());
// filter on the word "fox" and "dog"
filter.setPatterns("fox,dog");
filter.setMask("**");
boolean matched = filter.filter(presence);
// matches should not be found
assertTrue(matched);
// content has changed
assertEquals("** is now online!", presence.getStatus());
}
public void testFilterPresenceXML() throws Exception {
String presenceXML =
"<presence from=\"bob@127.0.0.1/frodo\">" +
"<show>away</show>" +
"<status>fox</status>" +
"<priority>0</priority>" +
"<x xmlns=\"vcard-temp:x:update\">" +
"<photo>f9a514f112c0bcb988d5aa12bc1a9a6f22de5262</photo>" +
"</x>" +
"<c xmlns=\"http://jabber.org/protocol/caps\" node=\"apple:ichat:caps\" ver=\"392\" ext=\"avavail maudio mvideo avcap audio\"/>" +
"<x xmlns=\"http://jabber.org/protocol/tune\"/>" +
"</presence>";
XPPReader packetReader = new XPPReader();
Document doc = packetReader.read(new StringReader(presenceXML));
Presence p = new Presence(doc.getRootElement());
// filter on the word "fox" and "dog"
filter.setPatterns("fox,dog,message");
filter.setMask("**");
String expectedXML = presenceXML.replaceAll("fox", filter.getMask());
// do filter
boolean matched = filter.filter(p);
assertTrue(matched);
assertEquals(expectedXML, expectedXML, p.toXML());
}
package org.jivesoftware.openfire.plugin;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.XPPReader;
import org.jdom.filter.ContentFilter;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.xmlpull.v1.XmlPullParserException;
import org.xmpp.packet.Message;
import org.xmpp.packet.Presence;
import java.io.IOException;
import java.io.StringReader;
import java.util.regex.PatternSyntaxException;
import static org.junit.Assert.*;
/**
* Basic unit tests for ContentFilter.
*
* @author chayes
*/
public class ContentFilterTest {
private ContentFilter filter;
public static void main(String[] args) {
junit.textui.TestRunner.run(ContentFilterTest.class);
}
@Before
protected void setUp() throws Exception {
filter = new ContentFilter();
}
@After
protected void tearDown() throws Exception {
filter.clearMask();
filter.clearPatterns();
filter = null;
}
@Test
public void testSetInvalidPatterns() {
try {
filter.setPatterns("$*[");
fail("expected PatternSyntaxException");
} catch (PatternSyntaxException e) {
}
}
@Test
public void testSetContentMask() {
assertFalse(filter.isMaskingContent());
filter.setMask("dummy");
assertTrue(filter.isMaskingContent());
filter.clearMask();
assertFalse(filter.isMaskingContent());
}
@Test
public void testFilterWithEmptyMessage() {
Message message = new Message();
boolean matched = filter.filter(message);
// no matches should be found
assertFalse(matched);
// message should not have changed
assertEquals(new Message().toXML(), message.toXML());
}
@Test
public void testFilterMessageSubject() {
// filter on the word fox
filter.setPatterns("fox");
// test message
Message message = new Message();
message.setSubject("the quick brown fox jumped over the lazy dog");
boolean matched = filter.filter(message);
// matches should be found
assertTrue(matched);
// content has not changed as there is no content mask
assertEquals("the quick brown fox jumped over the lazy dog", message
.getSubject());
assertNull(message.getBody());
}
@Test
public void testFilterMessageSubjectWithMask() {
// filter on the word fox
filter.setPatterns("fox");
// set a content mask
filter.setMask("**");
// test message
Message message = new Message();
message.setSubject("the quick brown fox jumped over the lazy dog");
boolean matched = filter.filter(message);
// matches should be found
assertTrue(matched);
// content has changed
assertEquals("the quick brown ** jumped over the lazy dog", message
.getSubject());
assertNull(message.getBody());
}
@Test
public void testFilterMessageBody() {
// filter on the word fox
filter.setPatterns("fox");
// test message
Message message = new Message();
message.setBody("the quick brown fox jumped over the lazy dog");
boolean matched = filter.filter(message);
// matches should be found
assertTrue(matched);
// content has not changed as there is no content mask
assertEquals("the quick brown fox jumped over the lazy dog", message
.getBody());
assertNull(message.getSubject());
}
@Test
public void testFilterMessageBodyWithMask() {
// filter on the word "fox" and "dog"
filter.setPatterns("fox,dog");
filter.setMask("**");
// test message
Message message = new Message();
message.setBody("the quick brown fox jumped over the lazy dog");
boolean matched = filter.filter(message);
// matches should not be found
assertTrue(matched);
// content has changed
assertEquals("the quick brown ** jumped over the lazy **", message
.getBody());
assertNull(message.getSubject());
}
@Test
public void testFilterWholeWords() {
filter.setPatterns("at"); //match every instance of "at" in string
filter.setMask("**");
Message message = new Message();
message.setBody("At noon the fat cats ate lunch at Rizzos");
boolean matched = filter.filter(message);
assertTrue(matched);
assertEquals("At noon the f** c**s **e lunch ** Rizzos", message.getBody());
filter.setPatterns("(?i)\\bat\\b"); //match only whole word instances of "at" ignoring case
message.setBody("At noon the fat cats ate lunch at Rizzos");
matched = filter.filter(message);
assertTrue(matched);
assertEquals("** noon the fat cats ate lunch ** Rizzos", message.getBody());
}
@Test
public void testFilterChatMessage() throws DocumentException, IOException, XmlPullParserException {
String chatXML =
"<message to=\"doe@127.0.0.1/Adium\" type=\"chat\" id=\"iChat_E8B5ED64\" from=\"bob@127.0.0.1/frodo\">" +
"<body>fox</body>" +
"<html xmlns=\"http://jabber.org/protocol/xhtml-im\">" +
"<body xmlns=\"http://www.w3.org/1999/xhtml\" style=\"background-color:#E8A630;color:#000000\">fox</body>" +
"</html>" +
"<x xmlns=\"jabber:x:event\">" +
"<composing/>" +
"</x>" +
"</message>";
XPPReader packetReader = new XPPReader();
Document doc = packetReader.read(new StringReader(chatXML));
Message m = new Message(doc.getRootElement());
// filter on the word "fox" and "dog"
filter.setPatterns("fox,dog,message");
filter.setMask("**");
String expectedXML = chatXML.replaceAll("fox", filter.getMask());
// do filter
boolean matched = filter.filter(m);
assertTrue(matched);
assertEquals(expectedXML, expectedXML, m.toXML());
}
@Test
public void testFilterAvailablePresence() throws Exception {
// setup available presence
Presence presence = new Presence();
presence.setStatus("fox is now online!");
System.out.println(presence.toXML());
// filter on the word "fox" and "dog"
filter.setPatterns("fox,dog");
filter.setMask("**");
boolean matched = filter.filter(presence);
// matches should not be found
assertTrue(matched);
// content has changed
assertEquals("** is now online!", presence.getStatus());
}
@Test
public void testFilterPresenceXML() throws Exception {
String presenceXML =
"<presence from=\"bob@127.0.0.1/frodo\">" +
"<show>away</show>" +
"<status>fox</status>" +
"<priority>0</priority>" +
"<x xmlns=\"vcard-temp:x:update\">" +
"<photo>f9a514f112c0bcb988d5aa12bc1a9a6f22de5262</photo>" +
"</x>" +
"<c xmlns=\"http://jabber.org/protocol/caps\" node=\"apple:ichat:caps\" ver=\"392\" ext=\"avavail maudio mvideo avcap audio\"/>" +
"<x xmlns=\"http://jabber.org/protocol/tune\"/>" +
"</presence>";
XPPReader packetReader = new XPPReader();
Document doc = packetReader.read(new StringReader(presenceXML));
Presence p = new Presence(doc.getRootElement());
// filter on the word "fox" and "dog"
filter.setPatterns("fox,dog,message");
filter.setMask("**");
String expectedXML = presenceXML.replaceAll("fox", filter.getMask());
// do filter
boolean matched = filter.filter(p);
assertTrue(matched);
assertEquals(expectedXML, expectedXML, p.toXML());
}
}
\ No newline at end of file
package org.jivesoftware.admin;
import junit.framework.TestCase;
import org.junit.Test;
/**
*
*/
public class AuthCheckFilterTest extends TestCase {
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class AuthCheckFilterTest {
// login.jsp,index.jsp?logout=true,setup/index.jsp,setup/setup-,.gif,.png,error-serverdown.jsp
@Test
public void testExcludeRules() {
assertFalse(AuthCheckFilter.testURLPassesExclude("blahblah/login.jsp", "login.jsp"));
assertTrue(AuthCheckFilter.testURLPassesExclude("login.jsp", "login.jsp"));
......
package org.jivesoftware.openfire;
import junit.framework.Assert;
import org.junit.Test;
import org.xmpp.packet.Message;
import org.xmpp.packet.PacketExtension;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* This tests the business rules for storing messages as described in <a href="http://xmpp.org/extensions/xep-0160.html#types">3. Handling of Message Types</a>.
*
......@@ -17,7 +19,7 @@ public class OfflineMessageStoreTest {
// XEP-0160: "groupchat" message types SHOULD NOT be stored offline
Message message = new Message();
message.setType(Message.Type.groupchat);
Assert.assertFalse(OfflineMessageStore.shouldStoreMessage(message));
assertFalse(OfflineMessageStore.shouldStoreMessage(message));
}
@Test
......@@ -25,7 +27,7 @@ public class OfflineMessageStoreTest {
// XEP-0160: "headline" message types SHOULD NOT be stored offline
Message message = new Message();
message.setType(Message.Type.headline);
Assert.assertFalse(OfflineMessageStore.shouldStoreMessage(message));
assertFalse(OfflineMessageStore.shouldStoreMessage(message));
}
@Test
......@@ -33,7 +35,7 @@ public class OfflineMessageStoreTest {
// XEP-0160: "error" message types SHOULD NOT be stored offline,
Message message = new Message();
message.setType(Message.Type.error);
Assert.assertFalse(OfflineMessageStore.shouldStoreMessage(message));
assertFalse(OfflineMessageStore.shouldStoreMessage(message));
}
@Test
......@@ -41,10 +43,10 @@ public class OfflineMessageStoreTest {
// XEP-0160: Messages with a 'type' attribute whose value is "normal" (or messages with no 'type' attribute) SHOULD be stored offline.
Message message = new Message();
message.setType(Message.Type.normal);
Assert.assertTrue(OfflineMessageStore.shouldStoreMessage(message));
assertTrue(OfflineMessageStore.shouldStoreMessage(message));
Message message2 = new Message();
Assert.assertTrue(OfflineMessageStore.shouldStoreMessage(message2));
assertTrue(OfflineMessageStore.shouldStoreMessage(message2));
}
@Test
......@@ -52,7 +54,7 @@ public class OfflineMessageStoreTest {
// XEP-0160: "chat" message types SHOULD be stored offline unless they only contain chat state notifications
Message message = new Message();
message.setType(Message.Type.chat);
Assert.assertFalse(OfflineMessageStore.shouldStoreMessage(message));
assertFalse(OfflineMessageStore.shouldStoreMessage(message));
}
@Test
......@@ -61,7 +63,7 @@ public class OfflineMessageStoreTest {
Message message = new Message();
message.setType(Message.Type.chat);
message.setBody(" ");
Assert.assertTrue(OfflineMessageStore.shouldStoreMessage(message));
assertTrue(OfflineMessageStore.shouldStoreMessage(message));
}
@Test
......@@ -70,7 +72,7 @@ public class OfflineMessageStoreTest {
message.setType(Message.Type.chat);
PacketExtension chatState = new PacketExtension("composing", "http://jabber.org/protocol/chatstates");
message.addExtension(chatState);
Assert.assertFalse(OfflineMessageStore.shouldStoreMessage(message));
assertFalse(OfflineMessageStore.shouldStoreMessage(message));
}
@Test
......@@ -81,6 +83,6 @@ public class OfflineMessageStoreTest {
message.addExtension(chatState);
PacketExtension packetExtension2 = new PacketExtension("received", "urn:xmpp:receipts");
message.addExtension(packetExtension2);
Assert.assertTrue(OfflineMessageStore.shouldStoreMessage(message));
assertTrue(OfflineMessageStore.shouldStoreMessage(message));
}
}
package org.jivesoftware.openfire.carbons;
import junit.framework.Assert;
import org.jivesoftware.openfire.forward.Forwarded;
import org.junit.Test;
import org.xmpp.packet.Message;
import static org.junit.Assert.assertEquals;
/**
* @author Christian Schudt
*/
......@@ -20,7 +21,7 @@ public class MessageCarbonsTest {
Sent sent = new Sent(forwarded);
String xml = sent.getElement().asXML();
Assert.assertEquals("<sent xmlns=\"urn:xmpp:carbons:2\"><forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body></message></forwarded></sent>", xml);
assertEquals("<sent xmlns=\"urn:xmpp:carbons:2\"><forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body></message></forwarded></sent>", xml);
}
@Test
......@@ -33,6 +34,6 @@ public class MessageCarbonsTest {
Received received = new Received(forwarded);
String xml = received.getElement().asXML();
Assert.assertEquals("<received xmlns=\"urn:xmpp:carbons:2\"><forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body></message></forwarded></received>", xml);
assertEquals("<received xmlns=\"urn:xmpp:carbons:2\"><forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body></message></forwarded></received>", xml);
}
}
package org.jivesoftware.openfire.forward;
import junit.framework.Assert;
import org.junit.Test;
import org.xmpp.packet.Message;
import static org.junit.Assert.assertEquals;
/**
* @author Christian Schudt
*/
......@@ -17,6 +18,6 @@ public class ForwardTest {
Forwarded forwarded = new Forwarded(message);
String xml = forwarded.getElement().asXML();
Assert.assertEquals("<forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body></message></forwarded>", xml);
assertEquals("<forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body></message></forwarded>", xml);
}
}
package org.jivesoftware.openfire.handler;
import junit.framework.Assert;
import org.dom4j.Element;
import org.jivesoftware.util.XMPPDateTimeFormat;
import org.junit.Test;
......@@ -12,6 +11,9 @@ import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* @author csh
*/
......@@ -20,16 +22,16 @@ public class IQEntityTimeHandlerTest {
@Test
public void testIQInfo() {
IQEntityTimeHandler iqEntityTimeHandler = new IQEntityTimeHandler();
Assert.assertTrue(iqEntityTimeHandler.getFeatures().hasNext());
Assert.assertEquals(iqEntityTimeHandler.getFeatures().next(), "urn:xmpp:time");
Assert.assertEquals(iqEntityTimeHandler.getInfo().getNamespace(), "urn:xmpp:time");
Assert.assertEquals(iqEntityTimeHandler.getInfo().getName(), "time");
assertTrue(iqEntityTimeHandler.getFeatures().hasNext());
assertEquals(iqEntityTimeHandler.getFeatures().next(), "urn:xmpp:time");
assertEquals(iqEntityTimeHandler.getInfo().getNamespace(), "urn:xmpp:time");
assertEquals(iqEntityTimeHandler.getInfo().getName(), "time");
}
@Test
public void testTimeZone() {
IQEntityTimeHandler iqEntityTimeHandler = new IQEntityTimeHandler();
Assert.assertEquals(iqEntityTimeHandler.formatsTimeZone(TimeZone.getTimeZone("GMT-8:00")), "-08:00");
assertEquals(iqEntityTimeHandler.formatsTimeZone(TimeZone.getTimeZone("GMT-8:00")), "-08:00");
}
@Test
......@@ -39,7 +41,7 @@ public class IQEntityTimeHandlerTest {
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
Assert.assertEquals(iqEntityTimeHandler.getUtcDate(date), DatatypeConverter.printDateTime(calendar));
assertEquals(iqEntityTimeHandler.getUtcDate(date), DatatypeConverter.printDateTime(calendar));
}
@Test
......@@ -67,12 +69,12 @@ public class IQEntityTimeHandlerTest {
IQEntityTimeHandler iqEntityTimeHandler = new IQEntityTimeHandler();
IQ input = new IQ(IQ.Type.get, "1");
IQ result = iqEntityTimeHandler.handleIQ(input);
Assert.assertEquals(result.getChildElement().getName(), "time");
Assert.assertEquals(result.getChildElement().getNamespace().getText(), "urn:xmpp:time");
Assert.assertEquals(result.getChildElement().content().size(), 2);
Assert.assertTrue(result.getChildElement().content().get(0) instanceof Element);
Assert.assertTrue(result.getChildElement().content().get(1) instanceof Element);
Assert.assertEquals(((Element) result.getChildElement().content().get(0)).getName(), "tzo");
Assert.assertEquals(((Element) result.getChildElement().content().get(1)).getName(), "utc");
assertEquals(result.getChildElement().getName(), "time");
assertEquals(result.getChildElement().getNamespace().getText(), "urn:xmpp:time");
assertEquals(result.getChildElement().content().size(), 2);
assertTrue(result.getChildElement().content().get(0) instanceof Element);
assertTrue(result.getChildElement().content().get(1) instanceof Element);
assertEquals(((Element) result.getChildElement().content().get(0)).getName(), "tzo");
assertEquals(((Element) result.getChildElement().content().get(1)).getName(), "utc");
}
}
......@@ -14,21 +14,19 @@ import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Iterator;
import junit.framework.TestCase;
import org.dom4j.Element;
import org.jivesoftware.admin.AdminConsole;
import org.junit.After;
import org.junit.Test;
public class AdminConsoleTest extends TestCase {
public AdminConsoleTest() {
import static org.junit.Assert.*;
}
public class AdminConsoleTest {
/**
* Resets the admin console internal data structures.
*/
@Override
@After
public void tearDown() throws Exception {
Class c = AdminConsole.class;
Method init = c.getDeclaredMethod("load", (Class[])null);
......@@ -36,6 +34,7 @@ public class AdminConsoleTest extends TestCase {
init.invoke((Object)null, (Object[])null);
}
@Test
public void testGetGlobalProps() throws Exception {
String name = AdminConsole.getAppName();
String image = AdminConsole.getLogoImage();
......@@ -43,6 +42,7 @@ public class AdminConsoleTest extends TestCase {
assertEquals("images/header-title.gif", image);
}
@Test
public void testModifyGlobalProps() throws Exception {
// Add a new stream to the AdminConsole:
String filename = TestUtils.prepareFilename(
......@@ -56,6 +56,7 @@ public class AdminConsoleTest extends TestCase {
assertEquals("foo.gif", img);
}
@Test
public void testNewTabs() throws Exception {
// Add a new stream to the AdminConsole:
String filename = TestUtils.prepareFilename(
......@@ -67,8 +68,8 @@ public class AdminConsoleTest extends TestCase {
assertNotNull(tabs);
assertTrue(tabs.size() > 0);
boolean found = false;
for (Iterator iter=tabs.iterator(); iter.hasNext(); ) {
Element tab = (Element)iter.next();
for (Object tab1 : tabs) {
Element tab = (Element) tab1;
if ("foobar".equals(tab.attributeValue("id"))) {
found = true;
assertEquals("Foo Bar", tab.attributeValue("name"));
......@@ -80,6 +81,7 @@ public class AdminConsoleTest extends TestCase {
}
}
@Test
public void testTabOverwrite() throws Exception {
// Add a new stream to the AdminConsole:
String filename = TestUtils.prepareFilename(
......@@ -88,8 +90,8 @@ public class AdminConsoleTest extends TestCase {
AdminConsole.addModel("test3", in);
in.close();
boolean found = false;
for (Iterator tabs=AdminConsole.getModel().selectNodes("//tab").iterator(); tabs.hasNext(); ) {
Element tab = (Element)tabs.next();
for (Object o : AdminConsole.getModel().selectNodes("//tab")) {
Element tab = (Element) o;
if ("server".equals(tab.attributeValue("id"))) {
found = true;
assertEquals("New Server Title", tab.attributeValue("name"));
......
package org.jivesoftware.util;
import java.util.UUID;
import junit.framework.TestCase;
import org.junit.Test;
public class AesEncryptorTest extends TestCase {
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
public class AesEncryptorTest {
@Test
public void testEncryptionUsingDefaultKey() {
......@@ -47,15 +50,10 @@ public class AesEncryptorTest extends TestCase {
@Test
public void testEncryptionForNullString() {
String test = null;
Encryptor encryptor = new AesEncryptor();
String b64Encrypted = encryptor.encrypt(test);
String b64Encrypted = encryptor.encrypt(null);
assertNull(b64Encrypted);
}
}
......@@ -2,11 +2,13 @@ package org.jivesoftware.util;
import java.util.UUID;
import junit.framework.TestCase;
import org.junit.Test;
public class BlowfishEncryptorTest extends TestCase {
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
public class BlowfishEncryptorTest {
@Test
public void testEncryptionUsingDefaultKey() {
......@@ -49,15 +51,10 @@ public class BlowfishEncryptorTest extends TestCase {
@Test
public void testEncryptionForNullString() {
String test = null;
Encryptor encryptor = new Blowfish();
String b64Encrypted = encryptor.encrypt(test);
assertNull(b64Encrypted);
}
Encryptor encryptor = new Blowfish();
String b64Encrypted = encryptor.encrypt(null);
assertNull(b64Encrypted);
}
}
......@@ -5,18 +5,21 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Basic tests for code used by CertificateManager.
*
* @author Gaston Dombiak
*/
public class CertificateTest extends TestCase {
public class CertificateTest {
/**
* Verify that all CN elements are found.
*/
@Test
public void testCN() {
Pattern cnPattern = Pattern.compile("(?i)(cn=)([^,]*)");
String text = "EMAILADDRESS=XXXXX@scifi.com, CN=scifi.com, CN=jabber.scifi.com, OU=Domain validated only, O=XX, L=Skx, C=SE";
......
......@@ -19,22 +19,27 @@
*/
package org.jivesoftware.util;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Simple test of the int enum class.
*
* @author Iain Shigeoka
*/
public class IntEnumTest extends TestCase {
public class IntEnumTest {
/**
* Create a test case with a given name.
*
* @param name The name of the test
* Tests the IntEnum's enforcement of unique int values for each enum type
*/
public IntEnumTest (String name){
super(name);
@Test
public void testStaticEnumUniqueEnforcement(){
IntEnum e = new IntEnum("plain",1);
IntEnum.register(e);
new TestIntEnum("test",1); // auto registers the same value - does it clash with super class?
assertEquals("plain",IntEnum.getEnumFromInt(IntEnum.class,1).getName());
assertEquals("test",TestIntEnum.getTypeFromInt(1).getName());
}
static public class TestIntEnum extends IntEnum{
......@@ -46,14 +51,4 @@ public class IntEnumTest extends TestCase {
return (TestIntEnum) getEnumFromInt(TestIntEnum.class,value);
}
}
/**
* Tests the IntEnum's enforcement of unique int values for each enum type
*/
public void testStaticEnumUniqueEnforcement(){
IntEnum e = new IntEnum("plain",1);
IntEnum.register(e);
new TestIntEnum("test",1); // auto registers the same value - does it clash with super class?
assertEquals("plain",IntEnum.getEnumFromInt(IntEnum.class,1).getName());
assertEquals("test",TestIntEnum.getTypeFromInt(1).getName());
}
}
\ No newline at end of file
......@@ -7,17 +7,21 @@
package org.jivesoftware.util;
import junit.framework.TestCase;
import org.junit.Test;
import org.xmpp.packet.JID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Test cases for the JID class.
*
* @author Gaston Dombiak
*/
public class JIDTest extends TestCase {
public class JIDTest {
@Test
public void testDomain() {
new JID("mycomapny.com");
new JID("wfink-adm");
......@@ -39,6 +43,7 @@ public class JIDTest extends TestCase {
assertTrue("A domain with _ was accepted", failed);
}
@Test
public void testUsernames() {
new JID("john@mycomapny.com");
new JID("john_paul@mycomapny.com");
......@@ -52,6 +57,7 @@ public class JIDTest extends TestCase {
assertTrue("A username with spaces was accepted", failed);
}
@Test
public void testCompare() {
JID jid1 = new JID("john@mycomapny.com");
JID jid2 = new JID("john@mycomapny.com");
......
......@@ -9,15 +9,17 @@
*/
package org.jivesoftware.util;
import junit.framework.TestCase;
import org.jivesoftware.openfire.ldap.LdapManager;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
/**
* @author Daniel Henninger
*/
public class LDAPTest extends TestCase {
public class LDAPTest {
@Test
public void testEncloseDN() {
String before = "ou=Jive Software\\, Inc,dc=support,dc=jive,dc=com";
String after = "ou=\"Jive Software, Inc\",dc=\"support\",dc=\"jive\",dc=\"com\"";
......
......@@ -22,10 +22,14 @@ package org.jivesoftware.util;
import java.io.ByteArrayInputStream;
import junit.framework.TestCase;
import org.junit.Test;
public class XMLPropertiesTest extends TestCase {
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class XMLPropertiesTest {
@Test
public void testAttributes() throws Exception {
String xml = "<root><foo></foo></root>";
XMLProperties props = new XMLProperties(new ByteArrayInputStream(xml.getBytes()));
......@@ -35,6 +39,7 @@ public class XMLPropertiesTest extends TestCase {
assertEquals(props.getAttribute("foo","bar"), "test123");
}
@Test
public void testGetProperty() throws Exception {
XMLProperties props = new XMLProperties(
"./resources/org/jivesoftware/util/XMLProperties.test01.xml");
......@@ -44,6 +49,7 @@ public class XMLPropertiesTest extends TestCase {
assertNull(props.getProperty("nothing.something"));
}
@Test
public void testGetChildPropertiesIterator() throws Exception {
XMLProperties props = new XMLProperties(
"./resources/org/jivesoftware/util/XMLProperties.test02.xml");
......@@ -59,6 +65,7 @@ public class XMLPropertiesTest extends TestCase {
}
}
@Test
public void testGetPropertyWithXMLEntity() throws Exception {
String xml = "<root><foo>foo&amp;bar</foo></root>";
XMLProperties props = new XMLProperties(new ByteArrayInputStream(xml.getBytes()));
......
......@@ -19,26 +19,21 @@
*/
package org.jivesoftware.util;
import junit.framework.TestCase;
import org.junit.Ignore;
import org.junit.Test;
/**
* <p>Test the writing of dom4j documents using the XPP serializer.</p>
*
* @author Iain Shigeoka
*/
public class XPPWriterTest extends TestCase {
/**
* <p>Create a new test with the given name.</p>
*
* @param name The name of the test
*/
public XPPWriterTest(String name){
super(name);
}
public class XPPWriterTest {
/**
* <p>Run a standard config document through a round trip and compare.</p>
*/
@Test
@Ignore
public void testRoundtrip(){
// NOTE: disabling this test case until we get resources working again.
/*
......
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