From 217916603f5a5dd2997da72102344985de9c803b Mon Sep 17 00:00:00 2001 From: Justin Richer Date: Wed, 6 Mar 2013 09:48:04 -0500 Subject: [PATCH] cleaned out broken unit tests -- now we can start fresh --- .../jdbc/datasource/H2DataSourceFactory.java | 299 ------------------ .../jdbc/datasource/util/SqlFileParser.java | 164 ---------- .../src/test/resources/test-context.xml | 40 --- .../impl/JpaNonceRepositoryTest.java | 53 ---- .../src/test/resources/keystore.jks | Bin 2819 -> 0 bytes .../src/test/resources/log4j.xml | 41 --- .../src/test/resources/test-context.xml | 51 --- .../src/test/resources/test-data.sql | 5 - pom.xml | 6 - 9 files changed, 659 deletions(-) delete mode 100644 openid-connect-common/src/main/java/org/mitre/jdbc/datasource/H2DataSourceFactory.java delete mode 100644 openid-connect-common/src/main/java/org/mitre/jdbc/datasource/util/SqlFileParser.java delete mode 100644 openid-connect-common/src/test/resources/test-context.xml delete mode 100644 openid-connect-server/src/test/java/org/mitre/openid/connect/repository/impl/JpaNonceRepositoryTest.java delete mode 100644 openid-connect-server/src/test/resources/keystore.jks delete mode 100644 openid-connect-server/src/test/resources/log4j.xml delete mode 100644 openid-connect-server/src/test/resources/test-context.xml delete mode 100644 openid-connect-server/src/test/resources/test-data.sql diff --git a/openid-connect-common/src/main/java/org/mitre/jdbc/datasource/H2DataSourceFactory.java b/openid-connect-common/src/main/java/org/mitre/jdbc/datasource/H2DataSourceFactory.java deleted file mode 100644 index 4d1dce109..000000000 --- a/openid-connect-common/src/main/java/org/mitre/jdbc/datasource/H2DataSourceFactory.java +++ /dev/null @@ -1,299 +0,0 @@ -/******************************************************************************* - * Copyright 2012 The MITRE Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ******************************************************************************/ -package org.mitre.jdbc.datasource; - -import java.io.IOException; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.List; -import java.util.Map; - -import javax.annotation.PostConstruct; -import javax.sql.DataSource; - -import org.mitre.jdbc.datasource.util.SqlFileParser; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.FactoryBean; -import org.springframework.core.io.Resource; -import org.springframework.jdbc.datasource.DriverManagerDataSource; - -/** - * {@inheritDoc} - * - * @author Matt Franklin - *

- * Creates a JDBC DataSource that is fully initialized with the schema and data referenced in the - * application context. - *

- *

- * Usage: - * - * - * - * - * - * - * - * file:db/sequences/create_all_seq.sql - * file:db/tables/create_all_tables.sql - * classpath:test-data.sql - * - * - * - * - *

- */ -public class H2DataSourceFactory implements FactoryBean { - - private static Logger logger = LoggerFactory.getLogger(H2DataSourceFactory.class); - - protected String databaseName; - protected Boolean persist; - protected String executeScriptQuery; - protected List scriptLocations; - protected Map dateConversionPatterns; - - /** - * The DataSource singleton returned by the factory. - */ - protected DataSource dataSource; - - /** - * Creates a new factory with no initial values for required properties. - *

- * NOTE: If the factory is initialized using the default constructor, the required properties must be set prior to use - */ - public H2DataSourceFactory() { - } - - /** - * Creates a new factory and sets teh properties to the passed in parameters - * - * @param databaseName {@see setDatabaseName} - * @param scriptLocations {@see setScriptLocations} - * @param persist {@see setPersist} - * @param executeScriptQuery {@see setLoadDataQuery} - * @param dateConversionPatterns {@see setDateConversionPatterns} - */ - public H2DataSourceFactory(String databaseName, List scriptLocations, Boolean persist, String executeScriptQuery, Map dateConversionPatterns) { - setDatabaseName(databaseName); - setScriptLocations(scriptLocations); - setPersist(persist); - setExecuteScriptQuery(executeScriptQuery); - setDateConversionPatterns(dateConversionPatterns); - } - - /** - * Optional property - *

- * Sets a map of conversion patterns to register with the Oracle conversion utilities - * - * @param dateConversionPatterns map of patterns keyed by Oracle syntax with a value of a {@link java.text.DateFormat} - */ - public void setDateConversionPatterns(Map dateConversionPatterns) { - this.dateConversionPatterns = dateConversionPatterns; - } - - /** - * Optional Property - *

- * Sets whether or not to persist the database - * - * @param persist boolean value - */ - public void setPersist(Boolean persist) { - this.persist = persist; - } - - - /** - * Optional Property - *

- * Set the query used to determine whether or not to execute the scripts on initialization - * - * @param executeScriptQuery the query to execute. If there are no results of the query, the scripts referenced - * in setScriptLocations will be executed. The statement must be a select statement. - */ - public void setExecuteScriptQuery(String executeScriptQuery) { - this.executeScriptQuery = executeScriptQuery; - } - - /** - * Required Property - *

- * Sets the name of the in memory database/schema - * - * @param databaseName the name such as "mymii" - */ - public void setDatabaseName(String databaseName) { - this.databaseName = databaseName; - } - - /** - * Required Property - *

- * Sets the locations of the files containing DDL to be executed against the database - *

- * NOTE: Files are executed in order - * - * @param scriptLocations list of {@link Resource} compatible location strings - */ - public void setScriptLocations(List scriptLocations) { - this.scriptLocations = scriptLocations; - } - - @PostConstruct - public void initializeFactory() { - validateProperties(); - } - - public Object getObject() throws Exception { - return getDataSource(); - } - - public Class getObjectType() { - return DataSource.class; - } - - public boolean isSingleton() { - return true; - } - - /** - * Gets the singleton DataSource if created. Initializes if not already created. - * - * @return the DataSource - */ - public DataSource getDataSource() { - if (dataSource == null) { - initializeDataSource(); - } - return dataSource; - } - - /* - Helper methods - */ - protected void validateProperties() { - if (databaseName == null) { - throw new IllegalArgumentException("The name of the test database to create is required"); - } - if (scriptLocations == null) { - throw new IllegalArgumentException("The path to the database schema DDL is required"); - } - if(persist == null) { - persist = false; - } - } - - protected void initializeDataSource() { - this.dataSource = createDataSource(); - populateDataSourceIfNecessary(); - } - - protected DataSource createDataSource() { - DriverManagerDataSource ds = new DriverManagerDataSource(); - ds.setDriverClassName("org.h2.Driver"); - ds.setUrl(getConnectionString()); - ds.setUsername("sa"); - ds.setPassword(""); - logger.debug("Created dataSource: " + ds.toString()); - return ds; - } - - protected String getConnectionString() { - return persist ? - "jdbc:h2:file:" + databaseName + ";MODE=MySQL" : - "jdbc:h2:mem:" + databaseName + ";MODE=MySQL;DB_CLOSE_DELAY=-1"; - } - - protected void populateDataSourceIfNecessary() { - Connection conn = null; - try { - conn = dataSource.getConnection(); - if (!persist || testExecuteScriptQuery(conn, executeScriptQuery)) { - logger.debug("Database is empty. Loading script files"); - executeScripts(conn, scriptLocations); - } - } catch (SQLException e) { - logger.error("Error querying or populating database", e); - throw new RuntimeException(e); - } finally { - closeConnection(conn); - } - } - - /* - Static Helper methods - */ - protected static void executeScripts(Connection connection, List resources) { - for (Resource script : resources) { - try { - String sql = new SqlFileParser(script).getSQL(); - logger.debug("Executing sql:\n" + sql); - executeSql(sql, connection); - logger.debug("Successfully executed statement"); - - } catch (IOException e) { - throw new RuntimeException("File IO Exception while loading " + script.getFilename(), e); - } catch (SQLException e) { - throw new RuntimeException("SQL exception occurred loading data from " + script.getFilename(), e); - } - } - } - - protected static boolean testExecuteScriptQuery(Connection conn, String executeScriptQuery) { - boolean result; - try { - //If the ResultSet has any rows, the first method will return true - result = !executeQuery(conn, executeScriptQuery).first(); - } catch (SQLException e) { - //Only return true if the exception we got is that the table was not found - result = e.getMessage().toLowerCase().matches("table \".*\" not found.*\n*.*"); - } - logger.debug("Executed query " + executeScriptQuery + " with result " + result); - - return result; - } - - protected static void closeConnection(Connection conn) { - if (conn != null) { - try { - conn.close(); - } catch (SQLException e) { - logger.error("Error closing connection to database", e); - } - } - } - - protected static ResultSet executeQuery(Connection conn, String executeScriptQuery) throws SQLException { - Statement statement = conn.createStatement(); - return statement.executeQuery(executeScriptQuery); - - } - - - protected static void executeSql(String sql, Connection connection) throws SQLException { - Statement statement = connection.createStatement(); - statement.execute(sql); - } - - -} - diff --git a/openid-connect-common/src/main/java/org/mitre/jdbc/datasource/util/SqlFileParser.java b/openid-connect-common/src/main/java/org/mitre/jdbc/datasource/util/SqlFileParser.java deleted file mode 100644 index 71bf8c021..000000000 --- a/openid-connect-common/src/main/java/org/mitre/jdbc/datasource/util/SqlFileParser.java +++ /dev/null @@ -1,164 +0,0 @@ -/******************************************************************************* - * Copyright 2012 The MITRE Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ******************************************************************************/ -package org.mitre.jdbc.datasource.util; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.util.HashSet; -import java.util.Set; -import java.util.Stack; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.io.Resource; - -/** - * @author Matt Franklin - * - * Parses a file looking for create, alter, insert, update, delete or - * drop commands and appends them to an output string or follows @@ - * syntax to read child scripts. - * - */ -public class SqlFileParser { - - private static Logger logger = LoggerFactory.getLogger(SqlFileParser.class); - - private static final Pattern WORD_PATTERN = Pattern - .compile("^([a-zA-Z]*)[ ;]"); - private static final String CHILD_SCRIPT_INDICATOR = "@@"; - private static final Set commandSet; - - static { - commandSet = new HashSet(); - commandSet.add("create"); - commandSet.add("alter"); - commandSet.add("insert"); - commandSet.add("update"); - commandSet.add("drop"); - commandSet.add("delete"); - commandSet.add("commit"); - commandSet.add("set"); - commandSet.add("truncate"); - commandSet.add("rollback"); - } - - private enum State { - INIT, READFILE, READSQL - } - - private Stack stateStack; - private Resource resource; - - /** - * Constructor takes a Spring {@link Resource} - * - * @param resource - * the initial file to parse - */ - public SqlFileParser(Resource resource) { - stateStack = new Stack(); - this.resource = resource; - } - - /** - * Gets the executable SQL statements from the resource passed to the - * constructor and its children - * - * @return a valid executable string containing SQL statements - * @throws IOException - * if the resource or its children are not found - */ - public String getSQL() throws IOException { - return processResource(resource); - } - - private String processResource(Resource res) throws IOException { - StringBuilder sql = new StringBuilder(); - File resourceFile = res.getFile(); - stateStack.push(State.INIT); - processFile(resourceFile, sql); - stateStack.pop(); - - logger.debug(" SQL:: " + sql); - - return sql.toString(); - } - - private void processFile(File file, StringBuilder sql) throws IOException { - BufferedReader fileReader = new BufferedReader(new FileReader( - file.getAbsoluteFile())); - String line = null; - while ((line = fileReader.readLine()) != null) { - processLine(sql, line); - } - } - - private void processLine(StringBuilder sql, String line) throws IOException { - String lowerLine = line.toLowerCase().trim(); - switch (stateStack.peek()) { - case INIT: { - if (lowerLine.startsWith(CHILD_SCRIPT_INDICATOR)) { - // replace the current element in the stack with the new state - stateStack.pop(); - stateStack.push(State.READFILE); - processLine(sql, line); - } else if (commandSet.contains(getFirstWord(lowerLine))) { - - // replace the current element in the stack with the new state - stateStack.pop(); - stateStack.push(State.READSQL); - processLine(sql, line); - } - break; - } - case READFILE: { - stateStack.push(State.INIT); - Resource child = resource.createRelative(line.replace( - CHILD_SCRIPT_INDICATOR, "")); - sql.append(processResource(child)); - // Read File lines do not have a terminal character but are by - // definition only one line Long - stateStack.pop(); - stateStack.push(State.INIT); - break; - } - case READSQL: { - sql.append(line); - // add a space to accommodate line breaks. Not a big deal if - // extraneous spaces are added - sql.append(" "); - if (lowerLine.endsWith(";")) { - stateStack.pop(); - stateStack.push(State.INIT); - } - break; - } - default: { - throw new RuntimeException("Invalid State"); - } - } - } - - private static String getFirstWord(String line) { - Matcher match = WORD_PATTERN.matcher(line); - return match.find() ? match.group(1) : null; - } -} diff --git a/openid-connect-common/src/test/resources/test-context.xml b/openid-connect-common/src/test/resources/test-context.xml deleted file mode 100644 index c849de679..000000000 --- a/openid-connect-common/src/test/resources/test-context.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - file:db/tables/accesstoken.sql - file:db/tables/address.sql - file:db/tables/approvedsite.sql - file:db/tables/authorities.sql - file:db/tables/clientdetails.sql - file:db/tables/event.sql - file:db/tables/granttypes.sql - file:db/tables/idtoken.sql - file:db/tables/idtokenclaims.sql - file:db/tables/refreshtoken.sql - file:db/tables/scope.sql - file:db/tables/userinfo.sql - file:db/tables/whitelistedsite.sql - - classpath:test-data.sql - - - - - - - - - - - \ No newline at end of file diff --git a/openid-connect-server/src/test/java/org/mitre/openid/connect/repository/impl/JpaNonceRepositoryTest.java b/openid-connect-server/src/test/java/org/mitre/openid/connect/repository/impl/JpaNonceRepositoryTest.java deleted file mode 100644 index ce8d238e5..000000000 --- a/openid-connect-server/src/test/java/org/mitre/openid/connect/repository/impl/JpaNonceRepositoryTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.mitre.openid.connect.repository.impl; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.expectLastCall; -import static org.easymock.EasyMock.replay; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "classpath:test-context.xml" }) -public class JpaNonceRepositoryTest { - - @Test - public void getById_valid() { - - } - - @Test - public void getById_invalid() { - - } - - @Test - public void remove_valid() { - - } - - @Test - public void remove_invalid() { - - - } - - @Test - public void getExpired() { - - } - - @Test - public void getByClientId_valid() { - - } - - @Test - public void getByClientId_invalid() { - - } - -} diff --git a/openid-connect-server/src/test/resources/keystore.jks b/openid-connect-server/src/test/resources/keystore.jks deleted file mode 100644 index 714d95f2829e8c253359118eb45fe43a4ba18cf3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2819 zcmc&$X*Ap09?d_AnCGcVT|omsF|u#Metlh zgHURyre<}~mbRvg_O)osbG!PXZ@tfVy$`>&&iT4(Kj_B#6_=pHSrYIFmghvW z-CQC@&Oan6B3pQQ0HyQDc&f@0F>_CxuPT@57k=RY)wh}bp1O2okwW#BdCE~?MZeaJ zF3l9yBr)!zVxNrX{cd{H8#u+ehoLv>yvFLK4)n8l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S#n;RRd&h!C0BDyghRmR_^V z^W{C)vPPY{Aa1s49pkg;H6N`M)~$)l`zr1dYsC<@A_)2Q=kg!_DMctYbX?FtbOnK1 zWv}>kWV-Y;wH`La#H#8yCwzFZtH*G#hxV+Li#C6bYL+S=02{KtnRwhVSZgnOFGN$SA&PXixA&^KJY$V zTItQ_+wZ!678kS0lIXacphjpNlmkNm5b&cyrv^Ax2moEq-MLwOu`RtLU2v9aTG)R( zy6|lkliue2OJuY9*tezixI24&f8TH=@$D%_kVozUpgz`>wD z_6!AZTCe5k9$Q&miqel8gBs@F*jq3RMvRgM+(xiYDVfg2r0~sSkda;RgRuuiLMo%v ze(Iz!V)Ye=f>QLZO{nX8*SB^hrTQWI8dpV`>BH0{{6Q%rjwd&fo8GOC=t{NDm5nj| E4}0yLApigX diff --git a/openid-connect-server/src/test/resources/log4j.xml b/openid-connect-server/src/test/resources/log4j.xml deleted file mode 100644 index 17adb81db..000000000 --- a/openid-connect-server/src/test/resources/log4j.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/openid-connect-server/src/test/resources/test-context.xml b/openid-connect-server/src/test/resources/test-context.xml deleted file mode 100644 index dc4570ccb..000000000 --- a/openid-connect-server/src/test/resources/test-context.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - file:db/tables/accesstoken.sql - file:db/tables/address.sql - file:db/tables/approvedsite.sql - file:db/tables/authorities.sql - file:db/tables/clientdetails.sql - file:db/tables/event.sql - file:db/tables/granttypes.sql - file:db/tables/idtoken.sql - file:db/tables/idtokenclaims.sql - file:db/tables/refreshtoken.sql - file:db/tables/scope.sql - file:db/tables/userinfo.sql - file:db/tables/whitelistedsite.sql - - classpath:test-data.sql - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/openid-connect-server/src/test/resources/test-data.sql b/openid-connect-server/src/test/resources/test-data.sql deleted file mode 100644 index 4c106fc7c..000000000 --- a/openid-connect-server/src/test/resources/test-data.sql +++ /dev/null @@ -1,5 +0,0 @@ -INSERT INTO ADDRESS (ID, STREETADDRESS, LOCALITY, REGION, POSTALCODE, COUNTRY) VALUES (1, '7443 Et Road', 'Pass Christian', 'ID', '16183', 'Jordan'); -INSERT INTO ADDRESS (ID, STREETADDRESS, LOCALITY, REGION, POSTALCODE, COUNTRY) VALUES (2, 'P.O. Box 893, 2523 Felis Rd.', 'New Kensington', 'NT', 'I5V 3Z7', 'Israel'); - -INSERT INTO event (ID, TIMESTAMP, TYPE) VALUES (1, '1970-01-05 19:00:00.0', 0); -INSERT INTO event (ID, TIMESTAMP, TYPE) VALUES (2, '1970-01-10 19:00:00.0', 1); \ No newline at end of file diff --git a/pom.xml b/pom.xml index 83689d8ba..1d25cfb47 100644 --- a/pom.xml +++ b/pom.xml @@ -184,12 +184,6 @@ ${org.springframework-version} test - - com.h2database - h2 - 1.3.154 - test - cglib cglib