first commit

This commit is contained in:
jomu
2013-02-06 22:06:43 +00:00
parent 1a6d3e4c41
commit aef92c311d
84 changed files with 5334 additions and 0 deletions

View File

@ -0,0 +1,22 @@
package de.muehlencord.shared.network;
import java.net.URL;
import org.apache.log4j.PropertyConfigurator;
import org.junit.BeforeClass;
/**
*
* @author joern@muehlencord.de
*/
public class BaseTest {
/**
* inits logging according to default setup in package
*/
@BeforeClass
public static void initLogging() {
URL defaultConfigUrl = BaseTest.class.getResource("/logging.properties");
PropertyConfigurator.configure(defaultConfigUrl);
}
}

View File

@ -0,0 +1,152 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package de.muehlencord.shared.network.ftp;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
/**
*
* @author jomu
*/
public class FTPConnectionTest {
/** the properties loaded from the config file */
Properties props = null;
/** true, if init is complete to execute test */
boolean initDone = false;
@Before
public void initClass() {
System.out.println("\n[FTPConnectionTest]");
URL testConfigURL = FTPConnectionTest.class.getResource("/test.properties");
FileInputStream fin = null;
try {
File file = new File(testConfigURL.toURI());
props = new Properties();
if ((file == null) || (!file.exists())) {
initDone = false;
} else {
fin = new FileInputStream(file);
props.load(fin);
}
if ((props.containsKey("ftp.host")) && (props.containsKey("ftp.user")) && (props.containsKey("ftp.password")) && (props.containsKey("ftp.locale"))) {
initDone = true;
} else {
initDone = false;
}
} catch (Exception ex) {
initDone = false;
} finally {
try {
if (fin != null) {
fin.close();
}
} catch (IOException ex) {
Logger.getLogger(FTPConnectionTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
/** tests connect / disconnect */
@Test
public void testConnectAndDisconnect() throws FTPConnectionException {
System.out.println("testConnectAndDisconnect");
if (initDone) {
String remoteHost = props.getProperty("ftp.host");
String user = props.getProperty("ftp.user");
String password = props.getProperty("ftp.password");
Locale locale = new Locale(props.getProperty("ftp.locale"));
FTPConnection con = new FTPConnection(remoteHost, user, password, locale);
con.connect();
con.disconnect();
System.out.println("executed successfully");
} else {
System.out.println("Skipped because config is not complete");
}
}
@Test
@Ignore
public void testList() throws FTPConnectionException {
System.out.println("list");
String dir = "";
FTPConnection instance = null;
List expResult = null;
List result = instance.list(dir);
assertEquals(expResult, result);
fail("The test case is a prototype.");
}
@Test
@Ignore
public void testListDirsOnly() throws FTPConnectionException {
System.out.println("listDirsOnly");
String dir = "";
FTPConnection instance = null;
List expResult = null;
List result = instance.listDirsOnly(dir);
assertEquals(expResult, result);
fail("The test case is a prototype.");
}
@Test
@Ignore
public void testListFilesOnly() throws FTPConnectionException {
System.out.println("listFilesOnly");
String dir = "";
FTPConnection instance = null;
List expResult = null;
List result = instance.listFilesOnly(dir);
assertEquals(expResult, result);
fail("The test case is a prototype.");
}
@Test
@Ignore
public void testListLinksOnly() throws FTPConnectionException {
System.out.println("listLinksOnly");
String dir = "";
FTPConnection instance = null;
List expResult = null;
List result = instance.listLinksOnly(dir);
assertEquals(expResult, result);
fail("The test case is a prototype.");
}
@Test
@Ignore
public void testUploadFile() throws FTPConnectionException {
System.out.println("uploadFile");
String localFilename = "";
String remoteFileName = "";
FTPConnection instance = null;
instance.uploadFile(localFilename, remoteFileName);
}
@Test
@Ignore
public void testRename() throws FTPConnectionException {
System.out.println("rename");
String remoteOldName = "";
String remoteNewName = "";
FTPConnection instance = null;
instance.rename(remoteOldName, remoteNewName);
fail("The test case is a prototype.");
}
}

View File

@ -0,0 +1,85 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package de.muehlencord.shared.network.http;
import de.muehlencord.shared.network.BaseTest;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.junit.Ignore;
import org.junit.Test;
/**
*
* @author jomu
*/
public class HttpLayerTest extends BaseTest {
@Test
@Ignore
public void testPostByMap() throws Exception {
System.out.println("testPostByMap");
Map<String, String[]> map = new HashMap<String, String[]>();
String[] value = {"Hello World!", "Hello World again"};
map.put("message", value);
HttpLayer httpLayer = new HttpLayer(
"http://localhost:8080/HttpPostListener/HttpPostListener");
httpLayer.post(map);
}
@Test
@Ignore
public void testPostByMapList() throws Exception {
System.out.println("testPostByMapList");
List<Map<String, String[]>> list = new LinkedList<Map<String, String[]>>();
Map<String, String[]> map = new HashMap<String, String[]>();
String[] value = {"Hello World!", "Hello World again"};
map.put("message", value);
list.add(map);
map = new HashMap<String, String[]>();
String[] urlValue = {"http://localhost:8080/testurl"};
map.put("url", urlValue);
list.add(map);
HttpLayer httpLayer = new HttpLayer("http://localhost:8080/HttpPostListener/HttpPostListener");
httpLayer.post(list);
}
@Test
@Ignore
public void testByValue() throws Exception {
System.out.println("testByValue");
HttpLayer httpLayer = new HttpLayer(
"http://localhost:8080/HttpPostListener/HttpPostListener");
httpLayer.post("message", "Hello World by single parameter");
}
@Test(expected = MessageNotSendException.class)
public void testWithUnknownURL() throws MessageNotSendException {
System.out.println("testWithUnknownURL");
HttpLayer httpLayer = new HttpLayer(
"http://localhost/thisURLDoesNotExist");
httpLayer.post("message", "Hello World by single parameter");
}
@Test(expected = MessageNotSendException.class)
public void testInvalidURL() throws MessageNotSendException {
System.out.println("testInvalidURL");
HttpLayer httpLayer = new HttpLayer("joern@muehlencord.de");
httpLayer.post("message", "Hello World by single parameter");
}
@Test(expected = MessageNotSendException.class)
public void testUnsupportedURL() throws MessageNotSendException {
System.out.println("testUnsupportedURL");
HttpLayer httpLayer = new HttpLayer("ftp://localhost");
httpLayer.post("message", "Hello World by single parameter");
}
}

View File

@ -0,0 +1,43 @@
package de.muehlencord.shared.network.mail;
import de.muehlencord.shared.network.BaseTest;
import de.muehlencord.shared.network.mail.imap.ImapMailReader;
import java.io.File;
import java.net.URL;
import java.util.List;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
/**
*
* @author joern@muehlencord.de
*/
public class MailMessageUtilsTest extends BaseTest {
@Before
public void setup() {
System.out.println ("\n[MailMessageUtilsTest]");
}
@Test
public void testGetInstance() throws Exception {
System.out.println("testGetInstance");
URL testConfigURL = MailMessageUtilsTest.class.getResource("/test.properties");
File file = new File(testConfigURL.toURI());
if ((file == null) || (!file.exists())) {
return; // Skip test if config file is not available
}
String testConfigFile = file.toString();
MailReaderConfiguration config = MailReaderConfigurationFactory.getConfiguration(testConfigFile);
MailReader mr = new ImapMailReader(config);
mr.connect();
List<MailMessage> mm = mr.getMessages("INBOX");
mr.disconnect();
assertNotNull(mm);
assertTrue(mm.size() > 0);
}
}

View File

@ -0,0 +1,78 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package de.muehlencord.shared.network.mail.imap;
import de.muehlencord.shared.network.BaseTest;
import de.muehlencord.shared.network.mail.MailReader;
import de.muehlencord.shared.network.mail.MailReaderConfiguration;
import de.muehlencord.shared.network.mail.MailReaderConnectionException;
import de.muehlencord.shared.network.mail.MailReaderException;
import java.util.List;
import static org.junit.Assert.*;
import org.junit.Test;
/**
*
* @author jomu
*/
public class ImapMailReaderTest extends BaseTest {
/**
* tests the connection of the configured mailbox
*
* @throws Exception if the tests fails
*/
@Test
public void testConnect() throws Exception {
System.out.println("connect");
String meta = "meta.muehlencord.intra";
MailReaderConfiguration config = new MailReaderConfiguration(meta, meta, "jomutest", "jomutest");
MailReader instance = new ImapMailReader(config);
instance.connect();
instance.disconnect();
}
@Test
public void testGetFolder() throws Exception {
System.out.println("getFolder");
String meta = "meta.muehlencord.intra";
MailReaderConfiguration config = new MailReaderConfiguration(meta, meta, "jomutest", "jomutest");
MailReader instance = new ImapMailReader(config);
instance.connect();
String testFolder = "INBOX/test/test1";
String foundFolder = instance.getFolder(testFolder);
assertEquals(testFolder, foundFolder);
instance.disconnect();
}
@Test
public void testGetMessageCount() throws MailReaderConnectionException, MailReaderException {
System.out.println("testGetMessageCount");
String meta = "meta.muehlencord.intra";
MailReaderConfiguration config = new MailReaderConfiguration(meta, meta, "jomutest", "jomutest");
MailReader instance = new ImapMailReader(config);
instance.connect();
int value = instance.getMessageCount("INBOX/test/test1");
assertEquals(3, value);
instance.disconnect();
}
@Test
public void testGetSubFolder() throws MailReaderConnectionException, MailReaderException {
System.out.println("getSubFolder");
String meta = "meta.muehlencord.intra";
MailReaderConfiguration config = new MailReaderConfiguration(meta, meta, "jomutest", "jomutest");
MailReader instance = new ImapMailReader(config);
instance.connect();
List<String> subFolders = instance.getSubFolder("INBOX/test");
assertEquals(2, subFolders.size());
System.out.println(subFolders.toString());
assertTrue(subFolders.contains("INBOX.test.test1"));
assertTrue(subFolders.contains("INBOX.test.test2"));
instance.disconnect();
}
}

View File

@ -0,0 +1,8 @@
log4j.rootLogger=ALL, ConsoleLogger
log4j.debug=false
# ConsoleAppender
log4j.appender.ConsoleLogger=org.apache.log4j.ConsoleAppender
log4j.appender.ConsoleLogger.layout=org.apache.log4j.PatternLayout
log4j.appender.ConsoleLogger.layout.ConversionPattern= %d - %m (%c)%n
log4j.appender.ConsoleLogger.threshold=INFO

View File

@ -0,0 +1,13 @@
## connection to smtp server
smtp.server=meta.muehlencord.intra
## connection to imap server
imap.server=meta.muehlencord.intra
imap.username=jomutest
imap.password=jomutest
## ftp connection data
#ftp.host=
#ftp.user=
#ftp.password=
ftp.locale=en_EN

View File

@ -0,0 +1,15 @@
## connection to smtp server
smtp.server=meta.muehlencord.intra
## connection to imap server
imap.server=meta.muehlencord.intra
#imap.username=jomutest
#imap.password=jomutest
imap.username=jomu
imap.password=fR4vbHuL
## ftp connection data
ftp.host=ftp.bytecamp.net
ftp.user=asverked
ftp.password=76z0fs9Bsx
ftp.locale=en_EN