Skip to content
Snippets Groups Projects
Commit a95056bd authored by vkovtun's avatar vkovtun
Browse files

BIS-790: Added a test for large cell support.

parent e6270b0f
No related branches found
No related tags found
1 merge request!40SSDM-13578 : 2PT : Database and V3 Implementation - include the new AFS "free"...
/*
* Copyright ETH 2022 - 2023 Zürich, Scientific IT Services
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.ethz.sis.openbis.generic.server.xls.export;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.jmock.Expectations;
import org.jmock.api.Invocation;
import org.jmock.lib.action.CustomAction;
import ch.ethz.sis.openbis.generic.asapi.v3.IApplicationServerApi;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.EntityKind;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.id.EntityTypePermId;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.Experiment;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.id.ExperimentIdentifier;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.person.Person;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.project.Project;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.project.id.ProjectIdentifier;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.DataType;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.PropertyAssignment;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.PropertyType;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.fetchoptions.PropertyAssignmentFetchOptions;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.Sample;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.SampleType;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.fetchoptions.SampleFetchOptions;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.id.SampleIdentifier;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.id.SamplePermId;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.Space;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.id.SpacePermId;
import ch.ethz.sis.openbis.systemtest.asapi.v3.ExportTest;
import ch.systemsx.cisd.openbis.generic.server.business.bo.CollectionMatcher;
class SampleLargeCellExpectations extends Expectations
{
public SampleLargeCellExpectations(final IApplicationServerApi api, final boolean exportReferred)
{
if (exportReferred)
{
allowing(api).getSamples(with(XLSExportTest.SESSION_TOKEN),
with(new CollectionMatcher<>(List.of(new SamplePermId("200001010000000-0001")))),
with(any(SampleFetchOptions.class)));
}
allowing(api).getSamples(with(XLSExportTest.SESSION_TOKEN), with(new CollectionMatcher<>(
List.of(new SamplePermId("200001010000000-0001")))), with(any(SampleFetchOptions.class))
);
will(new CustomAction("getting samples")
{
@Override
public Object invoke(final Invocation invocation) throws Throwable
{
final SampleFetchOptions fetchOptions = (SampleFetchOptions) invocation.getParameter(2);
final PropertyAssignment namePropertyAssignment = getNamePropertyAssignment();
final PropertyAssignment boxesCountPropertyAssignment = getBoxesCountPropertyAssignment();
final SampleType sampleType = new SampleType();
sampleType.setCode("STORAGE");
sampleType.setPermId(new EntityTypePermId("STORAGE", EntityKind.SAMPLE));
sampleType.setFetchOptions(fetchOptions.withType());
sampleType.setPropertyAssignments(List.of(namePropertyAssignment, boxesCountPropertyAssignment));
final Space space = new Space();
space.setCode("ELN_SETTINGS");
space.setPermId(new SpacePermId("ELN_SETTINGS"));
final Project project = new Project();
project.setCode("STORAGES");
project.setIdentifier(new ProjectIdentifier("/ELN_SETTINGS/STORAGES"));
final Experiment experiment = new Experiment();
experiment.setCode("STORAGES_COLLECTION");
experiment.setIdentifier(new ExperimentIdentifier("/ELN_SETTINGS/STORAGES/STORAGES_COLLECTION"));
final Experiment defaultExperiment = new Experiment();
defaultExperiment.setCode("DEFAULT");
defaultExperiment.setIdentifier(new ExperimentIdentifier("/DEFAULT/DEFAULT/DEFAULT"));
final Calendar calendar = Calendar.getInstance();
calendar.set(2023, Calendar.MARCH, 10, 17, 23, 44);
final Date registrationDate = calendar.getTime();
calendar.set(2023, Calendar.MARCH, 11, 17, 23, 44);
final Date modificationDate = calendar.getTime();
final Person registrator = new Person();
registrator.setUserId("system");
final Person modifier = new Person();
modifier.setUserId("test");
final Sample[] samples = new Sample[1];
samples[0] = new Sample();
samples[0].setType(sampleType);
samples[0].setFetchOptions(fetchOptions);
samples[0].setPermId(new SamplePermId("200001010000000-0001"));
samples[0].setCode("BENCH");
samples[0].setIdentifier(new SampleIdentifier(space.getCode(), project.getCode(), null, "BENCH"));
samples[0].setSpace(space);
samples[0].setProject(project);
samples[0].setExperiment(experiment);
samples[0].setProperty("$NAME", getResourceFileContent("ch/ethz/sis/openbis/generic/server/xls/export/resources/lorem-ipsum.txt"));
samples[0].setProperty("$STORAGE.BOX_NUM", "9999");
samples[0].setRegistrator(registrator);
samples[0].setModifier(modifier);
samples[0].setRegistrationDate(registrationDate);
samples[0].setModificationDate(modificationDate);
return Arrays.stream(samples).collect(Collectors.toMap(Sample::getPermId, Function.identity(),
(sample1, sample2) -> sample2, LinkedHashMap::new));
}
private PropertyAssignment getBoxesCountPropertyAssignment()
{
final PropertyType propertyType = new PropertyType();
propertyType.setCode("$STORAGE.BOX_NUM");
propertyType.setLabel("Number of Boxes");
propertyType.setDescription("Number of Boxes");
propertyType.setDataType(DataType.INTEGER);
propertyType.setManagedInternally(true);
final PropertyAssignment propertyAssignment = new PropertyAssignment();
propertyAssignment.setFetchOptions(getPropertyAssignmentFetchOptions());
propertyAssignment.setPropertyType(propertyType);
propertyAssignment.setMandatory(false);
propertyAssignment.setShowInEditView(true);
propertyAssignment.setSection("General info");
return propertyAssignment;
}
private PropertyAssignment getNamePropertyAssignment()
{
final PropertyType propertyType = new PropertyType();
propertyType.setCode("$NAME");
propertyType.setLabel("Name");
propertyType.setDescription("Name");
propertyType.setDataType(DataType.VARCHAR);
propertyType.setManagedInternally(true);
final PropertyAssignment propertyAssignment = new PropertyAssignment();
propertyAssignment.setFetchOptions(getPropertyAssignmentFetchOptions());
propertyAssignment.setPropertyType(propertyType);
propertyAssignment.setMandatory(false);
propertyAssignment.setShowInEditView(true);
propertyAssignment.setSection("General info");
return propertyAssignment;
}
private PropertyAssignmentFetchOptions getPropertyAssignmentFetchOptions()
{
final PropertyAssignmentFetchOptions fetchOptions = new PropertyAssignmentFetchOptions();
fetchOptions.withPropertyType();
return fetchOptions;
}
});
}
private static String getResourceFileContent(final String filePath)
{
try (final InputStream exampleTextInputStream = ExportTest.class.getClassLoader().getResourceAsStream(filePath))
{
Objects.requireNonNull(exampleTextInputStream);
return new String(exampleTextInputStream.readAllBytes());
} catch (final IOException e)
{
throw new RuntimeException(e);
}
}
}
...@@ -30,6 +30,7 @@ import static org.testng.Assert.assertFalse; ...@@ -30,6 +30,7 @@ import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail; import static org.testng.Assert.fail;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
...@@ -58,6 +59,7 @@ import org.testng.annotations.Test; ...@@ -58,6 +59,7 @@ import org.testng.annotations.Test;
import ch.ethz.sis.openbis.generic.asapi.v3.IApplicationServerApi; import ch.ethz.sis.openbis.generic.asapi.v3.IApplicationServerApi;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.id.ObjectPermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.id.ObjectPermId;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.id.SpacePermId;
import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.common.exceptions.UserFailureException;
public class XLSExportTest public class XLSExportTest
...@@ -280,14 +282,38 @@ public class XLSExportTest ...@@ -280,14 +282,38 @@ public class XLSExportTest
} }
} }
// /** /**
// * Tests export of cells larger than 32k. * Tests export of cells larger than 32k.
// */ */
// @Test @Test
// public void testLargeCellExport() public void testLargeCellExport() throws IOException
// { {
// final Expectations expectations = new SampleLargeCellExpectations(api, false);
// } mockery.checking(expectations);
final XLSExport.PrepareWorkbookResult actualResult = XLSExport.prepareWorkbook(
api, SESSION_TOKEN, List.of(new ExportablePermId(SAMPLE, new SpacePermId("200001010000000-0001"))),
false, null, XLSExport.TextFormatting.PLAIN, false);
assertTrue(actualResult.getScripts().isEmpty());
assertTrue(actualResult.getWarnings().isEmpty());
final InputStream stream = getClass().getClassLoader().getResourceAsStream(
"ch/ethz/sis/openbis/generic/server/xls/export/resources/export-sample-large-cell.xlsx");
if (stream == null)
{
throw new IllegalArgumentException("File not found.");
}
final Workbook expectedResult = new XSSFWorkbook(stream);
assertWorkbooksEqual(actualResult.getWorkbook(), expectedResult);
final Map<String, String> valueFiles = actualResult.getValueFiles();
assertEquals(valueFiles.size(), 1);
final Map.Entry<String, String> entry = valueFiles.entrySet().iterator().next();
assertEquals(entry.getKey(), "value-M5.txt");
assertTrue(entry.getValue().length() > Short.MAX_VALUE);
}
public static void assertWorkbooksEqual(final Workbook actual, final Workbook expected) public static void assertWorkbooksEqual(final Workbook actual, final Workbook expected)
{ {
......
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