Search in sources :

Example 91 with Attachment

use of org.hl7.fhir.r4.model.Attachment in project cloudant-java-sdk by IBM.

the class CloudantTest method testPostDocumentWOptions.

@Test
public void testPostDocumentWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"id\": \"id\", \"rev\": \"rev\", \"ok\": true, \"caused_by\": \"causedBy\", \"error\": \"error\", \"reason\": \"reason\"}";
    String postDocumentPath = "/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the Attachment model
    Attachment attachmentModel = new Attachment.Builder().contentType("testString").data(TestUtilities.createMockByteArray("This is a mock byte array value.")).digest("testString").encodedLength(Long.valueOf("0")).encoding("testString").follows(true).length(Long.valueOf("0")).revpos(Long.valueOf("1")).stub(true).build();
    // Construct an instance of the Revisions model
    Revisions revisionsModel = new Revisions.Builder().ids(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).start(Long.valueOf("1")).build();
    // Construct an instance of the DocumentRevisionStatus model
    DocumentRevisionStatus documentRevisionStatusModel = new DocumentRevisionStatus.Builder().rev("testString").status("available").build();
    // Construct an instance of the Document model
    Document documentModel = new Document.Builder().attachments(new java.util.HashMap<String, Attachment>() {

        {
            put("foo", attachmentModel);
        }
    }).conflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).deleted(true).deletedConflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).id("testString").localSeq("testString").rev("testString").revisions(revisionsModel).revsInfo(new java.util.ArrayList<DocumentRevisionStatus>(java.util.Arrays.asList(documentRevisionStatusModel))).add("foo", "testString").build();
    // Construct an instance of the PostDocumentOptions model
    PostDocumentOptions postDocumentOptionsModel = new PostDocumentOptions.Builder().db("testString").document(documentModel).contentType("application/json").batch("ok").build();
    // Invoke operation with valid options model (positive test)
    Response<DocumentResult> response = cloudantService.postDocument(postDocumentOptionsModel).execute();
    assertNotNull(response);
    DocumentResult responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("batch"), "ok");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, postDocumentPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DocumentResult(com.ibm.cloud.cloudant.v1.model.DocumentResult) ArrayList(java.util.ArrayList) Attachment(com.ibm.cloud.cloudant.v1.model.Attachment) Revisions(com.ibm.cloud.cloudant.v1.model.Revisions) ReplicationDocument(com.ibm.cloud.cloudant.v1.model.ReplicationDocument) DesignDocument(com.ibm.cloud.cloudant.v1.model.DesignDocument) Document(com.ibm.cloud.cloudant.v1.model.Document) SchedulerDocument(com.ibm.cloud.cloudant.v1.model.SchedulerDocument) BulkGetResultDocument(com.ibm.cloud.cloudant.v1.model.BulkGetResultDocument) BulkGetQueryDocument(com.ibm.cloud.cloudant.v1.model.BulkGetQueryDocument) DocumentRevisionStatus(com.ibm.cloud.cloudant.v1.model.DocumentRevisionStatus) PostDocumentOptions(com.ibm.cloud.cloudant.v1.model.PostDocumentOptions) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 92 with Attachment

use of org.hl7.fhir.r4.model.Attachment in project cloudant-java-sdk by IBM.

the class CloudantTest method testPutLocalDocumentWOptions.

@Test
public void testPutLocalDocumentWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"id\": \"id\", \"rev\": \"rev\", \"ok\": true, \"caused_by\": \"causedBy\", \"error\": \"error\", \"reason\": \"reason\"}";
    String putLocalDocumentPath = "/testString/_local/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the Attachment model
    Attachment attachmentModel = new Attachment.Builder().contentType("testString").data(TestUtilities.createMockByteArray("This is a mock byte array value.")).digest("testString").encodedLength(Long.valueOf("0")).encoding("testString").follows(true).length(Long.valueOf("0")).revpos(Long.valueOf("1")).stub(true).build();
    // Construct an instance of the Revisions model
    Revisions revisionsModel = new Revisions.Builder().ids(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).start(Long.valueOf("1")).build();
    // Construct an instance of the DocumentRevisionStatus model
    DocumentRevisionStatus documentRevisionStatusModel = new DocumentRevisionStatus.Builder().rev("testString").status("available").build();
    // Construct an instance of the Document model
    Document documentModel = new Document.Builder().attachments(new java.util.HashMap<String, Attachment>() {

        {
            put("foo", attachmentModel);
        }
    }).conflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).deleted(true).deletedConflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).id("exampleid").localSeq("testString").rev("testString").revisions(revisionsModel).revsInfo(new java.util.ArrayList<DocumentRevisionStatus>(java.util.Arrays.asList(documentRevisionStatusModel))).add("brand", "Foo").add("colours", "[\"red\",\"green\",\"black\",\"blue\"]").add("description", "Slim Colourful Design Electronic Cooking Appliance for ...").add("image", "assets/img/0gmsnghhew.jpg").add("keywords", "[\"Foo\",\"Scales\",\"Weight\",\"Digital\",\"Kitchen\"]").add("name", "Digital Kitchen Scales").add("price", "14.99").add("productid", "1000042").add("taxonomy", "[\"Home\",\"Kitchen\",\"Small Appliances\"]").add("type", "product").build();
    // Construct an instance of the PutLocalDocumentOptions model
    PutLocalDocumentOptions putLocalDocumentOptionsModel = new PutLocalDocumentOptions.Builder().db("testString").docId("testString").document(documentModel).contentType("application/json").batch("ok").build();
    // Invoke operation with valid options model (positive test)
    Response<DocumentResult> response = cloudantService.putLocalDocument(putLocalDocumentOptionsModel).execute();
    assertNotNull(response);
    DocumentResult responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "PUT");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("batch"), "ok");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, putLocalDocumentPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) HashMap(java.util.HashMap) PutLocalDocumentOptions(com.ibm.cloud.cloudant.v1.model.PutLocalDocumentOptions) DocumentResult(com.ibm.cloud.cloudant.v1.model.DocumentResult) ArrayList(java.util.ArrayList) Attachment(com.ibm.cloud.cloudant.v1.model.Attachment) Revisions(com.ibm.cloud.cloudant.v1.model.Revisions) ReplicationDocument(com.ibm.cloud.cloudant.v1.model.ReplicationDocument) DesignDocument(com.ibm.cloud.cloudant.v1.model.DesignDocument) Document(com.ibm.cloud.cloudant.v1.model.Document) SchedulerDocument(com.ibm.cloud.cloudant.v1.model.SchedulerDocument) BulkGetResultDocument(com.ibm.cloud.cloudant.v1.model.BulkGetResultDocument) BulkGetQueryDocument(com.ibm.cloud.cloudant.v1.model.BulkGetQueryDocument) DocumentRevisionStatus(com.ibm.cloud.cloudant.v1.model.DocumentRevisionStatus) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 93 with Attachment

use of org.hl7.fhir.r4.model.Attachment in project cloudant-java-sdk by IBM.

the class CloudantTest method testPutReplicationDocumentWOptions.

@Test
public void testPutReplicationDocumentWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"id\": \"id\", \"rev\": \"rev\", \"ok\": true, \"caused_by\": \"causedBy\", \"error\": \"error\", \"reason\": \"reason\"}";
    String putReplicationDocumentPath = "/_replicator/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the Attachment model
    Attachment attachmentModel = new Attachment.Builder().contentType("testString").data(TestUtilities.createMockByteArray("This is a mock byte array value.")).digest("testString").encodedLength(Long.valueOf("0")).encoding("testString").follows(true).length(Long.valueOf("0")).revpos(Long.valueOf("1")).stub(true).build();
    // Construct an instance of the Revisions model
    Revisions revisionsModel = new Revisions.Builder().ids(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).start(Long.valueOf("1")).build();
    // Construct an instance of the DocumentRevisionStatus model
    DocumentRevisionStatus documentRevisionStatusModel = new DocumentRevisionStatus.Builder().rev("testString").status("available").build();
    // Construct an instance of the ReplicationCreateTargetParameters model
    ReplicationCreateTargetParameters replicationCreateTargetParametersModel = new ReplicationCreateTargetParameters.Builder().n(Long.valueOf("1")).partitioned(false).q(Long.valueOf("26")).build();
    // Construct an instance of the ReplicationDatabaseAuthBasic model
    ReplicationDatabaseAuthBasic replicationDatabaseAuthBasicModel = new ReplicationDatabaseAuthBasic.Builder().password("testString").username("testString").build();
    // Construct an instance of the ReplicationDatabaseAuthIam model
    ReplicationDatabaseAuthIam replicationDatabaseAuthIamModel = new ReplicationDatabaseAuthIam.Builder().apiKey("testString").build();
    // Construct an instance of the ReplicationDatabaseAuth model
    ReplicationDatabaseAuth replicationDatabaseAuthModel = new ReplicationDatabaseAuth.Builder().basic(replicationDatabaseAuthBasicModel).iam(replicationDatabaseAuthIamModel).build();
    // Construct an instance of the ReplicationDatabase model
    ReplicationDatabase replicationDatabaseModel = new ReplicationDatabase.Builder().auth(replicationDatabaseAuthModel).headers(new java.util.HashMap<String, String>() {

        {
            put("foo", "testString");
        }
    }).url("testString").build();
    // Construct an instance of the UserContext model
    UserContext userContextModel = new UserContext.Builder().db("testString").name("testString").roles(new java.util.ArrayList<String>(java.util.Arrays.asList("_reader"))).build();
    // Construct an instance of the ReplicationDocument model
    ReplicationDocument replicationDocumentModel = new ReplicationDocument.Builder().attachments(new java.util.HashMap<String, Attachment>() {

        {
            put("foo", attachmentModel);
        }
    }).conflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).deleted(true).deletedConflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).id("testString").localSeq("testString").rev("testString").revisions(revisionsModel).revsInfo(new java.util.ArrayList<DocumentRevisionStatus>(java.util.Arrays.asList(documentRevisionStatusModel))).cancel(true).checkpointInterval(Long.valueOf("0")).connectionTimeout(Long.valueOf("0")).continuous(false).createTarget(false).createTargetParams(replicationCreateTargetParametersModel).docIds(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).filter("testString").httpConnections(Long.valueOf("1")).queryParams(new java.util.HashMap<String, String>() {

        {
            put("foo", "testString");
        }
    }).retriesPerRequest(Long.valueOf("0")).selector(new java.util.HashMap<String, Object>() {

        {
            put("foo", "testString");
        }
    }).sinceSeq("testString").socketOptions("testString").source(replicationDatabaseModel).sourceProxy("testString").target(replicationDatabaseModel).targetProxy("testString").useCheckpoints(true).userCtx(userContextModel).workerBatchSize(Long.valueOf("1")).workerProcesses(Long.valueOf("1")).add("foo", "testString").build();
    // Construct an instance of the PutReplicationDocumentOptions model
    PutReplicationDocumentOptions putReplicationDocumentOptionsModel = new PutReplicationDocumentOptions.Builder().docId("testString").replicationDocument(replicationDocumentModel).ifMatch("testString").batch("ok").newEdits(false).rev("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<DocumentResult> response = cloudantService.putReplicationDocument(putReplicationDocumentOptionsModel).execute();
    assertNotNull(response);
    DocumentResult responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "PUT");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("batch"), "ok");
    assertEquals(Boolean.valueOf(query.get("new_edits")), Boolean.valueOf(false));
    assertEquals(query.get("rev"), "testString");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, putReplicationDocumentPath);
}
Also used : DocumentResult(com.ibm.cloud.cloudant.v1.model.DocumentResult) ArrayList(java.util.ArrayList) Attachment(com.ibm.cloud.cloudant.v1.model.Attachment) Revisions(com.ibm.cloud.cloudant.v1.model.Revisions) DocumentRevisionStatus(com.ibm.cloud.cloudant.v1.model.DocumentRevisionStatus) ReplicationDocument(com.ibm.cloud.cloudant.v1.model.ReplicationDocument) ReplicationDatabaseAuthBasic(com.ibm.cloud.cloudant.v1.model.ReplicationDatabaseAuthBasic) ReplicationDatabaseAuthIam(com.ibm.cloud.cloudant.v1.model.ReplicationDatabaseAuthIam) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) UserContext(com.ibm.cloud.cloudant.v1.model.UserContext) PutReplicationDocumentOptions(com.ibm.cloud.cloudant.v1.model.PutReplicationDocumentOptions) ReplicationCreateTargetParameters(com.ibm.cloud.cloudant.v1.model.ReplicationCreateTargetParameters) ReplicationDatabase(com.ibm.cloud.cloudant.v1.model.ReplicationDatabase) ReplicationDatabaseAuth(com.ibm.cloud.cloudant.v1.model.ReplicationDatabaseAuth) SecurityObject(com.ibm.cloud.cloudant.v1.model.SecurityObject) GeoJsonGeometryObject(com.ibm.cloud.cloudant.v1.model.GeoJsonGeometryObject) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 94 with Attachment

use of org.hl7.fhir.r4.model.Attachment in project cloudant-java-sdk by IBM.

the class AttachmentTest method testAttachment.

@Test
public void testAttachment() throws Throwable {
    Attachment attachmentModel = new Attachment.Builder().contentType("testString").data(TestUtilities.createMockByteArray("This is a mock byte array value.")).digest("testString").encodedLength(Long.valueOf("0")).encoding("testString").follows(true).length(Long.valueOf("0")).revpos(Long.valueOf("1")).stub(true).build();
    assertEquals(attachmentModel.contentType(), "testString");
    assertEquals(attachmentModel.data(), TestUtilities.createMockByteArray("This is a mock byte array value."));
    assertEquals(attachmentModel.digest(), "testString");
    assertEquals(attachmentModel.encodedLength(), Long.valueOf("0"));
    assertEquals(attachmentModel.encoding(), "testString");
    assertEquals(attachmentModel.follows(), Boolean.valueOf(true));
    assertEquals(attachmentModel.length(), Long.valueOf("0"));
    assertEquals(attachmentModel.revpos(), Long.valueOf("1"));
    assertEquals(attachmentModel.stub(), Boolean.valueOf(true));
    String json = TestUtilities.serialize(attachmentModel);
    Attachment attachmentModelNew = TestUtilities.deserialize(json, Attachment.class);
    assertTrue(attachmentModelNew instanceof Attachment);
    assertEquals(attachmentModelNew.contentType(), "testString");
    assertEquals(attachmentModelNew.data(), TestUtilities.createMockByteArray("This is a mock byte array value."));
    assertEquals(attachmentModelNew.digest(), "testString");
    assertEquals(attachmentModelNew.encodedLength(), Long.valueOf("0"));
    assertEquals(attachmentModelNew.encoding(), "testString");
    assertEquals(attachmentModelNew.follows(), Boolean.valueOf(true));
    assertEquals(attachmentModelNew.length(), Long.valueOf("0"));
    assertEquals(attachmentModelNew.revpos(), Long.valueOf("1"));
    assertEquals(attachmentModelNew.stub(), Boolean.valueOf(true));
}
Also used : Attachment(com.ibm.cloud.cloudant.v1.model.Attachment) Test(org.testng.annotations.Test)

Example 95 with Attachment

use of org.hl7.fhir.r4.model.Attachment in project cloudant-java-sdk by IBM.

the class BulkDocsTest method testBulkDocs.

@Test
public void testBulkDocs() throws Throwable {
    Attachment attachmentModel = new Attachment.Builder().contentType("testString").data(TestUtilities.createMockByteArray("This is a mock byte array value.")).digest("testString").encodedLength(Long.valueOf("0")).encoding("testString").follows(true).length(Long.valueOf("0")).revpos(Long.valueOf("1")).stub(true).build();
    assertEquals(attachmentModel.contentType(), "testString");
    assertEquals(attachmentModel.data(), TestUtilities.createMockByteArray("This is a mock byte array value."));
    assertEquals(attachmentModel.digest(), "testString");
    assertEquals(attachmentModel.encodedLength(), Long.valueOf("0"));
    assertEquals(attachmentModel.encoding(), "testString");
    assertEquals(attachmentModel.follows(), Boolean.valueOf(true));
    assertEquals(attachmentModel.length(), Long.valueOf("0"));
    assertEquals(attachmentModel.revpos(), Long.valueOf("1"));
    assertEquals(attachmentModel.stub(), Boolean.valueOf(true));
    Revisions revisionsModel = new Revisions.Builder().ids(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).start(Long.valueOf("1")).build();
    assertEquals(revisionsModel.ids(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(revisionsModel.start(), Long.valueOf("1"));
    DocumentRevisionStatus documentRevisionStatusModel = new DocumentRevisionStatus.Builder().rev("testString").status("available").build();
    assertEquals(documentRevisionStatusModel.rev(), "testString");
    assertEquals(documentRevisionStatusModel.status(), "available");
    Document documentModel = new Document.Builder().attachments(new java.util.HashMap<String, Attachment>() {

        {
            put("foo", attachmentModel);
        }
    }).conflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).deleted(true).deletedConflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).id("testString").localSeq("testString").rev("testString").revisions(revisionsModel).revsInfo(new java.util.ArrayList<DocumentRevisionStatus>(java.util.Arrays.asList(documentRevisionStatusModel))).add("foo", "testString").build();
    assertEquals(documentModel.getAttachments(), new java.util.HashMap<String, Attachment>() {

        {
            put("foo", attachmentModel);
        }
    });
    assertEquals(documentModel.getConflicts(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(documentModel.isDeleted(), Boolean.valueOf(true));
    assertEquals(documentModel.getDeletedConflicts(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(documentModel.getId(), "testString");
    assertEquals(documentModel.getLocalSeq(), "testString");
    assertEquals(documentModel.getRev(), "testString");
    assertEquals(documentModel.getRevisions(), revisionsModel);
    assertEquals(documentModel.getRevsInfo(), new java.util.ArrayList<DocumentRevisionStatus>(java.util.Arrays.asList(documentRevisionStatusModel)));
    assertEquals(documentModel.get("foo"), "testString");
    BulkDocs bulkDocsModel = new BulkDocs.Builder().docs(new java.util.ArrayList<Document>(java.util.Arrays.asList(documentModel))).newEdits(true).build();
    assertEquals(bulkDocsModel.docs(), new java.util.ArrayList<Document>(java.util.Arrays.asList(documentModel)));
    assertEquals(bulkDocsModel.newEdits(), Boolean.valueOf(true));
    String json = TestUtilities.serialize(bulkDocsModel);
    BulkDocs bulkDocsModelNew = TestUtilities.deserialize(json, BulkDocs.class);
    assertTrue(bulkDocsModelNew instanceof BulkDocs);
    assertEquals(bulkDocsModelNew.newEdits(), Boolean.valueOf(true));
}
Also used : ArrayList(java.util.ArrayList) Attachment(com.ibm.cloud.cloudant.v1.model.Attachment) Revisions(com.ibm.cloud.cloudant.v1.model.Revisions) Document(com.ibm.cloud.cloudant.v1.model.Document) DocumentRevisionStatus(com.ibm.cloud.cloudant.v1.model.DocumentRevisionStatus) BulkDocs(com.ibm.cloud.cloudant.v1.model.BulkDocs) Test(org.testng.annotations.Test)

Aggregations

Attachment (org.hl7.fhir.r4.model.Attachment)33 ArrayList (java.util.ArrayList)32 Attachment (com.ibm.cloud.cloudant.v1.model.Attachment)17 Reference (org.hl7.fhir.r4.model.Reference)17 Test (org.testng.annotations.Test)17 DocumentRevisionStatus (com.ibm.cloud.cloudant.v1.model.DocumentRevisionStatus)16 Revisions (com.ibm.cloud.cloudant.v1.model.Revisions)16 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)16 NotImplementedException (org.apache.commons.lang3.NotImplementedException)14 HashMap (java.util.HashMap)12 Coding (org.hl7.fhir.r4.model.Coding)11 Document (com.ibm.cloud.cloudant.v1.model.Document)10 List (java.util.List)10 DiagnosticReport (org.hl7.fhir.r4.model.DiagnosticReport)10 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)9 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)9 Observation (org.hl7.fhir.r4.model.Observation)9 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)8 Resource (org.hl7.fhir.r4.model.Resource)8 DesignDocument (com.ibm.cloud.cloudant.v1.model.DesignDocument)7