@Test void dehydrateOnetoMany() { String attrName = "attr"; Entity entity = mock(Entity.class); Entity oneToManyEntity0 = mock(Entity.class); String oneToManyEntity0IdValue = "ref0"; when(oneToManyEntity0.getIdValue()).thenReturn(oneToManyEntity0IdValue); Entity oneToManyEntity1 = mock(Entity.class); String oneToManyEntity1IdValue = "ref1"; when(oneToManyEntity1.getIdValue()).thenReturn(oneToManyEntity1IdValue); when(entity.getEntities(attrName)).thenReturn(newArrayList(oneToManyEntity0, oneToManyEntity1)); EntityType entityType = mock(EntityType.class); Attribute oneToManyAttr = mock(Attribute.class); when(oneToManyAttr.getName()).thenReturn(attrName); when(oneToManyAttr.getDataType()).thenReturn(ONE_TO_MANY); when(entityType.getAtomicAttributes()).thenReturn(singleton(oneToManyAttr)); when(entity.getEntityType()).thenReturn(entityType); assertEquals( singletonMap(attrName, newArrayList(oneToManyEntity0IdValue, oneToManyEntity1IdValue)), entityHydration.dehydrate(entity)); }
public Map<String, Object> dehydrate(Entity entity) { LOG.trace("Dehydrating entity {}", entity); Map<String, Object> dehydratedEntity = newHashMap(); EntityType entityType = entity.getEntityType(); entityType .getAtomicAttributes() .forEach( attribute -> { if (!attribute.hasExpression()) { String name = attribute.getName(); AttributeType type = attribute.getDataType(); dehydratedEntity.put(name, getValueBasedOnType(entity, name, type)); } }); return dehydratedEntity; }
EntityHydration { public Map<String, Object> dehydrate(Entity entity) { LOG.trace("Dehydrating entity {}", entity); Map<String, Object> dehydratedEntity = newHashMap(); EntityType entityType = entity.getEntityType(); entityType .getAtomicAttributes() .forEach( attribute -> { if (!attribute.hasExpression()) { String name = attribute.getName(); AttributeType type = attribute.getDataType(); dehydratedEntity.put(name, getValueBasedOnType(entity, name, type)); } }); return dehydratedEntity; } }
EntityHydration { public Map<String, Object> dehydrate(Entity entity) { LOG.trace("Dehydrating entity {}", entity); Map<String, Object> dehydratedEntity = newHashMap(); EntityType entityType = entity.getEntityType(); entityType .getAtomicAttributes() .forEach( attribute -> { if (!attribute.hasExpression()) { String name = attribute.getName(); AttributeType type = attribute.getDataType(); dehydratedEntity.put(name, getValueBasedOnType(entity, name, type)); } }); return dehydratedEntity; } EntityHydration(EntityManager entityManager); }
EntityHydration { public Map<String, Object> dehydrate(Entity entity) { LOG.trace("Dehydrating entity {}", entity); Map<String, Object> dehydratedEntity = newHashMap(); EntityType entityType = entity.getEntityType(); entityType .getAtomicAttributes() .forEach( attribute -> { if (!attribute.hasExpression()) { String name = attribute.getName(); AttributeType type = attribute.getDataType(); dehydratedEntity.put(name, getValueBasedOnType(entity, name, type)); } }); return dehydratedEntity; } EntityHydration(EntityManager entityManager); Entity hydrate(Map<String, Object> dehydratedEntity, EntityType entityType); Entity hydrate(
      Map<String, Object> dehydratedEntity,
      EntityType entityType,
      @Nullable @CheckForNull Fetch fetch); Map<String, Object> dehydrate(Entity entity); }
EntityHydration { public Map<String, Object> dehydrate(Entity entity) { LOG.trace("Dehydrating entity {}", entity); Map<String, Object> dehydratedEntity = newHashMap(); EntityType entityType = entity.getEntityType(); entityType .getAtomicAttributes() .forEach( attribute -> { if (!attribute.hasExpression()) { String name = attribute.getName(); AttributeType type = attribute.getDataType(); dehydratedEntity.put(name, getValueBasedOnType(entity, name, type)); } }); return dehydratedEntity; } EntityHydration(EntityManager entityManager); Entity hydrate(Map<String, Object> dehydratedEntity, EntityType entityType); Entity hydrate(
      Map<String, Object> dehydratedEntity,
      EntityType entityType,
      @Nullable @CheckForNull Fetch fetch); Map<String, Object> dehydrate(Entity entity);  }