Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mfriesen committed Jun 16, 2024
1 parent a9f6f12 commit e542730
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static com.formkiq.aws.dynamodb.SiteIdKeyGenerator.DEFAULT_SITE_ID;
import static com.formkiq.aws.dynamodb.objects.Objects.notNull;
import static com.formkiq.stacks.dynamodb.ConfigService.MAX_DOCUMENTS;
import static com.formkiq.testutils.aws.FkqDocumentService.waitForActionsComplete;
import static com.formkiq.testutils.aws.FkqDocumentService.waitForDocumentContent;
import static com.formkiq.testutils.aws.FkqDocumentService.waitForDocumentTag;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -54,6 +55,12 @@
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import com.formkiq.client.api.AttributesApi;
import com.formkiq.client.invoker.ApiResponse;
import com.formkiq.client.model.AddAction;
import com.formkiq.client.model.DocumentActionType;
import com.formkiq.client.model.GetAttributeResponse;
import com.formkiq.stacks.dynamodb.attributes.AttributeKeyReserved;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -911,4 +918,44 @@ public void testPost10() throws Exception {
}
}
}

/**
* Test Publish Document.
*
* @throws ApiException ApiException
*/
@Test
void testPublishDocument() throws ApiException, InterruptedException {
// given
String content = "test data";
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
ApiClient client = getApiClients(siteId).get(0);

DocumentsApi api = new DocumentsApi(client);
String path = UUID.randomUUID() + ".txt";

// when
AddDocumentRequest req = new AddDocumentRequest().contentType("text/plain").path(path)
.content(content).addActionsItem(new AddAction().type(DocumentActionType.PUBLISH));
String documentId = api.addDocument(req, siteId, null).getDocumentId();

// then
waitForDocumentContent(client, siteId, documentId, content);
waitForActionsComplete(client, siteId, documentId);

ApiResponse<Void> response = api.getPublishedDocumentContentWithHttpInfo(documentId, siteId);

String location = notNull(response.getHeaders()).get("content-disposition").get(0);
assertEquals("attachment; filename=\"" + path + "\"", location);

String contentType = notNull(response.getHeaders()).get("content-type").get(0);
assertEquals("text/plain", contentType);

// check attribute exists
AttributesApi attributesApi = new AttributesApi(client);
GetAttributeResponse attribute =
attributesApi.getAttribute(AttributeKeyReserved.PUBLICATION.getKey(), siteId);
assertNotNull(attribute);
}
}
}

0 comments on commit e542730

Please sign in to comment.