Search in sources :

Example 1 with CameraMessage

use of com.robo4j.core.httpunit.codec.CameraMessage in project robo4j by Robo4J.

the class RaspistillUnit method createImage.

// Private Methods
private void createImage() {
    final CameraMessage cameraMessage = new CameraMessage(FORMAT_IMAGE, DEFAULT, executeCommand(cameraCommand));
    final String message = codec.encode(cameraMessage);
    if (cameraMessage.getImage().length() != Constants.DEFAULT_VALUE_0) {
        final String postMessage = RoboHttpUtils.createPostRequest(client, clientUri, message);
        sendClientMessage(getContext(), postMessage);
    }
}
Also used : CameraMessage(com.robo4j.core.httpunit.codec.CameraMessage)

Example 2 with CameraMessage

use of com.robo4j.core.httpunit.codec.CameraMessage in project robo4j by Robo4J.

the class TestClientImageController method createImage.

// Private Methods
private void createImage() {
    final CameraMessage cameraMessage = new CameraMessage("jpg", "default", getSampleImage(cameraCommand));
    // "default", getSampleImage(cameraCommand));
    final String message = codec.encode(cameraMessage);
    if (cameraMessage.getImage().length() != 0) {
        final String postMessage = RoboHttpUtils.createPostRequest(client, clientUri, message);
        sendClientMessage(getContext(), postMessage);
    }
}
Also used : CameraMessage(com.robo4j.core.httpunit.codec.CameraMessage)

Example 3 with CameraMessage

use of com.robo4j.core.httpunit.codec.CameraMessage in project robo4j by Robo4J.

the class HttpUnitTests method testHttpCameraRealMessageImage.

@Test
public void testHttpCameraRealMessageImage() throws Exception {
    String encodedImage = HttpUnitHelperMain.getExampleCamera();
    final String jsonCammeraMessageCorrupted = "{ \"type\"  :  \"jpg\" ,  \"value\"   :  \"description\"  ,\"image\":\"" + encodedImage + "\"}";
    final String jsonCammeraMessage = "{\"type\":\"jpg\",\"value\":\"description\",\"image\":\"" + encodedImage + "\"}";
    HttpCodecRegistry registry = new HttpCodecRegistry("com.robo4j.core.httpunit.codec");
    HttpEncoder<CameraMessage> encoder = registry.getEncoder(CameraMessage.class);
    HttpDecoder<CameraMessage> decoder = registry.getDecoder(CameraMessage.class);
    Assert.assertNotNull(encoder);
    Assert.assertNotNull(decoder);
    CameraMessage cameraMessage = new CameraMessage("jpg", "description", encodedImage);
    String encoded = encoder.encode(cameraMessage);
    CameraMessage decoded = decoder.decode(jsonCammeraMessageCorrupted);
    final byte[] imageDecoded = Base64.getDecoder().decode(decoded.getImage());
    Assert.assertEquals(jsonCammeraMessage, encoded);
    Assert.assertEquals(cameraMessage.getType(), decoded.getType());
    Assert.assertEquals(cameraMessage.getValue(), decoded.getValue());
    Assert.assertNotNull(imageDecoded);
    Assert.assertTrue(imageDecoded.length > 0);
}
Also used : CameraMessage(com.robo4j.core.httpunit.codec.CameraMessage) Test(org.junit.Test)

Example 4 with CameraMessage

use of com.robo4j.core.httpunit.codec.CameraMessage in project robo4j by Robo4J.

the class HttpUnitTests method testHttpCameraMessage.

@Test
public void testHttpCameraMessage() {
    final String jsonCammeraMessageCorrupted = "{ \"type\"  :  \"jpg\" ,  \"value\"   :  \"description\"  ,\"image\":\"12345\"}";
    final String jsonCammeraMessage = "{\"type\":\"jpg\",\"value\":\"description\",\"image\":\"12345\"}";
    HttpCodecRegistry registry = new HttpCodecRegistry("com.robo4j.core.httpunit.codec");
    HttpEncoder<CameraMessage> encoder = registry.getEncoder(CameraMessage.class);
    HttpDecoder<CameraMessage> decoder = registry.getDecoder(CameraMessage.class);
    Assert.assertNotNull(encoder);
    Assert.assertNotNull(decoder);
    CameraMessage cameraMessage = new CameraMessage("jpg", "description", "12345");
    String encoded = encoder.encode(cameraMessage);
    CameraMessage decoded = decoder.decode(jsonCammeraMessageCorrupted);
    Assert.assertEquals(jsonCammeraMessage, encoded);
    Assert.assertEquals(cameraMessage.getType(), decoded.getType());
    Assert.assertEquals(cameraMessage.getValue(), decoded.getValue());
}
Also used : CameraMessage(com.robo4j.core.httpunit.codec.CameraMessage) Test(org.junit.Test)

Example 5 with CameraMessage

use of com.robo4j.core.httpunit.codec.CameraMessage in project robo4j by Robo4J.

the class HttpUnitTests method testHttpCameraMessageImage.

@Test
public void testHttpCameraMessageImage() throws Exception {
    final InputStream imageData = new BufferedInputStream(RoboClassLoader.getInstance().getResource("20161021_NoSignal_240.png"));
    byte[] imageArray = new byte[imageData.available()];
    imageData.read(imageArray);
    String encodedImage = Base64.getEncoder().encodeToString(imageArray);
    final String jsonCammeraMessageCorrupted = "{ \"type\"  :  \"jpg\" ,  \"value\"   :  \"description\"  ,\"image\":\"" + encodedImage + "\"}";
    final String jsonCammeraMessage = "{\"type\":\"jpg\",\"value\":\"description\",\"image\":\"" + encodedImage + "\"}";
    HttpCodecRegistry registry = new HttpCodecRegistry("com.robo4j.core.httpunit.codec");
    HttpEncoder<CameraMessage> encoder = registry.getEncoder(CameraMessage.class);
    HttpDecoder<CameraMessage> decoder = registry.getDecoder(CameraMessage.class);
    Assert.assertNotNull(encoder);
    Assert.assertNotNull(decoder);
    CameraMessage cameraMessage = new CameraMessage("jpg", "description", encodedImage);
    String encoded = encoder.encode(cameraMessage);
    CameraMessage decoded = decoder.decode(jsonCammeraMessageCorrupted);
    final byte[] imageDecoded = Base64.getDecoder().decode(decoded.getImage());
    Assert.assertEquals(jsonCammeraMessage, encoded);
    Assert.assertEquals(cameraMessage.getType(), decoded.getType());
    Assert.assertEquals(cameraMessage.getValue(), decoded.getValue());
    Assert.assertEquals(imageArray.length, imageDecoded.length);
}
Also used : CameraMessage(com.robo4j.core.httpunit.codec.CameraMessage) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Aggregations

CameraMessage (com.robo4j.core.httpunit.codec.CameraMessage)5 Test (org.junit.Test)3 BufferedInputStream (java.io.BufferedInputStream)1 InputStream (java.io.InputStream)1