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

SP-523 Recent bug fix improved and tested.

SVN: 28393
parent 9378c4ff
No related branches found
No related tags found
No related merge requests found
...@@ -357,12 +357,20 @@ class EntityExistenceChecker ...@@ -357,12 +357,20 @@ class EntityExistenceChecker
{ {
String value = property.getValue(); String value = property.getValue();
MaterialTypePE materialType = propertyTypePE.getMaterialType(); MaterialTypePE materialType = propertyTypePE.getMaterialType();
if (materialType != null) // if material type is null, it means, the property is of MaterialIdentifier materialIdentifier;
// "any material type", so we don't need to check if it if (materialType != null)
// exist {
materialIdentifier = new MaterialIdentifier(value, materialType.getCode());
} else
{
materialIdentifier = MaterialIdentifier.tryParseIdentifier(value);
}
if (materialIdentifier == null)
{
errors.add("Material identifier not in the form '<material code> (<material type code>)': "
+ value);
} else
{ {
MaterialIdentifier materialIdentifier =
new MaterialIdentifier(value, materialType.getCode());
materialExistenceManager.exists(materialIdentifier); materialExistenceManager.exists(materialIdentifier);
} }
} }
......
...@@ -448,6 +448,57 @@ public class EntityExistenceCheckerTest extends AssertJUnit ...@@ -448,6 +448,57 @@ public class EntityExistenceCheckerTest extends AssertJUnit
sample("/S1/A3", null, null, "material:B"))))); sample("/S1/A3", null, null, "material:B")))));
assertThat(checker.getErrors(), containsExactly(new String[0])); assertThat(checker.getErrors(), containsExactly(new String[0]));
context.assertIsSatisfied();
}
@Test
public void testCheckNewSamplesWithMaterialPropertOfAnyType()
{
MaterialType type = new MaterialType();
type.setCode("M1");
MaterialTypePE materialType = materialType(type, "ALPHA");
prepareForAssertMaterialTypeExists(type.getCode(), materialType);
SampleType sampleType = new SampleType();
sampleType.setCode("S1");
prepareForAssertSampleTypeExists(sampleType.getCode(),
sampleType((MaterialTypePE) null, "MATERIAL"));
context.checking(new Expectations()
{
{
one(materialDAO).tryFindMaterial(new MaterialIdentifier("B", "M1"));
will(returnValue(new MaterialPE()));
}
});
checker.checkNewMaterials(Arrays.asList(new NewMaterialsWithTypes(type, Arrays
.asList(material("A", "alpha:12")))));
checker.checkNewSamples(Arrays.asList(new NewSamplesWithTypes(sampleType, Arrays.asList(
sample("/S1/A1", null, null, "material:A (M1)"),
sample("/S1/A2", null, null, "material:B (M1)"),
sample("/S1/A3", null, null, "material:B (M1)")))));
assertThat(checker.getErrors(), containsExactly(new String[0]));
context.assertIsSatisfied();
}
@Test
public void testCheckNewSamplesWithMaterialPropertyOfAnyTypeWithInvalidMaterialIdentifier()
{
SampleType sampleType = new SampleType();
sampleType.setCode("S1");
prepareForAssertSampleTypeExists(sampleType.getCode(),
sampleType((MaterialTypePE) null, "MATERIAL"));
checker.checkNewSamples(Arrays.asList(new NewSamplesWithTypes(sampleType, Arrays.asList(
sample("/S1/A1", null, null, "material:A"),
sample("/S1/A2", null, null, "material:B"),
sample("/S1/A3", null, null, "material:B")))));
assertEquals("[Material identifier not in the form "
+ "'<material code> (<material type code>)': A, "
+ "Material identifier not in the form '<material code> "
+ "(<material type code>)': B]", checker.getErrors().toString());
context.assertIsSatisfied();
} }
@Test @Test
......
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