Praktikum 4: alles wieder grün
This commit is contained in:
parent
5b6b68f9fe
commit
a7cdce30d9
|
@ -19,6 +19,10 @@ public class KlausurenServer {
|
|||
load();
|
||||
|
||||
commands.put("test", ((writer, args) -> writer.write("Hallo Welt")));
|
||||
commands.put("delall", (writer, args) -> {
|
||||
data.clear();
|
||||
save();
|
||||
});
|
||||
commands.put("put", (writer, args) -> {
|
||||
if (args.size() >= 3) {
|
||||
TreeSet<Integer> set = new TreeSet<>();
|
||||
|
|
|
@ -24,6 +24,7 @@ public class KlausurenServerTest {
|
|||
@Test
|
||||
@Order(order = 1)
|
||||
public void test() {
|
||||
sendRequest("delall");
|
||||
assertEquals("Hallo Welt", sendRequest("test"));
|
||||
assertEquals("0", sendRequest("getall"));
|
||||
}
|
||||
|
@ -31,21 +32,22 @@ public class KlausurenServerTest {
|
|||
@Test(timeout = 120L)
|
||||
@Order(order = 2)
|
||||
public void put() {
|
||||
assertEquals("1", sendRequest("put max@maier 6, 5"));
|
||||
assertEquals("15, 6", sendRequest("put max@maier 7,8"));
|
||||
assertEquals("1 ", sendRequest("put max@maier 6, 5"));
|
||||
assertEquals("1 5,6", sendRequest("put max@maier 7,8"));
|
||||
assertEquals("0", sendRequest("put max@maier"));
|
||||
}
|
||||
|
||||
@Test(timeout = 60L)
|
||||
@Order(order = 3)
|
||||
public void getall() {
|
||||
assertEquals("1 [5, 6, 7, 8]", sendRequest("getall"));
|
||||
assertEquals("1 ", sendRequest("put max@baum 5, 6"));
|
||||
assertEquals("1 [5,6],[7,8]", sendRequest("getall"));
|
||||
}
|
||||
|
||||
@Test(timeout = 500L)
|
||||
@Order(order = 4)
|
||||
public void get() {
|
||||
assertEquals("1 5, 6, 7, 8", sendRequest("get max@maier"));
|
||||
assertEquals("1 7,8", sendRequest("get max@maier"));
|
||||
assertEquals("0", sendRequest("get max@müller"));
|
||||
assertEquals("0", sendRequest("get"));
|
||||
assertEquals("0", sendRequest("get max@müller 42"));
|
||||
|
@ -55,21 +57,22 @@ public class KlausurenServerTest {
|
|||
@Order(order = 5)
|
||||
public void del() {
|
||||
assertEquals("0", sendRequest("del max@maier baum"));
|
||||
assertEquals("1 5, 6, 7, 8", sendRequest("del max@maier"));
|
||||
assertEquals("1 7,8", sendRequest("del max@maier"));
|
||||
assertEquals("0", sendRequest("del max@maier"));
|
||||
assertEquals("0", sendRequest("get max@maier"));
|
||||
}
|
||||
@Test(timeout = 2000L)
|
||||
@Order(order = 6)
|
||||
public void saved() throws InterruptedException {
|
||||
assertEquals("1", sendRequest("put max@maier 5, 6, 7, 8"));
|
||||
assertEquals("1 ", sendRequest("put max@maier 5, 6, 7, 8"));
|
||||
assertEquals("1", sendRequest("stop"));
|
||||
//Thread.sleep(1000L);
|
||||
server = new KlausurenServer(6768);
|
||||
Thread.sleep(100L);
|
||||
assertEquals("1 [5, 6, 7, 8]", sendRequest("getall", 6768));
|
||||
assertEquals("1 5, 6, 7, 8", sendRequest("del max@maier", 6768));
|
||||
//sendRequest("stop");
|
||||
assertEquals("1 [5,6,7,8]", sendRequest("getall", 6768));
|
||||
assertEquals("1 5,6,7,8", sendRequest("del max@maier", 6768));
|
||||
assertEquals("1 5,6", sendRequest("del max@baum", 6768));
|
||||
|
||||
}
|
||||
|
||||
private String sendRequest(String command, int port) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package de.joethei.hs.java2.tests;
|
||||
|
||||
import de.joethei.hs.java2.praktikum.praktikum4.KlausurenServer;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
|
@ -20,7 +21,7 @@ public class KlausurenServerTest2 {
|
|||
String line;
|
||||
|
||||
public void opensocket() throws IOException {
|
||||
so = new Socket("localhost", 2000); //Port 2000 wird erwartet!
|
||||
so = new Socket("localhost", 6769); //Port 6769 wird erwartet!
|
||||
ausSo = new PrintWriter(so.getOutputStream(), true);
|
||||
einSo = new BufferedReader(new InputStreamReader(so.getInputStream()));
|
||||
}
|
||||
|
@ -29,9 +30,35 @@ public class KlausurenServerTest2 {
|
|||
so.close();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException {
|
||||
new KlausurenServer(6769);
|
||||
System.out.println("INITIALISIERUNG");
|
||||
opensocket();
|
||||
ausSo.println("del mail1");
|
||||
line = einSo.readLine();
|
||||
closesocket();
|
||||
opensocket();
|
||||
ausSo.println("del mail2");
|
||||
line = einSo.readLine();
|
||||
closesocket();
|
||||
opensocket();
|
||||
ausSo.println("del mail3");
|
||||
line = einSo.readLine();
|
||||
closesocket();
|
||||
opensocket();
|
||||
ausSo.println("del mail4");
|
||||
line = einSo.readLine();
|
||||
closesocket();
|
||||
opensocket();
|
||||
ausSo.println("del mail5");
|
||||
line = einSo.readLine();
|
||||
closesocket();
|
||||
System.out.println("INITIALISIERUNG OK"+"\n");
|
||||
}
|
||||
|
||||
@Test //alles in einer Test-Methode, weil die richtige Reihenfolge sonst nicht gewährleistet ist!
|
||||
public void all() throws IOException {
|
||||
new KlausurenServer(2000);
|
||||
|
||||
System.out.println("TEST: del mail1");
|
||||
opensocket();
|
||||
|
@ -78,7 +105,7 @@ public class KlausurenServerTest2 {
|
|||
closesocket();
|
||||
System.out.println("TEST: OK"+"\n");
|
||||
|
||||
System.out.println("TEST: put mail5 44,45");
|
||||
System.out.println("TEST: put mail4 44,45");
|
||||
opensocket();
|
||||
ausSo.println("put mail5 44,45");
|
||||
line = einSo.readLine();
|
||||
|
@ -161,11 +188,6 @@ public class KlausurenServerTest2 {
|
|||
closesocket();
|
||||
System.out.println("TEST: OK"+"\n");
|
||||
|
||||
opensocket();
|
||||
ausSo.println("del mail2");
|
||||
line = einSo.readLine();
|
||||
closesocket();
|
||||
|
||||
System.out.println("TEST: stop");
|
||||
opensocket();
|
||||
ausSo.println("stop");
|
||||
|
|
Loading…
Reference in New Issue