use of com.consol.citrus.samples.todolist.model.TodoEntry in project citrus-samples by christophd.
the class TodoListService method setStatus.
public void setStatus(final UUID uuid, final boolean done) {
final TodoEntry entry = getEntry(uuid);
entry.setDone(done);
todoListDao.update(entry);
}
use of com.consol.citrus.samples.todolist.model.TodoEntry in project citrus-samples by christophd.
the class TodoWebServiceEndpoint method addTodoEntry.
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "addTodoEntryRequest")
@ResponsePayload
public AddTodoEntryResponse addTodoEntry(@RequestPayload AddTodoEntryRequest request, MessageContext messageContext) {
TodoEntry entry = new TodoEntry(request.getTitle(), request.getDescription());
Iterator<org.springframework.ws.mime.Attachment> it = ((SoapMessage) messageContext.getRequest()).getAttachments();
if (it.hasNext()) {
org.springframework.ws.mime.Attachment attachment = it.next();
Attachment todoAttachment = new Attachment();
String contentId = attachment.getContentId();
if (contentId.startsWith("<") && contentId.endsWith(">")) {
contentId = contentId.substring(1, contentId.length() - 1);
}
todoAttachment.setCid(contentId);
todoAttachment.setContentType(attachment.getContentType());
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
FileCopyUtils.copy(attachment.getInputStream(), out);
todoAttachment.setData(Base64.getEncoder().encodeToString(out.toByteArray()));
} catch (IOException e) {
throw new RuntimeException("Failed to read attachment", e);
}
entry.setAttachment(todoAttachment);
}
todoListService.addEntry(entry);
AddTodoEntryResponse response = new AddTodoEntryResponse();
response.setSuccess(true);
return response;
}
use of com.consol.citrus.samples.todolist.model.TodoEntry in project citrus-samples by christophd.
the class TodoListIT method testObjectMapping.
@Test
@CitrusTest
public void testObjectMapping() {
final UUID uuid = UUID.randomUUID();
variable("todoId", uuid.toString());
variable("todoName", "citrus:concat('todo_', citrus:randomNumber(4))");
variable("todoDescription", "Description: ${todoName}");
http().client(todoClient).send().post("/api/todolist").contentType(ContentType.APPLICATION_JSON.getMimeType()).payload(new TodoEntry(uuid, "${todoName}", "${todoDescription}"), objectMapper);
http().client(todoClient).receive().response(HttpStatus.OK).messageType(MessageType.PLAINTEXT).payload("${todoId}");
http().client(todoClient).send().get("/api/todo/${todoId}").accept(ContentType.APPLICATION_JSON.getMimeType());
http().client(todoClient).receive().response(HttpStatus.OK).validationCallback(new JsonMappingValidationCallback<TodoEntry>(TodoEntry.class, objectMapper) {
@Override
public void validate(TodoEntry todoEntry, Map<String, Object> headers, TestContext context) {
Assert.assertNotNull(todoEntry);
Assert.assertEquals(todoEntry.getId(), uuid);
}
});
}
use of com.consol.citrus.samples.todolist.model.TodoEntry in project citrus-samples by christophd.
the class TodoListIT method testObjectMarshalling.
@Test
@CitrusTest
public void testObjectMarshalling() {
final UUID uuid = UUID.randomUUID();
variable("todoId", uuid.toString());
variable("todoName", "citrus:concat('todo_', citrus:randomNumber(4))");
variable("todoDescription", "Description: ${todoName}");
http().client(todoClient).send().post("/api/todolist").contentType(ContentType.APPLICATION_XML.getMimeType()).payload(new TodoEntry(uuid, "${todoName}", "${todoDescription}"), marshaller);
http().client(todoClient).receive().response(HttpStatus.OK).messageType(MessageType.PLAINTEXT).payload("${todoId}");
http().client(todoClient).send().get("/api/todo/${todoId}").accept(ContentType.APPLICATION_XML.getMimeType());
http().client(todoClient).receive().response(HttpStatus.OK).validationCallback(new XmlMarshallingValidationCallback<TodoEntry>(marshaller) {
@Override
public void validate(TodoEntry todoEntry, Map<String, Object> headers, TestContext context) {
Assert.assertNotNull(todoEntry);
Assert.assertEquals(todoEntry.getId(), uuid);
}
});
}
use of com.consol.citrus.samples.todolist.model.TodoEntry in project citrus-samples by christophd.
the class TodoWebServiceEndpoint method getTodoList.
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getTodoListRequest")
@ResponsePayload
public GetTodoListResponse getTodoList(@RequestPayload GetTodoListRequest request) {
List<TodoEntry> todoEntryList = todoListService.getAllEntries();
GetTodoListResponse response = new GetTodoListResponse();
response.setList(new GetTodoListResponse.List());
for (TodoEntry todoEntry : todoEntryList) {
GetTodoListResponse.List.TodoEntry entry = new GetTodoListResponse.List.TodoEntry();
entry.setId(todoEntry.getId().toString());
entry.setTitle(todoEntry.getTitle());
entry.setDescription(todoEntry.getDescription());
if (todoEntry.getAttachment() != null) {
GetTodoListResponse.List.TodoEntry.Attachment attachment = new GetTodoListResponse.List.TodoEntry.Attachment();
attachment.setCid(todoEntry.getAttachment().getCid());
attachment.setContentType(todoEntry.getAttachment().getContentType());
attachment.setData(todoEntry.getAttachment().getData());
entry.setAttachment(attachment);
}
response.getList().getTodoEntry().add(entry);
}
return response;
}
Aggregations