示例#1
0
 public void assertNull(Object p) {
   try {
     Assert.assertNull(p);
   } catch (Error e) {
     lastTestFailed = true;
     throw e;
   }
 }
  @Test
  public void store_get_delete() throws Exception {
    JdbcContentPersistenceService tested = getTested();

    // case - get from noexisting table
    Assert.assertNull(tested.get("a-1", "tt"));

    String sysContentType = "testtype_1";
    Map<String, Object> content = null;
    // case - store into nonexisting table, nonexisting id
    tested.store("aaa-1", sysContentType, content);

    assertRowCount(tested, sysContentType, 1);
    Assert.assertNull(tested.get("aaa-1", sysContentType));

    // case - get nonexisting id from existing table
    Assert.assertNull(tested.get("a-1", sysContentType));

    // case - test persistence after commit
    assertRowCount(tested, sysContentType, 1);
    Assert.assertNull(tested.get("aaa-1", sysContentType));

    // case - store into existing table, nonexisting id
    content = new HashMap<String, Object>();
    content.put("testkey", "testvalue");
    tested.store("aaa-2", sysContentType, content);
    assertRowCount(tested, sysContentType, 2);
    Assert.assertNull(tested.get("aaa-1", sysContentType));
    TestUtils.assertJsonContent(
        "{\"testkey\" : \"testvalue\"}", tested.get("aaa-2", sysContentType));

    // case - store into existing table, existing id so update, sys_updated is Date instance
    content.put(ContentObjectFields.SYS_UPDATED, new Date(65463749865l));
    tested.store("aaa-1", sysContentType, content);
    assertRowCount(tested, sysContentType, 2);
    TestUtils.assertJsonContent(
        "{\"testkey\" : \"testvalue\", \"sys_updated\":\"1972-01-28T16:22:29.865Z\"}",
        tested.get("aaa-1", sysContentType));
    assertTableContent(
        tested,
        sysContentType,
        "aaa-1",
        SearchUtils.getISODateFormat().parse("1972-01-28T16:22:29.865+0000"));
    // case - store into existing table, existing id so update, sys_updated is ISO String instance
    content.put(ContentObjectFields.SYS_UPDATED, "1973-01-28T17:22:29.865+0100");
    tested.store("aaa-2", sysContentType, content);
    assertRowCount(tested, sysContentType, 2);
    TestUtils.assertJsonContent(
        "{\"testkey\" : \"testvalue\", \"sys_updated\":\"1973-01-28T17:22:29.865+0100\"}",
        tested.get("aaa-2", sysContentType));
    assertTableContent(
        tested,
        sysContentType,
        "aaa-2",
        SearchUtils.getISODateFormat().parse("1973-01-28T17:22:29.865+0100"));

    // case - store into existing table, existing id so update, sys_updated is invalid String
    // instance but no
    // exception and table is correctly filled
    content.put(ContentObjectFields.SYS_UPDATED, "sdfasdf");
    tested.store("aaa-2", sysContentType, content);
    assertRowCount(tested, sysContentType, 2);
    TestUtils.assertJsonContent(
        "{\"testkey\" : \"testvalue\", \"sys_updated\":\"sdfasdf\"}",
        tested.get("aaa-2", sysContentType));
    assertTableContent(tested, sysContentType, "aaa-2", null);

    // case - delete from nonexisting table
    tested.delete("aaa", "jj");

    // case - delete from existing table, nonexisting id
    tested.delete("a-1", sysContentType);
    assertRowCount(tested, sysContentType, 2);

    // case - delete existing id
    tested.delete("aaa-1", sysContentType);
    assertRowCount(tested, sysContentType, 1);
    Assert.assertNull(tested.get("aaa-1", sysContentType));
    Assert.assertNotNull(tested.get("aaa-2", sysContentType));
  }