Search in sources :

Example 91 with Package

use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.

the class RepositoryCopierTest method testCopyRepository.

@Test
public void testCopyRepository() {
    Repository<Entity> repository = getMockRepository();
    @SuppressWarnings("unchecked") Query<Entity> query = mock(Query.class);
    @SuppressWarnings("unchecked") Stream<Entity> entitiesStream = mock(Stream.class);
    when(query.findAll()).thenReturn(entitiesStream);
    when(repository.query()).thenReturn(query);
    String entityTypeId = "copiedEntityTypeId";
    Package package_ = mock(Package.class);
    when(package_.toString()).thenReturn("Package");
    String entityTypeLabel = "copiedEntityTypeLabel";
    @SuppressWarnings("unchecked") Repository<Entity> copiedRepository = mock(Repository.class);
    when(metaDataService.createRepository(any(EntityType.class))).thenReturn(copiedRepository);
    assertEquals(repositoryCopier.copyRepository(repository, entityTypeId, package_, entityTypeLabel), copiedRepository);
    ArgumentCaptor<EntityType> entityTypeCaptor = ArgumentCaptor.forClass(EntityType.class);
    verify(metaDataService).createRepository(entityTypeCaptor.capture());
    EntityType copiedEntityType = entityTypeCaptor.getValue();
    assertEquals(copiedEntityType.getId(), entityTypeId);
    assertEquals(copiedEntityType.getLabel(), entityTypeLabel);
    assertEquals(copiedEntityType.getPackage(), package_);
    verify(copiedRepository).add(entitiesStream);
}
Also used : Entity(org.molgenis.data.Entity) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 92 with Package

use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.

the class DataExplorerController method getNavigatorLinks.

@GetMapping("/navigatorLinks")
@ResponseBody
public List<NavigatorLink> getNavigatorLinks(@RequestParam("entity") String entityTypeId) {
    List<NavigatorLink> result = new LinkedList<>();
    EntityType entityType = dataService.getEntityType(entityTypeId);
    String navigatorPath = menuReaderService.getMenu().findMenuItemPath(NAVIGATOR);
    if (entityType != null) {
        Package pack = entityType.getPackage();
        getNavigatorLinks(result, pack, navigatorPath);
        // add root navigator link
        result.add(NavigatorLink.create(navigatorPath + "/", "glyphicon-home"));
        Collections.reverse(result);
    }
    return result;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Package(org.molgenis.data.meta.model.Package)

Example 93 with Package

use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.

the class EntityTypeUtilsTest method buildFullNamePackageDefault.

@Test
public void buildFullNamePackageDefault() {
    Package defaultPackage = when(mock(Package.class).getId()).thenReturn(PACKAGE_DEFAULT).getMock();
    assertEquals(EntityTypeUtils.buildFullName(defaultPackage, "simpleName"), PACKAGE_DEFAULT + "_simpleName");
}
Also used : Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Example 94 with Package

use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.

the class SearchAllServiceTest method setUp.

@BeforeClass
public void setUp() {
    dataService = mock(DataService.class);
    searchAllService = new SearchAllService(dataService);
    LocaleContextHolder.setLocale(Locale.ENGLISH);
    pack1 = mock(Package.class);
    when(pack1.getLabel()).thenReturn("package test nr 1");
    when(pack1.getId()).thenReturn("package id 1");
    when(pack1.getDescription()).thenReturn("package description 1");
    pack2 = mock(Package.class);
    when(pack2.getLabel()).thenReturn("package nr 2");
    when(pack2.getId()).thenReturn("package id 2");
    when(pack2.getDescription()).thenReturn("package description 2");
    pack_sys = mock(Package.class);
    when(pack_sys.getLabel()).thenReturn("package sys");
    when(pack_sys.getId()).thenReturn(PACKAGE_SYSTEM);
    when(pack_sys.getDescription()).thenReturn("package test description");
    pack3 = mock(Package.class);
    when(pack3.getLabel()).thenReturn("package nr 3");
    when(pack3.getId()).thenReturn("package id 3");
    when(pack3.getDescription()).thenReturn(null);
    // matches label
    attr1 = mock(Attribute.class);
    when(attr1.getLabel("en")).thenReturn("attr test nr 1");
    when(attr1.getName()).thenReturn("attr id 1");
    when(attr1.getDescription("en")).thenReturn("attr description 1");
    when(attr1.getDataType()).thenReturn(BOOL);
    // no match
    attr2 = mock(Attribute.class);
    when(attr2.getLabel("en")).thenReturn("attr nr 2");
    when(attr2.getName()).thenReturn("attr id 2");
    when(attr2.getDescription("en")).thenReturn(null);
    when(attr2.getDataType()).thenReturn(BOOL);
    // no match
    attr3 = mock(Attribute.class);
    when(attr3.getLabel("en")).thenReturn("attr nr 3");
    when(attr3.getName()).thenReturn("attr id 3");
    when(attr3.getDescription("en")).thenReturn("attr description 3");
    when(attr3.getDataType()).thenReturn(BOOL);
    // no match
    attr4 = mock(Attribute.class);
    when(attr4.getLabel("en")).thenReturn("attr nr 4");
    when(attr4.getName()).thenReturn("attr id 4");
    when(attr4.getDescription("en")).thenReturn("attr description 4");
    when(attr4.getDataType()).thenReturn(BOOL);
    // no match
    attr5 = mock(Attribute.class);
    when(attr5.getLabel("en")).thenReturn("attr nr 5");
    when(attr5.getName()).thenReturn("attr id 5");
    when(attr5.getDescription("en")).thenReturn("attr description 5");
    when(attr5.getDataType()).thenReturn(BOOL);
    entity1 = mock(EntityType.class);
    when(entity1.getLabel("en")).thenReturn("entity nr 1");
    when(entity1.getId()).thenReturn("entity id 1");
    when(entity1.getDescription("en")).thenReturn("entity description 1");
    when(entity1.getAllAttributes()).thenReturn(singletonList(attr1));
    when(entity1.getPackage()).thenReturn(pack2);
    entity2 = mock(EntityType.class);
    when(entity2.getLabel("en")).thenReturn("entity nr 2");
    when(entity2.getId()).thenReturn("entity id 2");
    when(entity2.getDescription("en")).thenReturn("entity description 2");
    when(entity2.getAllAttributes()).thenReturn(Arrays.asList(attr2, attr5));
    when(entity2.getPackage()).thenReturn(pack2);
    entity3 = mock(EntityType.class);
    when(entity3.getLabel("en")).thenReturn("entity test nr 3");
    when(entity3.getId()).thenReturn("entity id 3");
    when(entity3.getDescription("en")).thenReturn("entity description 3");
    when(entity3.getAllAttributes()).thenReturn(singletonList(attr3));
    when(entity3.getPackage()).thenReturn(pack3);
    entity4 = mock(EntityType.class);
    when(entity4.getLabel("en")).thenReturn("entity nr 4");
    when(entity4.getId()).thenReturn("entity id 4");
    when(entity4.getDescription("en")).thenReturn("entity test description 4");
    when(entity4.getAllAttributes()).thenReturn(singletonList(attr4));
    when(entity4.getPackage()).thenReturn(null);
    abstractEntity = mock(EntityType.class);
    when(abstractEntity.getLabel("en")).thenReturn("abstract");
    when(abstractEntity.getId()).thenReturn("abstract");
    when(abstractEntity.getDescription("en")).thenReturn("abstract");
    when(abstractEntity.getAllAttributes()).thenReturn(singletonList(attr1));
    when(abstractEntity.isAbstract()).thenReturn(true);
    when(abstractEntity.getPackage()).thenReturn(pack1);
}
Also used : SearchAllService(org.molgenis.searchall.service.SearchAllService) Package(org.molgenis.data.meta.model.Package) DataService(org.molgenis.data.DataService) BeforeClass(org.testng.annotations.BeforeClass)

Example 95 with Package

use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.

the class RestControllerV2Test method mocksForCopyEntitySuccess.

private Package mocksForCopyEntitySuccess(Repository<Entity> repositoryToCopy) {
    Package pack = mock(Package.class);
    when(pack.getId()).thenReturn("org_molgenis_blah");
    when(dataService.hasRepository("entity")).thenReturn(true);
    when(dataService.hasRepository("org_molgenis_blah_duplicateEntity")).thenReturn(true);
    when(dataService.hasRepository("org_molgenis_blah_newEntity")).thenReturn(false);
    when(dataService.getRepository("entity")).thenReturn(repositoryToCopy);
    EntityType entityType = mock(EntityType.class);
    when(entityType.getId()).thenReturn("entityTypeId");
    when(repositoryToCopy.getEntityType()).thenReturn(entityType);
    when(entityType.getPackage()).thenReturn(pack);
    when(repositoryToCopy.getName()).thenReturn("entity");
    when(permissionService.hasPermission(new EntityTypeIdentity("entity"), EntityTypePermission.READ)).thenReturn(true);
    Set<RepositoryCapability> capabilities = Sets.newHashSet(RepositoryCapability.WRITABLE);
    when(dataService.getCapabilities("entity")).thenReturn(capabilities);
    @SuppressWarnings("unchecked") Repository<Entity> repository = mock(Repository.class);
    when(repository.getName()).thenReturn("org_molgenis_blah_newEntity");
    when(dataService.getRepository("org_molgenis_blah_newEntity")).thenReturn(repository);
    when(repoCopier.copyRepository(repositoryToCopy, "newEntity", pack, "newEntity")).thenReturn(repository);
    doNothing().when(permissionSystemService).giveUserWriteMetaPermissions(any(EntityType.class));
    return pack;
}
Also used : EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Package(org.molgenis.data.meta.model.Package)

Aggregations

Package (org.molgenis.data.meta.model.Package)98 Test (org.testng.annotations.Test)70 EntityType (org.molgenis.data.meta.model.EntityType)22 Stream (java.util.stream.Stream)20 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)13 Attribute (org.molgenis.data.meta.model.Attribute)11 DefaultPackage (org.molgenis.data.meta.DefaultPackage)10 MolgenisValidationException (org.molgenis.data.validation.MolgenisValidationException)10 Objects.requireNonNull (java.util.Objects.requireNonNull)6 L10nString (org.molgenis.data.i18n.model.L10nString)6 PackageIdentity (org.molgenis.data.security.PackageIdentity)6 Collectors.toList (java.util.stream.Collectors.toList)5 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)5 DataService (org.molgenis.data.DataService)5 QueryImpl (org.molgenis.data.support.QueryImpl)5 RepositoryCollection (org.molgenis.data.RepositoryCollection)4 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)3 java.util (java.util)3 Collections.singletonList (java.util.Collections.singletonList)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3