Search in sources :

Example 61 with Package

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

the class PackageValidatorTest method testValidatePackageValidName.

@Test
public void testValidatePackageValidName() throws Exception {
    Package package_ = when(mock(Package.class).getId()).thenReturn("test_myPackage").getMock();
    when(package_.getParent()).thenReturn(testPackage);
    when(package_.getRootPackage()).thenReturn(testPackage);
    packageValidator.validate(package_);
}
Also used : Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Example 62 with Package

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

the class PackageValidatorTest method testValidateSystemPackageInRegistry.

@Test
public void testValidateSystemPackageInRegistry() throws Exception {
    Package package_ = when(mock(Package.class).getId()).thenReturn(PACKAGE_SYSTEM + '_' + "myPackage").getMock();
    when(package_.getParent()).thenReturn(systemPackage);
    when(package_.getRootPackage()).thenReturn(systemPackage);
    when(systemPackageRegistry.containsPackage(package_)).thenReturn(true);
    packageValidator.validate(package_);
}
Also used : Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Example 63 with Package

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

the class PackageRepositorySecurityDecoratorTest method testUpdate.

@Test
public void testUpdate() {
    Package pack = mock(Package.class);
    Package parent = mock(Package.class);
    when(pack.getId()).thenReturn("1");
    when(parent.getId()).thenReturn("2");
    when(pack.getParent()).thenReturn(parent);
    MutableAcl acl = mock(MutableAcl.class);
    MutableAcl parentAcl = mock(MutableAcl.class);
    when(mutableAclService.readAclById(any())).thenAnswer(invocation -> {
        Object argument = invocation.getArguments()[0];
        if (argument.equals(new PackageIdentity("1"))) {
            return acl;
        } else if (argument.equals(new PackageIdentity("2"))) {
            return parentAcl;
        }
        return null;
    });
    repo.update(pack);
    verify(mutableAclService).updateAcl(acl);
    verify(delegateRepository).update(pack);
}
Also used : PackageIdentity(org.molgenis.data.security.PackageIdentity) MutableAcl(org.springframework.security.acls.model.MutableAcl) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Example 64 with Package

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

the class PackageRepositorySecurityDecoratorTest method testDelete1.

@Test
public void testDelete1() {
    Package package1 = mock(Package.class);
    Package package2 = mock(Package.class);
    when(package1.getId()).thenReturn("1");
    when(package2.getId()).thenReturn("2");
    Stream<Package> packages = Stream.of(package1, package2);
    repo.delete(packages);
    // TODO: how to verify the deleteAcl method in the "filter" of the stream
    ArgumentCaptor<Stream<Package>> captor = ArgumentCaptor.forClass(Stream.class);
    verify(delegateRepository).delete(captor.capture());
    assertEquals(captor.getValue().collect(toList()), asList(package1, package2));
}
Also used : Stream(java.util.stream.Stream) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Example 65 with Package

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

the class PackageRepositorySecurityDecoratorTest method testDelete.

@Test
public void testDelete() {
    Package pack = mock(Package.class);
    when(pack.getId()).thenReturn("1");
    repo.delete(pack);
    verify(mutableAclService).deleteAcl(new PackageIdentity("1"), true);
    verify(delegateRepository).delete(pack);
}
Also used : PackageIdentity(org.molgenis.data.security.PackageIdentity) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

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