source: DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDaoTest.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: 3.7 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 java.io.File;
22import java.io.FileNotFoundException;
23import java.net.URISyntaxException;
24import java.net.URL;
25import java.util.Scanner;
26import java.util.UUID;
27import org.junit.After;
28import org.junit.Before;
29import org.junit.Test;
30import org.springframework.beans.factory.annotation.Autowired;
31import org.springframework.dao.DataAccessException;
32import org.springframework.jdbc.core.JdbcTemplate;
33import static org.junit.Assert.*;
34import org.junit.Ignore;
35import org.junit.runner.RunWith;
36import org.springframework.test.context.ContextConfiguration;
37import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
38/**
39 *
40 * @author olhsha
41 */
42@RunWith(SpringJUnit4ClassRunner.class)
43@ContextConfiguration({"/spring-test-config/dataSource.xml"})
44public 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}
Note: See TracBrowser for help on using the repository browser.