Esempio n. 1
0
  @Test
  public void testUpdateAndDeleteOfChildren() {
    final Library lib = createTestData();
    {
      String content =
          doGetRequest(
              LibraryModelPackage.INSTANCE.getLibraryEClass().getName(),
              null,
              HttpServletResponse.SC_OK);
      final List<Object> objects = deserialize(content);
      Assert.assertEquals(1, objects.size());
      final ResponseType responseType = (ResponseType) objects.get(0);
      final Library libResult = (Library) responseType.getData().get(0);
      Assert.assertNotSame(lib, libResult);
      Assert.assertEquals(lib.getDb_Id(), libResult.getDb_Id());

      // now remove parts from the library
      Writer w = libResult.getWriters().get(0);
      libResult.getBooks().removeAll(w.getBooks());
      libResult.getWriters().remove(w);
      libResult.setName("updated"); // $NON-NLS-1$
      content = serialize(libResult);
      doContentRequest(
          getObjectUrlPart(libResult), content, HttpServletResponse.SC_OK, null, HttpMethod.PUT);
      checkExists(w, false);
      for (Book bk : w.getBooks()) {
        checkExists(bk, false);
      }
    }

    // check that the name of the library got updated
    {
      String content =
          doGetRequest(
              LibraryModelPackage.INSTANCE.getLibraryEClass().getName(),
              null,
              HttpServletResponse.SC_OK);
      final List<Object> objects = deserialize(content);
      Assert.assertEquals(1, objects.size());
      final ResponseType responseType = (ResponseType) objects.get(0);
      final Library resultLib = (Library) responseType.getData().get(0);
      Assert.assertEquals("updated", resultLib.getName()); // $NON-NLS-1$
    }
  }
Esempio n. 2
0
  private Library createTestDataInstance() {
    final LibraryModelFactory factory = LibraryModelPackage.MODELFACTORY;
    final int COUNT = 5;

    // create testdata
    final Library lib = factory.createLibrary();
    lib.setName("name"); // $NON-NLS-1$

    for (int w = 0; w < COUNT; w++) {
      final Writer writer = factory.createWriter();
      lib.getWriters().add(writer);

      for (int b = 0; b < COUNT; b++) {
        final Book bk = factory.createBook();
        bk.setAuthor(writer);
        writer.getBooks().add(bk);
        lib.getBooks().add(bk);
      }
    }
    return lib;
  }