Skip to content

Commit

Permalink
add unit test cases #4 and documentation #5
Browse files Browse the repository at this point in the history
  • Loading branch information
arjenzhou committed Jul 21, 2021
1 parent 1775c05 commit bc7c342
Show file tree
Hide file tree
Showing 40 changed files with 601 additions and 115 deletions.
54 changes: 33 additions & 21 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,39 @@ on:
branches: [ master ]

jobs:
build:

unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
- name: Get gradlew
run: gradle wrapper
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Test with Gradle
run: ./gradlew test

code-coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
- name: Get gradlew
run: gradle wrapper
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Test with Gradle
run: ./gradlew test
- name: codeCoverage report
run: ./gradlew codeCoverageReport
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
token: ${{secrets.CODECOV_TOKEN}}
file: ./build/reports/jacoco/codeCoverageReport/codeCoverageReport.xml
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
- name: Get gradlew
run: gradle wrapper
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: codeCoverage report
run: ./gradlew codeCoverageReport
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
token: ${{secrets.CODECOV_TOKEN}}
file: ./build/reports/jacoco/codeCoverageReport/codeCoverageReport.xml
2 changes: 1 addition & 1 deletion api/src/main/java/de/xab/porter/api/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.sql.JDBCType;

/**
* A bean class describe the definition of table
* A entity class describe the definition of table
*/
public class Column {
// not null
Expand Down
5 changes: 5 additions & 0 deletions api/src/main/java/de/xab/porter/api/Result.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package de.xab.porter.api;

/**
* the outer data structure includes real data and its sequence number of batch
*
* @param <T> the type of data transferred
*/
public class Result<T> {
private long sequenceNum;
private T result;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
package de.xab.porter.api.dataconnection;

/**
* super class of any input data structure
* {@link SrcConnection} {@link SinkConnection}
*/
public class DataConnection {
String type;
String url;
String username;
String password;
String catalog;
String schema;
String table;
private String type;
private String url;
private String username;
private String password;
private String catalog;
private String schema;
private String table;

public DataConnection() {
}

protected DataConnection(Builder<?> builder) {
this.type = builder.type;
this.url = builder.url;
this.username = builder.username;
this.password = builder.password;
this.catalog = builder.catalog;
this.schema = builder.schema;
this.table = builder.table;
}

//setter and getter
public String getType() {
return type;
}
Expand Down Expand Up @@ -64,4 +82,52 @@ public String getTable() {
public void setTable(String table) {
this.table = table;
}

//builder
public abstract static class Builder<T extends DataConnection> {
private String type;
private String url;
private String username;
private String password;
private String catalog;
private String schema;
private String table;

public Builder<T> type(String type) {
this.type = type;
return this;
}

public Builder<T> url(String url) {
this.url = url;
return this;
}

public Builder<T> username(String username) {
this.username = username;
return this;
}

public Builder<T> password(String password) {
this.password = password;
return this;
}

public Builder<T> catalog(String catalog) {
this.catalog = catalog;
return this;
}

public Builder<T> schema(String schema) {
this.schema = schema;
return this;
}

public Builder<T> table(String table) {
this.table = table;
return this;
}

public abstract T build();
}
}
102 changes: 86 additions & 16 deletions api/src/main/java/de/xab/porter/api/dataconnection/SinkConnection.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
package de.xab.porter.api.dataconnection;

/**
* connection message of sink datasource, inner class {@link Properties} describe the behavior how sink table was handled
*/
public class SinkConnection extends DataConnection {
private Properties properties = new Properties();

//constructors
public SinkConnection() {
super();
}

protected SinkConnection(Builder builder) {
super(builder);
}

public Properties getProperties() {
return properties;
}

public void setProperties(Properties properties) {
this.properties = properties;
public static final class Builder extends DataConnection.Builder<SinkConnection> {
private Properties properties;

public Builder properties(Properties properties) {
this.properties = properties;
return this;
}

@Override
public SinkConnection build() {
return new SinkConnection(this);
}
}

//inner class
public static class Properties {
public static final String PREPARE_BATCH_MODE = "PREPARE_BATCH";
public static final String STATEMENT_BATCH_MODE = "STATEMENT_BATCH";
Expand All @@ -23,6 +46,23 @@ public static class Properties {
private boolean create = false;
private boolean drop = false;

private Properties(Builder builder) {
writeMode = builder.writeMode;
allColumns = builder.allColumns;
quote = builder.quote;
tableIdentifier = builder.tableIdentifier;
create = builder.create;
drop = builder.drop;
}

public Properties() {

}

public static Builder builder() {
return new Builder();
}

public static String getPrepareBatchMode() {
return PREPARE_BATCH_MODE;
}
Expand All @@ -39,18 +79,10 @@ public String getWriteMode() {
return writeMode;
}

public void setWriteMode(String writeMode) {
this.writeMode = writeMode;
}

public boolean isAllColumns() {
return allColumns;
}

public void setAllColumns(boolean allColumns) {
this.allColumns = allColumns;
}

public String getQuote() {
return quote;
}
Expand All @@ -71,16 +103,54 @@ public boolean isCreate() {
return create;
}

public void setCreate(boolean create) {
this.create = create;
}

public boolean isDrop() {
return drop;
}

public void setDrop(boolean drop) {
this.drop = drop;
public static class Builder {
private String writeMode;
private boolean allColumns;
private String quote;
private String tableIdentifier;
private boolean create;
private boolean drop;

private Builder() {
}

public Builder writeMode(String writeMode) {
this.writeMode = writeMode;
return this;
}

public Builder allColumns(boolean allColumns) {
this.allColumns = allColumns;
return this;
}

public Builder quote(String quote) {
this.quote = quote;
return this;
}

public Builder tableIdentifier(String tableIdentifier) {
this.tableIdentifier = tableIdentifier;
return this;
}

public Builder create(boolean create) {
this.create = create;
return this;
}

public Builder drop(boolean drop) {
this.drop = drop;
return this;
}

public Properties build() {
return new Properties(this);
}
}
}
}
Loading

0 comments on commit bc7c342

Please sign in to comment.