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

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

setting up perfixes with UriInfo? from context. Setting up a mockery for it (perversion!)

File size: 5.9 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.TestInstances;
22import eu.dasish.annotation.schema.User;
23import java.util.UUID;
24import org.junit.Test;
25import static org.junit.Assert.*;
26import org.junit.runner.RunWith;
27import org.springframework.beans.factory.annotation.Autowired;
28import org.springframework.test.context.ContextConfiguration;
29import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
30
31/**
32 *
33 * @author olhsha
34 */
35@RunWith(SpringJUnit4ClassRunner.class)
36@ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-config/userDao.xml"})
37public class JdbcUserDaoTest extends JdbcResourceDaoTest {
38
39    @Autowired
40    JdbcUserDao jdbcUserDao;
41    TestInstances testInstances = new TestInstances();
42   
43     /**
44     * Test of stringURItoExternalID method
45     * public String stringURItoExternalID(String uri);
46     */
47    @Test
48    public void testStringURItoExternalID() {
49        System.out.println("test stringURItoExternalID");
50        jdbcUserDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI_users);
51        String randomUUID = UUID.randomUUID().toString();
52        String uri = TestBackendConstants._TEST_SERVLET_URI_users + randomUUID;
53        String externalID = jdbcUserDao.stringURItoExternalID(uri);
54        assertEquals(randomUUID, externalID);
55    }
56   
57    /**
58     * Test of externalIDtoURI method
59     * public String externalIDtoURI(String externalID);
60     */
61    @Test
62    public void testExternalIDtoURI() {
63        System.out.println("test stringURItoExternalID");
64        jdbcUserDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI_users);
65        String randomUUID = UUID.randomUUID().toString();
66        String uri = TestBackendConstants._TEST_SERVLET_URI_users+randomUUID;
67        String uriResult = jdbcUserDao.externalIDtoURI(randomUUID);
68        assertEquals(uri, uriResult);
69    }
70
71    /**
72     * Test of getInternalID method, of class JdbcUserDao. Number
73     * getInternalID(UUID UUID);
74     */
75    @Test
76    public void testGetInternalID() {
77        Number testOne = jdbcUserDao.getInternalID(UUID.fromString(TestBackendConstants._TEST_USER_3_EXT_ID));
78        assertEquals(3, testOne.intValue());
79
80        Number testTwo = jdbcUserDao.getInternalID(UUID.fromString(TestBackendConstants._TEST_USER_XXX_EXT_ID));
81        assertEquals(null, testTwo);
82
83        Number testThree = jdbcUserDao.getInternalID(null);
84        assertEquals(null, testThree);
85    }
86
87    /**
88     * public UUID getExternalID(Number internalId)
89     */
90    @Test
91    public void testGetExternalID() {
92        UUID testOne = jdbcUserDao.getExternalID(3);
93        assertEquals(TestBackendConstants._TEST_USER_3_EXT_ID, testOne.toString());
94
95        UUID testTwo = jdbcUserDao.getExternalID(null);
96        assertEquals(null, testTwo);
97    }
98
99    @Test
100    public void testGetUser() {
101        System.out.println("test getUser");
102        jdbcUserDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI_users);
103        Number internalID = 1;
104        User result = jdbcUserDao.getUser(internalID);
105        assertEquals("a user", result.getDisplayName());
106        assertEquals("a.user@gmail.com", result.getEMail());
107        assertEquals(TestBackendConstants._TEST_SERVLET_URI_users+TestBackendConstants._TEST_UID_1_, result.getURI());
108    }
109
110    @Test
111    public void testAddUser() {
112        System.out.println("test addUser");
113        jdbcUserDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI_users);
114        String freshUserName = "Guilherme";
115        String freshUserEmail = "guisil@mpi.nl";
116
117        User freshUser = new User();
118        freshUser.setDisplayName(freshUserName);
119        freshUser.setEMail(freshUserEmail);
120
121        Number result = jdbcUserDao.addUser(freshUser, "secret X");
122        assertEquals(7, result.intValue());
123        User addedUser = jdbcUserDao.getUser(result);
124        assertEquals(freshUserName, addedUser.getDisplayName());
125        assertEquals(freshUserEmail, addedUser.getEMail());
126        assertFalse(null == jdbcUserDao.stringURItoExternalID(addedUser.getURI()));
127    }
128
129    @Test
130    public void testDeleteUser() {
131        System.out.println("test deleteUser");
132        jdbcUserDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI_users);
133
134        int result = jdbcUserDao.deleteUser(6);
135        assertEquals(1, result);
136        User check = jdbcUserDao.getUser(6);
137        assertTrue(null==check);
138    }
139   
140   
141    @Test
142    public void testUserIsInUse(){
143        assertTrue(jdbcUserDao.userIsInUse(2));
144        assertTrue(jdbcUserDao.userIsInUse(5));
145        assertFalse(jdbcUserDao.userIsInUse(6));
146    }
147
148    @Test
149    public void tesUserExists() {
150        System.out.println("test userExists");
151        jdbcUserDao.setServiceURI(TestBackendConstants._TEST_SERVLET_URI_users);
152
153        User freshUser = new User();
154        freshUser.setDisplayName("Guilherme");
155        freshUser.setEMail("guisil@mpi.nl");
156        assertEquals(false,jdbcUserDao.userExists(freshUser));
157
158        User user = new User();
159        user.setDisplayName("Olha");
160        user.setEMail("olhsha@mpi.nl");
161        assertTrue(jdbcUserDao.userExists(user));
162
163    }
164}
Note: See TracBrowser for help on using the repository browser.