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 | */ |
---|
18 | package eu.dasish.annotation.backend.dao.impl; |
---|
19 | |
---|
20 | import eu.dasish.annotation.backend.TestBackendConstants; |
---|
21 | import eu.dasish.annotation.schema.CachedRepresentationInfo; |
---|
22 | import java.util.UUID; |
---|
23 | import org.junit.Test; |
---|
24 | import static org.junit.Assert.*; |
---|
25 | import org.junit.runner.RunWith; |
---|
26 | import org.springframework.beans.factory.annotation.Autowired; |
---|
27 | import org.springframework.test.context.ContextConfiguration; |
---|
28 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
---|
29 | |
---|
30 | /** |
---|
31 | * |
---|
32 | * @author olhsha |
---|
33 | */ |
---|
34 | |
---|
35 | @RunWith(SpringJUnit4ClassRunner.class) |
---|
36 | @ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-config/cachedRepresentationDao.xml"}) |
---|
37 | public class JdbcCachedRepresentationDaoTest extends JdbcResourceDaoTest{ |
---|
38 | |
---|
39 | @Autowired |
---|
40 | JdbcCachedRepresentationDao jdbcCachedRepresentationDao; |
---|
41 | |
---|
42 | |
---|
43 | public JdbcCachedRepresentationDaoTest() { |
---|
44 | } |
---|
45 | |
---|
46 | |
---|
47 | |
---|
48 | /** |
---|
49 | * Test of getExternalId method, of class JdbcCachedRepresentationDao. |
---|
50 | * public UUID getExternalId(Number internalID); |
---|
51 | |
---|
52 | */ |
---|
53 | @Test |
---|
54 | public void testGetExternalId() { |
---|
55 | System.out.println("getExternalId"); |
---|
56 | Number internalID = 1; |
---|
57 | UUID expResult = UUID.fromString(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_); |
---|
58 | UUID result = jdbcCachedRepresentationDao.getExternalID(internalID); |
---|
59 | assertEquals(expResult, result); |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | /** |
---|
64 | * Test of getInternalId method, of class JdbcCachedRepresentationDao. |
---|
65 | * public Number getInternalId(UUID externalID); |
---|
66 | */ |
---|
67 | @Test |
---|
68 | public void testGetInternalId() { |
---|
69 | System.out.println("getInternalId"); |
---|
70 | UUID externalID = UUID.fromString(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_); |
---|
71 | Number result = jdbcCachedRepresentationDao.getInternalID(externalID); |
---|
72 | assertEquals(1, result.intValue()); |
---|
73 | } |
---|
74 | |
---|
75 | /** |
---|
76 | * Test of getCachedRepresentationInfo method, of class JdbcCachedRepresentationDao. |
---|
77 | * public CachedRepresentationInfo getCachedRepresentationInfo(Number internalID); |
---|
78 | */ |
---|
79 | @Test |
---|
80 | public void testGetCachedRepresentationInfo() { |
---|
81 | System.out.println("getCachedRepresentationInfo"); |
---|
82 | |
---|
83 | jdbcCachedRepresentationDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI); |
---|
84 | CachedRepresentationInfo result = jdbcCachedRepresentationDao.getCachedRepresentationInfo(1); |
---|
85 | assertEquals(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_, result.getRef()); |
---|
86 | assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_MIME_TYPE_, result.getMimeType()); |
---|
87 | assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_TOOL_, result.getTool()); |
---|
88 | assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_TYPE_, result.getType()); |
---|
89 | assertEquals(TestBackendConstants._TEST_SERVLET_URI+TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_, result.getRef()); |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | /** |
---|
94 | * Test of deleteCachedRepresentationInfo method, of class JdbcCachedRepresentationDao. |
---|
95 | * public int deleteCachedRepresentationInfo(Number internalID); |
---|
96 | */ |
---|
97 | @Test |
---|
98 | public void testDeleteCachedRepresentationInfo() { |
---|
99 | System.out.println("deleteCachedRepresentationInfo"); |
---|
100 | Number internalID = 6; /// deleted because no version refers to it |
---|
101 | int result = jdbcCachedRepresentationDao.deleteCachedRepresentationInfo(internalID); |
---|
102 | assertEquals(1, result); |
---|
103 | |
---|
104 | int resultTwo = jdbcCachedRepresentationDao.deleteCachedRepresentationInfo(internalID); |
---|
105 | assertEquals(0, resultTwo); |
---|
106 | |
---|
107 | Number internalIDDoNotDelete = 5; |
---|
108 | int resultThree =jdbcCachedRepresentationDao.deleteCachedRepresentationInfo(internalIDDoNotDelete); |
---|
109 | assertEquals(0, resultThree); |
---|
110 | } |
---|
111 | |
---|
112 | /** |
---|
113 | * Test of addCachedRepresentationInfo method, of class JdbcCachedRepresentationDao. |
---|
114 | * public CachedRepresentationInfo addCachedRepresentationInfo(CachedRepresentationInfo cached); |
---|
115 | */ |
---|
116 | @Test |
---|
117 | public void testAddCachedRepresentationInfo() { |
---|
118 | System.out.println("addCachedRepresentationInfo"); |
---|
119 | |
---|
120 | CachedRepresentationInfo cached = new CachedRepresentationInfo(); |
---|
121 | cached.setMimeType("text/plain"); |
---|
122 | cached.setTool("vi"); |
---|
123 | cached.setType("text"); |
---|
124 | cached.setRef(null); |
---|
125 | |
---|
126 | Number result = jdbcCachedRepresentationDao.addCachedRepresentationInfo(cached); |
---|
127 | // checking |
---|
128 | CachedRepresentationInfo addedCached = jdbcCachedRepresentationDao.getCachedRepresentationInfo(result); |
---|
129 | assertEquals(8, result.intValue()); |
---|
130 | assertEquals("text/plain", addedCached.getMimeType()); |
---|
131 | assertEquals("vi", addedCached.getTool()); |
---|
132 | assertEquals("text", addedCached.getType()); |
---|
133 | assertFalse(addedCached.getRef() == null); // new non-null external identifier should be assigned |
---|
134 | } |
---|
135 | |
---|
136 | |
---|
137 | } |
---|