Package com.streamreduce.rest.resource

Examples of com.streamreduce.rest.resource.ErrorMessage


                        .build())
                .build();

        Response createResponse = connectionResource.createConnection(connectionObject);
        Assert.assertEquals(createResponse.getStatus(), 400);
        ErrorMessage errorMessage = (ErrorMessage) createResponse.getEntity();
        Assert.assertEquals(errorMessage.getErrorMessage(), "The destination URL was invalid: no protocol: as/");
    }
View Full Code Here


        Response createResponse = connectionResource.createConnection(connectionObject);
        ConnectionResponseDTO createConnectionResponseDTO = (ConnectionResponseDTO) createResponse.getEntity();
        Assert.assertEquals(200, createResponse.getStatus());
        Response updateResponse = connectionResource.updateConnection(createConnectionResponseDTO.getId().toString(),
                updateObject);
        ErrorMessage errorMessage = (ErrorMessage) updateResponse.getEntity();
        Assert.assertEquals(errorMessage.getErrorMessage(), "The destination URL was invalid: no protocol: as/");
    }
View Full Code Here

                authnToken = httpReponse.getFirstHeader(Constants.NODEABLE_AUTH_TOKEN).getValue();
            } else {
                String response = IOUtils.toString(httpReponse.getEntity().getContent());

                try {
                    ErrorMessage em = jsonToObject(response,
                            TypeFactory.defaultInstance().constructType(ErrorMessage.class));
                    throw new Exception(em.getErrorMessage());
                } catch (Exception e) {
                    throw new Exception("Unable to login: " + response);
                }
            }
        } finally {
View Full Code Here

        try {
            return (T) om.readValue(json, type);
        } catch (Exception e) {
            try {
                ErrorMessage em = om.readValue(json, ErrorMessage.class);

                throw new Exception(em.getErrorMessage());
            } catch (IOException e2) {
                throw new IOException(e.getMessage() + ": " + json);
            }
        }
    }
View Full Code Here

        JSONObject imgPayload  = TestUtils.createValidSampleIMGPayload();
        Response response = gatewayResource.createCustomConnectionMessage(imgPayload); //magic happens here

        //Start verification
        if (response.getStatus() != 201) {
            ErrorMessage e = (ErrorMessage) response.getEntity();
            Assert.fail("Unable to verify test due to IMG failure.  Response has a status of " + response.getStatus() +
                    " and an error message of : " + e.getErrorMessage());
        }

        //Give enough time for this to trickle to SQS and back to server
        Thread.sleep(TimeUnit.SECONDS.toMillis(10));
View Full Code Here

        JSONObject imgPayload  = TestUtils.createValidSampleIMGPayload();
        Response response = gatewayResource.createCustomConnectionMessage(imgPayload); //magic happens here

        //Start verification
        if (response.getStatus() != 201) {
            ErrorMessage e = (ErrorMessage) response.getEntity();
            Assert.fail("Unable to verify test due to IMG failure.  Response has a status of " + response.getStatus() +
                    " and an error message of : " + e.getErrorMessage());
        }

        ConnectionCredentials s3Creds = new ArrayList<>(
                testIMGConnection.getOutboundConfigurations()).get(0).getCredentials();
        s3TestUtils = new S3TestUtils(s3Creds);
View Full Code Here

        assertFalse(response == null || response.equals(""));

        try {
            // Create an invalid invite
            ErrorMessage errorMessage = jsonToObject(makeRequest(usersBaseUrl + "/invite/" + userToInvite, "POST",
                    null, authToken), TypeFactory.defaultInstance().constructType(ErrorMessage.class));

            assertEquals("A user with that email address has already been invited.", errorMessage.getErrorMessage());

            // Resend the invite
            response = makeRequest(usersBaseUrl + "/invite/resend/" + userToInvite, "GET", null, authToken);

            assertEquals("200", response);

            // Resend the invalid invite
            errorMessage = jsonToObject(makeRequest(usersBaseUrl + "/invite/resend/fake_" + userToInvite, "GET",
                    null, authToken), TypeFactory.defaultInstance().constructType(ErrorMessage.class));

            assertEquals("User not found.", errorMessage.getErrorMessage());

            // Delete the invalid invite
            errorMessage = jsonToObject(makeRequest(usersBaseUrl + "/invite/fake_" + userToInvite, "DELETE",
                    null, authToken), TypeFactory.defaultInstance().constructType(ErrorMessage.class));

            assertEquals("No user found with the following id: fake_" + userToInvite, errorMessage.getErrorMessage());

            // Delete the valid invite
            response = makeRequest(usersBaseUrl + "/invite/" + userToInvite, "DELETE", null, authToken);

            assertEquals("200", response);
View Full Code Here

    public void testGMGInboundDisabled() throws Exception {
        // Disable inbound IMG support
        account.setConfigValue(Account.ConfigKey.DISABLE_INBOUND_API, true);
        applicationManager.getUserService().updateAccount(account);

        ErrorMessage error = jsonToObject(makeRequest(imgBaseUrl, "POST", new JSONObject(), apiKey,
                                                      AuthTokenType.GATEWAY),
                                          TypeFactory.defaultInstance().constructType(ErrorMessage.class));

        assertTrue(error.getErrorMessage().equals("This account is not provisioned for inbound payloads, please " +
                                                          "contact support@nodeable.com."));
    }
View Full Code Here

    }

    @Test
    @Ignore
    public void testInvalidGMGPayloads() throws Exception {
        ErrorMessage error = jsonToObject(makeRequest(imgBaseUrl, "POST", new JSONObject(), apiKey,
                                                      AuthTokenType.GATEWAY),
                                          TypeFactory.defaultInstance().constructType(ErrorMessage.class));

        // Invalid message because the message or metrics attributes were missing
        assertTrue(error.getErrorMessage().equals("You must supply at least a 'message' or 'metrics' attribute in " +
                                                          "the payload."));

        // Invalid message because hashtags is a non-array
        JSONObject json = new JSONObject();

        json.put("message", "This message doesn't matter.");
        json.put("hashtags", 12345);

        error = jsonToObject(makeRequest(imgBaseUrl, "POST", json, apiKey,
                                         AuthTokenType.GATEWAY),
                             TypeFactory.defaultInstance().constructType(ErrorMessage.class));

        assertTrue(error.getErrorMessage().equals("'hashtags' must be a string array."));

        // Invalid message because hashtags is an array with non-string values
        JSONArray jsonArray = new JSONArray();
        json = new JSONObject();

        jsonArray.add(12345);

        json.put("message", "This message doesn't matter.");
        json.put("hashtags", jsonArray);

        error = jsonToObject(makeRequest(imgBaseUrl, "POST", json, apiKey,
                                         AuthTokenType.GATEWAY),
                             TypeFactory.defaultInstance().constructType(ErrorMessage.class));

        assertTrue(error.getErrorMessage()
                        .equals("All hashtags specified in the 'hashtags' attribute must be strings."));

        // Invalid message because metrics is a non-array
        json = new JSONObject();

        json.put("message", "This message doesn't matter.");
        json.put("metrics", 12345);

        error = jsonToObject(makeRequest(imgBaseUrl, "POST", json, apiKey,
                                         AuthTokenType.GATEWAY),
                             TypeFactory.defaultInstance().constructType(ErrorMessage.class));

        assertTrue(error.getErrorMessage().equals("'metrics' must be an object array."));

        // Invalid message because metrics is an array with non-object values
        json = new JSONObject();
        jsonArray = new JSONArray();

        jsonArray.add(12345);

        json.put("message", "This message doesn't matter.");
        json.put("metrics", jsonArray);

        error = jsonToObject(makeRequest(imgBaseUrl, "POST", json, apiKey,
                                         AuthTokenType.GATEWAY),
                             TypeFactory.defaultInstance().constructType(ErrorMessage.class));

        assertTrue(error.getErrorMessage()
                        .equals("All metrics specified in the 'metrics' attribute must be objects."));

        // Invalid message because metric in metrics doesn't contain name
        JSONObject metric = new JSONObject();
        json = new JSONObject();
        jsonArray = new JSONArray();

        jsonArray.add(metric);

        json.put("message", "This message doesn't matter.");
        json.put("metrics", jsonArray);

        error = jsonToObject(makeRequest(imgBaseUrl, "POST", json, apiKey,
                                         AuthTokenType.GATEWAY),
                             TypeFactory.defaultInstance().constructType(ErrorMessage.class));

        assertTrue(error.getErrorMessage()
                        .equals("'name' is required for each metric in the 'metrics' attribute."));

        // Invalid message because metric in metrics doesn't contain type
        metric = new JSONObject();
        json = new JSONObject();
        jsonArray = new JSONArray();

        metric.put("name", "This name doesn't matter.");

        jsonArray.add(metric);

        json.put("message", "This message doesn't matter.");
        json.put("metrics", jsonArray);

        error = jsonToObject(makeRequest(imgBaseUrl, "POST", json, apiKey,
                                         AuthTokenType.GATEWAY),
                             TypeFactory.defaultInstance().constructType(ErrorMessage.class));

        assertTrue(error.getErrorMessage()
                        .equals("'type' is required for each metric in the 'metrics' attribute and must be " +
                                        "either 'ABSOLUTE' or 'DELTA'."));

        // Invalid message because metric in metrics doesn't contain valid type
        metric = new JSONObject();
        json = new JSONObject();
        jsonArray = new JSONArray();

        metric.put("name", "This name doesn't matter.");
        metric.put("type", "FAKE");

        jsonArray.add(metric);

        json.put("message", "This message doesn't matter.");
        json.put("metrics", jsonArray);

        error = jsonToObject(makeRequest(imgBaseUrl, "POST", json, apiKey,
                                         AuthTokenType.GATEWAY),
                             TypeFactory.defaultInstance().constructType(ErrorMessage.class));

        assertTrue(error.getErrorMessage()
                        .equals("'type' is required for each metric in the 'metrics' attribute and must be " +
                                        "either 'ABSOLUTE' or 'DELTA'."));

        // Invalid message because metric in metrics doesn't contain value
        metric = new JSONObject();
        json = new JSONObject();
        jsonArray = new JSONArray();

        metric.put("name", "This name doesn't matter.");
        metric.put("type", "ABSOLUTE");

        jsonArray.add(metric);

        json.put("message", "This message doesn't matter.");
        json.put("metrics", jsonArray);

        error = jsonToObject(makeRequest(imgBaseUrl, "POST", json, apiKey,
                                         AuthTokenType.GATEWAY),
                             TypeFactory.defaultInstance().constructType(ErrorMessage.class));

        assertTrue(error.getErrorMessage()
                        .equals("'value' is required for each metric in the 'metrics' attribute and must " +
                                        "be a valid numerical value."));

        // Invalid message because metric in metrics doesn't contain valid value
        metric = new JSONObject();
        json = new JSONObject();
        jsonArray = new JSONArray();

        metric.put("name", "This name doesn't matter.");
        metric.put("type", "ABSOLUTE");
        metric.put("value", "fake");

        jsonArray.add(metric);

        json.put("message", "This message doesn't matter.");
        json.put("metrics", jsonArray);

        error = jsonToObject(makeRequest(imgBaseUrl, "POST", json, apiKey,
                                         AuthTokenType.GATEWAY),
                             TypeFactory.defaultInstance().constructType(ErrorMessage.class));

        assertTrue(error.getErrorMessage()
                        .equals("'value' for each metric in the 'metrics' attribute must be a numerical value."));

        // Invalid because it's a multi-entry request but the data attribute isn't a JSONArray
        json = new JSONObject();

        json.put("data", "This should be a JSONArray.");

        error = jsonToObject(makeRequest(imgBaseUrl, "POST", json, apiKey,
                                         AuthTokenType.GATEWAY),
                             TypeFactory.defaultInstance().constructType(ErrorMessage.class));

        assertTrue(error.getErrorMessage().equals("'data' must be an object array."));

        // Invalid because it's a multi-entry request but the data entry isn't an object
        json = new JSONObject();
        jsonArray = new JSONArray();

        jsonArray.add("This should be a JSONObject.");
        json.put("data", jsonArray);

        error = jsonToObject(makeRequest(imgBaseUrl, "POST", json, apiKey,
                                         AuthTokenType.GATEWAY),
                             TypeFactory.defaultInstance().constructType(ErrorMessage.class));

        assertTrue(error.getErrorMessage().equals("Every object in the 'data' array should be an object."));

        // Invalid because dateGenerated is not a number
        json = new JSONObject();

        json.put("message", "This is a test message.");
        json.put("dateGenerated", "This should be a number.");

        error = jsonToObject(makeRequest(imgBaseUrl, "POST", json, apiKey,
                                         AuthTokenType.GATEWAY),
                             TypeFactory.defaultInstance().constructType(ErrorMessage.class));

        assertTrue(error.getErrorMessage().equals("'dateGenerated' must be an number."));
    }
View Full Code Here

                                                          "FAKE is not a valid METRIC_CRITERIA.")
                                                     .build();
        String authToken = login(testUsername, testUsername);

        for (Map.Entry<String, String> urlToTest : urlsToTest.entrySet()) {
            ErrorMessage error = jsonToObject(makeRequest(urlToTest.getKey(), "GET", null, authToken),
                                              TypeFactory.defaultInstance().constructType(ErrorMessage.class));

            Assert.assertEquals(urlToTest.getValue(), error.getErrorMessage());
        }
    }
View Full Code Here

TOP

Related Classes of com.streamreduce.rest.resource.ErrorMessage

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.