Search in sources :

Example 81 with Package

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

the class MetaDataServiceImplTest method addPackage.

@Test
public void addPackage() {
    Package package_ = mock(Package.class);
    metaDataServiceImpl.addPackage(package_);
    verify(dataService).add(PACKAGE, package_);
    verifyNoMoreInteractions(dataService);
}
Also used : Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 82 with Package

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

the class MetaDataServiceImplTest method getRepositoryTypedEntityType.

@SuppressWarnings("unchecked")
@Test
public void getRepositoryTypedEntityType() {
    EntityType entityType = when(mock(EntityType.class).isAbstract()).thenReturn(false).getMock();
    String backendName = "backend";
    when(entityType.getBackend()).thenReturn(backendName);
    RepositoryCollection repoCollection = mock(RepositoryCollection.class);
    Repository<Package> repo = mock(Repository.class);
    when(repoCollection.getRepository(entityType)).thenReturn((Repository<Entity>) (Repository<?>) repo);
    when(repoCollectionRegistry.getRepositoryCollection(backendName)).thenReturn(repoCollection);
    assertEquals(metaDataServiceImpl.getRepository(entityType, Package.class), repo);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 83 with Package

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

the class MetaUtilsTest method isSystemPackageTrueNested.

@Test
public void isSystemPackageTrueNested() {
    Package rootPackage_ = mock(Package.class);
    when(rootPackage_.getId()).thenReturn(PACKAGE_SYSTEM);
    Package package_ = mock(Package.class);
    when(package_.getId()).thenReturn("systemChild");
    when(package_.getRootPackage()).thenReturn(rootPackage_);
    assertTrue(MetaUtils.isSystemPackage(package_));
}
Also used : Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Example 84 with Package

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

the class MetaUtilsTest method isSystemPackageFalse.

@Test
public void isSystemPackageFalse() {
    Package package_ = mock(Package.class);
    when(package_.getId()).thenReturn("notSystem");
    assertFalse(MetaUtils.isSystemPackage(package_));
}
Also used : Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Example 85 with Package

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

the class PackagePersisterTest method testUpsertPackages.

@Test
public void testUpsertPackages() throws Exception {
    String newPackageName = "newPackage";
    String unchangedPackageName = "unchangedPackage";
    String updatedPackageName = "updatedPackage";
    Package newPackage = mock(Package.class);
    when(newPackage.getId()).thenReturn("newPackageId");
    Package unchangedPackage = mock(Package.class);
    when(unchangedPackage.getId()).thenReturn("unchangedPackageId");
    Package updatedPackage = mock(Package.class);
    when(updatedPackage.getId()).thenReturn("updatedPackageId");
    Package existingUpdatedPackage = mock(Package.class);
    when(existingUpdatedPackage.getId()).thenReturn("updatedPackageId");
    @SuppressWarnings("unchecked") Query<Package> query = mock(Query.class);
    when(dataService.query(PACKAGE, Package.class)).thenReturn(query);
    when(query.in(eq(PackageMetadata.ID), any(Set.class))).thenReturn(query);
    when(query.findAll()).thenReturn(Stream.of(unchangedPackage, existingUpdatedPackage));
    packagePersister.upsertPackages(Stream.of(newPackage, unchangedPackage, updatedPackage));
    @SuppressWarnings("unchecked") ArgumentCaptor<Stream<Package>> addCaptor = ArgumentCaptor.forClass(Stream.class);
    verify(dataService).add(eq(PACKAGE), addCaptor.capture());
    assertEquals(addCaptor.getValue().collect(toList()), singletonList(newPackage));
    @SuppressWarnings("unchecked") ArgumentCaptor<Stream<Package>> updateCaptor = ArgumentCaptor.forClass(Stream.class);
    verify(dataService).update(eq(PACKAGE), updateCaptor.capture());
    assertEquals(updateCaptor.getValue().collect(toList()), singletonList(updatedPackage));
}
Also used : Set(java.util.Set) Stream(java.util.stream.Stream) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

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