@Test public void testGco2() throws IOException { try (DataInputStream dataInputStream = streamSimulator.getDataInputStream(); DataOutputStream dataOutputStream = streamSimulator.getDataOutputStream()) { Protocol protocol = new Protocol(dataInputStream, dataOutputStream); protocol.gco(); Assert.fail(); } catch (ProtocolStateException ignored) { } }
@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) { } }
@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(); } }
@Test public void testAyt1() throws IOException { try (DataInputStream dataInputStream = streamSimulator.getDataInputStream(); DataOutputStream dataOutputStream = streamSimulator.getDataOutputStream()) { Protocol protocol = new Protocol(dataInputStream, dataOutputStream); streamSimulator.writeForInputStream("ROK 1 9"); ReceiveMessage receiveMessage = protocol.ayt(); Assert.assertEquals(receiveMessage.getCommand(), Command.ROK); Assert.assertEquals( receiveMessage.getBody(), String.valueOf(9).getBytes(StandardCharsets.UTF_8)); Assert.assertEquals( streamSimulator.readLastFromOutputStream(), "AYT 0 ".getBytes(StandardCharsets.UTF_8)); } catch (ProtocolStateException ignored) { Assert.fail(); } }
@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(); } }
@AfterMethod public void tearDown() throws IOException { streamSimulator.exit(); }
@BeforeMethod public void setUp() throws IOException { streamSimulator = new StreamSimulator(); streamSimulator.init(); }