Search in sources :

Example 1 with DriveItem

use of com.microsoft.graph.models.extensions.DriveItem in project msgraph-sdk-java by microsoftgraph.

the class DefaultHttpProviderTests method testPostByte.

@Test
public void testPostByte() throws Exception {
    final String itemId = "itemId";
    final ITestConnectionData data = new ITestConnectionData() {

        @Override
        public int getRequestCode() {
            return 200;
        }

        @Override
        public String getJsonResponse() {
            return "{ \"id\": \"zzz\" }";
        }

        @Override
        public Map<String, String> getHeaders() {
            final HashMap<String, String> map = new HashMap<>();
            map.put("Content-Type", "application/json");
            return map;
        }
    };
    final DriveItem expectedItem = new DriveItem();
    expectedItem.id = itemId;
    setDefaultHttpProvider(expectedItem);
    mProvider.setConnectionFactory(new MockConnectionFactory(new MockConnection(data)));
    final AtomicBoolean progress = new AtomicBoolean(false);
    final AtomicBoolean success = new AtomicBoolean(false);
    final AtomicBoolean failure = new AtomicBoolean(false);
    final IProgressCallback<DriveItem> progressCallback = new IProgressCallback<DriveItem>() {

        @Override
        public void progress(final long current, final long max) {
            progress.set(true);
        }

        @Override
        public void success(final DriveItem item) {
            success.set(true);
        }

        @Override
        public void failure(final ClientException ex) {
            failure.set(true);
        }
    };
    mProvider.send(new MockHttpRequest(), progressCallback, DriveItem.class, new byte[] { 1, 2, 3, 4 });
    assertTrue(progress.get());
    assertTrue(success.get());
    assertEquals(1, mAuthenticationProvider.getInterceptionCount());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DriveItem(com.microsoft.graph.models.extensions.DriveItem) HashMap(java.util.HashMap) ClientException(com.microsoft.graph.core.ClientException) IProgressCallback(com.microsoft.graph.concurrency.IProgressCallback) Test(org.junit.Test)

Example 2 with DriveItem

use of com.microsoft.graph.models.extensions.DriveItem in project msgraph-sdk-java by microsoftgraph.

the class DefaultHttpProviderTests method testPostItem.

@Test
public void testPostItem() throws Exception {
    final String itemId = "itemId";
    final ITestConnectionData data = new ITestConnectionData() {

        @Override
        public int getRequestCode() {
            return 200;
        }

        @Override
        public String getJsonResponse() {
            return "{ \"id\": \"zzz\" }";
        }

        @Override
        public Map<String, String> getHeaders() {
            final HashMap<String, String> map = new HashMap<>();
            map.put("Content-Type", "application/json");
            return map;
        }
    };
    final DriveItem expectedItem = new DriveItem();
    expectedItem.id = itemId;
    setDefaultHttpProvider(expectedItem);
    mProvider.setConnectionFactory(new MockConnectionFactory(new MockConnection(data)));
    final DriveItem item = mProvider.send(new MockHttpRequest(), DriveItem.class, new DriveItem());
    assertEquals(itemId, item.id);
    assertEquals(1, mAuthenticationProvider.getInterceptionCount());
}
Also used : DriveItem(com.microsoft.graph.models.extensions.DriveItem) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with DriveItem

use of com.microsoft.graph.models.extensions.DriveItem in project msgraph-sdk-java by microsoftgraph.

the class DefaultHttpProviderTests method testBodyLessResponse.

@Test
public void testBodyLessResponse() throws Exception {
    final int[] codes = new int[] { 204, 304 };
    final AtomicInteger currentCode = new AtomicInteger(0);
    setDefaultHttpProvider(null);
    final ITestConnectionData data = new ITestConnectionData() {

        @Override
        public int getRequestCode() {
            return codes[currentCode.get()];
        }

        @Override
        public String getJsonResponse() {
            return null;
        }

        @Override
        public Map<String, String> getHeaders() {
            return new HashMap<>();
        }
    };
    mProvider.setConnectionFactory(new MockConnectionFactory(new MockConnection(data)));
    for (final int ignored : codes) {
        DriveItem result = mProvider.send(new MockHttpRequest(), DriveItem.class, null);
        currentCode.incrementAndGet();
        assertNull(result);
    }
    assertEquals(codes.length, mAuthenticationProvider.getInterceptionCount());
}
Also used : DriveItem(com.microsoft.graph.models.extensions.DriveItem) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

DriveItem (com.microsoft.graph.models.extensions.DriveItem)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 IProgressCallback (com.microsoft.graph.concurrency.IProgressCallback)1 ClientException (com.microsoft.graph.core.ClientException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1