Ejemplo n.º 1
0
 @Test
 public void testCtf1() throws IOException {
   try (DataInputStream dataInputStream = streamSimulator.getDataInputStream();
       DataOutputStream dataOutputStream = streamSimulator.getDataOutputStream()) {
     Protocol protocol = new Protocol(dataInputStream, dataOutputStream);
     streamSimulator.writeForInputStream("ROK 1 9");
     protocol.ayt();
     streamSimulator.writeForInputStream("ROK 0 ");
     protocol.sco("test");
     streamSimulator.writeForInputStream("ROK 13 crashed=false");
     protocol.ctt();
     streamSimulator.writeForInputStream("ROK 0 ");
     protocol.swa("test");
     streamSimulator.writeForInputStream("ROK 13 crashed=false");
     ReceiveMessage receiveMessage = protocol.ctf("abc123".getBytes(StandardCharsets.UTF_8));
     Assert.assertEquals(receiveMessage.getCommand(), Command.ROK);
     Assert.assertEquals(
         receiveMessage.getBody(), "crashed=false".getBytes(StandardCharsets.UTF_8));
     Assert.assertEquals(
         streamSimulator.readLastFromOutputStream(),
         "CTF 6 abc123".getBytes(StandardCharsets.UTF_8));
   } catch (ProtocolStateException ignored) {
     Assert.fail();
   }
 }
Ejemplo n.º 2
0
 @Test
 public void testAyt2() throws IOException {
   try (DataInputStream dataInputStream = streamSimulator.getDataInputStream();
       DataOutputStream dataOutputStream = streamSimulator.getDataOutputStream()) {
     Protocol protocol = new Protocol(dataInputStream, dataOutputStream);
     streamSimulator.writeForInputStream("ROK 1 9");
     protocol.ayt();
     streamSimulator.writeForInputStream("ROK 1 9");
     protocol.ayt();
     Assert.fail();
   } catch (ProtocolStateException ignored) {
   }
 }
Ejemplo n.º 3
0
 @Test
 public void testGco1() throws IOException {
   try (DataInputStream dataInputStream = streamSimulator.getDataInputStream();
       DataOutputStream dataOutputStream = streamSimulator.getDataOutputStream()) {
     Protocol protocol = new Protocol(dataInputStream, dataOutputStream);
     streamSimulator.writeForInputStream("ROK 1 9");
     protocol.ayt();
     streamSimulator.writeForInputStream("ROK 11 test1,test2");
     ReceiveMessage receiveMessage = protocol.gco();
     Assert.assertEquals(receiveMessage.getCommand(), Command.ROK);
     Assert.assertEquals(receiveMessage.getBody(), "test1,test2".getBytes(StandardCharsets.UTF_8));
     Assert.assertEquals(
         streamSimulator.readLastFromOutputStream(), "GCO 0 ".getBytes(StandardCharsets.UTF_8));
   } catch (ProtocolStateException ignored) {
     Assert.fail();
   }
 }
Ejemplo n.º 4
0
 @Test
 public void testScp1() throws IOException {
   try (DataInputStream dataInputStream = streamSimulator.getDataInputStream();
       DataOutputStream dataOutputStream = streamSimulator.getDataOutputStream()) {
     Protocol protocol = new Protocol(dataInputStream, dataOutputStream);
     streamSimulator.writeForInputStream("ROK 1 9");
     protocol.ayt();
     streamSimulator.writeForInputStream("ROK 0 ");
     protocol.sco("test");
     streamSimulator.writeForInputStream("ROK 0 ");
     Map<String, String> parameter = new HashMap<>(1);
     parameter.put("testkey1", "testvalue1");
     parameter.put("testkey2", "testvalue2");
     ReceiveMessage receiveMessage = protocol.scp(parameter);
     Assert.assertEquals(receiveMessage.getCommand(), Command.ROK);
     Assert.assertEquals(receiveMessage.getBody(), BYTES);
     Assert.assertEquals(
         streamSimulator.readLastFromOutputStream(),
         ("SCP 39 testkey2=testvalue2," + "testkey1=testvalue1").getBytes(StandardCharsets.UTF_8));
   } catch (ProtocolStateException ignored) {
     Assert.fail();
   }
 }