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 java.io.File; |
---|
22 | import java.io.FileNotFoundException; |
---|
23 | import java.net.URISyntaxException; |
---|
24 | import java.net.URL; |
---|
25 | import java.util.Scanner; |
---|
26 | import java.util.UUID; |
---|
27 | import org.junit.After; |
---|
28 | import org.junit.Before; |
---|
29 | import org.junit.Test; |
---|
30 | import org.springframework.beans.factory.annotation.Autowired; |
---|
31 | import org.springframework.dao.DataAccessException; |
---|
32 | import org.springframework.jdbc.core.JdbcTemplate; |
---|
33 | import static org.junit.Assert.*; |
---|
34 | import org.junit.Ignore; |
---|
35 | import org.junit.runner.RunWith; |
---|
36 | import org.springframework.test.context.ContextConfiguration; |
---|
37 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
---|
38 | /** |
---|
39 | * |
---|
40 | * @author olhsha |
---|
41 | */ |
---|
42 | @RunWith(SpringJUnit4ClassRunner.class) |
---|
43 | @ContextConfiguration({"/spring-test-config/dataSource.xml"}) |
---|
44 | public class JdbcResourceDaoTest { |
---|
45 | |
---|
46 | @Autowired |
---|
47 | private JdbcTemplate jdbcTemplate; |
---|
48 | |
---|
49 | private String getNormalisedSql() throws FileNotFoundException, URISyntaxException { |
---|
50 | // remove the unsupported sql for the test |
---|
51 | final URL sqlUrl = JdbcResourceDaoTest.class.getResource("/sql/DashishAnnotatorCreate.sql"); |
---|
52 | String sqlString = new Scanner(new File(sqlUrl.toURI()), "UTF8").useDelimiter("\\Z").next(); |
---|
53 | for (String unknownToken : new String[]{ |
---|
54 | "SET client_encoding", |
---|
55 | "CREATE DATABASE", |
---|
56 | "\\\\connect", |
---|
57 | "SET default_with_oids", |
---|
58 | "ALTER SEQUENCE", |
---|
59 | "ALTER TABLE ONLY", |
---|
60 | "ADD CONSTRAINT", |
---|
61 | "CREATE INDEX", // "ALTER TABLE ONLY [a-z]* ALTER COLUMN", |
---|
62 | // "ALTER TABLE ONLY [^A]* ADD CONSTRAINT" |
---|
63 | }) { |
---|
64 | sqlString = sqlString.replaceAll(unknownToken, "-- " + unknownToken); |
---|
65 | } |
---|
66 | // obsolete(?) Peter's stuff, before body has been decided to be a text with its mimetype: sqlString = sqlString.replaceAll("body_xml xml", "body_xml text"); |
---|
67 | sqlString = sqlString.replaceAll("CACHE 1;", "; -- CACHE 1;"); |
---|
68 | //sqlString = sqlString.replaceAll("UUID", "text"); |
---|
69 | sqlString = sqlString.replaceAll("SERIAL NOT NULL", "INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY"); |
---|
70 | return sqlString; |
---|
71 | } |
---|
72 | |
---|
73 | private String getTestDataInsertSql() throws FileNotFoundException, URISyntaxException { |
---|
74 | final URL sqlUrl = JdbcNotebookDaoTest.class.getResource("/test-data/InsertTestData.sql"); |
---|
75 | String sqlString = new Scanner(new File(sqlUrl.toURI()), "UTF8").useDelimiter("\\Z").next(); |
---|
76 | return sqlString; |
---|
77 | } |
---|
78 | |
---|
79 | @Before |
---|
80 | public void setUp() throws DataAccessException, FileNotFoundException, URISyntaxException { |
---|
81 | jdbcTemplate.execute("DROP SCHEMA PUBLIC CASCADE"); |
---|
82 | // consume the DashishAnnotatorCreate sql script to create the database |
---|
83 | jdbcTemplate.execute(getNormalisedSql()); |
---|
84 | jdbcTemplate.execute(getTestDataInsertSql()); |
---|
85 | } |
---|
86 | |
---|
87 | @After |
---|
88 | public void tearDown() { |
---|
89 | } |
---|
90 | |
---|
91 | @Test |
---|
92 | public void dummy(){ |
---|
93 | |
---|
94 | } |
---|
95 | |
---|
96 | } |
---|