Package com.box.boxjavalibv2.jsonparsing

Examples of com.box.boxjavalibv2.jsonparsing.BoxJSONParser


        statusLine = EasyMock.createMock(StatusLine.class);
    }

    @Test
    public void testCanParseBoxServerError() throws BoxRestException, IllegalStateException, IOException, BoxJSONException {
        BoxJSONParser jsonParser = new BoxJSONParser(new BoxResourceHub());
        EasyMock.reset(boxResponse, response, entity);
        inputStream = new ByteArrayInputStream(jsonParser.convertBoxObjectToJSONString(error).getBytes());
        EasyMock.expect(boxResponse.getHttpResponse()).andStubReturn(response);
        EasyMock.expect(response.getEntity()).andStubReturn(entity);
        EasyMock.expect(entity.getContent()).andStubReturn(inputStream);
        EasyMock.expect(entity.isStreaming()).andStubReturn(false);

        EasyMock.expect(boxResponse.getHttpResponse()).andStubReturn(response);
        EasyMock.expect(response.getStatusLine()).andStubReturn(statusLine);
        EasyMock.expect(statusLine.getStatusCode()).andStubReturn(statusCode);

        EasyMock.replay(boxResponse, response, entity, statusLine);
        ErrorResponseParser parser = new ErrorResponseParser(jsonParser);
        Object object = parser.parse(boxResponse);
        Assert.assertEquals(BoxServerError.class, object.getClass());

        Assert.assertEquals(jsonParser.convertBoxObjectToJSONString(error), jsonParser.convertBoxObjectToJSONString(object));
        EasyMock.verify(boxResponse, response, entity, statusLine);
    }
View Full Code Here


     *
     * @param resourceHub
     * @return
     */
    protected IBoxJSONParser createJSONParser(IBoxResourceHub resourceHub) {
        return new BoxJSONParser(resourceHub);
    }
View Full Code Here

    }

    @Test
    public void prepareRequestTest() throws AuthFatalFailureException {
        try {
            DefaultBoxRequest request = new DefaultBoxRequest(config, new BoxJSONParser(new BoxResourceHub()), uri, restMethod, null);
            request.addQueryParam("a", "b");
            request.setEntity(requestEntity);
            request.prepareRequest();
            HttpRequestBase rawRequest = request.getRawRequest();
            Assert.assertEquals(HttpPost.class, rawRequest.getClass());
View Full Code Here

        }
    }

    @Test
    public void ConstructHttpUriRequestTest() {
        BoxJSONParser parser = new BoxJSONParser(new BoxResourceHub());
        try {
            Assert.assertEquals(HttpGet.class, (new DefaultBoxRequest(config, parser, uri, RestMethod.GET, null)).constructHttpUriRequest().getClass());
            Assert.assertEquals(HttpPut.class, (new DefaultBoxRequest(config, parser, uri, RestMethod.PUT, null)).constructHttpUriRequest().getClass());
            Assert.assertEquals(HttpPost.class, (new DefaultBoxRequest(config, parser, uri, RestMethod.POST, null)).constructHttpUriRequest().getClass());
            Assert.assertEquals(HttpDelete.class, (new DefaultBoxRequest(config, parser, uri, RestMethod.DELETE, null)).constructHttpUriRequest().getClass());
View Full Code Here

public class DefaultAuthHeaderAuthTest {

    @Test
    public void testSetAuth() throws BoxRestException, AuthFatalFailureException {
        DefaultBoxRequest request = new DefaultBoxRequest(TestUtils.getConfig(), new BoxJSONParser(new BoxResourceHub()), "fakeuri", RestMethod.GET, null);
        String token = "test token";
        String apiKey = "test api key";
        String deviceId = "f9h30fhflzkhg84ghgzhgr534653";
        String deviceName = "Galaxy Death Star";
        DefaultAuthHeaderAuth auth = new DefaultAuthHeaderAuth(token, apiKey, deviceId, deviceName);
View Full Code Here

public class DefaultUsernamePasswordAuthTest {

    @Test
    public void testSetAuth() {
        try {
            DefaultBoxRequest request = new DefaultBoxRequest(TestUtils.getConfig(), new BoxJSONParser(new BoxResourceHub()), "/uri", RestMethod.GET, null);
            String userName = "testusername";
            String password = "testpassword";

            DefaultUsernamePasswordAuth auth = new DefaultUsernamePasswordAuth(userName, password);
            auth.setAuth(request);
View Full Code Here

            inputStream = new ByteArrayInputStream(testObject.toString().getBytes());
            EasyMock.expect(boxResponse.getHttpResponse()).andReturn(response);
            EasyMock.expect(response.getEntity()).andReturn(entity);
            EasyMock.expect(entity.getContent()).andReturn(inputStream);
            EasyMock.replay(boxResponse, response, entity);
            DefaultBoxJSONResponseParser parser = new DefaultBoxJSONResponseParser(TestObject.class, new BoxJSONParser(new BoxResourceHub()));
            Object object = parser.parse(boxResponse);
            Assert.assertEquals(TestObject.class, object.getClass());
            TestObject tObject = (TestObject) object;
            Assert.assertEquals(fieldA, tObject.getFieldAWithAnnotation());
            Assert.assertEquals(fieldB, tObject.getFieldB());
View Full Code Here

import com.box.restclientv2.requestsbase.DefaultBoxRequest;

public class MockRequest extends DefaultBoxRequest {

    public MockRequest() throws BoxRestException {
        super(TestUtils.getConfig(), new BoxJSONParser(new BoxResourceHub()), "uri", RestMethod.GET, null);
    }
View Full Code Here

        }
    }

    private static BoxClient getAuthenticatedClient(String code) throws BoxRestException,     BoxServerException, AuthFatalFailureException {
        BoxResourceHub hub = new BoxResourceHub();
        BoxJSONParser parser = new BoxJSONParser(hub);
        IBoxConfig config = (new BoxConfigBuilder()).build();
        BoxClient client = new BoxClient(key, secret, hub, parser, config);
        BoxOAuthToken bt = client.getOAuthManager().createOAuth(code, key, secret, "http://localhost:" + PORT);
        client.authenticate(bt);
        return client;
View Full Code Here

    private BoxCollaboration createCollaboration() throws InterruptedException {
        final Map<String, Object> headers = new HashMap<String, Object>();
        // parameter type is String
        headers.put("CamelBox.folderId", testFolderId);
        // parameter type is com.box.boxjavalibv2.requests.requestobjects.BoxCollabRequestObject
        final BoxCollabRequestObject collabObject = BoxCollabRequestObject.createCollabObject(testFolderId, null,
                "camel.test@localhost.com", BoxCollaborationRole.VIEWER);
        headers.put("CamelBox.collabRequest", collabObject);

        BoxCollaboration result = requestBodyAndHeaders("direct://CREATECOLLABORATION",
                null, headers);
View Full Code Here

TOP

Related Classes of com.box.boxjavalibv2.jsonparsing.BoxJSONParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.