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