Search in sources :

Example 1 with TodoEntry

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);
}
Also used : TodoEntry(com.consol.citrus.samples.todolist.model.TodoEntry)

Example 2 with TodoEntry

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;
}
Also used : Attachment(com.consol.citrus.samples.todolist.model.Attachment) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SoapMessage(org.springframework.ws.soap.SoapMessage) TodoEntry(com.consol.citrus.samples.todolist.model.TodoEntry)

Example 3 with TodoEntry

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);
        }
    });
}
Also used : TestContext(com.consol.citrus.context.TestContext) UUID(java.util.UUID) TodoEntry(com.consol.citrus.samples.todolist.model.TodoEntry) Test(org.testng.annotations.Test) CitrusTest(com.consol.citrus.annotations.CitrusTest) CitrusTest(com.consol.citrus.annotations.CitrusTest)

Example 4 with TodoEntry

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);
        }
    });
}
Also used : TestContext(com.consol.citrus.context.TestContext) UUID(java.util.UUID) TodoEntry(com.consol.citrus.samples.todolist.model.TodoEntry) Test(org.testng.annotations.Test) CitrusTest(com.consol.citrus.annotations.CitrusTest) CitrusTest(com.consol.citrus.annotations.CitrusTest)

Example 5 with TodoEntry

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;
}
Also used : Attachment(com.consol.citrus.samples.todolist.model.Attachment) TodoEntry(com.consol.citrus.samples.todolist.model.TodoEntry)

Aggregations

TodoEntry (com.consol.citrus.samples.todolist.model.TodoEntry)6 CitrusTest (com.consol.citrus.annotations.CitrusTest)2 TestContext (com.consol.citrus.context.TestContext)2 Attachment (com.consol.citrus.samples.todolist.model.Attachment)2 UUID (java.util.UUID)2 Test (org.testng.annotations.Test)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 SoapMessage (org.springframework.ws.soap.SoapMessage)1