Пример #1
0
  @Test
  public void deveAlterarUmaInstanciaEmUmRepositorio() throws RepositoryException {
    EntidadeExemplo instance = new EntidadeExemplo();

    this.keeper.persist(instance);
    assertNotNull(instance.getId());
    assertTrue(instance.getActive());
    assertTrue(this.manager.contains(instance));

    this.manager.detach(instance);
    assertFalse(this.manager.contains(instance));

    Field active = ReflectionUtil.getField(FieldEnum.ACTIVE.getValue(), EntidadeExemplo.class);
    ReflectionUtil.set(Boolean.FALSE, active, instance);

    String value = "Teste";
    instance.setStringField(value);

    this.keeper.persist(instance);

    assertNotNull(instance.getId());
    assertTrue(instance.getActive());

    EntidadeExemplo actualInstance = this.manager.find(EntidadeExemplo.class, instance.getId());
    assertEquals(value, actualInstance.getStringField());
  }
Пример #2
0
  @Test
  public void devePersistirUmaInstanciaEmUmRepositorio() throws RepositoryException {
    EntidadeExemplo instance = new EntidadeExemplo();

    this.keeper.persist(instance);

    assertNotNull(instance.getId());
    assertTrue(instance.getActive());
    assertTrue(this.manager.contains(instance));
    assertNotNull(this.manager.find(EntidadeExemplo.class, instance.getId()));
  }
Пример #3
0
  @Test
  public void deveRemoverDeFormaFisicaUmaInstanciaEmUmRepositorio() throws RepositoryException {
    EntidadeExemplo instance = new EntidadeExemplo();

    this.keeper.persist(instance);
    assertNotNull(instance.getId());
    assertTrue(instance.getActive());
    assertTrue(this.manager.contains(instance));

    this.keeper.remove(instance, RemoveEnum.PHYSICAL);

    assertNotNull(instance.getId());
    assertTrue(instance.getActive());
    assertFalse(this.manager.contains(instance));
    assertNull(this.manager.find(EntidadeExemplo.class, instance.getId()));
  }
Пример #4
0
  @Test
  public void naoDeveLancarExcecaoQuandoRemoverDeFormaFisicaUmaInstanciaInexistente() {
    try {
      EntidadeExemplo instance = new EntidadeExemplo();

      this.keeper.persist(instance);
      assertNotNull(instance.getId());
      assertTrue(instance.getActive());
      assertTrue(this.manager.contains(instance));

      this.keeper.remove(instance, RemoveEnum.PHYSICAL);

      assertNotNull(instance.getId());
      assertTrue(instance.getActive());
      assertFalse(this.manager.contains(instance));
      assertNull(this.manager.find(EntidadeExemplo.class, instance.getId()));

      this.keeper.remove(instance, RemoveEnum.PHYSICAL);
    } catch (RepositoryException e) {
      fail(e.getMessage());
    }
  }
Пример #5
0
  @Test
  public void deveRemoverDeFormaLogicaComParametroUmaInstanciaDetachedEmUmRepositorio()
      throws RepositoryException {
    EntidadeExemplo instance = new EntidadeExemplo();

    this.keeper.persist(instance);
    assertNotNull(instance.getId());
    assertTrue(instance.getActive());
    assertTrue(this.manager.contains(instance));

    this.manager.detach(instance);
    assertFalse(this.manager.contains(instance));

    Field active = ReflectionUtil.getField(FieldEnum.ACTIVE.getValue(), EntidadeExemplo.class);
    ReflectionUtil.set(Boolean.TRUE, active, instance);

    this.keeper.remove(instance, RemoveEnum.LOGICAL);

    assertNotNull(instance.getId());
    assertFalse(instance.getActive());
    assertNotNull(this.manager.find(EntidadeExemplo.class, instance.getId()));
  }