Skip to content
Snippets Groups Projects
Commit d20be5f5 authored by felmer's avatar felmer
Browse files

ExperimentRegistrationTest refactored and SampleRegistrationTest added

SVN: 16999
parent c7a7c898
No related branches found
No related tags found
No related merge requests found
......@@ -19,28 +19,26 @@ package ch.systemsx.cisd.openbis.systemtest.plugin.generic;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.fail;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.springframework.mock.web.MockMultipartFile;
import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ListSampleDisplayCriteria;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ResultSetWithEntityTypes;
import ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException;
import ch.systemsx.cisd.openbis.generic.client.web.server.UploadedFilesBean;
import ch.systemsx.cisd.openbis.generic.shared.basic.GridRowModel;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Attachment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AttachmentWithContent;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListSampleCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewAttachment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
......@@ -127,14 +125,10 @@ public class ExperimentRegistrationTest extends GenericSystemTestCase
{
logIntoCommonClientService();
HttpSession session = request.getSession();
UploadedFilesBean uploadedFilesBean = new UploadedFilesBean();
String batchSamplesFileContent = "identifier\torganism\n" +
"S1001\tfly\n" +
"S1002\tdog\n";
uploadedFilesBean.addMultipartFile(new MockMultipartFile("samples.txt",
batchSamplesFileContent.getBytes()));
session.setAttribute(SAMPLES_SESSION_KEY, uploadedFilesBean);
String batchSamplesFileContent = "identifier\torganism\n"
+ "S1001\tfly\n"
+ "S1002\tdog\n";
addMultiPartFile(SAMPLES_SESSION_KEY, "samples.txt", batchSamplesFileContent.getBytes());
String experimentCode = commonClientService.generateCode("EXP");
String experimentIdentifier = "/cisd/default/" + experimentCode;
NewExperiment newExperiment = new NewExperiment(experimentIdentifier, "SIRNA_HCS");
......@@ -153,15 +147,23 @@ public class ExperimentRegistrationTest extends GenericSystemTestCase
commonClientService.listSamples(new ListSampleDisplayCriteria(listCriteria));
assertEquals("[CELL_PLATE]", samples.getAvailableEntityTypes().toString());
Sample sample = samples.getResultSet().getList().get(0).getOriginalObject();
List<GridRowModel<Sample>> list = new ArrayList<GridRowModel<Sample>>(samples.getResultSet().getList());
Collections.sort(list, new Comparator<GridRowModel<Sample>>()
{
public int compare(GridRowModel<Sample> o1, GridRowModel<Sample> o2)
{
return o1.getOriginalObject().getCode().compareTo(o2.getOriginalObject().getCode());
}
});
Sample sample = list.get(0).getOriginalObject();
assertEquals("S1001", sample.getCode());
assertEquals("FLY", sample.getProperties().get(0).tryGetAsString());
assertEquals(experiment.getId(), sample.getExperiment().getId());
sample = samples.getResultSet().getList().get(1).getOriginalObject();
sample = list.get(1).getOriginalObject();
assertEquals("S1002", sample.getCode());
assertEquals("DOG", sample.getProperties().get(0).tryGetAsString());
assertEquals(experiment.getId(), sample.getExperiment().getId());
assertEquals(2, samples.getResultSet().getList().size());
assertEquals(2, list.size());
}
@Test
......@@ -169,13 +171,7 @@ public class ExperimentRegistrationTest extends GenericSystemTestCase
{
String sessionToken = logIntoCommonClientService().getSessionID();
HttpSession session = request.getSession();
UploadedFilesBean uploadedFilesBean = new UploadedFilesBean();
MockMultipartFile multipartFile =
new MockMultipartFile("hello.txt", "hello.txt", "", "hello world".getBytes());
uploadedFilesBean.addMultipartFile(multipartFile);
session.setAttribute(ATTACHMENTS_SESSION_KEY, uploadedFilesBean);
logIntoCommonClientService();
addMultiPartFile(ATTACHMENTS_SESSION_KEY, "hello.txt", "hello world".getBytes());
String experimentCode = commonClientService.generateCode("EXP");
String experimentIdentifier = "/cisd/default/" + experimentCode;
NewExperiment newExperiment = new NewExperiment(experimentIdentifier, "SIRNA_HCS");
......@@ -203,14 +199,4 @@ public class ExperimentRegistrationTest extends GenericSystemTestCase
assertEquals(1, attachment.getVersion());
assertEquals("hello world", new String(attachment.getContent()));
}
private IEntityProperty property(String type, String value)
{
EntityProperty property = new EntityProperty();
PropertyType propertyType = new PropertyType();
propertyType.setCode(type);
property.setPropertyType(propertyType);
property.setValue(value);
return property;
}
}
......@@ -16,8 +16,15 @@
package ch.systemsx.cisd.openbis.systemtest.plugin.generic;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockMultipartFile;
import ch.systemsx.cisd.openbis.generic.client.web.server.UploadedFilesBean;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType;
import ch.systemsx.cisd.openbis.plugin.generic.client.web.client.IGenericClientService;
import ch.systemsx.cisd.openbis.plugin.generic.shared.IGenericServer;
import ch.systemsx.cisd.openbis.systemtest.SystemTestCase;
......@@ -34,4 +41,28 @@ public class GenericSystemTestCase extends SystemTestCase
@Autowired
protected IGenericServer genericServer;
protected void addMultiPartFile(String sessionAttributeKey, String fileName, byte[] data)
{
HttpSession session = request.getSession();
UploadedFilesBean uploadedFilesBean =
(UploadedFilesBean) session.getAttribute(sessionAttributeKey);
if (uploadedFilesBean == null)
{
uploadedFilesBean = new UploadedFilesBean();
session.setAttribute(sessionAttributeKey, uploadedFilesBean);
}
MockMultipartFile multipartFile = new MockMultipartFile(fileName, fileName, "", data);
uploadedFilesBean.addMultipartFile(multipartFile);
}
protected IEntityProperty property(String type, String value)
{
EntityProperty property = new EntityProperty();
PropertyType propertyType = new PropertyType();
propertyType.setCode(type);
property.setPropertyType(propertyType);
property.setValue(value);
return property;
}
}
/*
* Copyright 2010 ETH Zuerich, CISD
*
* 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.systemsx.cisd.openbis.systemtest.plugin.generic;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.fail;
import java.util.List;
import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.GridRowModels;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ListSampleDisplayCriteria;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ResultSetWithEntityTypes;
import ch.systemsx.cisd.openbis.generic.shared.basic.GridRowModel;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListSampleCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
/**
*
*
* @author Franz-Josef Elmer
*/
@Test(groups = "system test")
public class SampleRegistrationTest extends GenericSystemTestCase
{
@Test
public void testSimpleRegistration()
{
logIntoCommonClientService();
NewSample sample = new NewSample();
String identifier = "/cisd/" + commonClientService.generateCode("S-");
sample.setIdentifier(identifier);
SampleType sampleType = new SampleType();
sampleType.setCode("CELL_PLATE");
sample.setSampleType(sampleType);
sample.setProperties(new IEntityProperty[] {property("COMMENT", "test sample")});
genericClientService.registerSample("session", sample);
Sample s = getSample(identifier);
List<IEntityProperty> properties = s.getProperties();
assertEquals("COMMENT", properties.get(0).getPropertyType().getCode());
assertEquals("test sample", properties.get(0).getValue());
assertEquals(1, properties.size());
}
private Sample getSample(String sampleIdentifier)
{
ListSampleCriteria listCriteria = new ListSampleCriteria();
listCriteria.setIncludeSpace(true);
ResultSetWithEntityTypes<Sample> samples =
commonClientService.listSamples(new ListSampleDisplayCriteria(listCriteria));
GridRowModels<Sample> list = samples.getResultSet().getList();
for (GridRowModel<Sample> gridRowModel : list)
{
Sample sample = gridRowModel.getOriginalObject();
System.out.println("SAMPLE:"+sample.getIdentifier());
if (sample.getIdentifier().endsWith(sampleIdentifier.toUpperCase()))
{
return sample;
}
}
fail("No sample of type found for identifier " + sampleIdentifier);
return null; // satisfy compiler
}
}
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