Project

General

Profile

« Previous | Next » 

Revision db1795af

Added by Katja Luther over 3 years ago

ref #8774: implement tests for dto handling - test changing representation

View differences:

cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/TermNodeServiceImplTest.java
17 17
import org.junit.Test;
18 18
import org.unitils.spring.annotation.SpringBeanByType;
19 19

  
20
import eu.etaxonomy.cdm.model.common.Language;
20 21
import  eu.etaxonomy.cdm.model.description.Character;
21 22
import eu.etaxonomy.cdm.model.description.Feature;
22 23
import eu.etaxonomy.cdm.model.term.DefinedTerm;
24
import eu.etaxonomy.cdm.model.term.Representation;
23 25
import eu.etaxonomy.cdm.model.term.TermNode;
24 26
import eu.etaxonomy.cdm.model.term.TermTree;
25 27
import eu.etaxonomy.cdm.model.term.TermType;
......
48 50

  
49 51

  
50 52
    @Test
51
    public void testSaveCharacterNode() {
53
    public void testSaveCharacterNode_supportedData() {
52 54
        DefinedTerm structure = DefinedTerm.NewInstance(TermType.Structure);
53 55
        TermTree<DefinedTerm> structureTree = TermTree.NewInstance(TermType.Structure);
54 56
        TermNode<DefinedTerm> nodeStructure = structureTree.getRoot().addChild(structure);
......
84 86
            characterTree = termTreeService.load(characterTreeUuid);
85 87
            List<TermNode<Feature>> childNodes = characterTree.getRoot().getChildNodes();
86 88
            TermNode<Feature> child = childNodes.get(0);
89

  
87 90
//            Assert.assertTrue(child.getTerm().isSupportsCategoricalData());
88 91

  
89 92
        }else{
90 93
            Assert.fail();
91 94
        }
95
    }
96

  
97
    @Test
98
    public void testSaveCharacterNode_representation() {
99
        DefinedTerm structure = DefinedTerm.NewInstance(TermType.Structure);
100
        TermTree<DefinedTerm> structureTree = TermTree.NewInstance(TermType.Structure);
101
        TermNode<DefinedTerm> nodeStructure = structureTree.getRoot().addChild(structure);
102

  
103
        DefinedTerm property = DefinedTerm.NewInstance(TermType.Property);
104
        TermTree<DefinedTerm> propertyTree = TermTree.NewInstance(TermType.Property);
105
        TermNode<DefinedTerm> nodeProperty = propertyTree.getRoot().addChild(property);
106
        termService.saveOrUpdate(property);
107
        termService.saveOrUpdate(structure);
108
        termTreeService.saveOrUpdate(structureTree);
109
        termTreeService.saveOrUpdate(propertyTree);
110

  
111
        TermTree<Feature> characterTree = TermTree.NewInstance(TermType.Feature);
112
        UUID characterTreeUuid = characterTree.getUuid();
113
        Character character = Character.NewInstance(nodeStructure, nodeProperty);
114
        character.setSupportsCategoricalData(false);
115

  
116
        characterTree.getRoot().addChild(character);
117
        termService.saveOrUpdate(character);
118
        termTreeService.saveOrUpdate(characterTree);
119
        termTreeService.getSession().flush();
120
        TermTreeDto dto = termTreeService.getTermTreeDtoByUuid(characterTreeUuid);
121
        List<TermNodeDto> children = dto.getRoot().getChildren();
122
        CharacterNodeDto nodeDto = (CharacterNodeDto) children.get(0);
123
        TermDto termDto = nodeDto.getTerm();
124
        if (termDto instanceof CharacterDto){
125
            CharacterDto characterDto = (CharacterDto) termDto;
126
            Representation rep = characterDto.getPreferredRepresentation(Language.DEFAULT());
127
            if (rep != null){
128
                rep.setText("Test");
129
            }else{
130
                rep = Representation.NewInstance("Test", "", "", Language.DEFAULT());
131
                characterDto.addRepresentation(rep);
132
            }
133
            List<CharacterNodeDto> dtos = new ArrayList<>();
134
            dtos.add(nodeDto);
135
            termNodeService.saveCharacterNodeDtoList(dtos);
136
            commitAndStartNewTransaction();
137
            characterTree = termTreeService.load(characterTreeUuid);
138
            List<TermNode<Feature>> childNodes = characterTree.getRoot().getChildNodes();
139
            TermNode<Feature> child = childNodes.get(0);
140

  
141
            Assert.assertTrue(child.getTerm().getPreferredRepresentation(Language.DEFAULT()).getText().equals("Test"));
142

  
143
        }else{
144
            Assert.fail();
145
        }
92 146

  
93 147

  
94 148

  

Also available in: Unified diff