Skip to content
Snippets Groups Projects
Commit c9d23994 authored by piotr.kupczyk@id.ethz.ch's avatar piotr.kupczyk@id.ethz.ch
Browse files

BIS-736 : external data table for AFS : more integration tests

parent a2e19024
No related branches found
No related tags found
No related merge requests found
......@@ -21,7 +21,16 @@ import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import ch.ethz.sis.afsserver.startup.AtomicFileSystemServerParameter;
import ch.ethz.sis.afsserver.startup.AtomicFileSystemServerParameterUtil;
import ch.ethz.sis.openbis.generic.OpenBIS;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.DataSetKind;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.create.DataSetCreation;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.create.PhysicalDataCreation;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.id.DataSetPermId;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.id.FileFormatTypePermId;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.id.ProprietaryStorageFormatPermId;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.id.RelativeLocationLocatorTypePermId;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.datastore.id.DataStorePermId;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.deletion.id.IDeletionId;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.id.EntityTypePermId;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.create.ExperimentCreation;
......@@ -299,6 +308,64 @@ public class IntegrationAfsDataTest extends AbstractIntegrationTest
assertDataSetExistsAtAFS(experimentId.getPermId(), false);
}
@Test
public void testWriteToDSSExperimentDataSetWithAccess() throws Exception
{
OpenBIS openBISInstanceAdmin = createOpenBIS();
openBISInstanceAdmin.login(INSTANCE_ADMIN, PASSWORD);
// create dataset with instance admin user
ProjectCreation projectCreation = new ProjectCreation();
projectCreation.setSpaceId(new SpacePermId(TEST_SPACE));
projectCreation.setCode(ENTITY_CODE_PREFIX + UUID.randomUUID());
ProjectPermId projectId = openBISInstanceAdmin.createProjects(List.of(projectCreation)).get(0);
ExperimentCreation experimentCreation = new ExperimentCreation();
experimentCreation.setTypeId(new EntityTypePermId("UNKNOWN"));
experimentCreation.setProjectId(projectId);
experimentCreation.setCode(ENTITY_CODE_PREFIX + UUID.randomUUID());
ExperimentPermId experimentId = openBISInstanceAdmin.createExperiments(List.of(experimentCreation)).get(0);
Integer shareId = AtomicFileSystemServerParameterUtil.getStorageIncomingShareId(getAfsServerConfiguration());
PhysicalDataCreation physicalCreation = new PhysicalDataCreation();
physicalCreation.setShareId(shareId.toString());
physicalCreation.setFileFormatTypeId(new FileFormatTypePermId("PROPRIETARY"));
physicalCreation.setLocatorTypeId(new RelativeLocationLocatorTypePermId());
physicalCreation.setLocation("test-location-" + UUID.randomUUID());
physicalCreation.setStorageFormatId(new ProprietaryStorageFormatPermId());
physicalCreation.setH5arFolders(false);
physicalCreation.setH5Folders(false);
DataSetCreation dataSetCreation = new DataSetCreation();
dataSetCreation.setDataStoreId(new DataStorePermId(TEST_DATA_STORE_CODE));
dataSetCreation.setDataSetKind(DataSetKind.PHYSICAL);
dataSetCreation.setTypeId(new EntityTypePermId("UNKNOWN"));
dataSetCreation.setExperimentId(experimentId);
dataSetCreation.setCode(ENTITY_CODE_PREFIX + UUID.randomUUID());
dataSetCreation.setPhysicalData(physicalCreation);
DataSetPermId dataSetId = openBISInstanceAdmin.createDataSetsAS(List.of(dataSetCreation)).get(0);
assertDSSDataSetExistsAtAS(dataSetId.getPermId(), true);
assertAFSDataSetExistsAtAS(dataSetId.getPermId(), false);
assertDataSetExistsAtAFS(dataSetId.getPermId(), false);
try
{
// try to write data to the dataset with instance admin user
openBISInstanceAdmin.getAfsServerFacade().write(dataSetId.getPermId(), "test-file.txt", 0L, "test-content".getBytes());
fail();
} catch (Exception e)
{
assertTrue(e.getMessage().contains("don't have rights [Write] over " + dataSetId));
}
assertDSSDataSetExistsAtAS(dataSetId.getPermId(), true);
assertAFSDataSetExistsAtAS(dataSetId.getPermId(), false);
assertDataSetExistsAtAFS(dataSetId.getPermId(), false);
}
@Test
public void testDeleteExperimentWithAfsDataSet() throws Exception
{
......
......@@ -53,6 +53,11 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.FileSystemResource;
import org.springframework.remoting.rmi.CodebaseAwareObjectInputStream;
import org.springframework.remoting.support.RemoteInvocation;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.GenericWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
......@@ -73,6 +78,8 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.id.SpacePermId;
import ch.ethz.sis.openbis.generic.server.asapi.v3.TransactionConfiguration;
import ch.ethz.sis.shared.startup.Configuration;
import ch.systemsx.cisd.common.filesystem.FileUtilities;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory;
import ch.systemsx.cisd.openbis.generic.shared.dto.DataStorePE;
import ch.systemsx.cisd.openbis.generic.shared.util.TestInstanceHostUtils;
/**
......@@ -82,6 +89,8 @@ public abstract class AbstractIntegrationTest
{
public static final String TEST_INTERACTIVE_SESSION_KEY = "integration-test-interactive-session-key";
public static final String TEST_DATA_STORE_CODE = "TEST";
public static final String DEFAULT_SPACE = "DEFAULT";
public static final String TEST_SPACE = "TEST";
......@@ -303,6 +312,22 @@ public abstract class AbstractIntegrationTest
final OpenBIS openBIS = createOpenBIS();
openBIS.login(INSTANCE_ADMIN, PASSWORD);
// create TEST data store server (we do not start the actual old DSS, but we still want to have some old DSS data sets for testing)
DataStorePE testDataStore = new DataStorePE();
testDataStore.setCode(TEST_DATA_STORE_CODE);
testDataStore.setDownloadUrl("");
testDataStore.setRemoteUrl("");
testDataStore.setDatabaseInstanceUUID("");
testDataStore.setSessionToken("");
testDataStore.setArchiverConfigured(false);
executeInApplicationServerTransaction((status) ->
{
IDAOFactory daoFactory = applicationServerSpringContext.getBean(IDAOFactory.class);
daoFactory.getDataStoreDAO().createOrUpdateDataStore(testDataStore);
return null;
});
// create AFS server user
PersonCreation afsUserCreation = new PersonCreation();
afsUserCreation.setUserId(configuration.getStringProperty(AtomicFileSystemServerParameter.openBISUser));
......@@ -544,6 +569,16 @@ public abstract class AbstractIntegrationTest
TestInstanceHostUtils.getAFSUrl() + TestInstanceHostUtils.getAFSPath());
}
public void executeInApplicationServerTransaction(TransactionCallback<?> callback)
{
PlatformTransactionManager manager = applicationServerSpringContext.getBean(PlatformTransactionManager.class);
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
definition.setReadOnly(false);
TransactionTemplate template = new TransactionTemplate(manager, definition);
template.execute(callback);
}
public void log(String message)
{
System.out.println("[TEST] " + message);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment