use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class EntityTypeMapperTest method testToEntityType.
@Test
public void testToEntityType() {
String id = "id";
String label = "label";
String i18nLabelLangEn = "en";
String i18nLabelValue = "en label";
Map<String, String> i18nLabel = singletonMap(i18nLabelLangEn, i18nLabelValue);
String description = "description";
String i18nDescriptionLangEn = "en";
String i18nDescriptionValue = "en description";
Map<String, String> i18nDescription = singletonMap(i18nDescriptionLangEn, i18nDescriptionValue);
boolean abstract_ = true;
String backend = "backend";
EditorPackageIdentifier editorPackageIdentifier = EditorPackageIdentifier.create("packageId", "package label");
EditorEntityTypeParent editorEntityTypeParent = EditorEntityTypeParent.create("entityTypeParentId", "entity type parent label", of(EditorAttributeIdentifier.create("parentAttrId0", "parent attribute #0")), null);
List<EditorEntityTypeIdentifier> entityTypeChildren = of(EditorEntityTypeIdentifier.create("entityTypeChild0", "entity type #0"));
List<EditorAttribute> editorAttributes = of(mock(EditorAttribute.class));
List<EditorAttributeIdentifier> editorReferringAttributes = of(mock(EditorAttributeIdentifier.class));
ImmutableList<EditorTagIdentifier> editorTags = of(EditorTagIdentifier.create("tag0", "tag #0"));
EditorAttributeIdentifier idAttribute = EditorAttributeIdentifier.create("idAttr", "id attribute");
EditorAttributeIdentifier labelAttribute = EditorAttributeIdentifier.create("labelAttr", "label attribute");
List<EditorAttributeIdentifier> lookupAttributes = of(EditorAttributeIdentifier.create("attr0", "attribute #0"));
EditorEntityType editorEntityType = EditorEntityType.create(id, label, i18nLabel, description, i18nDescription, abstract_, backend, editorPackageIdentifier, editorEntityTypeParent, editorAttributes, editorReferringAttributes, editorTags, idAttribute, labelAttribute, lookupAttributes);
EntityType entityType = mock(EntityType.class);
when(entityTypeFactory.create()).thenReturn(entityType);
Package package_ = mock(Package.class);
when(packageMapper.toPackageReference(editorPackageIdentifier)).thenReturn(package_);
EntityType parentEntityType = mock(EntityType.class);
when(entityTypeParentMapper.toEntityTypeReference(editorEntityTypeParent)).thenReturn(parentEntityType);
@SuppressWarnings("unchecked") Iterable<Tag> tags = mock(Iterable.class);
when(tagMapper.toTagReferences(editorTags)).thenReturn(tags);
@SuppressWarnings("unchecked") Iterable<Attribute> attributes = mock(Iterable.class);
when(attributeMapper.toAttributes(editorAttributes, editorEntityType)).thenReturn(attributes);
assertEquals(entityType, entityTypeMapper.toEntityType(editorEntityType));
verify(entityType).setId(id);
verify(entityType).setLabel(label);
verify(entityType).setLabel(i18nLabelLangEn, i18nLabelValue);
verify(entityType).setLabel("nl", null);
verify(entityType).setLabel("de", null);
verify(entityType).setLabel("es", null);
verify(entityType).setLabel("it", null);
verify(entityType).setLabel("pt", null);
verify(entityType).setLabel("fr", null);
verify(entityType).setLabel("xx", null);
verify(entityType).setDescription(description);
verify(entityType).setDescription(i18nDescriptionLangEn, i18nDescriptionValue);
verify(entityType).setDescription("nl", null);
verify(entityType).setDescription("de", null);
verify(entityType).setDescription("es", null);
verify(entityType).setDescription("it", null);
verify(entityType).setDescription("pt", null);
verify(entityType).setDescription("fr", null);
verify(entityType).setDescription("xx", null);
verify(entityType).setAbstract(abstract_);
verify(entityType).setBackend(backend);
verify(entityType).setPackage(package_);
verify(entityType).setExtends(parentEntityType);
verify(entityType).setOwnAllAttributes(attributes);
verify(entityType).setTags(tags);
verifyNoMoreInteractions(entityType);
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class EntityTypeMapperTest method testToEditorEntityType.
@Test
public void testToEditorEntityType() {
String id = "id";
String label = "label";
String i18nLabelLangEn = "en";
String i18nLabelValue = "en label";
Map<String, String> i18nLabel = singletonMap(i18nLabelLangEn, i18nLabelValue);
String description = "description";
String i18nDescriptionLangEn = "en";
String i18nDescriptionValue = "en description";
Map<String, String> i18nDescription = singletonMap(i18nDescriptionLangEn, i18nDescriptionValue);
boolean abstract_ = true;
String backend = "backend";
List<Attribute> referringAttributes = new ArrayList<>();
EntityType entityType = mock(EntityType.class);
when(entityType.getId()).thenReturn(id);
when(entityType.getLabel()).thenReturn(label);
when(entityType.getString(getI18nAttributeName(EntityTypeMetadata.LABEL, i18nLabelLangEn))).thenReturn(i18nLabelValue);
when(entityType.getDescription()).thenReturn(description);
when(entityType.getString(getI18nAttributeName(EntityTypeMetadata.DESCRIPTION, i18nDescriptionLangEn))).thenReturn(i18nDescriptionValue);
when(entityType.isAbstract()).thenReturn(true);
when(entityType.getBackend()).thenReturn(backend);
Package package_ = mock(Package.class);
when(entityType.getPackage()).thenReturn(package_);
EntityType extendsEntityType = mock(EntityType.class);
when(entityType.getExtends()).thenReturn(extendsEntityType);
@SuppressWarnings("unchecked") Iterable<Attribute> attributes = mock(Iterable.class);
when(entityType.getOwnAllAttributes()).thenReturn(attributes);
@SuppressWarnings("unchecked") Iterable<Tag> tags = mock(Iterable.class);
when(entityType.getTags()).thenReturn(tags);
Attribute idAttribute = mock(Attribute.class);
when(entityType.getIdAttribute()).thenReturn(idAttribute);
Attribute labelAttribute = mock(Attribute.class);
when(entityType.getLabelAttribute()).thenReturn(labelAttribute);
@SuppressWarnings("unchecked") Iterable<Attribute> lookupAttributes = mock(Iterable.class);
when(entityType.getLookupAttributes()).thenReturn(lookupAttributes);
EditorAttributeIdentifier editorIdAttribute = mock(EditorAttributeIdentifier.class);
when(attributeReferenceMapper.toEditorAttributeIdentifier(idAttribute)).thenReturn(editorIdAttribute);
EditorAttributeIdentifier editorLabelAttribute = mock(EditorAttributeIdentifier.class);
when(attributeReferenceMapper.toEditorAttributeIdentifier(labelAttribute)).thenReturn(editorLabelAttribute);
@SuppressWarnings("unchecked") ImmutableList<EditorAttributeIdentifier> editorLookupAttributes = mock(ImmutableList.class);
when(attributeReferenceMapper.toEditorAttributeIdentifiers(lookupAttributes)).thenReturn(editorLookupAttributes);
@SuppressWarnings("unchecked") ImmutableList<EditorAttributeIdentifier> editorReferringAttributes = mock(ImmutableList.class);
when(attributeReferenceMapper.toEditorAttributeIdentifiers(referringAttributes)).thenReturn(editorReferringAttributes);
ImmutableList<EditorAttribute> editorAttributes = mock(ImmutableList.class);
when(attributeMapper.toEditorAttributes(attributes)).thenReturn(editorAttributes);
EditorEntityTypeParent editorEntityTypeParent = mock(EditorEntityTypeParent.class);
when(entityTypeParentMapper.toEditorEntityTypeParent(extendsEntityType)).thenReturn(editorEntityTypeParent);
EditorPackageIdentifier editorPackageIdentifier = mock(EditorPackageIdentifier.class);
when(packageMapper.toEditorPackage(package_)).thenReturn(editorPackageIdentifier);
@SuppressWarnings("unchecked") ImmutableList<EditorTagIdentifier> editorTags = mock(ImmutableList.class);
when(tagMapper.toEditorTags(tags)).thenReturn(editorTags);
when(entityTypeFactory.create()).thenReturn(entityType);
EditorEntityType editorEntityType = entityTypeMapper.toEditorEntityType(entityType, referringAttributes);
EditorEntityType expectedEditorEntityType = EditorEntityType.create(id, label, i18nLabel, description, i18nDescription, abstract_, backend, editorPackageIdentifier, editorEntityTypeParent, editorAttributes, editorReferringAttributes, editorTags, editorIdAttribute, editorLabelAttribute, editorLookupAttributes);
assertEquals(editorEntityType, expectedEditorEntityType);
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class EntityServiceImplTest method testCreateEntity.
@Test
public void testCreateEntity() throws Exception {
String tableName = "super-powers";
List<Object> userNames = Arrays.asList("Mark", "Mariska", "Bart");
List<Object> superPowers = Arrays.asList("Arrow functions", "Cookies", "Knots");
List<Column> columns = Arrays.asList(Column.create("user name", 0, userNames), Column.create("super power", 1, superPowers));
DataCollection dataCollection = DataCollection.create(tableName, columns);
// mock auto id
String generatedId = "id_0";
when(idGenerator.generateId()).thenReturn(generatedId);
// mock attributes
Attribute idAttr = mock(Attribute.class);
when(idAttr.setName(anyString())).thenReturn(idAttr);
when(idAttr.setVisible(anyBoolean())).thenReturn(idAttr);
when(idAttr.setAuto(anyBoolean())).thenReturn(idAttr);
when(idAttr.setIdAttribute(anyBoolean())).thenReturn(idAttr);
Attribute nameAttr = mock(Attribute.class);
when(nameAttr.getDataType()).thenReturn(STRING);
Attribute powerAttr = mock(Attribute.class);
when(powerAttr.getDataType()).thenReturn(STRING);
when(attributeFactory.create()).thenReturn(idAttr, nameAttr, powerAttr);
// mock table
EntityType table = mock(EntityType.class);
when(entityTypeFactory.create()).thenReturn(table);
when(table.getId()).thenReturn(generatedId);
when(table.getAttribute("user_name")).thenReturn(nameAttr);
when(table.getAttribute("super_power")).thenReturn(powerAttr);
// mock package
Package package_ = mock(Package.class);
when(metaDataService.getPackage("package_")).thenReturn(package_);
when(dataService.getMeta()).thenReturn(metaDataService);
// mock rows
Entity row1 = mock(Entity.class);
when(row1.getEntityType()).thenReturn(table);
Entity row2 = mock(Entity.class);
when(row2.getEntityType()).thenReturn(table);
Entity row3 = mock(Entity.class);
when(row3.getEntityType()).thenReturn(table);
when(entityManager.create(table, NO_POPULATE)).thenReturn(row1, row2, row3);
when(oneClickImporterNamingService.asValidColumnName("user name")).thenReturn("user_name");
when(oneClickImporterNamingService.asValidColumnName("super power")).thenReturn("super_power");
when(oneClickImporterNamingService.getLabelWithPostFix("super-powers")).thenReturn("super-powers");
when(attributeTypeService.guessAttributeType(any())).thenReturn(STRING);
entityService = new EntityServiceImpl(entityTypeFactory, attributeFactory, idGenerator, dataService, metaDataService, entityManager, attributeTypeService, oneClickImporterService, oneClickImporterNamingService, packageFactory, permissionSystemService);
EntityType entityType = entityService.createEntityType(dataCollection, "package_");
assertEquals(entityType.getId(), generatedId);
verify(table).setPackage(package_);
verify(table).setId(generatedId);
verify(table).setLabel(tableName);
verify(permissionSystemService).giveUserWriteMetaPermissions(table);
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class PackageMapperTest method testToEditorPackage.
@Test
public void testToEditorPackage() {
String id = "id0";
String label = "label0";
Package package_ = mock(Package.class);
when(package_.getId()).thenReturn(id);
when(package_.getLabel()).thenReturn(label);
EditorPackageIdentifier editorPackage = packageMapper.toEditorPackage(package_);
assertEquals(editorPackage, EditorPackageIdentifier.create(id, label));
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class MetadataManagerServiceTest method testGetEditorPackages.
@Test
public void testGetEditorPackages() {
Package package_ = mock(Package.class);
when(package_.getId()).thenReturn("test");
List<Package> packages = newArrayList(package_);
when(metaDataService.getPackages()).thenReturn(packages);
EditorPackageIdentifier editorPackage = getEditorPackageIdentifier();
when(packageMapper.toEditorPackage(package_)).thenReturn(editorPackage);
List<EditorPackageIdentifier> actual = metadataManagerService.getEditorPackages();
List<EditorPackageIdentifier> expected = newArrayList(editorPackage);
assertEquals(actual, expected);
}
Aggregations