source: DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDaoTest.java @ 3455

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

replacing DaishIdentifier?-based classes with simply UUID. tested. Works, excpet that UUID seems not be be serailizable, see e.g. getAllAnnotations in NotebookResource? where I have to use Peter's workoaroun to put UUID in JAXBElement<UUID>

File size: 5.4 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.dao.impl;
19
20import eu.dasish.annotation.backend.TestBackendConstants;
21import eu.dasish.annotation.schema.Version;
22import java.util.ArrayList;
23import java.util.List;
24import java.util.UUID;
25import org.junit.Test;
26import static org.junit.Assert.*;
27import org.junit.runner.RunWith;
28import org.springframework.beans.factory.annotation.Autowired;
29import org.springframework.test.context.ContextConfiguration;
30import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
31
32/**
33 *
34 * @author olhsha
35 */
36@RunWith(SpringJUnit4ClassRunner.class)
37@ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-config/versionDao.xml"})
38public class JdbcVersionDaoTest extends JdbcResourceDaoTest {
39
40    @Autowired
41    JdbcVersionDao jdbcVersionDao;
42   
43
44    /**
45     * Test of getExternalId method, of class JdbcVersionDao.
46     */
47    @Test
48    public void testGetExternalId() {
49        System.out.println("getExternalId");
50        Number internalID = 1;
51        UUID result = jdbcVersionDao.getExternalID(internalID);
52        assertEquals(TestBackendConstants._TEST_VERSION_1_EXT_ID, result.toString());
53    }
54
55    /**
56     * Test of getInternalId method, of class JdbcVersionDao.
57     */
58    @Test
59    public void testGetInternalId() {
60        System.out.println("getInternalId");
61        UUID externalID = UUID.fromString(TestBackendConstants._TEST_VERSION_1_EXT_ID);
62        Number expResult = 1;
63        Number result = jdbcVersionDao.getInternalID(externalID);
64        assertEquals(expResult, result);
65    }
66
67    /**
68     * Test of getVersion method, of class JdbcVersionDao.
69     */
70    @Test
71    public void testGetVersion() {
72        System.out.println("getVersion");
73        Number internalID = 1;
74        Version result = jdbcVersionDao.getVersion(internalID);
75        assertEquals(TestBackendConstants._TEST_VERSION_1_EXT_ID, result.getVersion());
76        //TODO: once the schems is fixed, test "version" and "URI/external-id" separately
77        // at the moment "version" corresponds "external_id"
78    }
79
80    /**
81     *
82     *
83     * /**
84     * Test of deleteVersion method, of class JdbcVersionDao.
85     */
86    @Test
87    public void testDeleteVersion() {
88        System.out.println("deleteVersion");
89       
90        // remove the rows from the joint table to keep integrity
91        jdbcVersionDao.deleteAllVersionCachedRepresentation(6);
92        int result = jdbcVersionDao.deleteVersion(6);
93        assertEquals(1, result); 
94        assertEquals(0, jdbcVersionDao.deleteVersion(6)); // delete the same version: nothing happen
95       
96        int resultTwo = jdbcVersionDao.deleteVersion(5); // version is in use by the source 4
97        assertEquals(0, resultTwo);
98
99    }
100
101    /**
102     * Test of addVersion method, of class JdbcVersionDao.
103     */
104    @Test
105    public void testAddVersion() {
106        System.out.println("addVersion");
107
108        Version freshVersion = new Version();
109        Number result = jdbcVersionDao.addVersion(freshVersion);
110        assertEquals(8, result);
111        // detailed checking
112        Version addedVersion = jdbcVersionDao.getVersion(result);
113        assertFalse(null == addedVersion.getVersion()); // extend once "version" information is fixed, and becomes different from externalID
114    }
115   
116   
117   
118   
119
120    /**
121     * Test of retrieveCachedRepresentationList method, of class JdbcVersionDao.
122     * public List<Number> retrieveCachedRepresentationList(Number versionID);
123     */
124    @Test
125    public void testRetrieveCachedRepresentationList() {
126
127        System.out.println("retrieveCachedRepresentationList");
128        Number versionID = 1;
129
130        List expResult = new ArrayList<Number>();
131        expResult.add(1);
132        expResult.add(5);
133
134        List result = jdbcVersionDao.retrieveCachedRepresentationList(versionID);
135        assertEquals(expResult, result);
136    }
137    ////////////////////////////////////////////////////////
138    @Test
139    public void deleteVersionCachedRepresentation(){
140        System.out.println("test deleteVersionCachedRepresentation");
141        assertEquals(1, jdbcVersionDao.deleteVersionCachedRepresentation(1, 1));
142        assertEquals(0, jdbcVersionDao.deleteVersionCachedRepresentation(1, 2));
143       
144    }
145   
146    ////////////////////////////////////////////////////////
147    @Test
148    public void deleteAllVersionCachedRepresentation(){
149        System.out.println("test deleteAllVersionCachedRepresentation");
150        assertEquals(2, jdbcVersionDao.deleteAllVersionCachedRepresentation(1));
151    }
152   
153    ////////////////////////////////////////////////////////
154    @Test
155    public void addVersionCachedRepresentation(){
156        System.out.println("test addVersionCachedRepresentation");
157        assertEquals(1, jdbcVersionDao.addVersionCachedRepresentation(1, 7));
158    }
159}
Note: See TracBrowser for help on using the repository browser.