Project

General

Profile

« Previous | Next » 

Revision cafb8a16

Added by Katja Luther over 3 years ago

ref #8774: implement tests for dto handling - to be continued

View differences:

cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/TermNodeServiceImplTest.java
1
/**
2
* Copyright (C) 2020 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.api.service;
10

  
11
import java.io.FileNotFoundException;
12
import java.util.ArrayList;
13
import java.util.List;
14
import java.util.UUID;
15

  
16
import org.junit.Assert;
17
import org.junit.Test;
18
import org.unitils.spring.annotation.SpringBeanByType;
19

  
20
import  eu.etaxonomy.cdm.model.description.Character;
21
import eu.etaxonomy.cdm.model.description.Feature;
22
import eu.etaxonomy.cdm.model.term.DefinedTerm;
23
import eu.etaxonomy.cdm.model.term.TermNode;
24
import eu.etaxonomy.cdm.model.term.TermTree;
25
import eu.etaxonomy.cdm.model.term.TermType;
26
import eu.etaxonomy.cdm.persistence.dto.CharacterDto;
27
import eu.etaxonomy.cdm.persistence.dto.CharacterNodeDto;
28
import eu.etaxonomy.cdm.persistence.dto.TermDto;
29
import eu.etaxonomy.cdm.persistence.dto.TermNodeDto;
30
import eu.etaxonomy.cdm.persistence.dto.TermTreeDto;
31
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
32

  
33

  
34
/**
35
 * @author k.luther
36
 * @since Oct 30, 2020
37
 */
38
public class TermNodeServiceImplTest  extends CdmTransactionalIntegrationTest{
39

  
40
    @SpringBeanByType
41
    private ITermNodeService termNodeService;
42

  
43
    @SpringBeanByType
44
    private ITermTreeService termTreeService;
45

  
46
    @SpringBeanByType
47
    private ITermService termService;
48

  
49

  
50
    @Test
51
    public void testSaveCharacterNode() {
52
        DefinedTerm structure = DefinedTerm.NewInstance(TermType.Structure);
53
        TermTree<DefinedTerm> structureTree = TermTree.NewInstance(TermType.Structure);
54
        TermNode<DefinedTerm> nodeStructure = structureTree.getRoot().addChild(structure);
55

  
56
        DefinedTerm property = DefinedTerm.NewInstance(TermType.Property);
57
        TermTree<DefinedTerm> propertyTree = TermTree.NewInstance(TermType.Property);
58
        TermNode<DefinedTerm> nodeProperty = propertyTree.getRoot().addChild(property);
59
        termService.saveOrUpdate(property);
60
        termService.saveOrUpdate(structure);
61
        termTreeService.saveOrUpdate(structureTree);
62
        termTreeService.saveOrUpdate(propertyTree);
63

  
64
        TermTree<Feature> characterTree = TermTree.NewInstance(TermType.Feature);
65
        UUID characterTreeUuid = characterTree.getUuid();
66
        Character character = Character.NewInstance(nodeStructure, nodeProperty);
67
        character.setSupportsCategoricalData(false);
68

  
69
        characterTree.getRoot().addChild(character);
70
        termService.saveOrUpdate(character);
71
        termTreeService.saveOrUpdate(characterTree);
72
        termTreeService.getSession().flush();
73
        TermTreeDto dto = termTreeService.getTermTreeDtoByUuid(characterTreeUuid);
74
        List<TermNodeDto> children = dto.getRoot().getChildren();
75
        CharacterNodeDto nodeDto = (CharacterNodeDto) children.get(0);
76
        TermDto termDto = nodeDto.getTerm();
77
        if (termDto instanceof CharacterDto){
78
            CharacterDto characterDto = (CharacterDto) termDto;
79
            characterDto.setSupportsCategoricalData(true);
80
            List<CharacterNodeDto> dtos = new ArrayList<>();
81
            dtos.add(nodeDto);
82
            termNodeService.saveCharacterNodeDtoList(dtos);
83
            termNodeService.getSession().flush();
84
            characterTree = termTreeService.load(characterTreeUuid);
85
            List<TermNode<Feature>> childNodes = characterTree.getRoot().getChildNodes();
86
            TermNode<Feature> child = childNodes.get(0);
87
            Assert.assertTrue(child.getTerm().isSupportsCategoricalData());
88

  
89
        }else{
90
            Assert.fail();
91
        }
92

  
93

  
94

  
95

  
96
    }
97

  
98

  
99

  
100
    @Override
101
    public void createTestDataSet() throws FileNotFoundException {
102

  
103
    }
104

  
105
}

Also available in: Unified diff