Skip to content

Commit 564d1f4

Browse files
committed
adding batchprocessing - makes writing tests hopefully a bit easier.
1 parent cc67599 commit 564d1f4

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package net.sharksystem.asap.util;
2+
3+
import net.sharksystem.asap.ASAPException;
4+
import net.sharksystem.cmdline.CmdLineUI;
5+
6+
import java.io.ByteArrayInputStream;
7+
import java.io.ByteArrayOutputStream;
8+
import java.io.IOException;
9+
import java.io.PrintStream;
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
13+
public class Batchprocessor {
14+
private final boolean cleanup;
15+
List<String> cmdList = new ArrayList<>();
16+
17+
public Batchprocessor() {
18+
this(true);
19+
}
20+
21+
public Batchprocessor(boolean cleanup) {
22+
this.cleanup = cleanup;
23+
}
24+
25+
public void addCommand(String cmd) {
26+
this.cmdList.add(cmd);
27+
}
28+
29+
public void execute() throws IOException, ASAPException {
30+
// prepare output
31+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
32+
PrintStream ps = new PrintStream(baos);
33+
34+
for(String cmd : this.cmdList) {
35+
ps.println(cmd);
36+
}
37+
38+
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
39+
40+
CmdLineUI cmdLineUI = new CmdLineUI(System.out, bais);
41+
if(this.cleanup) {
42+
System.out.println("clean asap peers folders");
43+
cmdLineUI.doResetASAPStorages();
44+
}
45+
46+
cmdLineUI.runCommandLoop();
47+
}
48+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package net.sharksystem.asap;
2+
3+
import net.sharksystem.asap.util.Batchprocessor;
4+
import org.junit.Test;
5+
6+
import java.io.IOException;
7+
8+
public class BatchprocessorTest {
9+
@Test
10+
public void basicTest() throws IOException, ASAPException {
11+
Batchprocessor batchprocessor = new Batchprocessor();
12+
batchprocessor.addCommand("newpeer Clara");
13+
14+
batchprocessor.addCommand(
15+
"newapp Clara chat\n" +
16+
"newmessage Clara chat sn2://abChat HiBob");
17+
18+
batchprocessor.execute();
19+
}
20+
}

0 commit comments

Comments
 (0)