Search in sources :

Example 1 with ApiResponseError

use of com.formkiq.lambda.apigateway.ApiResponseError in project formkiq-core by formkiq.

the class DocumentIdUrlGetRequestHandlerTest method testHandleGetDocumentContent03.

/**
 * /documents/{documentId}/url request, document not found.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentContent03() throws Exception {
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
        // given
        ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid-url01.json");
        addParameter(event, "siteId", siteId);
        // when
        String response = handleRequest(event);
        // then
        Map<String, String> m = fromJson(response, Map.class);
        final int mapsize = 3;
        assertEquals(mapsize, m.size());
        assertEquals("404.0", String.valueOf(m.get("statusCode")));
        assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
        ApiResponseError resp = fromJson(m.get("body"), ApiResponseError.class);
        assertEquals("Document 39da0052-3cb3-47a6-94c7-7b97cd43f1ee not found.", resp.getMessage());
        assertNull(resp.getNext());
        assertNull(resp.getPrevious());
    }
}
Also used : ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) ApiResponseError(com.formkiq.lambda.apigateway.ApiResponseError) Test(org.junit.jupiter.api.Test)

Example 2 with ApiResponseError

use of com.formkiq.lambda.apigateway.ApiResponseError in project formkiq-core by formkiq.

the class ApiDocumentsRequestTest method testHandleGetDocuments09.

/**
 * Test user with User role with siteid.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocuments09() throws Exception {
    // given
    String siteId = UUID.randomUUID().toString();
    ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents03.json");
    addParameter(event, "siteId", siteId);
    // when
    String response = handleRequest(event);
    // then
    Map<String, String> m = fromJson(response, Map.class);
    final int mapsize = 3;
    assertEquals(mapsize, m.size());
    assertEquals("403.0", String.valueOf(m.get("statusCode")));
    assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
    ApiResponseError resp = fromJson(m.get("body"), ApiResponseError.class);
    assertEquals("Access Denied", resp.getMessage());
}
Also used : ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) ApiResponseError(com.formkiq.lambda.apigateway.ApiResponseError) Test(org.junit.jupiter.api.Test)

Example 3 with ApiResponseError

use of com.formkiq.lambda.apigateway.ApiResponseError in project formkiq-core by formkiq.

the class ApiDocumentsPatchRequestTest method assert404Response.

/**
 * Asserts 404 response.
 *
 * @param response {@link String}.
 * @throws IOException IOException
 */
@SuppressWarnings("unchecked")
private void assert404Response(final String response) throws IOException {
    Map<String, String> m = GsonUtil.getInstance().fromJson(response, Map.class);
    final int mapsize = 3;
    assertEquals(mapsize, m.size());
    assertEquals("404.0", String.valueOf(m.get("statusCode")));
    assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
    ApiResponseError resp = GsonUtil.getInstance().fromJson(m.get("body"), ApiResponseError.class);
    assertNotNull(resp.getMessage());
    assertNull(resp.getNext());
    assertNull(resp.getPrevious());
}
Also used : ApiResponseError(com.formkiq.lambda.apigateway.ApiResponseError)

Example 4 with ApiResponseError

use of com.formkiq.lambda.apigateway.ApiResponseError in project formkiq-core by formkiq.

the class ApiDocumentsRequestTest method testHandleGetDocuments08.

/**
 * Test user with no roles with siteid.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocuments08() throws Exception {
    // given
    String siteId = UUID.randomUUID().toString();
    ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents03.json");
    addParameter(event, "siteId", siteId);
    setCognitoGroup(event, "");
    // when
    String response = handleRequest(event);
    // then
    Map<String, String> m = fromJson(response, Map.class);
    final int mapsize = 3;
    assertEquals(mapsize, m.size());
    assertEquals("403.0", String.valueOf(m.get("statusCode")));
    assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
    ApiResponseError resp = fromJson(m.get("body"), ApiResponseError.class);
    assertEquals("Access Denied", resp.getMessage());
}
Also used : ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) ApiResponseError(com.formkiq.lambda.apigateway.ApiResponseError) Test(org.junit.jupiter.api.Test)

Aggregations

ApiResponseError (com.formkiq.lambda.apigateway.ApiResponseError)4 ApiGatewayRequestEvent (com.formkiq.lambda.apigateway.ApiGatewayRequestEvent)3 Test (org.junit.jupiter.api.Test)3