use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.
the class PolytomousKeyGeneratorTest method testInvokeMergeReuseFeature.
@Test
public void testInvokeMergeReuseFeature() {
PolytomousKeyGeneratorConfigurator configurator = createDefaultConfig();
td1.removeElement(qtd31);
td2.removeElement(qtd32);
td3.removeElement(qtd33);
td4.removeElement(qtd34);
catd12.addStateData(oval);
catd12.addStateData(circular);
configurator.setMerge(true);
PolytomousKey result = generator.invoke(configurator);
result.setTitleCache("Merge Key with feature reuse", true);
assertNotNull("Key should exist (merge mode with feature reuse).", result);
if (debug) {
result.print(System.out);
}
// Assertions
assertNotNull("Key should exist.", result);
PolytomousKeyNode root = result.getRoot();
Assert.assertEquals(featureShape, root.getFeature());
// triangular or oval
PolytomousKeyNode ovalOrTriangularNode = root.getChildren().stream().filter(pkn -> pkn.getStatement().getLabelText(Language.DEFAULT()).equals("Oval or Triangular")).findFirst().get();
Assert.assertEquals("Oval or Triangular", label(ovalOrTriangularNode));
// blue
PolytomousKeyNode blueNode = ovalOrTriangularNode.getChildAt(0);
Assert.assertEquals(blue.getLabel(), label(blueNode));
// triangular
PolytomousKeyNode triangularNode = blueNode.getChildAt(0);
Assert.assertEquals("Shape of head should be reused in this branch", "Triangular", label(triangularNode));
// yellow
PolytomousKeyNode yellowNode = ovalOrTriangularNode.getChildAt(1);
Assert.assertEquals(yellow.getLabel(), label(yellowNode));
// triangular
PolytomousKeyNode ovalNode = yellowNode.getChildAt(1);
Assert.assertEquals("Shape of head should be reused in this branch, " + "but only for remaining states triangular and oval. " + "'Circular' must not be available anymore", "Oval", label(ovalNode));
PolytomousKeyNode circularNode = root.getChildren().stream().filter(pkn -> pkn.getStatement().getLabelText(Language.DEFAULT()).equals("Circular")).findFirst().get();
// presence yes
PolytomousKeyNode presenceNode = circularNode.getChildAt(0);
Assert.assertEquals(yes.getLabel(), label(presenceNode));
// blue
blueNode = presenceNode.getChildAt(0);
Assert.assertEquals(blue.getLabel(), label(blueNode));
// length
PolytomousKeyNode lowerNode = blueNode.getChildAt(0);
// test no feature left
assertIsTaxonList(lowerNode, LESS_3, taxon5, taxon6);
}
use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.
the class PolytomousKeyGeneratorTest method testInvokeMergeModeON.
@Test
public void testInvokeMergeModeON() {
PolytomousKeyGeneratorConfigurator configurator = createDefaultConfig();
configurator.setMerge(true);
PolytomousKey result = generator.invoke(configurator);
result.setTitleCache("Merge Key", true);
assertNotNull("Key should exist (merge mode ON).", result);
if (debug) {
result.print(System.out);
}
// Assertions
assertNotNull("Key should exist.", result);
PolytomousKeyNode root = result.getRoot();
Assert.assertEquals(featureShape, root.getFeature());
Assert.assertNull(root.getTaxon());
// triangular or oval
PolytomousKeyNode triangularNode = root.getChildAt(0);
assertInnerNode(triangularNode, "Oval or Triangular", featureLength);
// <3
PolytomousKeyNode lessNode = triangularNode.getChildAt(0);
assertInnerNode(lessNode, LESS_3, featureColour);
// blue
assertSingleTaxon(lessNode.getChildAt(0), taxon1, blue);
// yellow
assertSingleTaxon(lessNode.getChildAt(1), taxon2, yellow);
// >3
PolytomousKeyNode gtNode = triangularNode.getChildAt(1);
assertInnerNode(gtNode, GT_3, featureColour);
// blue
assertSingleTaxon(gtNode.getChildAt(0), taxon3, blue);
// yellow
assertSingleTaxon(gtNode.getChildAt(1), taxon4, yellow);
// circular
PolytomousKeyNode circularNode = root.getChildAt(1);
assertInnerNode(circularNode, circular, featurePresence);
// yes
PolytomousKeyNode yesNode = circularNode.getChildAt(0);
assertInnerNode(yesNode, yes, featureLength);
// <3
assertIsTaxonList(yesNode.getChildAt(0), LESS_3, taxon5, taxon6);
// >3
assertSingleTaxon(yesNode.getChildAt(1), taxon7, GT_3);
// no
assertSingleTaxon(circularNode.getChildAt(1), taxon8, no);
}
use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.
the class PolytomousKeyDaoImpl method list.
@Override
public List<PolytomousKey> list() {
Criteria crit = getSession().createCriteria(type);
@SuppressWarnings("unchecked") List<PolytomousKey> result = crit.list();
return result;
}
use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.
the class PolytomousKeyDaoHibernateImplTest method testSavePolytomousKey.
@Test
@DataSet("PolytomousKeyDaoHibernateImplTest.xml")
public // @ExpectedDataSet //for some reason this result in an infinite waiting of the connection pool
void testSavePolytomousKey() {
PolytomousKey existingKey = polytomousKeyDao.findByUuid(UUID.fromString("bab66772-2c83-428a-bb6d-655d12ac6097"));
Assert.assertNotNull("", existingKey);
PolytomousKeyNode root = existingKey.getRoot();
Assert.assertNotNull("Root should not be null", root);
Assert.assertEquals(2, root.childCount());
// new key
PolytomousKey newKey = PolytomousKey.NewInstance();
PolytomousKeyNode newRoot = newKey.getRoot();
PolytomousKeyNode child1 = PolytomousKeyNode.NewInstance();
child1.addQuestionText("Question1", null);
child1.addQuestionText("Question1German", Language.GERMAN());
child1.addStatementText("Statement1", null);
PolytomousKeyNode child2 = PolytomousKeyNode.NewInstance();
child2.addStatementText("Statement2", null);
child2.addQuestionText("Question2German", Language.DEFAULT());
PolytomousKeyNode child3 = PolytomousKeyNode.NewInstance();
child3.addStatementText("Statement3", null);
child3.addStatementText("Statement3German", Language.GERMAN());
newRoot.addChild(child1);
newRoot.addChild(child3);
newRoot.addChild(child2, 1);
newKey = polytomousKeyDao.save(newKey);
// doesn't make sense as long as there is no new session
PolytomousKey newKeyFromDb = polytomousKeyDao.findByUuid(newKey.getUuid());
// List<PolytomousKeyNode> children = newKeyFromDb.getRoot().getChildren();
// Assert.assertEquals(child1.getUuid(), children.get(0).getUuid());
// Assert.assertNotSame(child1.getUuid(), children.get(0).getUuid());
// printDataSet(System.out, new String[]{"PolytomousKeyNode", "KeyStatement", "KeyStatement_LanguageString", "LanguageString"});
}
use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.
the class PolytomousKeyDaoHibernateImplTest method testDeletePolyotomousKey.
@Test
public void testDeletePolyotomousKey() {
UUID uuid = UUID.fromString("bab66772-2c83-428a-bb6d-655d12ac6097");
PolytomousKey existingKey = polytomousKeyDao.findByUuid(uuid);
Assert.assertNotNull("", existingKey);
PolytomousKeyNode node = existingKey.getRoot();
polytomousKeyDao.delete(existingKey);
commitAndStartNewTransaction(null);
// try {if (true){printDataSet(System.out, new String[]{"POLYTOMOUSKEY", "POLYTOMOUSKEYNODE"});}
// } catch(Exception e) { logger.warn(e);}
PolytomousKey nonExistingKey = polytomousKeyDao.findByUuid(uuid);
Assert.assertNull("", nonExistingKey);
node = polytomousKeyNodeDao.findByUuid(node.getUuid());
Assert.assertNull("", node);
}
Aggregations