You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by vi...@apache.org on 2013/04/30 22:48:28 UTC
svn commit: r1477819 - in /oozie/trunk: ./ tools/ tools/src/test/
tools/src/test/java/ tools/src/test/java/org/
tools/src/test/java/org/apache/ tools/src/test/java/org/apache/oozie/
tools/src/test/java/org/apache/oozie/tools/ tools/src/test/resources/
Author: virag
Date: Tue Apr 30 20:48:27 2013
New Revision: 1477819
URL: http://svn.apache.org/r1477819
Log:
OOZIE-1329 fix coverage org.apache.oozie.tools (agorshkov)
Added:
oozie/trunk/tools/src/test/
oozie/trunk/tools/src/test/java/
oozie/trunk/tools/src/test/java/org/
oozie/trunk/tools/src/test/java/org/apache/
oozie/trunk/tools/src/test/java/org/apache/oozie/
oozie/trunk/tools/src/test/java/org/apache/oozie/tools/
oozie/trunk/tools/src/test/java/org/apache/oozie/tools/FakeConnection.java
oozie/trunk/tools/src/test/java/org/apache/oozie/tools/FakeDriver.java
oozie/trunk/tools/src/test/java/org/apache/oozie/tools/LauncherSecurityManager.java
oozie/trunk/tools/src/test/java/org/apache/oozie/tools/TestOozieDBCLI.java
oozie/trunk/tools/src/test/java/org/apache/oozie/tools/TestOozieMySqlDBCLI.java
oozie/trunk/tools/src/test/java/org/apache/oozie/tools/TestOozieSharelibCLI.java
oozie/trunk/tools/src/test/resources/
oozie/trunk/tools/src/test/resources/fake-oozie-site.xml
oozie/trunk/tools/src/test/resources/hsqldb-oozie-site.xml
Modified:
oozie/trunk/release-log.txt
oozie/trunk/tools/pom.xml
Modified: oozie/trunk/release-log.txt
URL: http://svn.apache.org/viewvc/oozie/trunk/release-log.txt?rev=1477819&r1=1477818&r2=1477819&view=diff
==============================================================================
--- oozie/trunk/release-log.txt (original)
+++ oozie/trunk/release-log.txt Tue Apr 30 20:48:27 2013
@@ -1,5 +1,6 @@
-- Oozie 4.1.0 release (trunk - unreleased)
+OOZIE-1329 fix coverage org.apache.oozie.tools (agorshkov)
OOZIE-1351 Oozie jobs with state PAUSEDWITHERROR should change to SUSPENDEDWITHERROR state when suspended (bowenzhangusa via virag)
OOZIE-1346 Modularize hbase credentials to separate the populating of jobconf and obtaining token for job (virag)
OOZIE-1341 Have Action Main classes in Oozie webapp (virag)
Modified: oozie/trunk/tools/pom.xml
URL: http://svn.apache.org/viewvc/oozie/trunk/tools/pom.xml?rev=1477819&r1=1477818&r2=1477819&view=diff
==============================================================================
--- oozie/trunk/tools/pom.xml (original)
+++ oozie/trunk/tools/pom.xml Tue Apr 30 20:48:27 2013
@@ -32,6 +32,32 @@
<packaging>jar</packaging>
<dependencies>
+ <dependency>
+ <groupId>org.apache.oozie</groupId>
+ <artifactId>oozie-hcatalog</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.oozie</groupId>
+ <artifactId>oozie-sharelib-hive</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-minicluster</artifactId>
+ <version>1.1.1</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.oozie</groupId>
+ <artifactId>oozie-core</artifactId>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.oozie</groupId>
<artifactId>oozie-client</artifactId>
Added: oozie/trunk/tools/src/test/java/org/apache/oozie/tools/FakeConnection.java
URL: http://svn.apache.org/viewvc/oozie/trunk/tools/src/test/java/org/apache/oozie/tools/FakeConnection.java?rev=1477819&view=auto
==============================================================================
--- oozie/trunk/tools/src/test/java/org/apache/oozie/tools/FakeConnection.java (added)
+++ oozie/trunk/tools/src/test/java/org/apache/oozie/tools/FakeConnection.java Tue Apr 30 20:48:27 2013
@@ -0,0 +1,1288 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.oozie.tools;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.CallableStatement;
+import java.sql.Clob;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.Date;
+import java.sql.NClob;
+import java.sql.PreparedStatement;
+import java.sql.Ref;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.RowId;
+import java.sql.SQLClientInfoException;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.SQLXML;
+import java.sql.Savepoint;
+import java.sql.Statement;
+import java.sql.Struct;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.mockito.Mockito.*;
+
+public class FakeConnection implements Connection {
+ public static boolean CREATE = true;
+ public static boolean SYSTEM_TABLE = true;
+
+ @Override
+ public boolean isWrapperFor(Class<?> arg0) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public <T> T unwrap(Class<T> arg0) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public void clearWarnings() throws SQLException {
+ }
+
+ @Override
+ public void close() throws SQLException {
+
+ }
+
+ @Override
+ public void commit() throws SQLException {
+
+ }
+
+ @Override
+ public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Blob createBlob() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Clob createClob() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public NClob createNClob() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public SQLXML createSQLXML() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Statement createStatement() throws SQLException {
+ Statement result = mock(Statement.class);
+ ResultSet rsFordbVersion = mock(ResultSet.class);
+ when(rsFordbVersion.next()).thenReturn(true);
+ when(rsFordbVersion.getString(1)).thenReturn("1");
+
+ when(result.executeQuery("select data from OOZIE_SYS where name = 'db.version'")).thenReturn(rsFordbVersion);
+
+ if (CREATE) {
+ when(result.executeQuery("select count(*) from WF_JOBS where status IN ('RUNNING', 'SUSPENDED')")).thenReturn(
+ new FakeResultSet(-1));
+ }
+ else {
+ when(result.executeQuery("select count(*) from WF_JOBS where status IN ('RUNNING', 'SUSPENDED')")).thenReturn(
+ new FakeResultSet(1));
+ }
+ if (SYSTEM_TABLE) {
+ when(result.executeQuery("select count(*) from OOZIE_SYS")).thenReturn(new FakeResultSet(1));
+
+ }
+ else {
+ when(result.executeQuery("select count(*) from OOZIE_SYS")).thenReturn(new FakeResultSet(-1));
+
+ }
+ return result;
+ }
+
+ @Override
+ public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public boolean getAutoCommit() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public String getCatalog() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Properties getClientInfo() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public String getClientInfo(String name) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public int getHoldability() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public DatabaseMetaData getMetaData() throws SQLException {
+ DatabaseMetaData result = mock(DatabaseMetaData.class);
+ when(result.getJDBCMajorVersion()).thenReturn(4);
+ when(result.supportsGetGeneratedKeys()).thenReturn(true);
+ return result;
+ }
+
+ @Override
+ public int getTransactionIsolation() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public Map<String, Class<?>> getTypeMap() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public SQLWarning getWarnings() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public boolean isClosed() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean isReadOnly() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean isValid(int timeout) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public String nativeSQL(String sql) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public CallableStatement prepareCall(String sql) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException {
+ return null;
+ }
+
+ @Override
+ public PreparedStatement prepareStatement(String sql) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException {
+ return null;
+ }
+
+ @Override
+ public void releaseSavepoint(Savepoint savepoint) throws SQLException {
+
+ }
+
+ @Override
+ public void rollback() throws SQLException {
+
+ }
+
+ @Override
+ public void rollback(Savepoint savepoint) throws SQLException {
+
+ }
+
+ @Override
+ public void setAutoCommit(boolean autoCommit) throws SQLException {
+
+ }
+
+ @Override
+ public void setCatalog(String catalog) throws SQLException {
+
+ }
+
+ @Override
+ public void setClientInfo(Properties properties) throws SQLClientInfoException {
+
+ }
+
+ @Override
+ public void setClientInfo(String name, String value) throws SQLClientInfoException {
+
+ }
+
+ @Override
+ public void setHoldability(int holdability) throws SQLException {
+
+ }
+
+ @Override
+ public void setReadOnly(boolean readOnly) throws SQLException {
+
+ }
+
+ @Override
+ public Savepoint setSavepoint() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Savepoint setSavepoint(String name) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public void setTransactionIsolation(int level) throws SQLException {
+
+ }
+
+ @Override
+ public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
+
+ }
+
+ @SuppressWarnings( "deprecation" )
+ private static class FakeResultSet implements ResultSet {
+
+ private int counter = 0;
+
+ public FakeResultSet(int counter) {
+ this.counter = counter;
+ }
+
+ @Override
+ public boolean isWrapperFor(Class<?> iface) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public <T> T unwrap(Class<T> iface) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public boolean absolute(int row) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public void afterLast() throws SQLException {
+
+ }
+
+ @Override
+ public void beforeFirst() throws SQLException {
+
+ }
+
+ @Override
+ public void cancelRowUpdates() throws SQLException {
+
+ }
+
+ @Override
+ public void clearWarnings() throws SQLException {
+
+ }
+
+ @Override
+ public void close() throws SQLException {
+
+ }
+
+ @Override
+ public void deleteRow() throws SQLException {
+
+ }
+
+ @Override
+ public int findColumn(String columnLabel) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public boolean first() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public Array getArray(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Array getArray(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public InputStream getAsciiStream(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public InputStream getAsciiStream(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public InputStream getBinaryStream(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public InputStream getBinaryStream(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Blob getBlob(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Blob getBlob(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public boolean getBoolean(int columnIndex) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean getBoolean(String columnLabel) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public byte getByte(int columnIndex) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public byte getByte(String columnLabel) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public byte[] getBytes(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public byte[] getBytes(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Reader getCharacterStream(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Reader getCharacterStream(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Clob getClob(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Clob getClob(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public int getConcurrency() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public String getCursorName() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Date getDate(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Date getDate(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Date getDate(int columnIndex, Calendar cal) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Date getDate(String columnLabel, Calendar cal) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public double getDouble(int columnIndex) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public double getDouble(String columnLabel) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getFetchDirection() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getFetchSize() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public float getFloat(int columnIndex) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public float getFloat(String columnLabel) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getHoldability() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getInt(int columnIndex) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public int getInt(String columnLabel) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public long getLong(int columnIndex) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public long getLong(String columnLabel) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public ResultSetMetaData getMetaData() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Reader getNCharacterStream(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Reader getNCharacterStream(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public NClob getNClob(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public NClob getNClob(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public String getNString(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public String getNString(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Object getObject(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Object getObject(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Object getObject(String columnLabel, Map<String, Class<?>> map) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Ref getRef(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Ref getRef(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public int getRow() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public RowId getRowId(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public RowId getRowId(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public SQLXML getSQLXML(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public SQLXML getSQLXML(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public short getShort(int columnIndex) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public short getShort(String columnLabel) throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public Statement getStatement() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public String getString(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public String getString(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Time getTime(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Time getTime(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Time getTime(int columnIndex, Calendar cal) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Time getTime(String columnLabel, Calendar cal) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Timestamp getTimestamp(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Timestamp getTimestamp(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public int getType() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public URL getURL(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public URL getURL(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public InputStream getUnicodeStream(int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public InputStream getUnicodeStream(String columnLabel) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public SQLWarning getWarnings() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public void insertRow() throws SQLException {
+
+ }
+
+ @Override
+ public boolean isAfterLast() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean isBeforeFirst() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean isClosed() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean isFirst() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean isLast() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean last() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public void moveToCurrentRow() throws SQLException {
+
+ }
+
+ @Override
+ public void moveToInsertRow() throws SQLException {
+
+ }
+
+ @Override
+ public boolean next() throws SQLException {
+ if (counter == -1) {
+ throw new SQLException();
+ }
+ counter--;
+ return counter < 0;
+ }
+
+ @Override
+ public boolean previous() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public void refreshRow() throws SQLException {
+
+ }
+
+ @Override
+ public boolean relative(int rows) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean rowDeleted() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean rowInserted() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean rowUpdated() throws SQLException {
+ return false;
+ }
+
+ @Override
+ public void setFetchDirection(int direction) throws SQLException {
+
+ }
+
+ @Override
+ public void setFetchSize(int rows) throws SQLException {
+
+ }
+
+ @Override
+ public void updateArray(int columnIndex, Array x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateArray(String columnLabel, Array x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBlob(int columnIndex, Blob x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBlob(String columnLabel, Blob x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBoolean(int columnIndex, boolean x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBoolean(String columnLabel, boolean x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateByte(int columnIndex, byte x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateByte(String columnLabel, byte x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBytes(int columnIndex, byte[] x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateBytes(String columnLabel, byte[] x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateCharacterStream(int columnIndex, Reader x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException {
+
+ }
+
+ @Override
+ public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateClob(int columnIndex, Clob x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateClob(String columnLabel, Clob x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateClob(int columnIndex, Reader reader) throws SQLException {
+
+ }
+
+ @Override
+ public void updateClob(String columnLabel, Reader reader) throws SQLException {
+
+ }
+
+ @Override
+ public void updateClob(int columnIndex, Reader reader, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateClob(String columnLabel, Reader reader, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateDate(int columnIndex, Date x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateDate(String columnLabel, Date x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateDouble(int columnIndex, double x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateDouble(String columnLabel, double x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateFloat(int columnIndex, float x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateFloat(String columnLabel, float x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateInt(int columnIndex, int x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateInt(String columnLabel, int x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateLong(int columnIndex, long x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateLong(String columnLabel, long x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNClob(int columnIndex, NClob nClob) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNClob(String columnLabel, NClob nClob) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNClob(int columnIndex, Reader reader) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNClob(String columnLabel, Reader reader) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNString(int columnIndex, String nString) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNString(String columnLabel, String nString) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNull(int columnIndex) throws SQLException {
+
+ }
+
+ @Override
+ public void updateNull(String columnLabel) throws SQLException {
+
+ }
+
+ @Override
+ public void updateObject(int columnIndex, Object x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateObject(String columnLabel, Object x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException {
+
+ }
+
+ @Override
+ public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException {
+
+ }
+
+ @Override
+ public void updateRef(int columnIndex, Ref x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateRef(String columnLabel, Ref x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateRow() throws SQLException {
+
+ }
+
+ @Override
+ public void updateRowId(int columnIndex, RowId x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateRowId(String columnLabel, RowId x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException {
+
+ }
+
+ @Override
+ public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException {
+
+ }
+
+ @Override
+ public void updateShort(int columnIndex, short x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateShort(String columnLabel, short x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateString(int columnIndex, String x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateString(String columnLabel, String x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateTime(int columnIndex, Time x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateTime(String columnLabel, Time x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException {
+
+ }
+
+ @Override
+ public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException {
+
+ }
+
+ @Override
+ public boolean wasNull() throws SQLException {
+ return false;
+ }
+
+ }
+}
Added: oozie/trunk/tools/src/test/java/org/apache/oozie/tools/FakeDriver.java
URL: http://svn.apache.org/viewvc/oozie/trunk/tools/src/test/java/org/apache/oozie/tools/FakeDriver.java?rev=1477819&view=auto
==============================================================================
--- oozie/trunk/tools/src/test/java/org/apache/oozie/tools/FakeDriver.java (added)
+++ oozie/trunk/tools/src/test/java/org/apache/oozie/tools/FakeDriver.java Tue Apr 30 20:48:27 2013
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.oozie.tools;
+
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverPropertyInfo;
+import java.sql.SQLException;
+import java.util.Properties;
+
+public class FakeDriver implements Driver {
+
+ @Override
+ public boolean acceptsURL(String url) throws SQLException {
+ return url != null && url.contains("fake");
+ }
+
+ @Override
+ public Connection connect(String url, Properties info) throws SQLException {
+ return new FakeConnection();
+ }
+
+ @Override
+ public int getMajorVersion() {
+ return 4;
+ }
+
+ @Override
+ public int getMinorVersion() {
+ return 0;
+ }
+
+ @Override
+ public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public boolean jdbcCompliant() {
+ return false;
+ }
+}
\ No newline at end of file
Added: oozie/trunk/tools/src/test/java/org/apache/oozie/tools/LauncherSecurityManager.java
URL: http://svn.apache.org/viewvc/oozie/trunk/tools/src/test/java/org/apache/oozie/tools/LauncherSecurityManager.java?rev=1477819&view=auto
==============================================================================
--- oozie/trunk/tools/src/test/java/org/apache/oozie/tools/LauncherSecurityManager.java (added)
+++ oozie/trunk/tools/src/test/java/org/apache/oozie/tools/LauncherSecurityManager.java Tue Apr 30 20:48:27 2013
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.oozie.tools;
+
+import java.security.Permission;
+
+/**
+ * class for masquerading System.exit()
+ */
+public class LauncherSecurityManager extends SecurityManager {
+ private static boolean exitInvoked;
+ private static int exitCode;
+ private SecurityManager securityManager;
+
+ public LauncherSecurityManager() {
+ reset();
+ securityManager = System.getSecurityManager();
+ System.setSecurityManager(this);
+ }
+
+ @Override
+ public void checkPermission(Permission perm, Object context) {
+ if (securityManager != null) {
+ // check everything with the original SecurityManager
+ securityManager.checkPermission(perm, context);
+ }
+ }
+
+ @Override
+ public void checkPermission(Permission perm) {
+ if (securityManager != null) {
+ // check everything with the original SecurityManager
+ securityManager.checkPermission(perm);
+ }
+ }
+
+ @Override
+ public void checkExit(int status) throws SecurityException {
+ exitInvoked = true;
+ exitCode = status;
+ throw new SecurityException("Intercepted System.exit(" + status + ")");
+ }
+
+ public static boolean getExitInvoked() {
+ return exitInvoked;
+ }
+
+ public static int getExitCode() {
+ return exitCode;
+ }
+
+ public static void reset() {
+ exitInvoked = false;
+ exitCode = 0;
+ }
+}
Added: oozie/trunk/tools/src/test/java/org/apache/oozie/tools/TestOozieDBCLI.java
URL: http://svn.apache.org/viewvc/oozie/trunk/tools/src/test/java/org/apache/oozie/tools/TestOozieDBCLI.java?rev=1477819&view=auto
==============================================================================
--- oozie/trunk/tools/src/test/java/org/apache/oozie/tools/TestOozieDBCLI.java (added)
+++ oozie/trunk/tools/src/test/java/org/apache/oozie/tools/TestOozieDBCLI.java Tue Apr 30 20:48:27 2013
@@ -0,0 +1,146 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.oozie.tools;
+
+import org.apache.hadoop.fs.FileUtil;
+import org.apache.oozie.test.XTestCase;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.PrintStream;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.Statement;
+
+/**
+ * Test OozieDBCLI for data base derby
+ */
+public class TestOozieDBCLI extends XTestCase {
+ private SecurityManager SECURITY_MANAGER;
+ private static String url = "jdbc:derby:target/test-data/oozietests/org.apache.oozie.tools.TestOozieDBCLI/data.db;create=true";
+ private String oozieConfig;
+
+ @BeforeClass
+ protected void setUp() throws Exception {
+ SECURITY_MANAGER = System.getSecurityManager();
+ new LauncherSecurityManager();
+ // remove an old variant
+ FileUtil.fullyDelete(new File("target/test-data/oozietests/org.apache.oozie.tools.TestOozieDBCLI/data.db"));
+ this.oozieConfig = System.getProperty("oozie.test.config.file");
+ File oozieConfig = new File("src/test/resources/hsqldb-oozie-site.xml");
+
+ System.setProperty("oozie.test.config.file", oozieConfig.getAbsolutePath());
+ Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
+ Connection conn = DriverManager.getConnection(url, "sa", "");
+ conn.close();
+
+ super.setUp();
+
+ }
+
+ @AfterClass
+ protected void tearDown() throws Exception {
+ System.setSecurityManager(SECURITY_MANAGER);
+ if(oozieConfig!=null){
+ System.setProperty("oozie.test.config.file", oozieConfig);
+ }else{
+ System.getProperties().remove("oozie.test.config.file");
+ }
+ super.tearDown();
+
+ }
+
+ private void execSQL(String sql) throws Exception {
+ Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
+ Connection conn = DriverManager.getConnection(url, "sa", "");
+
+ Statement st = conn.createStatement();
+ st.executeUpdate(sql);
+
+ st.close();
+ conn.close();
+ }
+
+ public void testOozieDBCLI() throws Exception {
+ // test script for create database
+ File createSql = new File(getTestCaseConfDir() + File.separator + "out.sql");
+ String[] argsCreate = { "create", "-sqlfile", createSql.getAbsolutePath(), "-run" };
+ int result = execOozieDBCLICommands(argsCreate);
+ assertEquals(0, result);
+ assertTrue(createSql.exists());
+
+ ByteArrayOutputStream data = new ByteArrayOutputStream();
+ PrintStream oldOut = System.out;
+ try {
+ // show versions
+ System.setOut(new PrintStream(data));
+ String[] argsVersion = { "version" };
+ assertEquals(0, execOozieDBCLICommands(argsVersion));
+
+ assertTrue(data.toString().contains("db.version: 2"));
+ // show help information
+ data.reset();
+ String[] argsHelp = { "help" };
+ assertEquals(0, execOozieDBCLICommands(argsHelp));
+ assertTrue(data.toString().contains("ooziedb.sh create <OPTIONS> : create Oozie DB schema"));
+ assertTrue(data.toString().contains("ooziedb.sh upgrade <OPTIONS> : upgrade Oozie DB"));
+ assertTrue(data.toString().contains("ooziedb.sh postupgrade <OPTIONS> : post upgrade Oozie DB"));
+ // try run invalid command
+ data.reset();
+ String[] argsInvalidCommand = { "invalidCommand" };
+ assertEquals(1, execOozieDBCLICommands(argsInvalidCommand));
+
+ }
+ finally {
+ System.setOut(oldOut);
+ }
+ // generate an upgrade script
+ File upgrade = new File(getTestCaseConfDir() + File.separator + "update.sql");
+ execSQL("DROP table OOZIE_SYS");
+ String[] argsUpgrade = { "upgrade", "-sqlfile", upgrade.getAbsolutePath(), "-run" };
+ assertEquals(0, execOozieDBCLICommands(argsUpgrade));
+
+ assertTrue(upgrade.exists());
+ File postUpgrade = new File(getTestCaseConfDir() + File.separator + "postUpdate.sql");
+ String[] argsPostUpgrade = { "postupgrade", "-sqlfile", postUpgrade.getAbsolutePath(), "-run" };
+ assertEquals(0, execOozieDBCLICommands(argsPostUpgrade));
+ assertTrue(postUpgrade.exists());
+ }
+
+ private int execOozieDBCLICommands(String[] args) {
+ try {
+ OozieDBCLI.main(args);
+
+ }
+ catch (SecurityException ex) {
+ if (LauncherSecurityManager.getExitInvoked()) {
+ System.out.println("Intercepting System.exit(" + LauncherSecurityManager.getExitCode() + ")");
+ System.err.println("Intercepting System.exit(" + LauncherSecurityManager.getExitCode() + ")");
+ return LauncherSecurityManager.getExitCode();
+
+ }
+ else {
+ throw ex;
+ }
+ }
+ return 1;
+ }
+}
Added: oozie/trunk/tools/src/test/java/org/apache/oozie/tools/TestOozieMySqlDBCLI.java
URL: http://svn.apache.org/viewvc/oozie/trunk/tools/src/test/java/org/apache/oozie/tools/TestOozieMySqlDBCLI.java?rev=1477819&view=auto
==============================================================================
--- oozie/trunk/tools/src/test/java/org/apache/oozie/tools/TestOozieMySqlDBCLI.java (added)
+++ oozie/trunk/tools/src/test/java/org/apache/oozie/tools/TestOozieMySqlDBCLI.java Tue Apr 30 20:48:27 2013
@@ -0,0 +1,121 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.oozie.tools;
+
+import org.apache.oozie.test.XTestCase;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.DriverManager;
+
+/**
+ * Test OozieDBCLI for mysql
+ */
+public class TestOozieMySqlDBCLI extends XTestCase {
+ private SecurityManager SECURITY_MANAGER;
+ private static String url = "jdbc:mysql:fake";
+ private String oozieConfig;
+
+ @BeforeClass
+ protected void setUp() throws Exception {
+ SECURITY_MANAGER = System.getSecurityManager();
+ DriverManager.registerDriver(new FakeDriver());
+ new LauncherSecurityManager();
+ this.oozieConfig = System.getProperty("oozie.test.config.file");
+
+ File oozieConfig = new File("src/test/resources/fake-oozie-site.xml");
+ System.setProperty("oozie.test.config.file", oozieConfig.getAbsolutePath());
+ Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
+ Connection conn = DriverManager.getConnection(url, "sa", "");
+ conn.close();
+
+ super.setUp();
+
+ }
+
+ @AfterClass
+ protected void tearDown() throws Exception {
+ System.setSecurityManager(SECURITY_MANAGER);
+ DriverManager.registerDriver(new FakeDriver());
+ if(oozieConfig!=null){
+ System.setProperty("oozie.test.config.file", oozieConfig);
+ }else{
+ System.getProperties().remove("oozie.test.config.file");
+ }
+ super.tearDown();
+
+ }
+
+ /**
+ * Test generate create script
+ */
+ public void testCreateMysql() throws Exception {
+ FakeConnection.SYSTEM_TABLE = false;
+
+ File createSql = new File(getTestCaseConfDir() + File.separator + "create.sql");
+ String[] argsCreate = { "create", "-sqlfile", createSql.getAbsolutePath(), "-run" };
+ int result = execOozieDBCLICommands(argsCreate);
+ assertEquals(0, result);
+ assertTrue(createSql.exists());
+
+ }
+
+ /**
+ * Test create upgrade script
+ */
+ public void testUpdateMysql() throws Exception {
+ new LauncherSecurityManager();
+ FakeConnection.SYSTEM_TABLE = true;
+ FakeConnection.CREATE = false;
+
+ File upgrade = new File(getTestCaseConfDir() + File.separator + "update.sql");
+ String[] argsUpgrade = { "upgrade", "-sqlfile", upgrade.getAbsolutePath(), "-run"};
+
+ assertEquals(0, execOozieDBCLICommands(argsUpgrade));
+ assertTrue(upgrade.exists());
+
+ FakeConnection.SYSTEM_TABLE = false;
+ upgrade.delete();
+
+ assertEquals(0, execOozieDBCLICommands(argsUpgrade));
+ assertTrue(upgrade.exists());
+
+ }
+
+ private int execOozieDBCLICommands(String[] args) {
+ try {
+ OozieDBCLI.main(args);
+
+ }
+ catch (SecurityException ex) {
+ if (LauncherSecurityManager.getExitInvoked()) {
+ System.out.println("Intercepting System.exit(" + LauncherSecurityManager.getExitCode() + ")");
+ System.err.println("Intercepting System.exit(" + LauncherSecurityManager.getExitCode() + ")");
+ return LauncherSecurityManager.getExitCode();
+
+ }
+ else {
+ throw ex;
+ }
+ }
+ return 1;
+ }
+}
Added: oozie/trunk/tools/src/test/java/org/apache/oozie/tools/TestOozieSharelibCLI.java
URL: http://svn.apache.org/viewvc/oozie/trunk/tools/src/test/java/org/apache/oozie/tools/TestOozieSharelibCLI.java?rev=1477819&view=auto
==============================================================================
--- oozie/trunk/tools/src/test/java/org/apache/oozie/tools/TestOozieSharelibCLI.java (added)
+++ oozie/trunk/tools/src/test/java/org/apache/oozie/tools/TestOozieSharelibCLI.java Tue Apr 30 20:48:27 2013
@@ -0,0 +1,188 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.oozie.tools;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintStream;
+import java.io.Writer;
+import java.net.URI;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.FileUtil;
+import org.apache.hadoop.fs.Path;
+import org.apache.oozie.service.HadoopAccessorService;
+import org.apache.oozie.service.ServiceException;
+import org.apache.oozie.service.Services;
+import org.apache.oozie.service.WorkflowAppService;
+import org.apache.oozie.test.XTestCase;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+/**
+ * Test OozieSharelibCLI
+ */
+public class TestOozieSharelibCLI extends XTestCase {
+ private SecurityManager SECURITY_MANAGER;
+ private String outPath = "outFolder";
+ private Services services = null;
+ private Path dstPath = null;
+ private FileSystem fs;
+
+ @BeforeClass
+ protected void setUp() throws Exception {
+ SECURITY_MANAGER = System.getSecurityManager();
+ new LauncherSecurityManager();
+ super.setUp();
+
+ }
+
+ @AfterClass
+ protected void tearDown() throws Exception {
+ System.setSecurityManager(SECURITY_MANAGER);
+ super.tearDown();
+
+ }
+
+ /**
+ * Test help command
+ */
+ public void testHelp() throws Exception {
+ ByteArrayOutputStream data = new ByteArrayOutputStream();
+ PrintStream oldPrintStream = System.out;
+ System.setOut(new PrintStream(data));
+ try {
+ String[] argsHelp = { "help" };
+ assertEquals(0, execOozieSharelibCLICommands(argsHelp));
+ assertTrue(data.toString().contains("oozie-setup.sh create <OPTIONS> : create oozie sharelib"));
+ assertTrue(data.toString().contains("oozie-setup.sh upgrade <OPTIONS> : upgrade oozie sharelib"));
+ assertTrue(data.toString().contains(" oozie-setup.sh help"));
+ }
+ finally {
+ System.setOut(oldPrintStream);
+ }
+
+ }
+
+ /**
+ * test copy libraries
+ */
+ public void testOozieSharelibCLI() throws Exception {
+
+ File libDirectory = new File(getTestCaseConfDir() + File.separator + "lib");
+
+ if (!libDirectory.exists()) {
+ libDirectory.mkdirs();
+ }
+ else {
+ FileUtil.fullyDelete(libDirectory);
+ libDirectory.mkdirs();
+ }
+
+ writeFile(libDirectory, "file1", "test File");
+ writeFile(libDirectory, "file2", "test File2");
+
+ String[] argsCreate = { "create", "-fs", outPath, "-locallib", libDirectory.getParentFile().getAbsolutePath() };
+ assertEquals(0, execOozieSharelibCLICommands(argsCreate));
+
+ FileSystem fs = getTargetFileSysyem();
+ // test files in new folder
+ assertEquals(9, fs.getFileStatus(new Path(getDistPath(), "file1")).getLen());
+ assertEquals(10, fs.getFileStatus(new Path(getDistPath(), "file2")).getLen());
+
+ }
+
+ /**
+ * test fake command
+ */
+ public void testFakeCommand() throws Exception {
+
+ ByteArrayOutputStream data = new ByteArrayOutputStream();
+ PrintStream oldPrintStream = System.err;
+ System.setErr(new PrintStream(data));
+ try {
+ String[] argsFake = { "fakeCommand" };
+ assertEquals(1, execOozieSharelibCLICommands(argsFake));
+ assertTrue(data.toString().contains("Invalid sub-command: invalid sub-command [fakeCommand]"));
+ assertTrue(data.toString().contains("use 'help [sub-command]' for help details"));
+ }
+ finally {
+ System.setErr(oldPrintStream);
+ }
+
+ }
+
+ private FileSystem getTargetFileSysyem() throws Exception {
+ if (fs == null) {
+ HadoopAccessorService has = getServices().get(HadoopAccessorService.class);
+ URI uri = new Path(outPath).toUri();
+ Configuration fsConf = has.createJobConf(uri.getAuthority());
+ fs = has.createFileSystem(System.getProperty("user.name"), uri, fsConf);
+ }
+ return fs;
+
+ }
+
+ private Services getServices() throws ServiceException {
+ if (services == null) {
+ services = new Services();
+ services.getConf().set(Services.CONF_SERVICE_CLASSES,
+ "org.apache.oozie.service.LiteWorkflowAppService, org.apache.oozie.service.HadoopAccessorService");
+ services.init();
+ }
+ return services;
+ }
+
+ private Path getDistPath() throws Exception {
+ if (dstPath == null) {
+ WorkflowAppService lwas = getServices().get(WorkflowAppService.class);
+ dstPath = lwas.getSystemLibPath();
+ }
+ return dstPath;
+ }
+
+ private void writeFile(File folder, String filename, String content) throws Exception {
+ File file = new File(folder.getAbsolutePath() + File.separator + filename);
+ Writer writer = new FileWriter(file);
+ writer.write(content);
+ writer.flush();
+ writer.close();
+
+ }
+
+ private int execOozieSharelibCLICommands(String[] args) throws Exception {
+ try {
+ OozieSharelibCLI.main(args);
+ }
+ catch (SecurityException ex) {
+ if (LauncherSecurityManager.getExitInvoked()) {
+ System.out.println("Intercepting System.exit(" + LauncherSecurityManager.getExitCode() + ")");
+ System.err.println("Intercepting System.exit(" + LauncherSecurityManager.getExitCode() + ")");
+ return LauncherSecurityManager.getExitCode();
+ }
+ else {
+ throw ex;
+ }
+ }
+ return 1;
+ }
+
+}
Added: oozie/trunk/tools/src/test/resources/fake-oozie-site.xml
URL: http://svn.apache.org/viewvc/oozie/trunk/tools/src/test/resources/fake-oozie-site.xml?rev=1477819&view=auto
==============================================================================
--- oozie/trunk/tools/src/test/resources/fake-oozie-site.xml (added)
+++ oozie/trunk/tools/src/test/resources/fake-oozie-site.xml Tue Apr 30 20:48:27 2013
@@ -0,0 +1,43 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+-->
+
+<configuration>
+
+ <property>
+ <name>oozie.service.JPAService.jdbc.driver</name>
+ <value>org.apache.oozie.tools.FakeDriver</value>
+ </property>
+ <property>
+ <name>oozie.service.JPAService.jdbc.username</name>
+ <value>sa</value>
+ </property>
+ <property>
+ <name>oozie.service.JPAService.jdbc.url</name>
+ <value>jdbc:mysql:fake</value>
+ </property>
+ <property>
+ <name>oozie.service.JPAService.jdbc.password</name>
+ <value> </value>
+ </property>
+ <property>
+ <name>oozie.service.WorkflowAppService.system.libpath</name>
+ <value>target/test-data/oozietests/org.apache.oozie.tools.TestOozieDBCLI/outlib</value>
+ </property>
+</configuration>
Added: oozie/trunk/tools/src/test/resources/hsqldb-oozie-site.xml
URL: http://svn.apache.org/viewvc/oozie/trunk/tools/src/test/resources/hsqldb-oozie-site.xml?rev=1477819&view=auto
==============================================================================
--- oozie/trunk/tools/src/test/resources/hsqldb-oozie-site.xml (added)
+++ oozie/trunk/tools/src/test/resources/hsqldb-oozie-site.xml Tue Apr 30 20:48:27 2013
@@ -0,0 +1,42 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+-->
+<configuration>
+
+ <property>
+ <name>oozie.service.JPAService.jdbc.driver</name>
+ <value>org.apache.derby.jdbc.EmbeddedDriver</value>
+ </property>
+ <property>
+ <name>oozie.service.JPAService.jdbc.username</name>
+ <value>sa</value>
+ </property>
+ <property>
+ <name>oozie.service.JPAService.jdbc.url</name>
+ <value>jdbc:derby:target/test-data/oozietests/org.apache.oozie.tools.TestOozieDBCLI/data.db</value>
+ </property>
+ <property>
+ <name>oozie.service.JPAService.jdbc.password</name>
+ <value> </value>
+ </property>
+ <property>
+ <name>oozie.service.WorkflowAppService.system.libpath</name>
+ <value>target/test-data/oozietests/org.apache.oozie.tools.TestOozieDBCLI/outlib</value>
+ </property>
+</configuration>