source: DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestInstances.java @ 3347

Last change on this file since 3347 was 3347, checked in by olhsha, 11 years ago

nrefactored method addAnnotation from annotation-dao is tested

File size: 4.7 KB
Line 
1/**
2 * Copyright (C) 2013 DASISH
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18package eu.dasish.annotation.backend;
19
20import eu.dasish.annotation.schema.Annotation;
21import eu.dasish.annotation.schema.AnnotationBody;
22import eu.dasish.annotation.schema.NewOrExistingSourceInfo;
23import eu.dasish.annotation.schema.NewOrExistingSourceInfos;
24import eu.dasish.annotation.schema.NewSourceInfo;
25import eu.dasish.annotation.schema.ResourceREF;
26import eu.dasish.annotation.schema.SourceInfo;
27import java.util.List;
28
29/**
30 *
31 * @author olhsha
32 */
33public class TestInstances {
34   
35    final private Annotation _annotationOne;
36    final private Annotation _annotationToAdd;
37    final private Annotation _annotationToAddNewSource;
38   
39    public TestInstances(){
40        _annotationOne = makeAnnotationOne();
41        _annotationToAdd = makeAnnotationToAdd();
42        _annotationToAddNewSource = makeAnnotationToAddNewSource();       
43    }
44   
45   
46    private Annotation makeAnnotationOne(){
47        Annotation result = makeAnnotation(TestBackendConstants._TEST_ANNOT_2_BODY, TestBackendConstants._TEST_ANNOT_2_HEADLINE, TestBackendConstants._TEST_ANNOT_2_OWNER);
48        return result;
49    }
50   
51    private Annotation makeAnnotationToAdd(){
52       Annotation result = makeAnnotation(TestBackendConstants._TEST_ANNOT_TO_ADD_BODY, TestBackendConstants._TEST_ANNOT_TO_ADD_HEADLINE, 5);
53       
54       SourceInfo sourceInfo =  new SourceInfo();
55       sourceInfo.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);
56       sourceInfo.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
57       sourceInfo.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID); 
58       
59       NewOrExistingSourceInfo noeSourceInfo =  new NewOrExistingSourceInfo();
60       noeSourceInfo.setSource(sourceInfo);
61       NewOrExistingSourceInfos noeSourceInfos =  new NewOrExistingSourceInfos();
62       noeSourceInfos.getTarget().add(noeSourceInfo);
63       result.setTargetSources(noeSourceInfos);
64       
65       return result;
66    }
67   
68    private Annotation makeAnnotationToAddNewSource(){
69       Annotation result = makeAnnotation(TestBackendConstants._TEST_ANNOT_TO_ADD_NEW_SOURCE_BODY, TestBackendConstants._TEST_ANNOT_TO_ADD_NEW_SOURCE_HEADLINE, 5);
70       
71       NewSourceInfo newSourceInfo =  new NewSourceInfo();
72       newSourceInfo.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);
73       newSourceInfo.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID);
74       // TODO: so far, the version is the external version id generated when a version is added
75       // because for now the version is used to keep external id of the version, not is human-friendly headline
76       // fix it by adding external Id to the version
77       newSourceInfo.setVersion(null); 
78       
79       NewOrExistingSourceInfo noeSourceInfo =  new NewOrExistingSourceInfo();
80       noeSourceInfo.setNewSource(newSourceInfo);
81       NewOrExistingSourceInfos noeSourceInfos =  new NewOrExistingSourceInfos();
82       noeSourceInfos.getTarget().add(noeSourceInfo);
83       result.setTargetSources(noeSourceInfos);
84       
85       return result;
86    }
87   
88   
89    // so far tests only adding annot with existing sources!!!
90    // TODO: add non-existing sources
91    private Annotation makeAnnotation(String bodyTxt, String headline, int ownerId){
92        Annotation result = new Annotation();
93        AnnotationBody body = new AnnotationBody();
94        List<Object> bodyContent = body.getAny();
95        bodyContent.add(bodyTxt);       
96        result.setBody(body);
97        result.setHeadline(headline);
98        ResourceREF owner = new ResourceREF();
99        owner.setRef(String.valueOf(ownerId));
100        result.setOwner(owner); 
101       
102        result.setTimeStamp(null); 
103        result.setURI(null);
104        result.setTargetSources(null);
105        result.setURI(null);
106       
107       return result;
108    }
109   
110    //private
111   
112   
113    public Annotation getAnnotationOne(){
114        return _annotationOne;
115    }
116   
117    public Annotation getAnnotationToAdd(){
118        return _annotationToAdd;
119    }
120   
121   public Annotation getAnnotationToAddNewSource(){
122        return _annotationToAddNewSource;
123    }
124   
125}
Note: See TracBrowser for help on using the repository browser.