Permalink
Browse files

Added simple test for base server

  • Loading branch information...
1 parent c496f74 commit bfce1a8bf664ddd1802337a7bfd106fd2e0fd624 @horstmeier committed Aug 17, 2013
Showing with 65 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +61 −0 src/test/java/com/horstmeier/java/tftp/TFTPBaseServerTest.java
View
@@ -1 +1,5 @@
target/
+# Intellij
+.idea/
+*.iml
+*.iws
@@ -0,0 +1,61 @@
+package com.horstmeier.java.tftp;
+
+import com.horstmeier.java.tftp.interfaces.IFileNameMapper;
+import org.apache.commons.net.tftp.TFTPClient;
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+
+import java.io.*;
+
+/**
+ * Created by jens on 17.08.13.
+ */
+public class TFTPBaseServerTest {
+
+ class TestFileMapperRead implements IFileNameMapper {
+
+ @Override
+ public InputStream openInputStream(String fileName) throws IOException {
+ if (fileName.equals("$#")) {
+ return new ByteArrayInputStream("Hello World".getBytes());
+ }
+ throw new IOException("Illegal file name");
+ }
+
+ @Override
+ public OutputStream openOutputStream(String fileName) throws IOException {
+ throw new IOException("Illegal operation");
+ }
+
+ @Override
+ public boolean canRead() {
+ return true;
+ }
+
+ @Override
+ public boolean canWrite() {
+ return false;
+ }
+ }
+
+ public void setUp() throws Exception {
+
+ }
+
+ public void tearDown() throws Exception {
+
+ }
+
+ public void testBaseServer() throws Exception
+ {
+ Logger.getRootLogger().addAppender(new ConsoleAppender(new PatternLayout()));
+ TFTPBaseServer baseServer = new TFTPBaseServer(new TestFileMapperRead(), 8088);
+ TFTPClient client = new TFTPClient();
+ client.open();
+ ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
+ client.receiveFile("$#", 1, os, "localhost", 8088);
+ assert os.toString().equals("Hello World");
+ baseServer.shutdown();
+ }
+}

0 comments on commit bfce1a8

Please sign in to comment.