use of org.apache.nifi.processors.standard.relp.frame.RELPFrame in project nifi by apache.
the class TestRELPResponse method testResponseToFrame.
@Test
public void testResponseToFrame() throws IOException {
final long txnr = 123456789;
final int code = RELPResponse.OK;
final String message = "this is a message";
final String data = "this is some data";
final RELPResponse response = new RELPResponse(txnr, code, message, data);
final RELPFrame frame = response.toFrame(StandardCharsets.UTF_8);
Assert.assertEquals(txnr, frame.getTxnr());
Assert.assertEquals(RELPResponse.RSP_CMD, frame.getCommand());
final String result = new String(frame.getData(), StandardCharsets.UTF_8);
final String expected = code + " " + message + "\n" + data;
Assert.assertEquals(expected, result);
Assert.assertEquals(expected.length(), frame.getDataLength());
}
use of org.apache.nifi.processors.standard.relp.frame.RELPFrame in project nifi by apache.
the class TestRELPResponse method testResponseToFrameNoDataNoMessage.
@Test
public void testResponseToFrameNoDataNoMessage() throws IOException {
final long txnr = 123456789;
final int code = RELPResponse.OK;
final RELPResponse response = new RELPResponse(txnr, code);
final RELPFrame frame = response.toFrame(StandardCharsets.UTF_8);
Assert.assertEquals(txnr, frame.getTxnr());
Assert.assertEquals(RELPResponse.RSP_CMD, frame.getCommand());
final String result = new String(frame.getData(), StandardCharsets.UTF_8);
final String expected = code + "";
Assert.assertEquals(expected, result);
Assert.assertEquals(expected.length(), frame.getDataLength());
}
use of org.apache.nifi.processors.standard.relp.frame.RELPFrame in project nifi by apache.
the class TestRELPResponse method testCreateOpenResponse.
@Test
public void testCreateOpenResponse() {
final long txnr = 123456789;
final Map<String, String> offers = new HashMap<>();
offers.put("key1", "val1");
offers.put("key2", "val2");
final RELPResponse openResponse = RELPResponse.open(txnr, offers);
final RELPFrame frame = openResponse.toFrame(StandardCharsets.UTF_8);
Assert.assertEquals(txnr, frame.getTxnr());
Assert.assertEquals(RELPResponse.RSP_CMD, frame.getCommand());
final String result = new String(frame.getData(), StandardCharsets.UTF_8);
final String expected1 = RELPResponse.OK + " OK\n" + "key1=val1\nkey2=val2";
final String expected2 = RELPResponse.OK + " OK\n" + "key2=val2\nkey1=val1";
Assert.assertTrue(result.equals(expected1) || result.equals(expected2));
Assert.assertEquals(expected1.length(), frame.getDataLength());
}
use of org.apache.nifi.processors.standard.relp.frame.RELPFrame in project nifi by apache.
the class TestRELPResponse method testResponseToFrameNoMessage.
@Test
public void testResponseToFrameNoMessage() throws IOException {
final long txnr = 123456789;
final int code = RELPResponse.OK;
final String data = "this is some data";
final RELPResponse response = new RELPResponse(txnr, code, null, data);
final RELPFrame frame = response.toFrame(StandardCharsets.UTF_8);
Assert.assertEquals(txnr, frame.getTxnr());
Assert.assertEquals(RELPResponse.RSP_CMD, frame.getCommand());
final String result = new String(frame.getData(), StandardCharsets.UTF_8);
final String expected = code + "\n" + data;
Assert.assertEquals(expected, result);
Assert.assertEquals(expected.length(), frame.getDataLength());
}
use of org.apache.nifi.processors.standard.relp.frame.RELPFrame in project nifi by apache.
the class TestRELPResponse method testResponseToFrameNoData.
@Test
public void testResponseToFrameNoData() throws IOException {
final long txnr = 123456789;
final int code = RELPResponse.OK;
final String message = "this is a message";
final RELPResponse response = new RELPResponse(txnr, code, message, null);
final RELPFrame frame = response.toFrame(StandardCharsets.UTF_8);
Assert.assertEquals(txnr, frame.getTxnr());
Assert.assertEquals(RELPResponse.RSP_CMD, frame.getCommand());
final String result = new String(frame.getData(), StandardCharsets.UTF_8);
final String expected = code + " " + message;
Assert.assertEquals(expected, result);
Assert.assertEquals(expected.length(), frame.getDataLength());
}
Aggregations