Example usage for org.springframework.data.rest.webmvc.json.patch PatchException getMessage

List of usage examples for org.springframework.data.rest.webmvc.json.patch PatchException getMessage

Introduction

In this page you can find the example usage for org.springframework.data.rest.webmvc.json.patch PatchException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.springframework.data.rest.webmvc.json.patch.JsonPatchTest.java

@Test
public void failureAtBeginning() throws Exception {
    // initial Todo list
    List<Todo> todos = new ArrayList<Todo>();
    todos.add(new Todo(1L, "A", true));
    todos.add(new Todo(2L, "B", false));
    todos.add(new Todo(3L, "C", false));
    todos.add(new Todo(4L, "D", false));
    todos.add(new Todo(5L, "E", false));
    todos.add(new Todo(6L, "F", false));

    Patch patch = readJsonPatch("patch-failing-operation-first.json");

    try {//  w  ww .  j av  a 2 s .com
        patch.apply(todos, Todo.class);
        fail();
    } catch (PatchException e) {
        assertEquals("Test against path '/5/description' failed.", e.getMessage());
    }

    // nothing should have changed
    assertEquals(6, todos.size());
    assertFalse(todos.get(1).isComplete());
    assertEquals("D", todos.get(3).getDescription());
    assertEquals("E", todos.get(4).getDescription());
    assertEquals("F", todos.get(5).getDescription());
}

From source file:org.springframework.data.rest.webmvc.json.patch.JsonPatchTest.java

@Test
public void failureInMiddle() throws Exception {
    // initial Todo list
    List<Todo> todos = new ArrayList<Todo>();
    todos.add(new Todo(1L, "A", true));
    todos.add(new Todo(2L, "B", false));
    todos.add(new Todo(3L, "C", false));
    todos.add(new Todo(4L, "D", false));
    todos.add(new Todo(5L, "E", false));
    todos.add(new Todo(6L, "F", false));

    Patch patch = readJsonPatch("patch-failing-operation-in-middle.json");

    try {//from  w w w  . ja va  2  s  .  c om
        patch.apply(todos, Todo.class);
        fail();
    } catch (PatchException e) {
        assertEquals("Test against path '/5/description' failed.", e.getMessage());
    }

    // nothing should have changed
    assertEquals(6, todos.size());
    assertFalse(todos.get(1).isComplete());
    assertEquals("D", todos.get(3).getDescription());
    assertEquals("E", todos.get(4).getDescription());
    assertEquals("F", todos.get(5).getDescription());
}