Search in sources :

Example 1 with IProgressCallback

use of com.microsoft.graph.concurrency.IProgressCallback in project msgraph-sdk-java by microsoftgraph.

the class GraphServiceClientTest method testOverrideOfDefaultExecutors.

@Test
public void testOverrideOfDefaultExecutors() {
    IExecutors ex = new IExecutors() {

        @Override
        public void performOnBackground(Runnable runnable) {
        // do nothing
        }

        @Override
        public <Result> void performOnForeground(Result result, ICallback<Result> callback) {
        // do nothing
        }

        @Override
        public <Result> void performOnForeground(int progress, int progressMax, IProgressCallback<Result> callback) {
        // do nothing
        }

        @Override
        public <Result> void performOnForeground(ClientException exception, ICallback<Result> callback) {
        // do nothing
        }
    };
    IGraphServiceClient client = // 
    GraphServiceClient.builder().authenticationProvider(// 
    auth).executors(// 
    ex).buildClient();
    assertEquals(ex, client.getExecutors());
    assertEquals(auth, client.getAuthenticationProvider());
    assertNotNull(client.getHttpProvider());
    assertNotNull(client.getLogger());
    assertNotNull(client.getSerializer());
    assertEquals(ex, ((DefaultHttpProvider) client.getHttpProvider()).getExecutors());
}
Also used : ICallback(com.microsoft.graph.concurrency.ICallback) IExecutors(com.microsoft.graph.concurrency.IExecutors) ClientException(com.microsoft.graph.core.ClientException) IProgressCallback(com.microsoft.graph.concurrency.IProgressCallback) IGraphServiceClient(com.microsoft.graph.models.extensions.IGraphServiceClient) Test(org.junit.Test)

Example 2 with IProgressCallback

use of com.microsoft.graph.concurrency.IProgressCallback 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)

Aggregations

IProgressCallback (com.microsoft.graph.concurrency.IProgressCallback)2 ClientException (com.microsoft.graph.core.ClientException)2 Test (org.junit.Test)2 ICallback (com.microsoft.graph.concurrency.ICallback)1 IExecutors (com.microsoft.graph.concurrency.IExecutors)1 DriveItem (com.microsoft.graph.models.extensions.DriveItem)1 IGraphServiceClient (com.microsoft.graph.models.extensions.IGraphServiceClient)1 HashMap (java.util.HashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1