@SuppressWarnings("unchecked") @Test void deserializeEntityTypeWithAttributes() { String serializedEntityType = "{\"id\":\"MyEntityTypeId\",\"packageId\":\"MyPackage\",\"label\":\"My Entity Type\",\"labelI18n\":{},\"description\":\"My Entity Type description\",\"descriptionI18n\":{},\"attributes\":[{\"id\":\"MyAttributeId\",\"name\":\"myAttributeName\",\"sequenceNr\":4,\"type\":\"onetomany\",\"idAttribute\":true,\"labelAttribute\":true,\"lookupAttributeIndex\":3,\"refEntityTypeId\":\"MyRefEntityType\",\"cascadeDelete\":{\"value\":true},\"mappedById\":\"myMappedByAttributeId\",\"orderBy\":\"myAttributeName,DESC\",\"label\":\"My Attribute\",\"labelI18n\":{},\"description\":\"My Attribute description\",\"descriptionI18n\":{},\"nullable\":true,\"auto\":false,\"visible\":true,\"unique\":true,\"readOnly\":true,\"aggregatable\":true,\"expression\":\"MyExpression\",\"enumOptions\":[],\"tagIds\":[\"MyAttributeTagId\"],\"nullableExpression\":\"MyNullableExpression\",\"visibleExpression\":\"MyVisibleExpression\",\"validationExpression\":\"MyValidationExpression\",\"defaultValue\":\"MyDefaultValue\"}],\"abstract0\":true,\"extendsId\":\"MyExtendsEntityTypeId\",\"tagIds\":[\"MyTagId\"],\"backend\":\"PostgreSQL\",\"indexingDepth\":2}"; EntityType entityType = mock(EntityType.class); when(entityTypeFactory.create()).thenReturn(entityType); Attribute attribute = mock(Attribute.class); when(attributeFactory.create()).thenReturn(attribute); when(attribute.setEntity(entityType)).thenReturn(attribute); EntityType extendsEntityType = mock(EntityType.class); doReturn(extendsEntityType) .when(dataService) .findOneById( EntityTypeMetadata.ENTITY_TYPE_META_DATA, "MyExtendsEntityTypeId", new Fetch().field(EntityTypeMetadata.ID), EntityType.class); EntityType refEntityType = mock(EntityType.class); doReturn(refEntityType) .when(dataService) .findOneById( EntityTypeMetadata.ENTITY_TYPE_META_DATA, "MyRefEntityType", new Fetch().field(EntityTypeMetadata.ID), EntityType.class); Package entityTypePackage = mock(Package.class); when(dataService.findOneById( PackageMetadata.PACKAGE, "MyPackage", new Fetch().field(PackageMetadata.ID), Package.class)) .thenReturn(entityTypePackage); Attribute mappedByAttribute = mock(Attribute.class); when(dataService.findOneById( AttributeMetadata.ATTRIBUTE_META_DATA, "myMappedByAttributeId", new Fetch().field(AttributeMetadata.ID), Attribute.class)) .thenReturn(mappedByAttribute); Tag entityTypeTag = mock(Tag.class); Tag attributeTag = mock(Tag.class); when(dataService.findAll( eq(TagMetadata.TAG), any(Stream.class), eq(new Fetch().field(TagMetadata.ID)), eq(Tag.class))) .thenReturn(Stream.of(entityTypeTag)) .thenReturn(Stream.of(attributeTag)); EntityType deserializedEntityType = entityTypeSerializerImpl.deserializeEntityType(serializedEntityType); assertAll( () -> verify(deserializedEntityType).setId("MyEntityTypeId"), () -> verify(deserializedEntityType).setPackage(entityTypePackage), () -> verify(deserializedEntityType).setLabel("My Entity Type"), () -> verify(deserializedEntityType).setDescription("My Entity Type description"), () -> verify(deserializedEntityType).setOwnAllAttributes(singletonList(attribute)), () -> verify(deserializedEntityType).setAbstract(true), () -> verify(deserializedEntityType).setExtends(extendsEntityType), () -> verify(deserializedEntityType).setTags(singletonList(entityTypeTag)), () -> verify(deserializedEntityType).setBackend("PostgreSQL"), () -> verify(deserializedEntityType).setIndexingDepth(2), () -> verifyNoMoreInteractions(deserializedEntityType), () -> verify(attribute).setIdentifier("MyAttributeId"), () -> verify(attribute).setName("myAttributeName"), () -> verify(attribute).setEntity(entityType), () -> verify(attribute).setSequenceNumber(4), () -> verify(attribute).setDataType(AttributeType.ONE_TO_MANY), () -> verify(attribute).setIdAttribute(true), () -> verify(attribute).setLabelAttribute(true), () -> verify(attribute).setLabelAttribute(true), () -> verify(attribute).setLookupAttributeIndex(3), () -> verify(attribute).setRefEntity(refEntityType), () -> verify(attribute).setCascadeDelete(true), () -> verify(attribute).setMappedBy(mappedByAttribute), () -> verify(attribute).setOrderBy(new Sort("myAttributeName", Direction.DESC)), () -> verify(attribute).setLabel("My Attribute"), () -> verify(attribute).setDescription("My Attribute description"), () -> verify(attribute).setNillable(true), () -> verify(attribute).setAuto(false), () -> verify(attribute).setVisible(true), () -> verify(attribute).setUnique(true), () -> verify(attribute).setReadOnly(true), () -> verify(attribute).setAggregatable(true), () -> verify(attribute).setExpression("MyExpression"), () -> verify(attribute).setEnumOptions(emptyList()), () -> verify(attribute).setTags(singletonList(attributeTag)), () -> verify(attribute).setNullableExpression("MyNullableExpression"), () -> verify(attribute).setVisibleExpression("MyVisibleExpression"), () -> verify(attribute).setValidationExpression("MyValidationExpression"), () -> verify(attribute).setDefaultValue("MyDefaultValue"), () -> verify(attribute).setRangeMin(null), () -> verify(attribute).setRangeMax(null), () -> verify(attribute).setParent(null), () -> verifyNoMoreInteractions(attribute)); }
@Override public EntityType deserializeEntityType(String serializedEntityType) { SerializableEntityType serializableEntityType = gson.fromJson(serializedEntityType, SerializableEntityType.class); return toEntityType(serializableEntityType); }
EntityTypeSerializerImpl implements EntityTypeSerializer { @Override public EntityType deserializeEntityType(String serializedEntityType) { SerializableEntityType serializableEntityType = gson.fromJson(serializedEntityType, SerializableEntityType.class); return toEntityType(serializableEntityType); } }
EntityTypeSerializerImpl implements EntityTypeSerializer { @Override public EntityType deserializeEntityType(String serializedEntityType) { SerializableEntityType serializableEntityType = gson.fromJson(serializedEntityType, SerializableEntityType.class); return toEntityType(serializableEntityType); } EntityTypeSerializerImpl(
      DataService dataService,
      EntityTypeFactory entityTypeFactory,
      AttributeFactory attributeFactory); }
EntityTypeSerializerImpl implements EntityTypeSerializer { @Override public EntityType deserializeEntityType(String serializedEntityType) { SerializableEntityType serializableEntityType = gson.fromJson(serializedEntityType, SerializableEntityType.class); return toEntityType(serializableEntityType); } EntityTypeSerializerImpl(
      DataService dataService,
      EntityTypeFactory entityTypeFactory,
      AttributeFactory attributeFactory); @Override String serializeEntityType(EntityType entityType); @Override EntityType deserializeEntityType(String serializedEntityType); }
EntityTypeSerializerImpl implements EntityTypeSerializer { @Override public EntityType deserializeEntityType(String serializedEntityType) { SerializableEntityType serializableEntityType = gson.fromJson(serializedEntityType, SerializableEntityType.class); return toEntityType(serializableEntityType); } EntityTypeSerializerImpl(
      DataService dataService,
      EntityTypeFactory entityTypeFactory,
      AttributeFactory attributeFactory); @Override String serializeEntityType(EntityType entityType); @Override EntityType deserializeEntityType(String serializedEntityType);  }