Changeset 3151
- Timestamp:
- 07/17/13 14:12:25 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java
r3146 r3151 34 34 public interface AnnotationDao extends ResourceDao{ 35 35 36 // Returns the list of annotation Id-s for the notebook id. 37 List<Number> getAnnotationIDs(Number notebookID); 38 39 // Returns the list of annotation info-s for the notebook id. 36 // Returns the list of annotation info-s for the notebook id. 40 37 List<AnnotationInfo> getAnnotationInfos(List<Number> annotationIDs); 41 38 42 // Returns the list of annotation info-s for the notebook id. 43 List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID); 44 39 45 40 // Returns the list of annotations Id-s for the notebook id. 46 41 List<ResourceREF> getAnnotationREFs(List<Number> annotationIDs); 47 42 48 // Returns the list of annotations Id-s for the notebook id.49 List<ResourceREF> getAnnotationREFsOfNotebook(Number notebookID);50 51 // Returns the annotations object for the notebook id.52 Annotations getAnnotations(Number notebookID);53 54 43 55 44 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/NotebookDao.java
r3146 r3151 21 21 import eu.dasish.annotation.backend.identifiers.NotebookIdentifier; 22 22 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 23 import eu.dasish.annotation.schema.AnnotationInfo; 24 import eu.dasish.annotation.schema.Annotations; 23 25 import eu.dasish.annotation.schema.Notebook; 24 26 import eu.dasish.annotation.schema.NotebookInfo; 27 import eu.dasish.annotation.schema.ResourceREF; 25 28 import java.util.List; 26 29 … … 47 50 // Adds an annotation _aid_ to the list of annotations of _nid_. 48 51 public int addAnnotation(NotebookIdentifier notebookId, AnnotationIdentifier annotationId); 52 53 // Returns the list of annotation Id-s for the notebook id. 54 List<Number> getAnnotationIDs(Number notebookID); 55 56 /*Returns the list of annotation info-s for the notebook id. 57 /List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID); */ 58 59 // Returns the list of annotations Id-s for the notebook id. 60 List<ResourceREF> getAnnotationREFsOfNotebook(Number notebookID); 61 62 // Returns the Annotations object for the notebook id. 63 Annotations getAnnotations(Number notebookID); 64 65 49 66 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r3146 r3151 47 47 48 48 49 //////////////////////////////////////////////////////////////////////// 50 /** 51 * 52 * @param notebookID 53 * @return the list of annotation-ids belonging to the notebook with notebookId 54 * returns null if notebookId is null or is not in the DB 55 * TODO: do we need to return null here? using an additional check. 56 */ 57 @Override 58 public List<Number> getAnnotationIDs(Number notebookID) { 59 if (notebookID == null) { 60 return null; 61 } 62 63 if (isNotebookInTheDataBase(notebookID)) { 64 String sql = "SELECT notebooks_annotations.annotation_id FROM notebooks_annotations where notebook_id = ?"; 65 return getSimpleJdbcTemplate().query(sql, annotationIDRowMapper, notebookID.toString()); 66 } else { 67 return null; 68 } 69 } 70 71 private final RowMapper<Number> annotationIDRowMapper = new RowMapper<Number>() { 72 @Override 73 public Integer mapRow(ResultSet rs, int rowNumber) throws SQLException { 74 Integer annotationId = rs.getInt("annotation_id"); 75 return annotationId; 76 } 77 }; 78 49 79 50 //////////////////////////////////////////////////////////////////////////// 80 51 … … 115 86 116 87 117 ////////////////////////////////////////////////// 118 119 /** 120 * 121 * @param notebookID 122 * @return the list of annotation-infos of the annotations from notebookID; 123 * if notebook not in the DB or null returns null 124 * if the notebook contains no annotations returns an empty list 125 */ 126 127 @Override 128 public List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID) { 129 return getAnnotationInfos(getAnnotationIDs(notebookID)); 130 } 131 88 132 89 ///////////////////////////////////////////////// 133 90 … … 164 121 }; 165 122 166 ////////////////////////////////////////////// 167 /** 168 * 169 * @param notebookID 170 * @return the list of annotation References from the notebookID 171 * returns null if notebookID == null or it does not exists in the DB 172 */ 123 124 173 125 174 @Override175 public List<ResourceREF> getAnnotationREFsOfNotebook(Number notebookID) {176 return getAnnotationREFs(getAnnotationIDs(notebookID));177 }178 179 180 181 ////////////////////////////////////////////////////////////////////////////182 /**183 *184 * @param notebookID185 * @return the Annotations (as a list of references) from the notebookID *186 * returns null if notebookID == null, or it does not exists in th DB, or the list of annotations is empty,187 * or something wrong happened when extracting annotations from the notebook188 * (according to dasish.xsd if an Annotation is created then its list of annotations must contain at least one element!)189 *190 */191 192 @Override193 public Annotations getAnnotations(Number notebookID) {194 195 if (notebookID == null) {196 return null;197 }198 199 if (isNotebookInTheDataBase(notebookID)) {200 Annotations result = new Annotations();201 List<ResourceREF> annotREFs = result.getAnnotation();202 // TODO: what of annotREFS is null????203 boolean test = annotREFs.addAll(getAnnotationREFsOfNotebook(notebookID));204 return (test ? result : null);205 } else {206 return null;207 }208 209 }210 126 211 127 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java
r3146 r3151 23 23 import eu.dasish.annotation.backend.identifiers.NotebookIdentifier; 24 24 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 25 import eu.dasish.annotation.schema.AnnotationInfo; 26 import eu.dasish.annotation.schema.Annotations; 25 27 import eu.dasish.annotation.schema.Notebook; 26 28 import eu.dasish.annotation.schema.NotebookInfo; 29 import eu.dasish.annotation.schema.ResourceREF; 27 30 import java.sql.ResultSet; 28 31 import java.sql.SQLException; … … 110 113 } 111 114 // notebook.setURI(rs.getString("URI_ID")); 112 notebook.setAnnotations( jdbcAnnotationDao.getAnnotations(rs.getInt("notebook_id")));115 notebook.setAnnotations(getAnnotations(rs.getInt("notebook_id"))); 113 116 return notebook; 114 117 } … … 138 141 } 139 142 } 143 144 //////////////////////////////////////////////////////////////////////// 145 /** 146 * 147 * @param notebookID 148 * @return the list of annotation-ids belonging to the notebook with notebookId 149 * returns null if notebookId is null or is not in the DB 150 * TODO: do we need to return null here? using an additional check. 151 */ 152 @Override 153 public List<Number> getAnnotationIDs(Number notebookID) { 154 if (notebookID == null) { 155 return null; 156 } 157 158 if (isNotebookInTheDataBase(notebookID)) { 159 String sql = "SELECT notebooks_annotations.annotation_id FROM notebooks_annotations where notebook_id = ?"; 160 return getSimpleJdbcTemplate().query(sql, annotationIDRowMapper, notebookID.toString()); 161 } else { 162 return null; 163 } 164 } 165 166 private final RowMapper<Number> annotationIDRowMapper = new RowMapper<Number>() { 167 @Override 168 public Integer mapRow(ResultSet rs, int rowNumber) throws SQLException { 169 Integer annotationId = rs.getInt("annotation_id"); 170 return annotationId; 171 } 172 }; 173 174 ////////////////////////////////////////////////// 175 176 /** 177 * 178 * @param notebookID 179 * @return the list of annotation-infos of the annotations from notebookID; 180 * if notebook not in the DB or null returns null 181 * if the notebook contains no annotations returns an empty list 182 * 183 184 @Override 185 public List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID) { 186 return jdbcAnnotationDao.getAnnotationInfos(getAnnotationIDs(notebookID)); 187 }*/ 188 189 190 ////////////////////////////////////////////// 191 /** 192 * 193 * @param notebookID 194 * @return the list of annotation References from the notebookID 195 * returns null if notebookID == null or it does not exists in the DB 196 */ 197 198 @Override 199 public List<ResourceREF> getAnnotationREFsOfNotebook(Number notebookID) { 200 return jdbcAnnotationDao.getAnnotationREFs(getAnnotationIDs(notebookID)); 201 } 202 203 //////////////////////////////////////////////////////////////////////////// 204 /** 205 * 206 * @param notebookID 207 * @return the Annotations (as a list of references) from the notebookID * 208 * returns null if notebookID == null, or it does not exists in th DB, or the list of annotations is empty, 209 * or something wrong happened when extracting annotations from the notebook 210 * (according to dasish.xsd if an Annotation is created then its list of annotations must contain at least one element!) 211 * 212 */ 213 214 @Override 215 public Annotations getAnnotations(Number notebookID) { 216 217 if (notebookID == null) { 218 return null; 219 } 220 221 if (isNotebookInTheDataBase(notebookID)) { 222 Annotations result = new Annotations(); 223 List<ResourceREF> annotREFs = result.getAnnotation(); 224 // TODO: what of annotREFS is null???? 225 boolean test = annotREFs.addAll(getAnnotationREFsOfNotebook(notebookID)); 226 return (test ? result : null); 227 } else { 228 return null; 229 } 230 231 } 140 232 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r3146 r3151 20 20 import eu.dasish.annotation.backend.TestBackendConstants; 21 21 import eu.dasish.annotation.schema.AnnotationInfo; 22 import eu.dasish.annotation.schema.Annotations;23 22 import eu.dasish.annotation.schema.ResourceREF; 24 import java.io.File;25 import java.io.FileNotFoundException;26 import java.net.URISyntaxException;27 import java.net.URL;28 23 import java.util.ArrayList; 29 24 import java.util.List; 30 import java.util.Scanner;31 import org.junit.After;32 25 import static org.junit.Assert.*; 33 import org.junit.Before;34 import org.junit.Ignore;35 26 import org.junit.Test; 36 27 import org.junit.runner.RunWith; 37 28 import org.springframework.beans.factory.annotation.Autowired; 38 import org.springframework.dao.DataAccessException;39 import org.springframework.jdbc.core.JdbcTemplate;40 29 import org.springframework.test.context.ContextConfiguration; 41 30 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; … … 58 47 } 59 48 60 /** 61 * Test of getAnnotationIDs method, of class JdbcAnnotationDao. 62 * List<Number> getAnnotationIDs(Number notebookID) 63 */ 64 @Test 65 public void testGetAnnotationIDs() { 66 System.out.println("getAnnotationIDs"); 67 68 // test one, 2-element notebook 69 final List<Number> annotationIDs = jdbcAnnotationDao.getAnnotationIDs(TestBackendConstants._TEST_NOTEBOOK_1_INT); 70 assertEquals(2, annotationIDs.size()); 71 assertEquals(TestBackendConstants._TEST_ANNOT_1_INT, annotationIDs.get(0).intValue()); 72 assertEquals(TestBackendConstants._TEST_ANNOT_2_INT, annotationIDs.get(1).intValue()); 73 74 // test two, 1-element notebook 75 final List<Number> annotationIDsTwo = jdbcAnnotationDao.getAnnotationIDs(TestBackendConstants._TEST_NOTEBOOK_2_INT); 76 assertEquals(1, annotationIDsTwo.size()); 77 assertEquals(TestBackendConstants._TEST_ANNOT_3_INT, annotationIDsTwo.get(0).intValue()); 78 79 // test three, empty notebook 80 final List<Number> annotationIDsThree = jdbcAnnotationDao.getAnnotationIDs(TestBackendConstants._TEST_NOTEBOOK_3_INT); 81 assertEquals(0, annotationIDsThree.size()); 82 83 // test four, null-notebook 84 final List<Number> annotationIDsFour = jdbcAnnotationDao.getAnnotationIDs(null); 85 assertEquals(null, annotationIDsFour); 86 87 //test five, the notebook not in the DB 88 final List<Number> annotationIDsFive = jdbcAnnotationDao.getAnnotationIDs(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB); 89 assertEquals(null, annotationIDsFive); 90 91 } 49 92 50 93 51 /** … … 127 85 } 128 86 129 /** 130 * Test of getAnnotationInfosOfNotebook method, of class JdbcAnnotationDao. 131 * List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID) 132 */ 133 @Test 134 public void testGetAnnotationInfosOfNotebook() { 135 System.out.println("getAnnotationInfosOfNotebook"); 136 137 //test One 138 final List<AnnotationInfo> annotationInfos = jdbcAnnotationDao.getAnnotationInfosOfNotebook(TestBackendConstants._TEST_NOTEBOOK_1_INT); 139 assertEquals(2, annotationInfos.size()); 140 141 assertEquals(TestBackendConstants._TEST_ANNOT_1_HEADLINE, annotationInfos.get(0).getHeadline()); 142 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_1_OWNER), annotationInfos.get(0).getOwner().getRef()); 143 //assertEquals(TestBackendConstants._TEST_ANNOT_1_TARGETS, annotationInfos.get(0).getTargetSources()); 144 145 assertEquals(TestBackendConstants._TEST_ANNOT_2_HEADLINE, annotationInfos.get(1).getHeadline()); 146 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_2_OWNER), annotationInfos.get(1).getOwner().getRef()); 147 //assertEquals(TestBackendConstants._TEST_ANNOT_2_TARGETS, annotationInfos.get(1).getTargetSources()); 148 149 150 //test Two 151 final List<AnnotationInfo> annotationInfosTwo = jdbcAnnotationDao.getAnnotationInfosOfNotebook(TestBackendConstants._TEST_NOTEBOOK_2_INT); 152 assertEquals(1, annotationInfosTwo.size()); 153 154 assertEquals(TestBackendConstants._TEST_ANNOT_3_HEADLINE, annotationInfosTwo.get(0).getHeadline()); 155 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_3_OWNER), annotationInfosTwo.get(0).getOwner().getRef()); 156 //assertEquals(TestBackendConstants._TEST_ANNOT_3_TARGETS, annotationInfosTwo.get(0).getTargetSources()); 157 158 //test notebook with no annotations 159 final List<AnnotationInfo> annotationInfosThree = jdbcAnnotationDao.getAnnotationInfosOfNotebook(TestBackendConstants._TEST_NOTEBOOK_3_INT); 160 assertEquals(0, annotationInfosThree.size()); 161 162 //non-existing notebook 163 final List<AnnotationInfo> annotationInfosFour = jdbcAnnotationDao.getAnnotationInfosOfNotebook(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB); 164 assertEquals(null, annotationInfosFour); 165 166 167 //null notebook 168 final List<AnnotationInfo> annotationInfosFive = jdbcAnnotationDao.getAnnotationInfosOfNotebook(null); 169 assertEquals(null, annotationInfosFive); 170 171 172 } 173 87 174 88 /** 175 89 * Test of getAnnotationREFs method, of class JdbcAnnotationDao. … … 199 113 } 200 114 201 /** 202 * Test of getAnnotationREFsOfNotebook method, of class JdbcAnnotationDao. 203 * List<ResourceREF> getAnnotationREFsOfNotebook(Number notebookID) 204 */ 205 @Test 206 public void testGetAnnotationREFsOfNotebook() { 207 System.out.println("getAnnotationREFsOfNotebook"); 208 209 // test One 210 List<ResourceREF> testList = jdbcAnnotationDao.getAnnotationREFsOfNotebook(TestBackendConstants._TEST_NOTEBOOK_1_INT); 211 assertEquals(2, testList.size()); 212 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_1_INT), testList.get(0).getRef()); 213 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_2_INT), testList.get(1).getRef()); 214 215 // test One 216 List<ResourceREF> testListTwo = jdbcAnnotationDao.getAnnotationREFsOfNotebook(TestBackendConstants._TEST_NOTEBOOK_2_INT); 217 assertEquals(1, testListTwo.size()); 218 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_3_INT), testListTwo.get(0).getRef()); 219 220 // test Three "empty" 221 List<ResourceREF> testListThree = jdbcAnnotationDao.getAnnotationREFsOfNotebook(TestBackendConstants._TEST_NOTEBOOK_3_INT); 222 assertEquals(0, testListThree.size()); 223 224 // test Four, non-existing notebook 225 List<ResourceREF> testListFour = jdbcAnnotationDao.getAnnotationREFsOfNotebook(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB); 226 assertEquals(null, testListFour); 227 228 // test Five Null-notebook 229 List<ResourceREF> testListFive = jdbcAnnotationDao.getAnnotationREFsOfNotebook(null); 230 assertEquals(null, testListFive); 231 } 232 233 /** 234 * Test of getAnnotations method, of class JdbcAnnotationDao. 235 * Annotations getAnnotations(Number notebookID) 236 */ 237 @Test 238 public void testGetAnnotations() { 239 System.out.println("getAnnotations"); 240 241 // test One 242 Annotations annotations = jdbcAnnotationDao.getAnnotations(TestBackendConstants._TEST_NOTEBOOK_1_INT); 243 assertEquals(2, annotations.getAnnotation().size()); 244 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_1_INT), annotations.getAnnotation().get(0).getRef()); 245 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_2_INT), annotations.getAnnotation().get(1).getRef()); 246 247 // test One 248 Annotations annotationsTwo = jdbcAnnotationDao.getAnnotations(TestBackendConstants._TEST_NOTEBOOK_2_INT); 249 assertEquals(1, annotationsTwo.getAnnotation().size()); 250 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_3_INT), annotationsTwo.getAnnotation().get(0).getRef()); 251 252 // test Three "empty" list of annotations 253 // according to dasish.xsd if an Annotation is created then its list of annotations must contain at least one element! 254 // therefore: no annotations in the notebook ==> Annotations-pbject must be null :( 255 Annotations annotationsThree = jdbcAnnotationDao.getAnnotations(TestBackendConstants._TEST_NOTEBOOK_3_INT); 256 assertEquals(null, annotationsThree); 257 258 // test Five, non-existing notebook 259 Annotations annotationsFour = jdbcAnnotationDao.getAnnotations(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB); 260 assertEquals(null, annotationsFour); 261 262 // test Five Null-notebook 263 Annotations annotationsFive = jdbcAnnotationDao.getAnnotations(null); 264 assertEquals(null, annotationsFive); 265 } 115 266 116 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDaoTest.java
r3146 r3151 22 22 import eu.dasish.annotation.backend.identifiers.NotebookIdentifier; 23 23 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 24 import eu.dasish.annotation.schema.AnnotationInfo; 24 25 import eu.dasish.annotation.schema.Annotations; 25 26 import eu.dasish.annotation.schema.Notebook; 26 27 import eu.dasish.annotation.schema.NotebookInfo; 28 import eu.dasish.annotation.schema.ResourceREF; 27 29 import java.net.URISyntaxException; 30 import java.util.ArrayList; 31 import java.util.Arrays; 28 32 import java.util.Calendar; 29 33 import java.util.List; … … 45 49 */ 46 50 @RunWith(SpringJUnit4ClassRunner.class) 47 @ContextConfiguration({"/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/dataSource.xml", "/spring-config/notebookDao.xml"}) 51 @ContextConfiguration({"/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml", 52 "/spring-test-config/dataSource.xml", "/spring-config/notebookDao.xml"}) 48 53 public class JdbcNotebookDaoTest extends JdbcResourceDaoTest{ 49 54 … … 79 84 int month = Calendar.getInstance().get(Calendar.MONTH); 80 85 int day = Calendar.getInstance().get(Calendar.DAY_OF_MONTH); 81 mockery.checking(new Expectations() { 82 { 83 oneOf(annotationDao).getAnnotations(1); 84 will(returnValue(new Annotations())); 85 oneOf(annotationDao).getAnnotations(2); 86 will(returnValue(new Annotations())); 86 87 ResourceREF testRef = new ResourceREF(); 88 testRef.setRef("1"); 89 final List<ResourceREF> testResult = Arrays.asList(new ResourceREF[] {testRef}); 90 91 mockery.checking(new Expectations() { 92 { 93 exactly(2).of(annotationDao).getAnnotationREFs(Arrays.asList(new Number[] {1}));// exactly 2 notebooks (their id-s 1 and 2) contains the annotation 1 94 will(returnValue(testResult)); 87 95 } 88 96 }); 97 89 98 final List<Notebook> notebooks = jdbcNotebookDao.getUsersNotebooks(new UserIdentifier(TestBackendConstants._TEST_UID_2_)); 90 99 … … 97 106 assertEquals(month + 1, notebooks.get(0).getTimeStamp().getMonth()); 98 107 assertEquals(day, notebooks.get(0).getTimeStamp().getDay()); 99 mockery.checking(new Expectations() { 100 { 101 oneOf(annotationDao).getAnnotations(0); 102 will(returnValue(new Annotations())); 108 109 110 mockery.checking(new Expectations() { 111 { 112 oneOf(annotationDao).getAnnotationREFs(new ArrayList<Number>()); 113 will(returnValue(new ArrayList<ResourceREF>())); 103 114 } 104 115 }); 116 105 117 final List<Notebook> notebooksEmpty = jdbcNotebookDao.getUsersNotebooks(new UserIdentifier(TestBackendConstants._TEST_UID_1_)); 106 118 assertEquals(0, notebooksEmpty.size()); … … 126 138 assertEquals(1, result); 127 139 } 140 141 /** 142 * Test of getAnnotationIDs method, of class JdbcAnnotationDao. 143 * List<Number> getAnnotationIDs(Number notebookID) 144 */ 145 @Test 146 public void testGetAnnotationIDs() { 147 System.out.println("getAnnotationIDs"); 148 149 // test one, 2-element notebook 150 final List<Number> annotationIDs = jdbcNotebookDao.getAnnotationIDs(TestBackendConstants._TEST_NOTEBOOK_1_INT); 151 assertEquals(2, annotationIDs.size()); 152 assertEquals(TestBackendConstants._TEST_ANNOT_1_INT, annotationIDs.get(0).intValue()); 153 assertEquals(TestBackendConstants._TEST_ANNOT_2_INT, annotationIDs.get(1).intValue()); 154 155 // test two, 1-element notebook 156 final List<Number> annotationIDsTwo = jdbcNotebookDao.getAnnotationIDs(TestBackendConstants._TEST_NOTEBOOK_2_INT); 157 assertEquals(1, annotationIDsTwo.size()); 158 assertEquals(TestBackendConstants._TEST_ANNOT_3_INT, annotationIDsTwo.get(0).intValue()); 159 160 // test three, empty notebook 161 final List<Number> annotationIDsThree = jdbcNotebookDao.getAnnotationIDs(TestBackendConstants._TEST_NOTEBOOK_3_INT); 162 assertEquals(0, annotationIDsThree.size()); 163 164 // test four, null-notebook 165 final List<Number> annotationIDsFour = jdbcNotebookDao.getAnnotationIDs(null); 166 assertEquals(null, annotationIDsFour); 167 168 //test five, the notebook not in the DB 169 final List<Number> annotationIDsFive = jdbcNotebookDao.getAnnotationIDs(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB); 170 assertEquals(null, annotationIDsFive); 171 172 } 173 174 /** 175 * Test of getAnnotationInfosOfNotebook method, of class JdbcAnnotationDao. 176 * List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID) 177 178 @Test 179 public void testGetAnnotationInfosOfNotebook() { 180 System.out.println("getAnnotationInfosOfNotebook"); 181 182 mockery.checking(new Expectations() { 183 { 184 exactly(2).of(annotationDao).getAnnotationInfos(Arrays.asList(new Number[] {21, 22}));// exactly 2 notebooks (their id-s 1 and 2) contains the annotation 1 185 will(returnValue(testResult)); 186 } 187 }); 188 189 //test One 190 final List<AnnotationInfo> annotationInfos = jdbcNotebookDao.getAnnotationInfosOfNotebook(TestBackendConstants._TEST_NOTEBOOK_1_INT); 191 assertEquals(2, annotationInfos.size()); 192 193 assertEquals(TestBackendConstants._TEST_ANNOT_1_HEADLINE, annotationInfos.get(0).getHeadline()); 194 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_1_OWNER), annotationInfos.get(0).getOwner().getRef()); 195 //assertEquals(TestBackendConstants._TEST_ANNOT_1_TARGETS, annotationInfos.get(0).getTargetSources()); 196 197 assertEquals(TestBackendConstants._TEST_ANNOT_2_HEADLINE, annotationInfos.get(1).getHeadline()); 198 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_2_OWNER), annotationInfos.get(1).getOwner().getRef()); 199 //assertEquals(TestBackendConstants._TEST_ANNOT_2_TARGETS, annotationInfos.get(1).getTargetSources()); 200 201 202 //test Two 203 final List<AnnotationInfo> annotationInfosTwo = jdbcNotebookDao.getAnnotationInfosOfNotebook(TestBackendConstants._TEST_NOTEBOOK_2_INT); 204 assertEquals(1, annotationInfosTwo.size()); 205 206 assertEquals(TestBackendConstants._TEST_ANNOT_3_HEADLINE, annotationInfosTwo.get(0).getHeadline()); 207 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_3_OWNER), annotationInfosTwo.get(0).getOwner().getRef()); 208 //assertEquals(TestBackendConstants._TEST_ANNOT_3_TARGETS, annotationInfosTwo.get(0).getTargetSources()); 209 210 //test notebook with no annotations 211 final List<AnnotationInfo> annotationInfosThree = jdbcNotebookDao.getAnnotationInfosOfNotebook(TestBackendConstants._TEST_NOTEBOOK_3_INT); 212 assertEquals(0, annotationInfosThree.size()); 213 214 //non-existing notebook 215 final List<AnnotationInfo> annotationInfosFour = jdbcNotebookDao.getAnnotationInfosOfNotebook(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB); 216 assertEquals(null, annotationInfosFour); 217 218 219 //null notebook 220 final List<AnnotationInfo> annotationInfosFive = jdbcNotebookDao.getAnnotationInfosOfNotebook(null); 221 assertEquals(null, annotationInfosFive); 222 223 } 224 * */ 225 226 /** 227 * Test of getAnnotationREFsOfNotebook method, of class JdbcAnnotationDao. 228 * List<ResourceREF> getAnnotationREFsOfNotebook(Number notebookID) 229 */ 230 @Test 231 public void testGetAnnotationREFsOfNotebook() { 232 System.out.println("getAnnotationREFsOfNotebook"); 233 234 // test One 235 setMockeryNotebookOne(); 236 List<ResourceREF> testList = jdbcNotebookDao.getAnnotationREFsOfNotebook(TestBackendConstants._TEST_NOTEBOOK_1_INT); 237 assertEquals(2, testList.size()); 238 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_1_INT), testList.get(0).getRef()); 239 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_2_INT), testList.get(1).getRef()); 240 241 // test Two 242 setMockeryNotebookTwo(); 243 List<ResourceREF> testListTwo = jdbcNotebookDao.getAnnotationREFsOfNotebook(TestBackendConstants._TEST_NOTEBOOK_2_INT); 244 assertEquals(1, testListTwo.size()); 245 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_3_INT), testListTwo.get(0).getRef()); 246 247 // test Three "empty" 248 setMockeryNotebookThreeEmpty(); 249 List<ResourceREF> testListThree = jdbcNotebookDao.getAnnotationREFsOfNotebook(TestBackendConstants._TEST_NOTEBOOK_3_INT); 250 assertEquals(0, testListThree.size()); 251 252 // test Four, non-existing notebook 253 setMockeryNotebookNonExisting(); 254 List<ResourceREF> testListFour = jdbcNotebookDao.getAnnotationREFsOfNotebook(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB); 255 assertEquals(null, testListFour); 256 257 // test Five Null-notebook 258 setMockeryNotebookNonExisting(); 259 List<ResourceREF> testListFive = jdbcNotebookDao.getAnnotationREFsOfNotebook(null); 260 assertEquals(null, testListFive); 261 } 262 263 /** 264 * Test of getAnnotations method, of class JdbcAnnotationDao. 265 * Annotations getAnnotations(Number notebookID) 266 */ 267 @Test 268 public void testGetAnnotations() { 269 System.out.println("getAnnotations"); 270 271 // test One 272 setMockeryNotebookOne(); 273 Annotations annotations = jdbcNotebookDao.getAnnotations(TestBackendConstants._TEST_NOTEBOOK_1_INT); 274 assertEquals(2, annotations.getAnnotation().size()); 275 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_1_INT), annotations.getAnnotation().get(0).getRef()); 276 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_2_INT), annotations.getAnnotation().get(1).getRef()); 277 278 // test Two 279 setMockeryNotebookTwo(); 280 Annotations annotationsTwo = jdbcNotebookDao.getAnnotations(TestBackendConstants._TEST_NOTEBOOK_2_INT); 281 assertEquals(1, annotationsTwo.getAnnotation().size()); 282 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_3_INT), annotationsTwo.getAnnotation().get(0).getRef()); 283 284 // test Three "empty" list of annotations 285 // according to dasish.xsd if an Annotation is created then its list of annotations must contain at least one element! 286 // therefore: no annotations in the notebook ==> Annotations-pbject must be null :( 287 setMockeryNotebookThreeEmpty(); 288 Annotations annotationsThree = jdbcNotebookDao.getAnnotations(TestBackendConstants._TEST_NOTEBOOK_3_INT); 289 assertEquals(null, annotationsThree); 290 291 // test Five, non-existing notebook 292 setMockeryNotebookNonExisting(); 293 Annotations annotationsFour = jdbcNotebookDao.getAnnotations(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB); 294 assertEquals(null, annotationsFour); 295 296 // test Five Null-notebook 297 setMockeryNotebookNonExisting(); 298 Annotations annotationsFive = jdbcNotebookDao.getAnnotations(null); 299 assertEquals(null, annotationsFive); 300 } 301 302 303 //////////////////////////////////////////////////////////////////// 304 //////// Setting Mockeries ///////////////////////////////////////// 305 /////////////////////////////////////////////////////////////////// 306 307 private void setMockeryNotebookOne(){ 308 ResourceREF testRefOne = new ResourceREF(); 309 testRefOne.setRef(String.valueOf(TestBackendConstants._TEST_ANNOT_1_INT)); 310 ResourceREF testRefTwo = new ResourceREF(); 311 testRefTwo.setRef(String.valueOf(TestBackendConstants._TEST_ANNOT_2_INT)); 312 final List<ResourceREF> testResult = Arrays.asList(new ResourceREF[] {testRefOne, testRefTwo}); 313 314 mockery.checking(new Expectations() { 315 { 316 oneOf(annotationDao).getAnnotationREFs(Arrays.asList(new Number[] {TestBackendConstants._TEST_ANNOT_1_INT, TestBackendConstants._TEST_ANNOT_2_INT})); 317 will(returnValue(testResult)); 318 } 319 }); 320 } 321 322 private void setMockeryNotebookTwo(){ 323 ResourceREF testRef = new ResourceREF(); 324 testRef.setRef(String.valueOf(TestBackendConstants._TEST_ANNOT_3_INT)); 325 final List<ResourceREF> testResultTwo = Arrays.asList(new ResourceREF[] {testRef}); 326 327 mockery.checking(new Expectations() { 328 { 329 oneOf(annotationDao).getAnnotationREFs(Arrays.asList(new Number[] {TestBackendConstants._TEST_ANNOT_3_INT})); 330 will(returnValue(testResultTwo)); 331 } 332 }); 333 } 334 335 private void setMockeryNotebookThreeEmpty(){ 336 mockery.checking(new Expectations() { 337 { 338 oneOf(annotationDao).getAnnotationREFs(new ArrayList<Number>()); 339 will(returnValue(new ArrayList<ResourceREF>())); 340 } 341 }); 342 } 343 344 private void setMockeryNotebookNonExisting() { 345 mockery.checking(new Expectations() { 346 { 347 oneOf(annotationDao).getAnnotationREFs(null); 348 will(returnValue(null)); 349 } 350 }); 351 } 352 128 353 }
Note: See TracChangeset
for help on using the changeset viewer.