Search in sources :

Example 46 with DynamicObject

use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.

the class WebhooksServiceImplTest method testFindWebhook02.

/**
 * Test Finding missing webhook.
 */
@Test
public void testFindWebhook02() {
    // given
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
        String id = UUID.randomUUID().toString();
        // when
        DynamicObject o = this.service.findWebhook(siteId, id);
        // then
        assertNull(o);
    }
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) Test(org.junit.jupiter.api.Test)

Example 47 with DynamicObject

use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.

the class WebhooksServiceImplTest method testFindWebhook01.

/**
 * Test Finding webhook.
 */
@Test
public void testFindWebhook01() {
    // given
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
        ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
        String id = this.service.saveWebhook(siteId, "test", "joe", Date.from(now.toInstant()), "true");
        // when
        DynamicObject o = this.service.findWebhook(siteId, id);
        // then
        assertNotNull(o.getString("documentId"));
        assertNotNull(o.getString("path"));
        assertNotNull(o.getString("userId"));
        assertNotNull(o.getString("inserteddate"));
        assertNotNull(o.getString("TimeToLive"));
        LocalDateTime time = LocalDateTime.ofEpochSecond(Long.parseLong(o.getString("TimeToLive")), 0, ZoneOffset.UTC);
        assertEquals(now.getYear(), time.getYear());
        assertEquals(now.getMonth(), time.getMonth());
        assertEquals(now.getDayOfMonth(), time.getDayOfMonth());
        assertEquals(now.getHour(), time.getHour());
        assertEquals(now.getMinute(), time.getMinute());
        assertEquals(now.getSecond(), time.getSecond());
        // when
        this.service.deleteWebhook(siteId, id);
        // then
        assertEquals(0, this.service.findWebhooks(siteId).size());
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.jupiter.api.Test)

Example 48 with DynamicObject

use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.

the class WebhooksServiceImplTest method testUpdateTimeToLive01.

/**
 * Test Updating webhooks Time To Live.
 */
@Test
public void testUpdateTimeToLive01() {
    // given
    ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
    Date ttl = Date.from(now.toInstant());
    ZonedDateTime tomorrow = ZonedDateTime.now(ZoneOffset.UTC).plusDays(1);
    Date tomorrowttl = Date.from(tomorrow.toInstant());
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
        String webhookId = this.service.saveWebhook(siteId, "test", "joe", ttl, "true");
        DocumentTag tag0 = new DocumentTag(webhookId, "category", "person", new Date(), "joe");
        this.service.addTags(siteId, webhookId, Arrays.asList(tag0), null);
        DynamicObject tag = this.service.findTag(siteId, webhookId, "category");
        assertNull(tag.getString("TimeToLive"));
        // when
        this.service.updateTimeToLive(siteId, webhookId, tomorrowttl);
        // then
        DynamicObject result = this.service.findWebhook(siteId, webhookId);
        assertEquals("test", result.getString("path"));
        assertNotNull(result.getString("documentId"));
        assertNotNull(result.getString("path"));
        assertNotNull(result.getString("userId"));
        assertNotNull(result.getString("inserteddate"));
        assertEquals(String.valueOf(tomorrowttl.getTime() / MILLISECONDS), result.getString("TimeToLive"));
        tag = this.service.findTag(siteId, webhookId, "category");
        assertNotNull(tag.getString("TimeToLive"));
        assertEquals(String.valueOf(tomorrowttl.getTime() / MILLISECONDS), tag.getString("TimeToLive"));
    }
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) ZonedDateTime(java.time.ZonedDateTime) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 49 with DynamicObject

use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.

the class WebhooksServiceImpl method deleteWebhookTags.

private void deleteWebhookTags(final String siteId, final String id, final PaginationMapToken token) {
    PaginationResults<DynamicObject> tags = findTags(siteId, id, token);
    for (DynamicObject t : tags.getResults()) {
        String pk = t.getString("PK");
        String sk = t.getString("SK");
        Map<String, AttributeValue> key = Map.of("PK", AttributeValue.builder().s(pk).build(), "SK", AttributeValue.builder().s(sk).build());
        this.dynamoDB.deleteItem(DeleteItemRequest.builder().tableName(this.documentTableName).key(key).build());
    }
    if (tags.getToken() != null) {
        deleteWebhookTags(siteId, id, tags.getToken());
    }
}
Also used : AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject)

Example 50 with DynamicObject

use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.

the class DocumentsRestrictionsMaxContentLengthTest method testEnforced04.

/**
 * Max Content Length, Content Length greater.
 */
@Test
public void testEnforced04() {
    // given
    Long contentLength = Long.valueOf("15");
    String siteId = UUID.randomUUID().toString();
    DynamicObject ob = this.awsservice.configService().get(siteId);
    ob.put(ConfigService.MAX_DOCUMENT_SIZE_BYTES, "10");
    this.awsservice.configService().save(siteId, ob);
    // when
    String value = service.getValue(this.awsservice, siteId);
    boolean result = service.enforced(this.awsservice, siteId, value, contentLength);
    // then
    assertTrue(result);
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) Test(org.junit.jupiter.api.Test)

Aggregations

DynamicObject (com.formkiq.stacks.common.objects.DynamicObject)93 Test (org.junit.jupiter.api.Test)55 Map (java.util.Map)46 ApiGatewayRequestEvent (com.formkiq.lambda.apigateway.ApiGatewayRequestEvent)39 Date (java.util.Date)26 HashMap (java.util.HashMap)17 DocumentItemDynamoDb (com.formkiq.stacks.dynamodb.DocumentItemDynamoDb)12 DocumentTag (com.formkiq.stacks.dynamodb.DocumentTag)10 ZonedDateTime (java.time.ZonedDateTime)10 ApiRequestHandlerResponse (com.formkiq.lambda.apigateway.ApiRequestHandlerResponse)8 List (java.util.List)8 AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)7 S3Client (software.amazon.awssdk.services.s3.S3Client)7 ApiMapResponse (com.formkiq.lambda.apigateway.ApiMapResponse)6 BadException (com.formkiq.lambda.apigateway.exception.BadException)6 Collectors (java.util.stream.Collectors)6 NotFoundException (com.formkiq.lambda.apigateway.exception.NotFoundException)5 FormKiqClientV1 (com.formkiq.stacks.client.FormKiqClientV1)5 LocalDate (java.time.LocalDate)5 Test (org.junit.Test)5