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

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

all basic Dao for CachedRepresentation?, Version, Source, Annotation, User and Notebooks are tested well. However, JdbcUserDao? and JdbcNotebookDao? are obsolete.

File size: 5.5 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.backend.identifiers.VersionIdentifier;
22import eu.dasish.annotation.schema.Version;
23import java.util.ArrayList;
24import java.util.List;
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        VersionIdentifier 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        VersionIdentifier externalID = new VersionIdentifier(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        Version addedVersion = jdbcVersionDao.getVersion(result);
112        assertFalse(null == addedVersion.getVersion()); // extend once "version" information is fixed, and becomes different from externalID
113    }
114   
115   
116   
117   
118
119    /**
120     * Test of retrieveCachedRepresentationList method, of class JdbcVersionDao.
121     * public List<Number> retrieveCachedRepresentationList(Number versionID);
122     */
123    @Test
124    public void testRetrieveCachedRepresentationList() {
125
126        System.out.println("retrieveCachedRepresentationList");
127        Number versionID = 1;
128
129        List expResult = new ArrayList<Number>();
130        expResult.add(1);
131        expResult.add(5);
132
133        List result = jdbcVersionDao.retrieveCachedRepresentationList(versionID);
134        assertEquals(expResult, result);
135    }
136    ////////////////////////////////////////////////////////
137    @Test
138    public void deleteVersionCachedRepresentation(){
139        System.out.println("test deleteVersionCachedRepresentation");
140        assertEquals(1, jdbcVersionDao.deleteVersionCachedRepresentation(1, 1));
141        assertEquals(0, jdbcVersionDao.deleteVersionCachedRepresentation(1, 2));
142       
143    }
144   
145    ////////////////////////////////////////////////////////
146    @Test
147    public void deleteAllVersionCachedRepresentation(){
148        System.out.println("test deleteAllVersionCachedRepresentation");
149        assertEquals(2, jdbcVersionDao.deleteAllVersionCachedRepresentation(1));
150    }
151   
152    ////////////////////////////////////////////////////////
153    @Test
154    public void addVersionCachedRepresentation(){
155        System.out.println("test addVersionCachedRepresentation");
156        assertEquals(1, jdbcVersionDao.addVersionCachedRepresentation(1, 7));
157    }
158}
Note: See TracBrowser for help on using the repository browser.