Skip to content

Commit

Permalink
(#29) Added getter Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
svettwer committed Feb 5, 2019
1 parent d297108 commit b0dadc7
Show file tree
Hide file tree
Showing 3 changed files with 369 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

package com.consol.citrus.db.driver;

import com.consol.citrus.db.driver.data.Row;
import org.apache.http.client.HttpClient;

import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URL;
import java.sql.Array;
import java.sql.Blob;
Expand All @@ -37,9 +39,12 @@
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Map;
import java.util.Objects;

public class JdbcCallableStatement extends JdbcPreparedStatement implements CallableStatement {

private Row resultRow;

public JdbcCallableStatement(final HttpClient httpClient, final String callableStatement, final String serverUrl, final JdbcConnection connection) {
super(httpClient, callableStatement, serverUrl, connection);
}
Expand All @@ -61,47 +66,47 @@ public boolean wasNull() throws SQLException {

@Override
public String getString(final int parameterIndex) throws SQLException {
return null;
return (String) getData(parameterIndex);
}

@Override
public boolean getBoolean(final int parameterIndex) throws SQLException {
return false;
return (Boolean) getData(parameterIndex);
}

@Override
public byte getByte(final int parameterIndex) throws SQLException {
return 0;
return (byte) getData(parameterIndex);
}

@Override
public short getShort(final int parameterIndex) throws SQLException {
return 0;
return (short) getData(parameterIndex);
}

@Override
public int getInt(final int parameterIndex) throws SQLException {
return 0;
return (int) getData(parameterIndex);
}

@Override
public long getLong(final int parameterIndex) throws SQLException {
return 0;
return (long) getData(parameterIndex);
}

@Override
public float getFloat(final int parameterIndex) throws SQLException {
return 0;
return (float) getData(parameterIndex);
}

@Override
public double getDouble(final int parameterIndex) throws SQLException {
return 0;
return (double) getData(parameterIndex);
}

@Override
public BigDecimal getBigDecimal(final int parameterIndex, final int scale) throws SQLException {
return null;
return getBigDecimal(parameterIndex).setScale(scale, RoundingMode.HALF_UP);
}

@Override
Expand Down Expand Up @@ -131,7 +136,7 @@ public Object getObject(final int parameterIndex) throws SQLException {

@Override
public BigDecimal getBigDecimal(final int parameterIndex) throws SQLException {
return null;
return (BigDecimal) getData(parameterIndex);
}

@Override
Expand Down Expand Up @@ -326,47 +331,47 @@ public void setNull(final String parameterName, final int sqlType, final String

@Override
public String getString(final String parameterName) throws SQLException {
return null;
return (String) getData(parameterName);
}

@Override
public boolean getBoolean(final String parameterName) throws SQLException {
return false;
return (boolean) getData(parameterName);
}

@Override
public byte getByte(final String parameterName) throws SQLException {
return 0;
return (byte) getData(parameterName);
}

@Override
public short getShort(final String parameterName) throws SQLException {
return 0;
return (short) getData(parameterName);
}

@Override
public int getInt(final String parameterName) throws SQLException {
return 0;
return (int) getData(parameterName);
}

@Override
public long getLong(final String parameterName) throws SQLException {
return 0;
return (long) getData(parameterName);
}

@Override
public float getFloat(final String parameterName) throws SQLException {
return 0;
return (float) getData(parameterName);
}

@Override
public double getDouble(final String parameterName) throws SQLException {
return 0;
return (double) getData(parameterName);
}

@Override
public byte[] getBytes(final String parameterName) throws SQLException {
return new byte[0];
return (byte[]) getData(parameterName);
}

@Override
Expand All @@ -386,12 +391,12 @@ public Timestamp getTimestamp(final String parameterName) throws SQLException {

@Override
public Object getObject(final String parameterName) throws SQLException {
return null;
return getData(parameterName);
}

@Override
public BigDecimal getBigDecimal(final String parameterName) throws SQLException {
return null;
return (BigDecimal) getData(parameterName);
}

@Override
Expand Down Expand Up @@ -646,4 +651,19 @@ private void setOutParameter(final int parameterIndex) {
private void setOutParameter(final String parameterName) {
setParameter(parameterName, "?");
}

private Object getData(final int parameterIndex) throws SQLException {
return getDataRow().getValue(parameterIndex - 1);
}

private Object getData(final String parameterName) throws SQLException {
return getDataRow().getValues().get(parameterName);
}

private Row getDataRow() throws SQLException {
if(Objects.isNull(resultRow)){
resultRow = dataSet.getNextRow();
}
return resultRow;
}
}
15 changes: 8 additions & 7 deletions driver/src/main/java/com/consol/citrus/db/driver/data/Row.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@
package com.consol.citrus.db.driver.data;

import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.SortedMap;
import java.util.TreeMap;

/**
* @author Christoph Deppisch
*/
public class Row {

/** Row values with column name as key */
private Map<String, Object> values = new LinkedHashMap<>();
private SortedMap<String, Object> values = new TreeMap<>();

private Object lastValue;

Expand All @@ -45,7 +46,7 @@ public List<String> getColumns() {
* @param columnName
* @return
*/
public Object getValue(String columnName) {
public Object getValue(final String columnName) {
lastValue = values.get(columnName);
return lastValue;
}
Expand All @@ -55,7 +56,7 @@ public Object getValue(String columnName) {
* @param columnIndex
* @return
*/
public Object getValue(int columnIndex) {
public Object getValue(final int columnIndex) {
lastValue = values.values().toArray()[columnIndex];
return lastValue;
}
Expand All @@ -74,15 +75,15 @@ public Map<String, Object> getValues() {
*
* @param values
*/
public void setValues(Map<String, Object> values) {
public void setValues(final SortedMap<String, Object> values) {
this.values = values;
}

@Override
public boolean equals(Object o) {
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Row row = (Row) o;
final Row row = (Row) o;
return Objects.equals(values, row.values);
}

Expand Down
Loading

0 comments on commit b0dadc7

Please sign in to comment.