@Test public void toIntListEntity() throws ParseException { Integer id0 = Integer.valueOf(0); Integer id1 = Integer.valueOf(1); Entity entity0 = when(mock(Entity.class).getIdValue()).thenReturn(id0).getMock(); Entity entity1 = when(mock(Entity.class).getIdValue()).thenReturn(id1).getMock(); assertEquals(DataConverter.toIntList(Arrays.asList(entity0, entity1)), Arrays.asList(id0, id1)); }
@Test public void toListEntity() throws ParseException { String id0 = "0"; String id1 = "1"; Entity entity0 = when(mock(Entity.class).getIdValue()).thenReturn(id0).getMock(); Entity entity1 = when(mock(Entity.class).getIdValue()).thenReturn(id1).getMock(); assertEquals(DataConverter.toList(Arrays.asList(entity0, entity1)), Arrays.asList(id0, id1)); }
@Test public void convertDateTime() throws ParseException { AttributeMetaData attr = new DefaultAttributeMetaData("attr").setDataType(MolgenisFieldTypes.DATETIME); assertEquals( DataConverter.convert("2015-05-22T11:12:13+0500", attr), MolgenisDateFormat.getDateTimeFormat().parse("2015-05-22T11:12:13+0500")); }
private void validateEntityValueReferences(Entity entity, ValidationResource validationResource) { validationResource .getRefAttrs() .forEach( refAttr -> { HugeSet<Object> refEntityIds = validationResource.getRefEntitiesIds().get(refAttr.getRefEntity().getName()); Iterable<Entity> refEntities; if (refAttr.getDataType() instanceof XrefField) { Entity refEntity = entity.getEntity(refAttr.getName()); if (refEntity != null) { refEntities = singleton(refEntity); } else { refEntities = emptyList(); } } else { refEntities = entity.getEntities(refAttr.getName()); } for (Entity refEntity : refEntities) { if (!refEntityIds.contains(refEntity.getIdValue())) { boolean selfReference = entity.getEntityMetaData().getName().equals(refAttr.getRefEntity().getName()); if (!(selfReference && entity.getIdValue().equals(refEntity.getIdValue()))) { String message = String.format( "Unknown xref value '%s' for attribute '%s' of entity '%s'.", DataConverter.toString(refEntity.getIdValue()), refAttr.getName(), getName()); ConstraintViolation constraintViolation = new ConstraintViolation( message, refAttr, Long.valueOf(validationResource.getRow())); validationResource.addViolation(constraintViolation); } } validationResource.addRefEntityId(getName(), refEntity.getIdValue()); } }); }
@Test public void toIntListInteger() throws ParseException { Integer id0 = Integer.valueOf(0); Integer id1 = Integer.valueOf(1); assertEquals(DataConverter.toIntList(Arrays.asList(id0, id1)), Arrays.asList(id0, id1)); }
@Test public void toListString() throws ParseException { String id0 = "0"; String id1 = "1"; assertEquals(DataConverter.toList(Arrays.asList(id0, id1)), Arrays.asList(id0, id1)); }
@Test public void convert() { assertEquals(DataConverter.convert("test", String.class), "test"); assertEquals(DataConverter.convert(5L, Number.class).longValue(), 5L); }