Search in sources :

Example 1 with MockLogger

use of com.microsoft.graph.logger.MockLogger in project msgraph-sdk-java by microsoftgraph.

the class BaseRequestTests method setUp.

@Before
public void setUp() throws Exception {
    mAuthenticationProvider = new MockAuthenticationProvider();
    mBaseClient = new MockBaseClient();
    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;
        }
    };
    MockHttpProvider mProvider = new MockHttpProvider(new MockSerializer(null, ""), mAuthenticationProvider, new MockExecutors(), new MockLogger());
    mProvider.setConnectionFactory(new MockConnectionFactory(new MockConnection(data)));
    mBaseClient.setHttpProvider(mProvider);
    request = new BaseRequest("https://a.b.c", mBaseClient, null, null) {
    };
}
Also used : MockSerializer(com.microsoft.graph.serializer.MockSerializer) HashMap(java.util.HashMap) MockBaseClient(com.microsoft.graph.core.MockBaseClient) MockExecutors(com.microsoft.graph.concurrency.MockExecutors) MockLogger(com.microsoft.graph.logger.MockLogger) MockAuthenticationProvider(com.microsoft.graph.authentication.MockAuthenticationProvider) Before(org.junit.Before)

Example 2 with MockLogger

use of com.microsoft.graph.logger.MockLogger in project msgraph-sdk-java by microsoftgraph.

the class DefaultExecutorsTests method setUp.

@Before
public void setUp() throws Exception {
    mLogger = new MockLogger();
    defaultExecutors = new DefaultExecutors(mLogger);
}
Also used : MockLogger(com.microsoft.graph.logger.MockLogger) Before(org.junit.Before)

Example 3 with MockLogger

use of com.microsoft.graph.logger.MockLogger in project msgraph-sdk-java by microsoftgraph.

the class BaseStreamRequestTests method testSendWithContent.

@Test
public void testSendWithContent() {
    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;
        }
    };
    DefaultHttpProvider mProvider = new DefaultHttpProvider(new MockSerializer(null, ""), mAuthenticationProvider, new MockExecutors(), new MockLogger());
    mProvider.setConnectionFactory(new MockConnectionFactory(new MockConnection(data)));
    mBaseClient.setHttpProvider(mProvider);
    final BaseStreamRequest<InputStream> request = new BaseStreamRequest<InputStream>("https://a.b.c", mBaseClient, null, InputStream.class) {
    };
    request.send(new byte[] { 1, 2, 3, 4 });
    assertEquals(1, mAuthenticationProvider.getInterceptionCount());
}
Also used : MockSerializer(com.microsoft.graph.serializer.MockSerializer) HashMap(java.util.HashMap) InputStream(java.io.InputStream) MockExecutors(com.microsoft.graph.concurrency.MockExecutors) MockLogger(com.microsoft.graph.logger.MockLogger) Test(org.junit.Test)

Example 4 with MockLogger

use of com.microsoft.graph.logger.MockLogger in project msgraph-sdk-java by microsoftgraph.

the class BaseStreamRequestTests method testSendWithContentAndCallback.

@Test
public void testSendWithContentAndCallback() {
    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;
        }
    };
    DefaultHttpProvider mProvider = new DefaultHttpProvider(new MockSerializer(null, ""), mAuthenticationProvider, new MockExecutors(), new MockLogger());
    mProvider.setConnectionFactory(new MockConnectionFactory(new MockConnection(data)));
    mBaseClient.setHttpProvider(mProvider);
    final AtomicBoolean success = new AtomicBoolean(false);
    final AtomicBoolean failure = new AtomicBoolean(false);
    final ICallback<InputStream> callback = new ICallback<InputStream>() {

        @Override
        public void success(InputStream inputStream) {
            success.set(true);
        }

        @Override
        public void failure(ClientException ex) {
            failure.set(true);
        }
    };
    final BaseStreamRequest<InputStream> request = new BaseStreamRequest<InputStream>("https://a.b.c", mBaseClient, null, InputStream.class) {
    };
    request.send(new byte[] { 1, 2, 3, 4 }, callback);
    assertTrue(success.get());
    assertFalse(failure.get());
    assertEquals(1, mAuthenticationProvider.getInterceptionCount());
}
Also used : MockSerializer(com.microsoft.graph.serializer.MockSerializer) HashMap(java.util.HashMap) InputStream(java.io.InputStream) MockExecutors(com.microsoft.graph.concurrency.MockExecutors) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ICallback(com.microsoft.graph.concurrency.ICallback) MockLogger(com.microsoft.graph.logger.MockLogger) ClientException(com.microsoft.graph.core.ClientException) Test(org.junit.Test)

Example 5 with MockLogger

use of com.microsoft.graph.logger.MockLogger in project msgraph-sdk-java by microsoftgraph.

the class BaseStreamRequestTests method testSendWithCallback.

@Test
public void testSendWithCallback() {
    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;
        }
    };
    DefaultHttpProvider mProvider = new DefaultHttpProvider(new MockSerializer(null, ""), mAuthenticationProvider, new MockExecutors(), new MockLogger());
    mProvider.setConnectionFactory(new MockConnectionFactory(new MockConnection(data)));
    mBaseClient.setHttpProvider(mProvider);
    final AtomicBoolean success = new AtomicBoolean(false);
    final AtomicBoolean failure = new AtomicBoolean(false);
    final ICallback<InputStream> callback = new ICallback<InputStream>() {

        @Override
        public void success(InputStream inputStream) {
            success.set(true);
        }

        @Override
        public void failure(ClientException ex) {
            failure.set(true);
        }
    };
    final BaseStreamRequest<InputStream> request = new BaseStreamRequest<InputStream>("https://a.b.c", mBaseClient, null, InputStream.class) {
    };
    request.send(callback);
    assertTrue(success.get());
    assertFalse(failure.get());
    assertEquals(1, mAuthenticationProvider.getInterceptionCount());
}
Also used : MockSerializer(com.microsoft.graph.serializer.MockSerializer) HashMap(java.util.HashMap) InputStream(java.io.InputStream) MockExecutors(com.microsoft.graph.concurrency.MockExecutors) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ICallback(com.microsoft.graph.concurrency.ICallback) MockLogger(com.microsoft.graph.logger.MockLogger) ClientException(com.microsoft.graph.core.ClientException) Test(org.junit.Test)

Aggregations

MockLogger (com.microsoft.graph.logger.MockLogger)9 MockExecutors (com.microsoft.graph.concurrency.MockExecutors)8 MockSerializer (com.microsoft.graph.serializer.MockSerializer)8 HashMap (java.util.HashMap)7 Test (org.junit.Test)5 MockAuthenticationProvider (com.microsoft.graph.authentication.MockAuthenticationProvider)4 Before (org.junit.Before)4 InputStream (java.io.InputStream)3 JsonObject (com.google.gson.JsonObject)2 ICallback (com.microsoft.graph.concurrency.ICallback)2 ClientException (com.microsoft.graph.core.ClientException)2 MockBaseClient (com.microsoft.graph.core.MockBaseClient)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 JsonPrimitive (com.google.gson.JsonPrimitive)1 GraphErrorCodes (com.microsoft.graph.core.GraphErrorCodes)1 MockHttpProvider (com.microsoft.graph.http.MockHttpProvider)1