@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()); }
@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())); }
@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())); }
@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()); } }
@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())); }