Example usage for org.apache.http.entity.mime.content InputStreamBody InputStreamBody

List of usage examples for org.apache.http.entity.mime.content InputStreamBody InputStreamBody

Introduction

In this page you can find the example usage for org.apache.http.entity.mime.content InputStreamBody InputStreamBody.

Prototype

public InputStreamBody(final InputStream in, final String filename) 

Source Link

Usage

From source file:org.deviceconnect.android.profile.restful.test.NormalNotificationProfileTestCase.java

/**
 * ??????????.//from   w  ww.  java 2 s  .  c o m
 * 
 * <pre>
 * ?HTTP
 * Method: POST
 * Path: notification/notify?deviceId=xxxx&type=0&body=test_body
 * </pre>
 * 
 * <pre>
 * ??
 * result?0???????
 * notificationid?1???????
 * </pre>
 */
public void testPostNotifyOptional020() {
    StringBuilder builder = new StringBuilder();
    builder.append(DCONNECT_MANAGER_URI);
    builder.append("/" + NotificationProfileConstants.PROFILE_NAME);
    builder.append("/" + NotificationProfileConstants.ATTRIBUTE_NOTIFY);
    builder.append("?");
    builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TYPE + "=0");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_BODY + "=test_body");

    builder.append("&");
    builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
    try {
        HttpPost request = new HttpPost(builder.toString());
        String name = "test.png";
        AssetManager manager = getApplicationContext().getAssets();
        MultipartEntity entity = new MultipartEntity();
        entity.addPart(NotificationProfileConstants.PARAM_ICON, new InputStreamBody(manager.open(name), name));
        request.setEntity(entity);

        JSONObject root = sendRequest(request);
        Assert.assertNotNull("root is null.", root);
        Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        Assert.assertEquals("notificationid is not equals.",
                TestNotificationProfileConstants.NOTIFICATION_ID[0],
                root.getString(NotificationProfileConstants.PARAM_NOTIFICATION_ID));
    } catch (JSONException e) {
        fail("Exception in JSONObject." + e.getMessage());
    } catch (IOException e) {
        fail("Exception in JSONObject." + e.getMessage());
    }
}

From source file:org.deviceconnect.android.profile.restful.test.NormalNotificationProfileTestCase.java

/**
 * ??????????./*  w  w  w.j  a  v  a2s.c o  m*/
 * 
 * <pre>
 * ?HTTP
 * Method: POST
 * Path: notification/notify?deviceId=xxxx&type=0&dir=auto&body=test_body
 * </pre>
 * 
 * <pre>
 * ??
 * result?0???????
 * notificationid?1???????
 * </pre>
 */
public void testPostNotifyOptional021() {
    StringBuilder builder = new StringBuilder();
    builder.append(DCONNECT_MANAGER_URI);
    builder.append("/" + NotificationProfileConstants.PROFILE_NAME);
    builder.append("/" + NotificationProfileConstants.ATTRIBUTE_NOTIFY);
    builder.append("?");
    builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TYPE + "=0");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_DIR + "=auto");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_BODY + "=test_body");

    builder.append("&");
    builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
    try {
        HttpPost request = new HttpPost(builder.toString());
        String name = "test.png";
        AssetManager manager = getApplicationContext().getAssets();
        MultipartEntity entity = new MultipartEntity();
        entity.addPart(NotificationProfileConstants.PARAM_ICON, new InputStreamBody(manager.open(name), name));
        request.setEntity(entity);

        JSONObject root = sendRequest(request);
        Assert.assertNotNull("root is null.", root);
        Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        Assert.assertEquals("notificationid is not equals.",
                TestNotificationProfileConstants.NOTIFICATION_ID[0],
                root.getString(NotificationProfileConstants.PARAM_NOTIFICATION_ID));
    } catch (JSONException e) {
        fail("Exception in JSONObject." + e.getMessage());
    } catch (IOException e) {
        fail("Exception in JSONObject." + e.getMessage());
    }
}

From source file:org.deviceconnect.android.profile.restful.test.NormalNotificationProfileTestCase.java

/**
 * ??????????.//from w  w  w  .j a  v  a2 s  . co m
 * 
 * <pre>
 * ?HTTP
 * Method: POST
 * Path: notification/notify?deviceId=xxxx&type=0&lang=jp-JP&body=test_body
 * </pre>
 * 
 * <pre>
 * ??
 * result?0???????
 * notificationid?1???????
 * </pre>
 */
public void testPostNotifyOptional022() {
    StringBuilder builder = new StringBuilder();
    builder.append(DCONNECT_MANAGER_URI);
    builder.append("/" + NotificationProfileConstants.PROFILE_NAME);
    builder.append("/" + NotificationProfileConstants.ATTRIBUTE_NOTIFY);
    builder.append("?");
    builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TYPE + "=0");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_LANG + "=jp-JP");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_BODY + "=test_body");

    builder.append("&");
    builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
    try {
        HttpPost request = new HttpPost(builder.toString());
        String name = "test.png";
        AssetManager manager = getApplicationContext().getAssets();
        MultipartEntity entity = new MultipartEntity();
        entity.addPart(NotificationProfileConstants.PARAM_ICON, new InputStreamBody(manager.open(name), name));
        request.setEntity(entity);

        JSONObject root = sendRequest(request);
        Assert.assertNotNull("root is null.", root);
        Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        Assert.assertEquals("notificationid is not equals.",
                TestNotificationProfileConstants.NOTIFICATION_ID[0],
                root.getString(NotificationProfileConstants.PARAM_NOTIFICATION_ID));
    } catch (JSONException e) {
        fail("Exception in JSONObject." + e.getMessage());
    } catch (IOException e) {
        fail("Exception in JSONObject." + e.getMessage());
    }
}

From source file:org.deviceconnect.android.profile.restful.test.FailFileProfileTestCase.java

/**
 * ????./*from  ww w  .  j  a  v  a2  s.co m*/
 * 
 * @return ????
 */
private MultipartEntity getEntity() {
    AssetManager manager = getApplicationContext().getAssets();
    String name = "test.png";
    MultipartEntity entity = new MultipartEntity();
    try {
        entity.addPart(FileProfileConstants.PARAM_DATA, new InputStreamBody(manager.open(name), name));
    } catch (IOException e) {
        fail("Failed to obtain the file: " + e.getMessage());
    }
    return entity;
}

From source file:org.deviceconnect.android.profile.restful.test.NormalNotificationProfileTestCase.java

/**
 * ??????????.// w w w.java2 s.c  o m
 * 
 * <pre>
 * ?HTTP
 * Method: POST
 * Path: notification/notify?deviceId=xxxx&type=0&dir=auto&lang=jp-JP&body=test_body
 * </pre>
 * 
 * <pre>
 * ??
 * result?0???????
 * notificationid?1???????
 * </pre>
 */
public void testPostNotifyOptional023() {
    StringBuilder builder = new StringBuilder();
    builder.append(DCONNECT_MANAGER_URI);
    builder.append("/" + NotificationProfileConstants.PROFILE_NAME);
    builder.append("/" + NotificationProfileConstants.ATTRIBUTE_NOTIFY);
    builder.append("?");
    builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TYPE + "=0");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_DIR + "=auto");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_LANG + "=jp-JP");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_BODY + "=test_body");

    builder.append("&");
    builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
    try {
        HttpPost request = new HttpPost(builder.toString());
        String name = "test.png";
        AssetManager manager = getApplicationContext().getAssets();
        MultipartEntity entity = new MultipartEntity();
        entity.addPart(NotificationProfileConstants.PARAM_ICON, new InputStreamBody(manager.open(name), name));
        request.setEntity(entity);

        JSONObject root = sendRequest(request);
        Assert.assertNotNull("root is null.", root);
        Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        Assert.assertEquals("notificationid is not equals.",
                TestNotificationProfileConstants.NOTIFICATION_ID[0],
                root.getString(NotificationProfileConstants.PARAM_NOTIFICATION_ID));
    } catch (JSONException e) {
        fail("Exception in JSONObject." + e.getMessage());
    } catch (IOException e) {
        fail("Exception in JSONObject." + e.getMessage());
    }
}

From source file:org.deviceconnect.android.profile.restful.test.NormalNotificationProfileTestCase.java

/**
 * ??????????.//from  www  . jav  a2 s .  c om
 * 
 * <pre>
 * ?HTTP
 * Method: POST
 * Path: notification/notify?deviceId=xxxx&type=0&tag=tag1,tag2,tag3
 * </pre>
 * 
 * <pre>
 * ??
 * result?0???????
 * notificationid?1???????
 * </pre>
 */
public void testPostNotifyOptional024() {
    StringBuilder builder = new StringBuilder();
    builder.append(DCONNECT_MANAGER_URI);
    builder.append("/" + NotificationProfileConstants.PROFILE_NAME);
    builder.append("/" + NotificationProfileConstants.ATTRIBUTE_NOTIFY);
    builder.append("?");
    builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TYPE + "=0");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TAG + "=tag1,tag2,tag3");

    builder.append("&");
    builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
    try {
        HttpPost request = new HttpPost(builder.toString());
        String name = "test.png";
        AssetManager manager = getApplicationContext().getAssets();
        MultipartEntity entity = new MultipartEntity();
        entity.addPart(NotificationProfileConstants.PARAM_ICON, new InputStreamBody(manager.open(name), name));
        request.setEntity(entity);

        JSONObject root = sendRequest(request);
        Assert.assertNotNull("root is null.", root);
        Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        Assert.assertEquals("notificationid is not equals.",
                TestNotificationProfileConstants.NOTIFICATION_ID[0],
                root.getString(NotificationProfileConstants.PARAM_NOTIFICATION_ID));
    } catch (JSONException e) {
        fail("Exception in JSONObject." + e.getMessage());
    } catch (IOException e) {
        fail("Exception in JSONObject." + e.getMessage());
    }
}

From source file:org.deviceconnect.android.profile.restful.test.NormalNotificationProfileTestCase.java

/**
 * ??????????./* w  w w  . j a  v  a  2  s.  c  o  m*/
 * 
 * <pre>
 * ?HTTP
 * Method: POST
 * Path: notification/notify?deviceId=xxxx&type=0&dir=auto&tag=tag1,tag2,tag3
 * </pre>
 * 
 * <pre>
 * ??
 * result?0???????
 * notificationid?1???????
 * </pre>
 */
public void testPostNotifyOptional025() {
    StringBuilder builder = new StringBuilder();
    builder.append(DCONNECT_MANAGER_URI);
    builder.append("/" + NotificationProfileConstants.PROFILE_NAME);
    builder.append("/" + NotificationProfileConstants.ATTRIBUTE_NOTIFY);
    builder.append("?");
    builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TYPE + "=0");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_DIR + "=auto");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TAG + "=tag1,tag2,tag3");

    builder.append("&");
    builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
    try {
        HttpPost request = new HttpPost(builder.toString());
        String name = "test.png";
        AssetManager manager = getApplicationContext().getAssets();
        MultipartEntity entity = new MultipartEntity();
        entity.addPart(NotificationProfileConstants.PARAM_ICON, new InputStreamBody(manager.open(name), name));
        request.setEntity(entity);

        JSONObject root = sendRequest(request);
        Assert.assertNotNull("root is null.", root);
        Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        Assert.assertEquals("notificationid is not equals.",
                TestNotificationProfileConstants.NOTIFICATION_ID[0],
                root.getString(NotificationProfileConstants.PARAM_NOTIFICATION_ID));
    } catch (JSONException e) {
        fail("Exception in JSONObject." + e.getMessage());
    } catch (IOException e) {
        fail("Exception in JSONObject." + e.getMessage());
    }
}

From source file:org.deviceconnect.android.profile.restful.test.NormalNotificationProfileTestCase.java

/**
 * ??????????.//  ww w .ja  v  a 2s .  co  m
 * 
 * <pre>
 * ?HTTP
 * Method: POST
 * Path: notification/notify?deviceId=xxxx&type=0&lang=jp-JP&tag=tag1,tag2,tag3
 * </pre>
 * 
 * <pre>
 * ??
 * result?0???????
 * notificationid?1???????
 * </pre>
 */
public void testPostNotifyOptional026() {
    StringBuilder builder = new StringBuilder();
    builder.append(DCONNECT_MANAGER_URI);
    builder.append("/" + NotificationProfileConstants.PROFILE_NAME);
    builder.append("/" + NotificationProfileConstants.ATTRIBUTE_NOTIFY);
    builder.append("?");
    builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TYPE + "=0");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_LANG + "=jp-JP");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TAG + "=tag1,tag2,tag3");

    builder.append("&");
    builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
    try {
        HttpPost request = new HttpPost(builder.toString());
        String name = "test.png";
        AssetManager manager = getApplicationContext().getAssets();
        MultipartEntity entity = new MultipartEntity();
        entity.addPart(NotificationProfileConstants.PARAM_ICON, new InputStreamBody(manager.open(name), name));
        request.setEntity(entity);

        JSONObject root = sendRequest(request);
        Assert.assertNotNull("root is null.", root);
        Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        Assert.assertEquals("notificationid is not equals.",
                TestNotificationProfileConstants.NOTIFICATION_ID[0],
                root.getString(NotificationProfileConstants.PARAM_NOTIFICATION_ID));
    } catch (JSONException e) {
        fail("Exception in JSONObject." + e.getMessage());
    } catch (IOException e) {
        fail("Exception in JSONObject." + e.getMessage());
    }
}

From source file:org.deviceconnect.android.profile.restful.test.NormalNotificationProfileTestCase.java

/**
 * ??????????.// w w w .ja  v  a2 s .c  om
 * 
 * <pre>
 * ?HTTP
 * Method: POST
 * Path: notification/notify?deviceId=xxxx&type=0&dir=auto&lang=jp-JP&tag=tag1,tag2,tag3
 * </pre>
 * 
 * <pre>
 * ??
 * result?0???????
 * notificationid?1???????
 * </pre>
 */
public void testPostNotifyOptional027() {
    StringBuilder builder = new StringBuilder();
    builder.append(DCONNECT_MANAGER_URI);
    builder.append("/" + NotificationProfileConstants.PROFILE_NAME);
    builder.append("/" + NotificationProfileConstants.ATTRIBUTE_NOTIFY);
    builder.append("?");
    builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TYPE + "=0");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_DIR + "=auto");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_LANG + "=jp-JP");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TAG + "=tag1,tag2,tag3");

    builder.append("&");
    builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
    try {
        HttpPost request = new HttpPost(builder.toString());
        String name = "test.png";
        AssetManager manager = getApplicationContext().getAssets();
        MultipartEntity entity = new MultipartEntity();
        entity.addPart(NotificationProfileConstants.PARAM_ICON, new InputStreamBody(manager.open(name), name));
        request.setEntity(entity);

        JSONObject root = sendRequest(request);
        Assert.assertNotNull("root is null.", root);
        Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        Assert.assertEquals("notificationid is not equals.",
                TestNotificationProfileConstants.NOTIFICATION_ID[0],
                root.getString(NotificationProfileConstants.PARAM_NOTIFICATION_ID));
    } catch (JSONException e) {
        fail("Exception in JSONObject." + e.getMessage());
    } catch (IOException e) {
        fail("Exception in JSONObject." + e.getMessage());
    }
}

From source file:org.deviceconnect.android.profile.restful.test.NormalNotificationProfileTestCase.java

/**
 * ??????????./*w  ww  . jav a2s .  c  om*/
 * 
 * <pre>
 * ?HTTP
 * Method: POST
 * Path: notification/notify?deviceId=xxxx&type=0&body=test_body&tag=tag1,tag2,tag3
 * </pre>
 * 
 * <pre>
 * ??
 * result?0???????
 * notificationid?1???????
 * </pre>
 */
public void testPostNotifyOptional028() {
    StringBuilder builder = new StringBuilder();
    builder.append(DCONNECT_MANAGER_URI);
    builder.append("/" + NotificationProfileConstants.PROFILE_NAME);
    builder.append("/" + NotificationProfileConstants.ATTRIBUTE_NOTIFY);
    builder.append("?");
    builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TYPE + "=0");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_BODY + "=test_body");
    builder.append("&");
    builder.append(NotificationProfileConstants.PARAM_TAG + "=tag1,tag2,tag3");

    builder.append("&");
    builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
    try {
        HttpPost request = new HttpPost(builder.toString());
        String name = "test.png";
        AssetManager manager = getApplicationContext().getAssets();
        MultipartEntity entity = new MultipartEntity();
        entity.addPart(NotificationProfileConstants.PARAM_ICON, new InputStreamBody(manager.open(name), name));
        request.setEntity(entity);

        JSONObject root = sendRequest(request);
        Assert.assertNotNull("root is null.", root);
        Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        Assert.assertEquals("notificationid is not equals.",
                TestNotificationProfileConstants.NOTIFICATION_ID[0],
                root.getString(NotificationProfileConstants.PARAM_NOTIFICATION_ID));
    } catch (JSONException e) {
        fail("Exception in JSONObject." + e.getMessage());
    } catch (IOException e) {
        fail("Exception in JSONObject." + e.getMessage());
    }
}