Skip to content
Snippets Groups Projects
Commit 75b4bcaf authored by anttil's avatar anttil
Browse files

BIS-341 / SP-536 : More tests

SVN: 28548
parent f4eef522
No related branches found
No related tags found
No related merge requests found
Showing
with 420 additions and 46 deletions
......@@ -70,6 +70,7 @@ import ch.systemsx.cisd.openbis.uitest.dsl.type.SampleBuilder;
import ch.systemsx.cisd.openbis.uitest.dsl.type.SamplePropertyTypeAssignmentBuilder;
import ch.systemsx.cisd.openbis.uitest.dsl.type.SampleTypeBuilder;
import ch.systemsx.cisd.openbis.uitest.dsl.type.SampleTypeUpdateBuilder;
import ch.systemsx.cisd.openbis.uitest.dsl.type.SampleUpdateBuilder;
import ch.systemsx.cisd.openbis.uitest.dsl.type.ScriptBuilder;
import ch.systemsx.cisd.openbis.uitest.dsl.type.SpaceBuilder;
import ch.systemsx.cisd.openbis.uitest.dsl.type.UpdateBuilder;
......@@ -620,7 +621,7 @@ public abstract class SeleniumTest
return importFile;
}
public Sample create(ImportFile file, SampleBuilder builder, IdentifiedBy identifiedBy)
public Sample create(ImportFile file, Builder<Sample> builder, IdentifiedBy identifiedBy)
{
Sample sample = assume(builder);
......@@ -639,7 +640,7 @@ public abstract class SeleniumTest
return sample;
}
public Sample create(ImportFile file, SampleBuilder builder)
public Sample create(ImportFile file, Builder<Sample> builder)
{
return create(file, builder, null);
}
......@@ -810,7 +811,12 @@ public abstract class SeleniumTest
return new SampleTypeUpdateBuilder(type);
}
protected void perform(UpdateBuilder builder)
protected SampleUpdateBuilder anUpdateOf(Sample sample)
{
return new SampleUpdateBuilder(sample);
}
protected void perform(UpdateBuilder<?> builder)
{
builder.update(openbis, ui);
}
......
......@@ -20,6 +20,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.UUID;
import ch.systemsx.cisd.openbis.uitest.dsl.Application;
import ch.systemsx.cisd.openbis.uitest.dsl.Ui;
......@@ -77,6 +78,12 @@ public class SampleBuilder implements Builder<Sample>
return this;
}
public SampleBuilder withCodePrefix(String prefix)
{
this.code = prefix + "_" + UUID.randomUUID().toString();
return this;
}
public SampleBuilder in(Space space)
{
this.space = space;
......
......@@ -24,7 +24,7 @@ import ch.systemsx.cisd.openbis.uitest.type.SampleType;
/**
* @author anttil
*/
public class SampleTypeUpdateBuilder implements UpdateBuilder
public class SampleTypeUpdateBuilder implements UpdateBuilder<SampleType>
{
private SampleTypeDsl type;
......@@ -47,8 +47,15 @@ public class SampleTypeUpdateBuilder implements UpdateBuilder
}
@Override
public void update(Application openbis, Ui ui)
public SampleType update(Application openbis, Ui ui)
{
openbis.execute(new UpdateSampleTypeGui(type));
return type;
}
@Override
public SampleType build(Application openbis, Ui ui)
{
return type;
}
}
/*
* Copyright 2012 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.uitest.dsl.type;
import ch.systemsx.cisd.openbis.uitest.dsl.Application;
import ch.systemsx.cisd.openbis.uitest.dsl.Ui;
import ch.systemsx.cisd.openbis.uitest.type.PropertyType;
import ch.systemsx.cisd.openbis.uitest.type.Sample;
/**
* @author anttil
*/
public class SampleUpdateBuilder implements UpdateBuilder<Sample>
{
private SampleDsl sample;
public SampleUpdateBuilder(Sample sample)
{
this.sample = (SampleDsl) sample;
}
public SampleUpdateBuilder settingContainerTo(Sample container)
{
sample.setContainer(container);
return this;
}
public SampleUpdateBuilder settingProperty(PropertyType propertyType, Object object)
{
sample.getProperties().put(propertyType, object);
return this;
}
@Override
public Sample update(Application openbis, Ui ui)
{
return sample;
}
@Override
public Sample build(Application openbis, Ui ui)
{
return sample;
}
}
......@@ -22,7 +22,7 @@ import ch.systemsx.cisd.openbis.uitest.dsl.Ui;
/**
* @author anttil
*/
public interface UpdateBuilder
public interface UpdateBuilder<T> extends Builder<T>
{
public void update(Application openbis, Ui ui);
public T update(Application openbis, Ui ui);
}
......@@ -18,11 +18,15 @@ package ch.systemsx.cisd.openbis.uitest.suite.main;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.UUID;
import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.uitest.dsl.CommandNotSuccessful;
import ch.systemsx.cisd.openbis.uitest.dsl.IdentifiedBy;
import ch.systemsx.cisd.openbis.uitest.dsl.SeleniumTest;
import ch.systemsx.cisd.openbis.uitest.type.GeneralBatchImportFile;
import ch.systemsx.cisd.openbis.uitest.type.PropertyType;
import ch.systemsx.cisd.openbis.uitest.type.Sample;
import ch.systemsx.cisd.openbis.uitest.type.SampleType;
import ch.systemsx.cisd.openbis.uitest.type.Space;
......@@ -52,7 +56,7 @@ public class GeneralBatchImportRegistrationTest extends MainSuite
}
@Test
public void spaceOfSampleIdentifiedWithCodeDefinedByDefaultSpaceOfImportFile()
public void spaceOfSampleIdentifiedWithCodeIsDefinedByDefaultSpaceOfImportFile()
throws Exception
{
GeneralBatchImportFile file =
......@@ -65,7 +69,7 @@ public class GeneralBatchImportRegistrationTest extends MainSuite
}
@Test
public void spaceOfSampleIdentifiedWithCodeDefinedByUserHomeSpaceIfDefaultSpaceOfImportFileIsNotSet()
public void spaceOfSampleIdentifiedWithCodeIsDefinedByUserHomeSpaceIfDefaultSpaceOfImportFileIsNotSet()
throws Exception
{
GeneralBatchImportFile file = create(aGeneralBatchImportFile());
......@@ -83,7 +87,16 @@ public class GeneralBatchImportRegistrationTest extends MainSuite
GeneralBatchImportFile file = create(aGeneralBatchImportFile());
create(in(file), aSample().ofType(basic), IdentifiedBy.CODE);
as(user(withoutHomeSpace), generalBatchImport(file));
try
{
as(user(withoutHomeSpace), generalBatchImport(file));
} finally
{
if (SeleniumTest.ADMIN_USER.equals(loggedInAs()) == false)
{
user(assume(aUser().withName(SeleniumTest.ADMIN_USER)));
}
}
}
@Test
......@@ -145,7 +158,7 @@ public class GeneralBatchImportRegistrationTest extends MainSuite
}
@Test
public void componentSampleIdentifiedWithSpaceAndCodeAndSubcodeCreatedAsSampleWithoutContainer()
public void componentSampleIdentifiedWithSpaceAndCodeAndSubcodeIsCreatedAsSampleWithoutContainer()
throws Exception
{
GeneralBatchImportFile file =
......@@ -303,10 +316,55 @@ public class GeneralBatchImportRegistrationTest extends MainSuite
generalBatchImport(file);
}
@Test
public void propertiesOfSamplesAreImported() throws Exception
{
SampleType sampleType = create(aSampleType());
PropertyType propertyType = create(aVarcharPropertyType());
create(aSamplePropertyTypeAssignment()
.with(sampleType)
.with(propertyType));
String propertyValue = UUID.randomUUID().toString();
GeneralBatchImportFile file = create(aGeneralBatchImportFile());
Sample sample =
create(in(file), aSample().ofType(sampleType).withProperty(propertyType,
propertyValue).in(sampleSpace));
generalBatchImport(file);
assertThat(browserEntryOf(sample), containsValue(propertyType.getLabel(), propertyValue));
}
@Test
public void registrationOfMultipleSamplesPerTypeIsPossible() throws Exception
{
GeneralBatchImportFile file =
create(aGeneralBatchImportFile()
.withoutSampleContainerColumn());
Sample container = create(in(file), aSample().ofType(basic).in(sampleSpace));
Sample container2 = create(in(file), aSample().ofType(basic).in(sampleSpace));
Sample contained =
create(in(file), aSample().containedBy(container).ofType(componentType).in(
sampleSpace));
Sample contained2 =
create(in(file), aSample().containedBy(container2).ofType(componentType).in(
sampleSpace));
generalBatchImport(file);
assertThat(browserEntryOf(container), exists());
assertThat(browserEntryOf(contained), exists());
assertThat(browserEntryOf(container2), exists());
assertThat(browserEntryOf(contained2), exists());
}
@Override
public void fixture()
{
System.out.println("GeneralBatchImportRegistrationTest - Fixture");
defaultSpace = create(aSpace().withCodePrefix("DEFAULT_SPACE"));
sampleSpace = create(aSpace().withCodePrefix("SAMPLE_SPACE"));
homeSpace = create(aSpace().withCodePrefix("HOME_SPACE"));
......
/*
* Copyright 2012 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.uitest.suite.main;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.UUID;
import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.uitest.dsl.IdentifiedBy;
import ch.systemsx.cisd.openbis.uitest.type.GeneralBatchImportFile;
import ch.systemsx.cisd.openbis.uitest.type.PropertyType;
import ch.systemsx.cisd.openbis.uitest.type.Sample;
import ch.systemsx.cisd.openbis.uitest.type.SampleType;
import ch.systemsx.cisd.openbis.uitest.type.Space;
import ch.systemsx.cisd.openbis.uitest.type.User;
/**
* @author anttil
*/
public class GeneralBatchImportUpdateTest extends MainSuite
{
// TODO
// The test framework thinks it can uniquely identify a sample with it's subcode.
// This is why we get IllegalStateException here, as there are multiple rows found
// with same subcode.
@Test(expectedExceptions = IllegalStateException.class)
public void containerOfSampleCannotBeChangedButNewSampleIsCreated() throws Exception
{
Sample newContainer =
create(aSample().ofType(basic).withCodePrefix("NEW_CONTAINER"));
GeneralBatchImportFile file = create(aGeneralBatchImportFile().withSampleContainerColumn());
create(in(file), anUpdateOf(component).settingContainerTo(newContainer),
IdentifiedBy.SPACE_AND_CODE);
generalBatchImport(file);
assertThat(browserEntryOf(component), hasContainer(newContainer));
}
@Test
public void updateOfSampleIdentifiedWithSpaceAndCodeWorks() throws Exception
{
String newValue = UUID.randomUUID().toString();
GeneralBatchImportFile file =
create(aGeneralBatchImportFile().withDefaultSpace(defaultSpace));
create(in(file), anUpdateOf(sample).settingProperty(propertyType, newValue),
IdentifiedBy.SPACE_AND_CODE);
generalBatchImport(file);
assertThat(browserEntryOf(sample), containsValue(propertyType.getLabel(), newValue));
}
@Test
public void updateOfSampleIdentifiedWithCodeAndDefaultSpaceWorks() throws Exception
{
String newValue = UUID.randomUUID().toString();
GeneralBatchImportFile file =
create(aGeneralBatchImportFile().withDefaultSpace(sampleSpace));
create(in(file), anUpdateOf(sample).settingProperty(propertyType, newValue),
IdentifiedBy.CODE);
generalBatchImport(file);
assertThat(browserEntryOf(sample), containsValue(propertyType.getLabel(), newValue));
}
@Override
public void fixture()
{
defaultSpace = create(aSpace().withCodePrefix("DEFAULT_SPACE"));
sampleSpace = create(aSpace().withCodePrefix("SAMPLE_SPACE"));
homeSpace = create(aSpace().withCodePrefix("HOME_SPACE"));
componentSpace = create(aSpace().withCodePrefix("COMPONENT_SPACE"));
basic = create(aSampleType().withCodePrefix("BASIC"));
componentType = create(aSampleType().thatCanBeComponent().withCodePrefix("COMPONENT"));
withHomeSpace = using(publicApi(), create(aUser().withHomeSpace(homeSpace)));
withoutHomeSpace = using(publicApi(), create(aUser()));
propertyType = create(aVarcharPropertyType());
create(aSamplePropertyTypeAssignment()
.with(basic)
.with(propertyType));
create(aSamplePropertyTypeAssignment()
.with(componentType)
.with(propertyType));
container = create(aSample().ofType(basic).in(sampleSpace)
.withProperty(propertyType, UUID.randomUUID().toString()));
component =
create(aSample().ofType(componentType).in(componentSpace).containedBy(container)
.withProperty(propertyType, UUID.randomUUID().toString()));
sample = create(aSample().ofType(basic).in(sampleSpace)
.withProperty(propertyType, UUID.randomUUID().toString()));
}
SampleType basic;
SampleType componentType;
Space sampleSpace;
Space defaultSpace;
Space homeSpace;
Space componentSpace;
User withHomeSpace;
User withoutHomeSpace;
PropertyType propertyType;
Sample container;
Sample component;
Sample sample;
}
......@@ -83,19 +83,16 @@ public class GeneralBatchImportFile implements ImportFile
for (SampleType type : types)
{
workbook.write(sampleSheet, "[" + type.getCode() + "]");
if (hasSampleContainerColumn && type.isShowContainer())
{
workbook.write(sampleSheet, "Identifier", "CURRENT_CONTAINER");
} else
{
workbook.write(sampleSheet, "Identifier");
}
Header header = new Header(type, hasSampleContainerColumn);
workbook.write(sampleSheet, header.getLabels().toArray(new String[0]));
for (Sample sample : samples)
{
if (sample.getType().equals(type))
{
workbook.write(sampleSheet, getCells(sample));
workbook.write(sampleSheet, header.getValuesFor(sample, identifierTypes)
.toArray(new String[0]));
}
}
}
......@@ -104,32 +101,6 @@ public class GeneralBatchImportFile implements ImportFile
return f.getAbsolutePath();
}
private String[] getCells(Sample sample)
{
List<String> cells = new ArrayList<String>();
cells.add(getIdentifier(sample));
if (hasSampleContainerColumn && sample.getContainer() != null)
{
cells.add(getIdentifier(sample.getContainer()));
}
return cells.toArray(new String[0]);
}
private String getIdentifier(Sample sample)
{
IdentifiedBy idType = identifierTypes.get(sample);
if (idType == null)
{
idType = IdentifiedBy.SPACE_AND_CODE;
}
return idType.format(sample);
}
@Override
public void add(Sample sample, IdentifiedBy idType)
{
......
/*
* Copyright 2013 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.uitest.type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import ch.systemsx.cisd.openbis.uitest.dsl.IdentifiedBy;
/**
* @author anttil
*/
public class Header
{
private SampleType type;
private List<String> labels;
public Header(SampleType type, boolean hasContainerColumn)
{
this.type = type;
this.labels = new ArrayList<String>();
labels.add("Identifier");
if (type.isShowContainer() && hasContainerColumn)
{
labels.add("CURRENT_CONTAINER");
}
for (PropertyTypeAssignment assignment : type.getPropertyTypeAssignments())
{
labels.add(assignment.getPropertyType().getCode());
}
}
public List<String> getLabels()
{
return labels;
}
public List<String> getValuesFor(Sample sample, Map<Sample, IdentifiedBy> idMap)
{
List<String> values = new ArrayList<String>();
for (String label : labels)
{
if (label.equals("Identifier"))
{
values.add(getIdentifier(sample, idMap));
}
else if (label.equals("CURRENT_CONTAINER"))
{
if (sample.getContainer() != null)
{
values.add(getIdentifier(sample.getContainer(), idMap));
} else
{
values.add("");
}
} else
{
PropertyType key = null;
for (PropertyTypeAssignment assignment : type.getPropertyTypeAssignments())
{
if (assignment.getPropertyType().getCode().equals(label))
{
key = assignment.getPropertyType();
break;
}
}
if (key == null)
{
throw new IllegalArgumentException("cannot find property type " + label
+ " from " + type.getPropertyTypeAssignments());
}
Object value = sample.getProperties().get(key);
if (value != null)
{
values.add(value.toString());
} else
{
values.add("");
}
}
}
return values;
}
private String getIdentifier(Sample sample, Map<Sample, IdentifiedBy> identifierTypes)
{
IdentifiedBy idType = identifierTypes.get(sample);
if (idType == null)
{
idType = IdentifiedBy.SPACE_AND_CODE;
}
return idType.format(sample);
}
}
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