Commit 43b2af7b authored by Matija Obreza's avatar Matija Obreza

Fixed tests after ACL changes

parent 7e25fd8c
......@@ -29,6 +29,7 @@ import org.genesys.catalog.persistence.dataset.DatasetRepository;
import org.genesys.catalog.persistence.traits.DescriptorRepository;
import org.genesys.catalog.service.DatasetService;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys.filerepository.persistence.RepositoryFilePersistence;
import org.genesys.test.config.ApplicationConfig;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.persistence.FaoInstituteRepository;
......@@ -74,6 +75,8 @@ public abstract class AbstractApiTest extends AbstractTest {
protected ShortFilterService shortFilterService;
@Autowired
private FaoInstituteRepository instituteRepository;
@Autowired
protected RepositoryFilePersistence repositoryFilePersistence;
protected MockMvc mockMvc;
@Rule
......@@ -97,6 +100,7 @@ public abstract class AbstractApiTest extends AbstractTest {
@Transactional
public void cleanup() throws Exception {
datasetRepository.deleteAll();
repositoryFilePersistence.deleteAll();
partnerRepository.deleteAll();
instituteRepository.deleteAll();
super.cleanup();
......
package org.genesys.test.base;
import java.util.ArrayList;
import java.util.List;
import org.genesys.blocks.auditlog.persistence.AuditLogRepository;
import org.genesys.blocks.persistence.ClassPKRepository;
import org.genesys.blocks.security.model.AclAwareModel;
import org.genesys.blocks.security.persistence.AclEntryPersistence;
import org.genesys.blocks.security.persistence.AclObjectIdentityPersistence;
import org.genesys.blocks.security.persistence.AclSidPersistence;
import org.genesys.blocks.security.service.CustomAclService;
import org.genesys.blocks.util.ClassAclOid;
import org.genesys.catalog.model.Partner;
import org.genesys.catalog.persistence.PartnerRepository;
import org.genesys.filerepository.model.RepositoryFolder;
import org.genesys.filerepository.persistence.RepositoryFolderRepository;
import org.genesys2.server.component.security.AsAdminInvoker;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.persistence.FaoInstituteRepository;
import org.junit.After;
import org.junit.Before;
import org.slf4j.Logger;
......@@ -9,6 +25,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.google.common.collect.Lists;
/**
* Do not touch
*
......@@ -22,19 +40,68 @@ public abstract class AbstractTest {
private AuditLogRepository auditLogRepo;
@Autowired
private ClassPKRepository classPKRepository;
@Autowired
private AclObjectIdentityPersistence aclOidRepository;
@Autowired
private AclEntryPersistence aclEntryRepository;
@Autowired
private AclSidPersistence aclSidRepository;
@Autowired
private AsAdminInvoker asAdminInvoker;
@Autowired
private CustomAclService aclService;
@Autowired
private RepositoryFolderRepository repositoryFolderRepository;
@Autowired
private PartnerRepository partnerRepository;
@Autowired
private FaoInstituteRepository instituteRepository;
@Transactional
@Before
public void beforeTest() throws Exception {
cleanup();
asAdminInvoker.invoke(() -> {
LOG.info("Making some Entities publicly readable by default");
for (Class<? extends AclAwareModel> clazz : Lists.newArrayList(Partner.class, FaoInstitute.class)) {
LOG.trace("Making {} publicly readable by default", clazz.getName());
aclService.createOrUpdatePermissions(ClassAclOid.forClass(clazz));
aclService.makePubliclyReadable(ClassAclOid.forClass(clazz), true);
}
return true;
});
}
@Transactional
@After
public void cleanup() throws Exception {
deleteFolders(repositoryFolderRepository.findAll());
partnerRepository.deleteAll();
instituteRepository.deleteAll();
auditLogRepo.deleteAll();
aclEntryRepository.deleteAll();
aclOidRepository.deleteAll();
aclSidRepository.deleteAll();
classPKRepository.deleteAll();
}
protected void deleteFolders(List<RepositoryFolder> toDelete) {
List<RepositoryFolder> pending = new ArrayList<RepositoryFolder>();
for (RepositoryFolder folder : toDelete) {
try {
repositoryFolderRepository.delete(folder);
} catch (Throwable e) {
LOG.debug("Folder not deleted {}: {}", folder, e.getMessage()); //, e);
pending.add(folder);
}
}
if (pending.size() > 0) {
deleteFolders(pending);
}
}
}
......@@ -36,6 +36,7 @@ import org.genesys.catalog.service.DescriptorService;
import org.genesys.catalog.service.PartnerService;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys.catalog.service.VocabularyService;
import org.genesys.filerepository.persistence.RepositoryFolderRepository;
import org.genesys.test.base.AbstractServiceTest;
import org.genesys2.server.api.model.AccessionHeaderJson;
import org.genesys2.server.model.genesys.Accession;
......@@ -45,6 +46,7 @@ import org.genesys2.server.persistence.FaoInstituteRepository;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.worker.AccessionUploader;
import org.junit.After;
import org.junit.Before;
import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -122,17 +124,27 @@ public abstract class CatalogServiceTest extends AbstractServiceTest {
@Autowired
protected AccessionRepository accessionRepository;
@Autowired
private RepositoryFolderRepository repositoryFolderRepository;
protected Partner partner;
protected Partner partner2;
@Before
@Override
public void beforeTest() throws Exception {
super.beforeTest();
partner = setupPartner(PARTNER_1, PARTNER_ACRONYM_1, Sets.newHashSet(URL_1));
partner2 = setupPartner(PARTNER_2, PARTNER_ACRONYM_2, Sets.newHashSet(URL_1));
}
@After
@Override
public void cleanup() throws Exception {
deleteFolders(repositoryFolderRepository.findAll());
partnerRepository.deleteAll();
accessionRepository.deleteAll();
instituteRepository.deleteAll();
partner = setupPartner(PARTNER_1, PARTNER_ACRONYM_1, Sets.newHashSet(URL_1));
partner2 = setupPartner(PARTNER_2, PARTNER_ACRONYM_2, Sets.newHashSet(URL_1));
super.cleanup();
}
......
......@@ -30,8 +30,12 @@ log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=warn, stdout
#log4j.category.org.genesys2=info
# We don't have proper ACL in tests
log4j.category.org.genesys.blocks.security=error
log4j.category.org.genesys2.server=warn
#log4j.category.org.hibernate.tool.hbm2ddl=trace
#log4j.category.org.genesys2.server.service.impl.KPIServiceImpl=trace
#log4j.category.org.genesys.test=debug
#log4j.category.org.genesys2.server.service.worker.AccessionUploader=trace
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment