Search in sources :

Example 6 with MockExecutors

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

the class BaseStreamRequestTests method testSend.

@Test
public void testSend() {
    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/octet-stream");
            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<String> request = new BaseStreamRequest<String>("https://a.b.c", mBaseClient, null, null) {
    };
    request.send();
    assertEquals(1, mAuthenticationProvider.getInterceptionCount());
}
Also used : MockSerializer(com.microsoft.graph.serializer.MockSerializer) HashMap(java.util.HashMap) MockLogger(com.microsoft.graph.logger.MockLogger) MockExecutors(com.microsoft.graph.concurrency.MockExecutors) Test(org.junit.Test)

Example 7 with MockExecutors

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

the class BaseClientTests method setUp.

@Before
public void setUp() throws Exception {
    baseClient = new BaseClient() {

        @Override
        public String getServiceRoot() {
            return mEndpoint;
        }

        @Override
        public void setServiceRoot(String value) {
            mEndpoint = value;
        }
    };
    mAuthenticationProvider = new MockAuthenticationProvider();
    mExecutors = new MockExecutors();
    mHttpProvider = new MockHttpProvider();
    mLogger = new MockLogger();
    mSerializer = new MockSerializer(null, "");
}
Also used : MockSerializer(com.microsoft.graph.serializer.MockSerializer) MockLogger(com.microsoft.graph.logger.MockLogger) MockAuthenticationProvider(com.microsoft.graph.authentication.MockAuthenticationProvider) MockExecutors(com.microsoft.graph.concurrency.MockExecutors) MockHttpProvider(com.microsoft.graph.http.MockHttpProvider) Before(org.junit.Before)

Example 8 with MockExecutors

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

the class DefaultHttpProviderTests method testVerboseErrorResponse.

@Test
public void testVerboseErrorResponse() throws Exception {
    final GraphErrorCodes expectedErrorCode = GraphErrorCodes.INVALID_REQUEST;
    final String expectedMessage = "Test error!";
    final GraphErrorResponse toSerialize = new GraphErrorResponse();
    toSerialize.error = new GraphError();
    toSerialize.error.code = expectedErrorCode.toString();
    toSerialize.error.message = expectedMessage;
    toSerialize.error.innererror = null;
    JsonObject raw = new JsonObject();
    raw.add("response", new JsonPrimitive("The raw request was invalid"));
    toSerialize.rawObject = raw;
    MockLogger logger = new MockLogger();
    logger.setLoggingLevel(LoggerLevel.DEBUG);
    mProvider = new DefaultHttpProvider(new MockSerializer(toSerialize, ""), mAuthenticationProvider = new MockAuthenticationProvider(), new MockExecutors(), logger);
    final ITestConnectionData data = new ITestConnectionData() {

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

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

        @Override
        public Map<String, String> getHeaders() {
            return new HashMap<>();
        }
    };
    mProvider.setConnectionFactory(new MockConnectionFactory(new MockConnection(data)));
    try {
        mProvider.send(new MockHttpRequest(), DriveItem.class, null);
        fail("Expected exception in previous statement");
    } catch (final GraphServiceException e) {
        assertFalse(e.getMessage().indexOf("truncated") > 0);
        assertTrue(e.getMessage().indexOf("The raw request was invalid") > 0);
    }
}
Also used : MockSerializer(com.microsoft.graph.serializer.MockSerializer) GraphErrorCodes(com.microsoft.graph.core.GraphErrorCodes) JsonPrimitive(com.google.gson.JsonPrimitive) HashMap(java.util.HashMap) MockExecutors(com.microsoft.graph.concurrency.MockExecutors) JsonObject(com.google.gson.JsonObject) MockLogger(com.microsoft.graph.logger.MockLogger) MockAuthenticationProvider(com.microsoft.graph.authentication.MockAuthenticationProvider) Test(org.junit.Test)

Aggregations

MockExecutors (com.microsoft.graph.concurrency.MockExecutors)8 MockLogger (com.microsoft.graph.logger.MockLogger)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 InputStream (java.io.InputStream)3 Before (org.junit.Before)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