@Test void toEntityType() { String id = "MyEntityTypeId"; I18nValue label = I18nValue.builder().setDefaultValue("My Entity Type").build(); String packageId = "MyPackageId"; String extendsEntityTypeId = "MyExtendsEntityTypeId"; ImmutableList<CreateAttributeRequest> attributes = ImmutableList.of(); CreateEntityTypeRequest createEntityTypeRequest = CreateEntityTypeRequest.builder() .setId(id) .setLabel(label) .setDescription(null) .setAbstract(false) .setPackage(packageId) .setExtends(extendsEntityTypeId) .setAttributes(attributes) .build(); Package aPackage = mock(Package.class); when(metaDataService.getPackage(packageId)).thenReturn(Optional.of(aPackage)); EntityType extendsEntityType = mock(EntityType.class); when(metaDataService.getEntityType(extendsEntityTypeId)) .thenReturn(Optional.of(extendsEntityType)); EntityType entityType = mock(EntityType.class); RepositoryCollection repositoryCollection = mock(RepositoryCollection.class); when(repositoryCollection.getName()).thenReturn("PostgreSQL"); when(metaDataService.getDefaultBackend()).thenReturn(repositoryCollection); when(entityTypeFactory.create()).thenReturn(entityType); EntityType mappedEntityType = entityTypeRequestMapper.toEntityType(createEntityTypeRequest); assertAll( () -> verify(mappedEntityType).setId("MyEntityTypeId"), () -> verify(mappedEntityType).setLabel("My Entity Type"), () -> verify(mappedEntityType).setBackend("PostgreSQL"), () -> verify(mappedEntityType).setPackage(aPackage), () -> verify(mappedEntityType).setExtends(extendsEntityType), () -> verify(mappedEntityType).setOwnAllAttributes(emptyList()), () -> verify(mappedEntityType).setAbstract(false), () -> verifyNoMoreInteractions(mappedEntityType)); }
@Override public EntityType toEntityType(CreateEntityTypeRequest entityTypeRequest) { EntityType entityType = entityTypeFactory.create(); String entityTypeId = entityTypeRequest.getId(); if (entityTypeId != null) { entityType.setId(entityTypeId); } String packageId = entityTypeRequest.getPackage(); Package pack = null; if (packageId != null) { pack = metaDataService .getPackage(packageId) .orElseThrow(() -> new UnknownPackageException(entityTypeRequest.getPackage())); } entityType.setPackage(pack); String extendsEntityTypeId = entityTypeRequest.getExtends(); if (extendsEntityTypeId != null) { EntityType extendsEntityType = metaDataService .getEntityType(extendsEntityTypeId) .orElseThrow(() -> new UnknownEntityTypeException(extendsEntityTypeId)); entityType.setExtends(extendsEntityType); } processI18nLabel(entityTypeRequest.getLabel(), entityType); processI18nDescription(entityTypeRequest.getDescription(), entityType); List<Attribute> ownAttributes = attributeRequestMapper.toAttributes( entityTypeRequest.getAttributes(), entityTypeRequest, entityType); entityType.setOwnAllAttributes(ownAttributes); Boolean abstractEntityType = entityTypeRequest.getAbstract(); if (abstractEntityType != null) { entityType.setAbstract(abstractEntityType); } entityType.setBackend(metaDataService.getDefaultBackend().getName()); processSelfReferencingAttributes(entityType, ownAttributes); return entityType; }
EntityTypeRequestMapperImpl implements EntityTypeRequestMapper { @Override public EntityType toEntityType(CreateEntityTypeRequest entityTypeRequest) { EntityType entityType = entityTypeFactory.create(); String entityTypeId = entityTypeRequest.getId(); if (entityTypeId != null) { entityType.setId(entityTypeId); } String packageId = entityTypeRequest.getPackage(); Package pack = null; if (packageId != null) { pack = metaDataService .getPackage(packageId) .orElseThrow(() -> new UnknownPackageException(entityTypeRequest.getPackage())); } entityType.setPackage(pack); String extendsEntityTypeId = entityTypeRequest.getExtends(); if (extendsEntityTypeId != null) { EntityType extendsEntityType = metaDataService .getEntityType(extendsEntityTypeId) .orElseThrow(() -> new UnknownEntityTypeException(extendsEntityTypeId)); entityType.setExtends(extendsEntityType); } processI18nLabel(entityTypeRequest.getLabel(), entityType); processI18nDescription(entityTypeRequest.getDescription(), entityType); List<Attribute> ownAttributes = attributeRequestMapper.toAttributes( entityTypeRequest.getAttributes(), entityTypeRequest, entityType); entityType.setOwnAllAttributes(ownAttributes); Boolean abstractEntityType = entityTypeRequest.getAbstract(); if (abstractEntityType != null) { entityType.setAbstract(abstractEntityType); } entityType.setBackend(metaDataService.getDefaultBackend().getName()); processSelfReferencingAttributes(entityType, ownAttributes); return entityType; } }
EntityTypeRequestMapperImpl implements EntityTypeRequestMapper { @Override public EntityType toEntityType(CreateEntityTypeRequest entityTypeRequest) { EntityType entityType = entityTypeFactory.create(); String entityTypeId = entityTypeRequest.getId(); if (entityTypeId != null) { entityType.setId(entityTypeId); } String packageId = entityTypeRequest.getPackage(); Package pack = null; if (packageId != null) { pack = metaDataService .getPackage(packageId) .orElseThrow(() -> new UnknownPackageException(entityTypeRequest.getPackage())); } entityType.setPackage(pack); String extendsEntityTypeId = entityTypeRequest.getExtends(); if (extendsEntityTypeId != null) { EntityType extendsEntityType = metaDataService .getEntityType(extendsEntityTypeId) .orElseThrow(() -> new UnknownEntityTypeException(extendsEntityTypeId)); entityType.setExtends(extendsEntityType); } processI18nLabel(entityTypeRequest.getLabel(), entityType); processI18nDescription(entityTypeRequest.getDescription(), entityType); List<Attribute> ownAttributes = attributeRequestMapper.toAttributes( entityTypeRequest.getAttributes(), entityTypeRequest, entityType); entityType.setOwnAllAttributes(ownAttributes); Boolean abstractEntityType = entityTypeRequest.getAbstract(); if (abstractEntityType != null) { entityType.setAbstract(abstractEntityType); } entityType.setBackend(metaDataService.getDefaultBackend().getName()); processSelfReferencingAttributes(entityType, ownAttributes); return entityType; } EntityTypeRequestMapperImpl(
      EntityTypeFactory entityTypeFactory,
      AttributeRequestMapper attributeRequestMapper,
      MetaDataService metaDataService); }
EntityTypeRequestMapperImpl implements EntityTypeRequestMapper { @Override public EntityType toEntityType(CreateEntityTypeRequest entityTypeRequest) { EntityType entityType = entityTypeFactory.create(); String entityTypeId = entityTypeRequest.getId(); if (entityTypeId != null) { entityType.setId(entityTypeId); } String packageId = entityTypeRequest.getPackage(); Package pack = null; if (packageId != null) { pack = metaDataService .getPackage(packageId) .orElseThrow(() -> new UnknownPackageException(entityTypeRequest.getPackage())); } entityType.setPackage(pack); String extendsEntityTypeId = entityTypeRequest.getExtends(); if (extendsEntityTypeId != null) { EntityType extendsEntityType = metaDataService .getEntityType(extendsEntityTypeId) .orElseThrow(() -> new UnknownEntityTypeException(extendsEntityTypeId)); entityType.setExtends(extendsEntityType); } processI18nLabel(entityTypeRequest.getLabel(), entityType); processI18nDescription(entityTypeRequest.getDescription(), entityType); List<Attribute> ownAttributes = attributeRequestMapper.toAttributes( entityTypeRequest.getAttributes(), entityTypeRequest, entityType); entityType.setOwnAllAttributes(ownAttributes); Boolean abstractEntityType = entityTypeRequest.getAbstract(); if (abstractEntityType != null) { entityType.setAbstract(abstractEntityType); } entityType.setBackend(metaDataService.getDefaultBackend().getName()); processSelfReferencingAttributes(entityType, ownAttributes); return entityType; } EntityTypeRequestMapperImpl(
      EntityTypeFactory entityTypeFactory,
      AttributeRequestMapper attributeRequestMapper,
      MetaDataService metaDataService); @Override EntityType toEntityType(CreateEntityTypeRequest entityTypeRequest); @Override void updateEntityType(EntityType entityType, Map<String, Object> entityTypeValues); }
EntityTypeRequestMapperImpl implements EntityTypeRequestMapper { @Override public EntityType toEntityType(CreateEntityTypeRequest entityTypeRequest) { EntityType entityType = entityTypeFactory.create(); String entityTypeId = entityTypeRequest.getId(); if (entityTypeId != null) { entityType.setId(entityTypeId); } String packageId = entityTypeRequest.getPackage(); Package pack = null; if (packageId != null) { pack = metaDataService .getPackage(packageId) .orElseThrow(() -> new UnknownPackageException(entityTypeRequest.getPackage())); } entityType.setPackage(pack); String extendsEntityTypeId = entityTypeRequest.getExtends(); if (extendsEntityTypeId != null) { EntityType extendsEntityType = metaDataService .getEntityType(extendsEntityTypeId) .orElseThrow(() -> new UnknownEntityTypeException(extendsEntityTypeId)); entityType.setExtends(extendsEntityType); } processI18nLabel(entityTypeRequest.getLabel(), entityType); processI18nDescription(entityTypeRequest.getDescription(), entityType); List<Attribute> ownAttributes = attributeRequestMapper.toAttributes( entityTypeRequest.getAttributes(), entityTypeRequest, entityType); entityType.setOwnAllAttributes(ownAttributes); Boolean abstractEntityType = entityTypeRequest.getAbstract(); if (abstractEntityType != null) { entityType.setAbstract(abstractEntityType); } entityType.setBackend(metaDataService.getDefaultBackend().getName()); processSelfReferencingAttributes(entityType, ownAttributes); return entityType; } EntityTypeRequestMapperImpl(
      EntityTypeFactory entityTypeFactory,
      AttributeRequestMapper attributeRequestMapper,
      MetaDataService metaDataService); @Override EntityType toEntityType(CreateEntityTypeRequest entityTypeRequest); @Override void updateEntityType(EntityType entityType, Map<String, Object> entityTypeValues);  }