use of com.ibm.cloud.cloudant.v1.model.DocsResultRow in project cloudant-java-sdk by IBM.
the class DocsResultRowTest method testDocsResultRow.
@Test
public void testDocsResultRow() throws Throwable {
DocsResultRow docsResultRowModel = new DocsResultRow();
assertNull(docsResultRowModel.getCausedBy());
assertNull(docsResultRowModel.getError());
assertNull(docsResultRowModel.getReason());
assertNull(docsResultRowModel.getDoc());
assertNull(docsResultRowModel.getId());
assertNull(docsResultRowModel.getKey());
assertNull(docsResultRowModel.getValue());
}
use of com.ibm.cloud.cloudant.v1.model.DocsResultRow in project knative-eventing-java-app by IBM.
the class CloudEventStoreCloudant method getEvents.
@Override
public List<CloudEvent<?, ?>> getEvents() {
try {
List<CloudEvent<?, ?>> events = new ArrayList<>();
PostAllDocsOptions docsOptions = new PostAllDocsOptions.Builder().db(this.dbName).includeDocs(true).build();
AllDocsResult allDocResults = this.client.postAllDocs(docsOptions).execute().getResult();
for (DocsResultRow docResult : allDocResults.getRows()) {
Document document = docResult.getDoc();
@SuppressWarnings("rawtypes") CloudEventImpl evt = this.gson.fromJson(document.toString(), CloudEventImpl.class);
events.add(evt);
}
return events;
} catch (NotFoundException e) {
logger.warn("Unable to retrieve all documents from Cloudant", e);
return Collections.emptyList();
}
}
use of com.ibm.cloud.cloudant.v1.model.DocsResultRow in project knative-eventing-java-app by IBM.
the class CloudEventStoreCloudant method removeAllEvents.
@Override
public void removeAllEvents() throws Exception {
try {
PostAllDocsOptions docsOptions = new PostAllDocsOptions.Builder().db(this.dbName).includeDocs(true).build();
AllDocsResult allDocResults = this.client.postAllDocs(docsOptions).execute().getResult();
for (DocsResultRow docResult : allDocResults.getRows()) {
Document document = docResult.getDoc();
DeleteDocumentOptions deleteDocumentOptions = new DeleteDocumentOptions.Builder().db(this.dbName).docId(document.getId()).rev(document.getRev()).build();
DocumentResult deleteDocumentResponse = client.deleteDocument(deleteDocumentOptions).execute().getResult();
if (!deleteDocumentResponse.isOk()) {
logger.info("Could not delete a document.");
}
}
} catch (NotFoundException e) {
String errMsg = "Unable to retrieve all documents from Cloudant";
logger.error(errMsg, e);
throw new Exception(errMsg, e);
}
}
use of com.ibm.cloud.cloudant.v1.model.DocsResultRow in project knative-eventing-java-app by IBM.
the class EventControllerEndpointTest method mockGetEvents.
public void mockGetEvents(@SuppressWarnings("rawtypes") final List<CloudEventImpl> docs) throws Exception {
Gson customGson = SBApplicationConfig.getCustomGsonBuilder().create();
List<DocsResultRow> docsResultRows = new ArrayList<>();
for (CloudEvent<?, ?> cloudEvent : docs) {
Document document = new Document();
document.setProperties(customGson.fromJson(customGson.toJson(cloudEvent), Map.class));
DocsResultRow docsResultRowMock = Mockito.mock(DocsResultRow.class);
Mockito.when(docsResultRowMock.getDoc()).thenReturn(document);
docsResultRows.add(docsResultRowMock);
}
long expectedNumEvents = docs.size();
@SuppressWarnings("unchecked") Response<AllDocsResult> responseMock = Mockito.mock(Response.class);
AllDocsResult allDocsResultMock = Mockito.mock(AllDocsResult.class);
Mockito.when(this.eventService.getNumEvents()).thenReturn(expectedNumEvents);
Mockito.when(responseMock.getResult()).thenReturn(allDocsResultMock);
Mockito.when(allDocsResultMock.getRows()).thenReturn(docsResultRows);
}
Aggregations