Search in sources :

Example 26 with PolytomousKey

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);
}
Also used : PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey) Test(org.junit.Test)

Example 27 with PolytomousKey

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);
}
Also used : PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey) Test(org.junit.Test)

Example 28 with PolytomousKey

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;
}
Also used : Criteria(org.hibernate.Criteria) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey)

Example 29 with PolytomousKey

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"});
}
Also used : PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 30 with PolytomousKey

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);
}
Also used : PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) UUID(java.util.UUID) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test)

Aggregations

PolytomousKey (eu.etaxonomy.cdm.model.description.PolytomousKey)33 PolytomousKeyNode (eu.etaxonomy.cdm.model.description.PolytomousKeyNode)23 Test (org.junit.Test)14 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)7 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)7 UUID (java.util.UUID)7 ArrayList (java.util.ArrayList)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)3 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)3 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)3 DataSet (org.unitils.dbunit.annotation.DataSet)3 CdmBase (eu.etaxonomy.cdm.model.common.CdmBase)2 DescriptiveDataSet (eu.etaxonomy.cdm.model.description.DescriptiveDataSet)2 Feature (eu.etaxonomy.cdm.model.description.Feature)2 TaxonDescription (eu.etaxonomy.cdm.model.description.TaxonDescription)2 LinkedPolytomousKeyNodeRowDto (eu.etaxonomy.cdm.remote.dto.polytomouskey.LinkedPolytomousKeyNodeRowDto)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 IdentifiableServiceConfiguratorImpl (eu.etaxonomy.cdm.api.service.config.IdentifiableServiceConfiguratorImpl)1 ReferencedObjectUndeletableException (eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException)1