@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()); }
private boolean hasEmptyPredicative(Proposition proposition) { Object[] predicative = proposition.getPredicative(); if (predicative.length == 0) { return true; } for (Object elementOfPredicative : predicative) { if (elementOfPredicative == null) { return true; } if (ReflectionUtil.isCollection(elementOfPredicative.getClass())) { List<?> list = (List<?>) elementOfPredicative; if (list.isEmpty()) { return true; } for (Object elementOfList : list) { if (elementOfList == null) { return true; } } } } return false; }
@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())); }