repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/FinalBeanTest.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/FinalBean.java // public class FinalBean { // // public final long id = 1; // // public final boolean booleanField = false; // // public final int intField = 1; // // public final String stringField = ""; // // public final DbIntValue intValueField = new DbIntValue(1); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/FinalBeanSql.java // public interface FinalBeanSql { // // @GetGeneratedKeys // @Sql("INSERT INTO bean(boolean_field, int_field, string_field, int_value_field) VALUES (:booleanField, :intField, :stringField, :intValueField)") // long insert(@BindBean FinalBean bean); // // @Sql("UPDATE bean SET boolean_field = :booleanField, int_field = :intField, string_field = :stringField, int_value_field = :intValueField WHERE id = :id") // int update(@BindBean FinalBean bean); // // }
import com.github.mjdbc.test.asset.model.FinalBean; import com.github.mjdbc.test.asset.sql.FinalBeanSql; import org.junit.Test;
package com.github.mjdbc.test; public class FinalBeanTest extends BaseSqlTest<FinalBeanSql> { public FinalBeanTest() { super(FinalBeanSql.class, "beans"); } @Test public void checkInsert() {
// Path: src/test/java/com/github/mjdbc/test/asset/model/FinalBean.java // public class FinalBean { // // public final long id = 1; // // public final boolean booleanField = false; // // public final int intField = 1; // // public final String stringField = ""; // // public final DbIntValue intValueField = new DbIntValue(1); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/FinalBeanSql.java // public interface FinalBeanSql { // // @GetGeneratedKeys // @Sql("INSERT INTO bean(boolean_field, int_field, string_field, int_value_field) VALUES (:booleanField, :intField, :stringField, :intValueField)") // long insert(@BindBean FinalBean bean); // // @Sql("UPDATE bean SET boolean_field = :booleanField, int_field = :intField, string_field = :stringField, int_value_field = :intValueField WHERE id = :id") // int update(@BindBean FinalBean bean); // // } // Path: src/test/java/com/github/mjdbc/test/FinalBeanTest.java import com.github.mjdbc.test.asset.model.FinalBean; import com.github.mjdbc.test.asset.sql.FinalBeanSql; import org.junit.Test; package com.github.mjdbc.test; public class FinalBeanTest extends BaseSqlTest<FinalBeanSql> { public FinalBeanTest() { super(FinalBeanSql.class, "beans"); } @Test public void checkInsert() {
long id = sql.insert(new FinalBean());
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/asset/sql/error/WildcardBatchParamSql.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/User.java // public final class User { // /** // * It is recommended to have type safe IDs. // */ // public UserId id; // public String login; // public String firstName; // public String lastName; // public Gender gender; // public long score; // public Timestamp registrationDate; // // /** // * Class to create User object from result set. // */ // @Mapper // public static final DbMapper<User> MAPPER = (r) -> { // User user = new User(); // user.id = new UserId(r.getInt("id")); // user.login = r.getString("login"); // user.firstName = r.getString("first_name"); // user.lastName = r.getString("last_name"); // user.gender = Gender.fromDbValue(r.getInt("gender")); // user.score = r.getLong("score"); // user.registrationDate = r.getTimestamp("reg_date"); // return user; // }; // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // User user = (User) o; // return score == user.score && // Objects.equals(id, user.id) && // Objects.equals(login, user.login) && // Objects.equals(firstName, user.firstName) && // Objects.equals(lastName, user.lastName) && // gender == user.gender && // Objects.equals(registrationDate, user.registrationDate); // } // // @Override // public int hashCode() { // return Objects.hash(id, login, firstName, lastName, gender, score, registrationDate); // } // }
import com.github.mjdbc.BindBean; import com.github.mjdbc.Sql; import com.github.mjdbc.test.asset.model.User; import java.util.List;
package com.github.mjdbc.test.asset.sql.error; public interface WildcardBatchParamSql { @Sql("UPDATE users SET score = :score WHERE id = :id")
// Path: src/test/java/com/github/mjdbc/test/asset/model/User.java // public final class User { // /** // * It is recommended to have type safe IDs. // */ // public UserId id; // public String login; // public String firstName; // public String lastName; // public Gender gender; // public long score; // public Timestamp registrationDate; // // /** // * Class to create User object from result set. // */ // @Mapper // public static final DbMapper<User> MAPPER = (r) -> { // User user = new User(); // user.id = new UserId(r.getInt("id")); // user.login = r.getString("login"); // user.firstName = r.getString("first_name"); // user.lastName = r.getString("last_name"); // user.gender = Gender.fromDbValue(r.getInt("gender")); // user.score = r.getLong("score"); // user.registrationDate = r.getTimestamp("reg_date"); // return user; // }; // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // User user = (User) o; // return score == user.score && // Objects.equals(id, user.id) && // Objects.equals(login, user.login) && // Objects.equals(firstName, user.firstName) && // Objects.equals(lastName, user.lastName) && // gender == user.gender && // Objects.equals(registrationDate, user.registrationDate); // } // // @Override // public int hashCode() { // return Objects.hash(id, login, firstName, lastName, gender, score, registrationDate); // } // } // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/WildcardBatchParamSql.java import com.github.mjdbc.BindBean; import com.github.mjdbc.Sql; import com.github.mjdbc.test.asset.model.User; import java.util.List; package com.github.mjdbc.test.asset.sql.error; public interface WildcardBatchParamSql { @Sql("UPDATE users SET score = :score WHERE id = :id")
void batchUpdateWithCollection(@BindBean List<? extends User> users);
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/asset/model/FinalBean.java
// Path: src/test/java/com/github/mjdbc/test/asset/types/DbIntValue.java // public class DbIntValue extends AbstractDbInt { // protected int value; // // public DbIntValue(int value) { // this.value = value; // } // // public final int getDbValue() { // return value; // } // // public String toString() { // return getClass().getSimpleName() + "[" + value + "]"; // } // }
import com.github.mjdbc.test.asset.types.DbIntValue;
package com.github.mjdbc.test.asset.model; /** * Bean with getters and setters methods and private fields. */ public class FinalBean { public final long id = 1; public final boolean booleanField = false; public final int intField = 1; public final String stringField = "";
// Path: src/test/java/com/github/mjdbc/test/asset/types/DbIntValue.java // public class DbIntValue extends AbstractDbInt { // protected int value; // // public DbIntValue(int value) { // this.value = value; // } // // public final int getDbValue() { // return value; // } // // public String toString() { // return getClass().getSimpleName() + "[" + value + "]"; // } // } // Path: src/test/java/com/github/mjdbc/test/asset/model/FinalBean.java import com.github.mjdbc.test.asset.types.DbIntValue; package com.github.mjdbc.test.asset.model; /** * Bean with getters and setters methods and private fields. */ public class FinalBean { public final long id = 1; public final boolean booleanField = false; public final int intField = 1; public final String stringField = "";
public final DbIntValue intValueField = new DbIntValue(1);
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/asset/model/error/BeanWithNullMapper.java
// Path: src/main/java/com/github/mjdbc/DbMapper.java // public interface DbMapper<T> { // // /** // * Maps a single row or all rows to the corresponding Java object. // * May return null for nullable primitive type fields (like nullable varchar field). // * Must never return null for complex java property objects (beans). // * // * @param r - open result set. // * @return Java object. // * @throws SQLException if SQLException occurs during the mapping process // */ // T map(@NotNull ResultSet r) throws SQLException; // }
import com.github.mjdbc.DbMapper; import com.github.mjdbc.Mapper;
package com.github.mjdbc.test.asset.model.error; /** * Object mapped by field marked with annotation. */ public class BeanWithNullMapper { public final int value; public BeanWithNullMapper(int value) { this.value = value; } @Mapper
// Path: src/main/java/com/github/mjdbc/DbMapper.java // public interface DbMapper<T> { // // /** // * Maps a single row or all rows to the corresponding Java object. // * May return null for nullable primitive type fields (like nullable varchar field). // * Must never return null for complex java property objects (beans). // * // * @param r - open result set. // * @return Java object. // * @throws SQLException if SQLException occurs during the mapping process // */ // T map(@NotNull ResultSet r) throws SQLException; // } // Path: src/test/java/com/github/mjdbc/test/asset/model/error/BeanWithNullMapper.java import com.github.mjdbc.DbMapper; import com.github.mjdbc.Mapper; package com.github.mjdbc.test.asset.model.error; /** * Object mapped by field marked with annotation. */ public class BeanWithNullMapper { public final int value; public BeanWithNullMapper(int value) { this.value = value; } @Mapper
public static final DbMapper<BeanWithNullMapper> MAPPER = null;
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/asset/model/error/NonPublicMapperBean.java
// Path: src/main/java/com/github/mjdbc/DbMapper.java // public interface DbMapper<T> { // // /** // * Maps a single row or all rows to the corresponding Java object. // * May return null for nullable primitive type fields (like nullable varchar field). // * Must never return null for complex java property objects (beans). // * // * @param r - open result set. // * @return Java object. // * @throws SQLException if SQLException occurs during the mapping process // */ // T map(@NotNull ResultSet r) throws SQLException; // }
import com.github.mjdbc.DbMapper; import com.github.mjdbc.Mapper;
package com.github.mjdbc.test.asset.model.error; /** * Object mapped by field marked with annotation. */ public class NonPublicMapperBean { @Mapper
// Path: src/main/java/com/github/mjdbc/DbMapper.java // public interface DbMapper<T> { // // /** // * Maps a single row or all rows to the corresponding Java object. // * May return null for nullable primitive type fields (like nullable varchar field). // * Must never return null for complex java property objects (beans). // * // * @param r - open result set. // * @return Java object. // * @throws SQLException if SQLException occurs during the mapping process // */ // T map(@NotNull ResultSet r) throws SQLException; // } // Path: src/test/java/com/github/mjdbc/test/asset/model/error/NonPublicMapperBean.java import com.github.mjdbc.DbMapper; import com.github.mjdbc.Mapper; package com.github.mjdbc.test.asset.model.error; /** * Object mapped by field marked with annotation. */ public class NonPublicMapperBean { @Mapper
final static DbMapper<NonPublicMapperBean> M = (r) -> new NonPublicMapperBean();
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/asset/sql/FinalBeanSql.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/FinalBean.java // public class FinalBean { // // public final long id = 1; // // public final boolean booleanField = false; // // public final int intField = 1; // // public final String stringField = ""; // // public final DbIntValue intValueField = new DbIntValue(1); // }
import com.github.mjdbc.BindBean; import com.github.mjdbc.GetGeneratedKeys; import com.github.mjdbc.Sql; import com.github.mjdbc.test.asset.model.FinalBean;
package com.github.mjdbc.test.asset.sql; public interface FinalBeanSql { @GetGeneratedKeys @Sql("INSERT INTO bean(boolean_field, int_field, string_field, int_value_field) VALUES (:booleanField, :intField, :stringField, :intValueField)")
// Path: src/test/java/com/github/mjdbc/test/asset/model/FinalBean.java // public class FinalBean { // // public final long id = 1; // // public final boolean booleanField = false; // // public final int intField = 1; // // public final String stringField = ""; // // public final DbIntValue intValueField = new DbIntValue(1); // } // Path: src/test/java/com/github/mjdbc/test/asset/sql/FinalBeanSql.java import com.github.mjdbc.BindBean; import com.github.mjdbc.GetGeneratedKeys; import com.github.mjdbc.Sql; import com.github.mjdbc.test.asset.model.FinalBean; package com.github.mjdbc.test.asset.sql; public interface FinalBeanSql { @GetGeneratedKeys @Sql("INSERT INTO bean(boolean_field, int_field, string_field, int_value_field) VALUES (:booleanField, :intField, :stringField, :intValueField)")
long insert(@BindBean FinalBean bean);
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/DbValuesSqlTest.java
// Path: src/test/java/com/github/mjdbc/test/asset/sql/DbValueSql.java // public interface DbValueSql { // // @Sql("SELECT integer_field FROM custom_types") // Integer getNullableInt(); // // @Sql("UPDATE custom_types SET integer_field = :value") // void setNullableDbInt(@Bind("value") @Nullable DbInt value); // // // @Sql("SELECT long_field FROM custom_types") // Long getNullableLong(); // // @Sql("UPDATE custom_types SET long_field = :value") // void setNullableDbLong(@Bind("value") @Nullable DbLong value); // // // @Sql("SELECT varchar_field FROM custom_types") // String getNullableString(); // // @Sql("UPDATE custom_types SET varchar_field = :value") // void setNullableDbString(@Bind("value") @Nullable DbString value); // // // @Sql("SELECT timestamp_field FROM custom_types") // Timestamp getNullableTimestamp(); // // @Sql("UPDATE custom_types SET timestamp_field = :value") // void setNullableDbTimestamp(@Bind("value") @Nullable DbTimestamp value); // } // // Path: src/test/java/com/github/mjdbc/test/asset/types/DbIntValue.java // public class DbIntValue extends AbstractDbInt { // protected int value; // // public DbIntValue(int value) { // this.value = value; // } // // public final int getDbValue() { // return value; // } // // public String toString() { // return getClass().getSimpleName() + "[" + value + "]"; // } // } // // Path: src/test/java/com/github/mjdbc/test/asset/types/DbLongValue.java // public class DbLongValue extends AbstractDbLong { // protected long value; // // public DbLongValue(int value) { // this.value = value; // } // // public final long getDbValue() { // return value; // } // // public String toString() { // return getClass().getSimpleName() + "[" + value + "]"; // } // }
import com.github.mjdbc.test.asset.sql.DbValueSql; import com.github.mjdbc.test.asset.types.DbIntValue; import com.github.mjdbc.test.asset.types.DbLongValue; import java.sql.Timestamp; import org.junit.Before; import org.junit.Test;
package com.github.mjdbc.test; /** * Tests for DbValue (Int,Long..) support. */ public class DbValuesSqlTest extends DbTest { private DbValueSql sql; public DbValuesSqlTest() { super("types"); } @Before public void setUp() { super.setUp(); sql = db.attachSql(DbValueSql.class); } @Test public void checkDbIntValueSql() { sql.setNullableDbInt(null); Integer v1 = sql.getNullableInt(); assertNull(v1);
// Path: src/test/java/com/github/mjdbc/test/asset/sql/DbValueSql.java // public interface DbValueSql { // // @Sql("SELECT integer_field FROM custom_types") // Integer getNullableInt(); // // @Sql("UPDATE custom_types SET integer_field = :value") // void setNullableDbInt(@Bind("value") @Nullable DbInt value); // // // @Sql("SELECT long_field FROM custom_types") // Long getNullableLong(); // // @Sql("UPDATE custom_types SET long_field = :value") // void setNullableDbLong(@Bind("value") @Nullable DbLong value); // // // @Sql("SELECT varchar_field FROM custom_types") // String getNullableString(); // // @Sql("UPDATE custom_types SET varchar_field = :value") // void setNullableDbString(@Bind("value") @Nullable DbString value); // // // @Sql("SELECT timestamp_field FROM custom_types") // Timestamp getNullableTimestamp(); // // @Sql("UPDATE custom_types SET timestamp_field = :value") // void setNullableDbTimestamp(@Bind("value") @Nullable DbTimestamp value); // } // // Path: src/test/java/com/github/mjdbc/test/asset/types/DbIntValue.java // public class DbIntValue extends AbstractDbInt { // protected int value; // // public DbIntValue(int value) { // this.value = value; // } // // public final int getDbValue() { // return value; // } // // public String toString() { // return getClass().getSimpleName() + "[" + value + "]"; // } // } // // Path: src/test/java/com/github/mjdbc/test/asset/types/DbLongValue.java // public class DbLongValue extends AbstractDbLong { // protected long value; // // public DbLongValue(int value) { // this.value = value; // } // // public final long getDbValue() { // return value; // } // // public String toString() { // return getClass().getSimpleName() + "[" + value + "]"; // } // } // Path: src/test/java/com/github/mjdbc/test/DbValuesSqlTest.java import com.github.mjdbc.test.asset.sql.DbValueSql; import com.github.mjdbc.test.asset.types.DbIntValue; import com.github.mjdbc.test.asset.types.DbLongValue; import java.sql.Timestamp; import org.junit.Before; import org.junit.Test; package com.github.mjdbc.test; /** * Tests for DbValue (Int,Long..) support. */ public class DbValuesSqlTest extends DbTest { private DbValueSql sql; public DbValuesSqlTest() { super("types"); } @Before public void setUp() { super.setUp(); sql = db.attachSql(DbValueSql.class); } @Test public void checkDbIntValueSql() { sql.setNullableDbInt(null); Integer v1 = sql.getNullableInt(); assertNull(v1);
sql.setNullableDbInt(new DbIntValue(1));
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/DbValuesSqlTest.java
// Path: src/test/java/com/github/mjdbc/test/asset/sql/DbValueSql.java // public interface DbValueSql { // // @Sql("SELECT integer_field FROM custom_types") // Integer getNullableInt(); // // @Sql("UPDATE custom_types SET integer_field = :value") // void setNullableDbInt(@Bind("value") @Nullable DbInt value); // // // @Sql("SELECT long_field FROM custom_types") // Long getNullableLong(); // // @Sql("UPDATE custom_types SET long_field = :value") // void setNullableDbLong(@Bind("value") @Nullable DbLong value); // // // @Sql("SELECT varchar_field FROM custom_types") // String getNullableString(); // // @Sql("UPDATE custom_types SET varchar_field = :value") // void setNullableDbString(@Bind("value") @Nullable DbString value); // // // @Sql("SELECT timestamp_field FROM custom_types") // Timestamp getNullableTimestamp(); // // @Sql("UPDATE custom_types SET timestamp_field = :value") // void setNullableDbTimestamp(@Bind("value") @Nullable DbTimestamp value); // } // // Path: src/test/java/com/github/mjdbc/test/asset/types/DbIntValue.java // public class DbIntValue extends AbstractDbInt { // protected int value; // // public DbIntValue(int value) { // this.value = value; // } // // public final int getDbValue() { // return value; // } // // public String toString() { // return getClass().getSimpleName() + "[" + value + "]"; // } // } // // Path: src/test/java/com/github/mjdbc/test/asset/types/DbLongValue.java // public class DbLongValue extends AbstractDbLong { // protected long value; // // public DbLongValue(int value) { // this.value = value; // } // // public final long getDbValue() { // return value; // } // // public String toString() { // return getClass().getSimpleName() + "[" + value + "]"; // } // }
import com.github.mjdbc.test.asset.sql.DbValueSql; import com.github.mjdbc.test.asset.types.DbIntValue; import com.github.mjdbc.test.asset.types.DbLongValue; import java.sql.Timestamp; import org.junit.Before; import org.junit.Test;
package com.github.mjdbc.test; /** * Tests for DbValue (Int,Long..) support. */ public class DbValuesSqlTest extends DbTest { private DbValueSql sql; public DbValuesSqlTest() { super("types"); } @Before public void setUp() { super.setUp(); sql = db.attachSql(DbValueSql.class); } @Test public void checkDbIntValueSql() { sql.setNullableDbInt(null); Integer v1 = sql.getNullableInt(); assertNull(v1); sql.setNullableDbInt(new DbIntValue(1)); Integer v2 = sql.getNullableInt(); assertEquals(new Integer(1), v2); } @Test public void checkDbLongValueSql() { sql.setNullableDbLong(null); Long v1 = sql.getNullableLong(); assertNull(v1);
// Path: src/test/java/com/github/mjdbc/test/asset/sql/DbValueSql.java // public interface DbValueSql { // // @Sql("SELECT integer_field FROM custom_types") // Integer getNullableInt(); // // @Sql("UPDATE custom_types SET integer_field = :value") // void setNullableDbInt(@Bind("value") @Nullable DbInt value); // // // @Sql("SELECT long_field FROM custom_types") // Long getNullableLong(); // // @Sql("UPDATE custom_types SET long_field = :value") // void setNullableDbLong(@Bind("value") @Nullable DbLong value); // // // @Sql("SELECT varchar_field FROM custom_types") // String getNullableString(); // // @Sql("UPDATE custom_types SET varchar_field = :value") // void setNullableDbString(@Bind("value") @Nullable DbString value); // // // @Sql("SELECT timestamp_field FROM custom_types") // Timestamp getNullableTimestamp(); // // @Sql("UPDATE custom_types SET timestamp_field = :value") // void setNullableDbTimestamp(@Bind("value") @Nullable DbTimestamp value); // } // // Path: src/test/java/com/github/mjdbc/test/asset/types/DbIntValue.java // public class DbIntValue extends AbstractDbInt { // protected int value; // // public DbIntValue(int value) { // this.value = value; // } // // public final int getDbValue() { // return value; // } // // public String toString() { // return getClass().getSimpleName() + "[" + value + "]"; // } // } // // Path: src/test/java/com/github/mjdbc/test/asset/types/DbLongValue.java // public class DbLongValue extends AbstractDbLong { // protected long value; // // public DbLongValue(int value) { // this.value = value; // } // // public final long getDbValue() { // return value; // } // // public String toString() { // return getClass().getSimpleName() + "[" + value + "]"; // } // } // Path: src/test/java/com/github/mjdbc/test/DbValuesSqlTest.java import com.github.mjdbc.test.asset.sql.DbValueSql; import com.github.mjdbc.test.asset.types.DbIntValue; import com.github.mjdbc.test.asset.types.DbLongValue; import java.sql.Timestamp; import org.junit.Before; import org.junit.Test; package com.github.mjdbc.test; /** * Tests for DbValue (Int,Long..) support. */ public class DbValuesSqlTest extends DbTest { private DbValueSql sql; public DbValuesSqlTest() { super("types"); } @Before public void setUp() { super.setUp(); sql = db.attachSql(DbValueSql.class); } @Test public void checkDbIntValueSql() { sql.setNullableDbInt(null); Integer v1 = sql.getNullableInt(); assertNull(v1); sql.setNullableDbInt(new DbIntValue(1)); Integer v2 = sql.getNullableInt(); assertEquals(new Integer(1), v2); } @Test public void checkDbLongValueSql() { sql.setNullableDbLong(null); Long v1 = sql.getNullableLong(); assertNull(v1);
sql.setNullableDbLong(new DbLongValue(1));
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/model/error/NonFinalMapperBean.java // public class NonFinalMapperBean { // // @Mapper // public static DbMapper<NonFinalMapperBean> M = (r) -> new NonFinalMapperBean(); // // }
import com.github.mjdbc.Sql; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.error.NonFinalMapperBean;
package com.github.mjdbc.test.asset.sql.error; public interface NonFinalMapperBeanSql { @Sql("SELECT 1")
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/model/error/NonFinalMapperBean.java // public class NonFinalMapperBean { // // @Mapper // public static DbMapper<NonFinalMapperBean> M = (r) -> new NonFinalMapperBean(); // // } // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java import com.github.mjdbc.Sql; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.error.NonFinalMapperBean; package com.github.mjdbc.test.asset.sql.error; public interface NonFinalMapperBeanSql { @Sql("SELECT 1")
NonFinalMapperBean select();
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/DbAttachSqlTest.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/BeanWithStaticFieldMapperSql.java // public interface BeanWithStaticFieldMapperSql { // // @Sql("SELECT 1") // BeanWithStaticFieldMapper select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptyQuerySql.java // public interface EmptyQuerySql { // // @Sql // void updateFirstNameWithReader(); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptySql.java // public interface EmptySql { // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/BeanWithNullMapperSql.java // public interface BeanWithNullMapperSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/DuplicateParametersSql.java // public interface DuplicateParametersSql { // // @Sql("SELECT login FROM users WHERE id = :val AND login = :val") // void update(@Bind("val") UserId id, @Bind("val") String login); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/IllegalParametersSql3.java // public interface IllegalParametersSql3 { // // @Sql("SELECT login FROM users WHERE id = :?val") // void update(@Bind("?val") UserId id); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java // public interface NonFinalMapperBeanSql { // // @Sql("SELECT 1") // NonFinalMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java // public interface NonPublicMapperBeanSql { // // @Sql("SELECT 1") // NonPublicMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonStaticMapperBeanSql.java // public interface NonStaticMapperBeanSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/UnboundParameterSql.java // public interface UnboundParameterSql { // // @Sql("SELECT 1") // void update(@Bind("p") Class c); // }
import com.github.mjdbc.DbImpl; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.ValidBean; import com.github.mjdbc.test.asset.model.error.MultipleMappersBean; import com.github.mjdbc.test.asset.sql.BeanWithStaticFieldMapperSql; import com.github.mjdbc.test.asset.sql.EmptyQuerySql; import com.github.mjdbc.test.asset.sql.EmptySql; import com.github.mjdbc.test.asset.sql.ValidBeansSql; import com.github.mjdbc.test.asset.sql.error.BeanWithNullMapperSql; import com.github.mjdbc.test.asset.sql.error.DuplicateParametersSql; import com.github.mjdbc.test.asset.sql.error.FakeGettersBeanSql; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql1; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql2; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql3; import com.github.mjdbc.test.asset.sql.error.MissedParameterSql; import com.github.mjdbc.test.asset.sql.error.MultipleMappersBean1Sql; import com.github.mjdbc.test.asset.sql.error.NonFinalMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonPublicMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonStaticMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.UnboundBeanParameterSql; import com.github.mjdbc.test.asset.sql.error.UnboundParameterSql; import com.github.mjdbc.test.asset.sql.error.WildcardParametrizedReturnTypeSql; import org.junit.Test;
package com.github.mjdbc.test; /** * Tests for Db::attachSql method. */ public class DbAttachSqlTest extends DbTest { /** * Check that empty Sql interface is OK. */ @Test public void sqlInterfaceWithNoMethodsIsOK() {
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/BeanWithStaticFieldMapperSql.java // public interface BeanWithStaticFieldMapperSql { // // @Sql("SELECT 1") // BeanWithStaticFieldMapper select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptyQuerySql.java // public interface EmptyQuerySql { // // @Sql // void updateFirstNameWithReader(); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptySql.java // public interface EmptySql { // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/BeanWithNullMapperSql.java // public interface BeanWithNullMapperSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/DuplicateParametersSql.java // public interface DuplicateParametersSql { // // @Sql("SELECT login FROM users WHERE id = :val AND login = :val") // void update(@Bind("val") UserId id, @Bind("val") String login); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/IllegalParametersSql3.java // public interface IllegalParametersSql3 { // // @Sql("SELECT login FROM users WHERE id = :?val") // void update(@Bind("?val") UserId id); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java // public interface NonFinalMapperBeanSql { // // @Sql("SELECT 1") // NonFinalMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java // public interface NonPublicMapperBeanSql { // // @Sql("SELECT 1") // NonPublicMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonStaticMapperBeanSql.java // public interface NonStaticMapperBeanSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/UnboundParameterSql.java // public interface UnboundParameterSql { // // @Sql("SELECT 1") // void update(@Bind("p") Class c); // } // Path: src/test/java/com/github/mjdbc/test/DbAttachSqlTest.java import com.github.mjdbc.DbImpl; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.ValidBean; import com.github.mjdbc.test.asset.model.error.MultipleMappersBean; import com.github.mjdbc.test.asset.sql.BeanWithStaticFieldMapperSql; import com.github.mjdbc.test.asset.sql.EmptyQuerySql; import com.github.mjdbc.test.asset.sql.EmptySql; import com.github.mjdbc.test.asset.sql.ValidBeansSql; import com.github.mjdbc.test.asset.sql.error.BeanWithNullMapperSql; import com.github.mjdbc.test.asset.sql.error.DuplicateParametersSql; import com.github.mjdbc.test.asset.sql.error.FakeGettersBeanSql; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql1; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql2; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql3; import com.github.mjdbc.test.asset.sql.error.MissedParameterSql; import com.github.mjdbc.test.asset.sql.error.MultipleMappersBean1Sql; import com.github.mjdbc.test.asset.sql.error.NonFinalMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonPublicMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonStaticMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.UnboundBeanParameterSql; import com.github.mjdbc.test.asset.sql.error.UnboundParameterSql; import com.github.mjdbc.test.asset.sql.error.WildcardParametrizedReturnTypeSql; import org.junit.Test; package com.github.mjdbc.test; /** * Tests for Db::attachSql method. */ public class DbAttachSqlTest extends DbTest { /** * Check that empty Sql interface is OK. */ @Test public void sqlInterfaceWithNoMethodsIsOK() {
EmptySql sql = db.attachSql(EmptySql.class);
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/DbAttachSqlTest.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/BeanWithStaticFieldMapperSql.java // public interface BeanWithStaticFieldMapperSql { // // @Sql("SELECT 1") // BeanWithStaticFieldMapper select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptyQuerySql.java // public interface EmptyQuerySql { // // @Sql // void updateFirstNameWithReader(); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptySql.java // public interface EmptySql { // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/BeanWithNullMapperSql.java // public interface BeanWithNullMapperSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/DuplicateParametersSql.java // public interface DuplicateParametersSql { // // @Sql("SELECT login FROM users WHERE id = :val AND login = :val") // void update(@Bind("val") UserId id, @Bind("val") String login); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/IllegalParametersSql3.java // public interface IllegalParametersSql3 { // // @Sql("SELECT login FROM users WHERE id = :?val") // void update(@Bind("?val") UserId id); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java // public interface NonFinalMapperBeanSql { // // @Sql("SELECT 1") // NonFinalMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java // public interface NonPublicMapperBeanSql { // // @Sql("SELECT 1") // NonPublicMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonStaticMapperBeanSql.java // public interface NonStaticMapperBeanSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/UnboundParameterSql.java // public interface UnboundParameterSql { // // @Sql("SELECT 1") // void update(@Bind("p") Class c); // }
import com.github.mjdbc.DbImpl; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.ValidBean; import com.github.mjdbc.test.asset.model.error.MultipleMappersBean; import com.github.mjdbc.test.asset.sql.BeanWithStaticFieldMapperSql; import com.github.mjdbc.test.asset.sql.EmptyQuerySql; import com.github.mjdbc.test.asset.sql.EmptySql; import com.github.mjdbc.test.asset.sql.ValidBeansSql; import com.github.mjdbc.test.asset.sql.error.BeanWithNullMapperSql; import com.github.mjdbc.test.asset.sql.error.DuplicateParametersSql; import com.github.mjdbc.test.asset.sql.error.FakeGettersBeanSql; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql1; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql2; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql3; import com.github.mjdbc.test.asset.sql.error.MissedParameterSql; import com.github.mjdbc.test.asset.sql.error.MultipleMappersBean1Sql; import com.github.mjdbc.test.asset.sql.error.NonFinalMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonPublicMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonStaticMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.UnboundBeanParameterSql; import com.github.mjdbc.test.asset.sql.error.UnboundParameterSql; import com.github.mjdbc.test.asset.sql.error.WildcardParametrizedReturnTypeSql; import org.junit.Test;
package com.github.mjdbc.test; /** * Tests for Db::attachSql method. */ public class DbAttachSqlTest extends DbTest { /** * Check that empty Sql interface is OK. */ @Test public void sqlInterfaceWithNoMethodsIsOK() { EmptySql sql = db.attachSql(EmptySql.class); assertNotNull(sql); } /** * Check that attach of class triggers IllegalArgumentException. */ @Test(expected = IllegalArgumentException.class) public void attachClassInstanceThrowsException() { db.attachSql(String.class); } /** * Check that empty Sql method triggers IllegalArgumentException. */ @Test(expected = IllegalArgumentException.class) public void emptySqlQueryThrowsException() {
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/BeanWithStaticFieldMapperSql.java // public interface BeanWithStaticFieldMapperSql { // // @Sql("SELECT 1") // BeanWithStaticFieldMapper select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptyQuerySql.java // public interface EmptyQuerySql { // // @Sql // void updateFirstNameWithReader(); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptySql.java // public interface EmptySql { // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/BeanWithNullMapperSql.java // public interface BeanWithNullMapperSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/DuplicateParametersSql.java // public interface DuplicateParametersSql { // // @Sql("SELECT login FROM users WHERE id = :val AND login = :val") // void update(@Bind("val") UserId id, @Bind("val") String login); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/IllegalParametersSql3.java // public interface IllegalParametersSql3 { // // @Sql("SELECT login FROM users WHERE id = :?val") // void update(@Bind("?val") UserId id); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java // public interface NonFinalMapperBeanSql { // // @Sql("SELECT 1") // NonFinalMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java // public interface NonPublicMapperBeanSql { // // @Sql("SELECT 1") // NonPublicMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonStaticMapperBeanSql.java // public interface NonStaticMapperBeanSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/UnboundParameterSql.java // public interface UnboundParameterSql { // // @Sql("SELECT 1") // void update(@Bind("p") Class c); // } // Path: src/test/java/com/github/mjdbc/test/DbAttachSqlTest.java import com.github.mjdbc.DbImpl; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.ValidBean; import com.github.mjdbc.test.asset.model.error.MultipleMappersBean; import com.github.mjdbc.test.asset.sql.BeanWithStaticFieldMapperSql; import com.github.mjdbc.test.asset.sql.EmptyQuerySql; import com.github.mjdbc.test.asset.sql.EmptySql; import com.github.mjdbc.test.asset.sql.ValidBeansSql; import com.github.mjdbc.test.asset.sql.error.BeanWithNullMapperSql; import com.github.mjdbc.test.asset.sql.error.DuplicateParametersSql; import com.github.mjdbc.test.asset.sql.error.FakeGettersBeanSql; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql1; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql2; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql3; import com.github.mjdbc.test.asset.sql.error.MissedParameterSql; import com.github.mjdbc.test.asset.sql.error.MultipleMappersBean1Sql; import com.github.mjdbc.test.asset.sql.error.NonFinalMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonPublicMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonStaticMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.UnboundBeanParameterSql; import com.github.mjdbc.test.asset.sql.error.UnboundParameterSql; import com.github.mjdbc.test.asset.sql.error.WildcardParametrizedReturnTypeSql; import org.junit.Test; package com.github.mjdbc.test; /** * Tests for Db::attachSql method. */ public class DbAttachSqlTest extends DbTest { /** * Check that empty Sql interface is OK. */ @Test public void sqlInterfaceWithNoMethodsIsOK() { EmptySql sql = db.attachSql(EmptySql.class); assertNotNull(sql); } /** * Check that attach of class triggers IllegalArgumentException. */ @Test(expected = IllegalArgumentException.class) public void attachClassInstanceThrowsException() { db.attachSql(String.class); } /** * Check that empty Sql method triggers IllegalArgumentException. */ @Test(expected = IllegalArgumentException.class) public void emptySqlQueryThrowsException() {
db.attachSql(EmptyQuerySql.class);
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/DbAttachSqlTest.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/BeanWithStaticFieldMapperSql.java // public interface BeanWithStaticFieldMapperSql { // // @Sql("SELECT 1") // BeanWithStaticFieldMapper select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptyQuerySql.java // public interface EmptyQuerySql { // // @Sql // void updateFirstNameWithReader(); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptySql.java // public interface EmptySql { // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/BeanWithNullMapperSql.java // public interface BeanWithNullMapperSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/DuplicateParametersSql.java // public interface DuplicateParametersSql { // // @Sql("SELECT login FROM users WHERE id = :val AND login = :val") // void update(@Bind("val") UserId id, @Bind("val") String login); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/IllegalParametersSql3.java // public interface IllegalParametersSql3 { // // @Sql("SELECT login FROM users WHERE id = :?val") // void update(@Bind("?val") UserId id); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java // public interface NonFinalMapperBeanSql { // // @Sql("SELECT 1") // NonFinalMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java // public interface NonPublicMapperBeanSql { // // @Sql("SELECT 1") // NonPublicMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonStaticMapperBeanSql.java // public interface NonStaticMapperBeanSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/UnboundParameterSql.java // public interface UnboundParameterSql { // // @Sql("SELECT 1") // void update(@Bind("p") Class c); // }
import com.github.mjdbc.DbImpl; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.ValidBean; import com.github.mjdbc.test.asset.model.error.MultipleMappersBean; import com.github.mjdbc.test.asset.sql.BeanWithStaticFieldMapperSql; import com.github.mjdbc.test.asset.sql.EmptyQuerySql; import com.github.mjdbc.test.asset.sql.EmptySql; import com.github.mjdbc.test.asset.sql.ValidBeansSql; import com.github.mjdbc.test.asset.sql.error.BeanWithNullMapperSql; import com.github.mjdbc.test.asset.sql.error.DuplicateParametersSql; import com.github.mjdbc.test.asset.sql.error.FakeGettersBeanSql; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql1; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql2; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql3; import com.github.mjdbc.test.asset.sql.error.MissedParameterSql; import com.github.mjdbc.test.asset.sql.error.MultipleMappersBean1Sql; import com.github.mjdbc.test.asset.sql.error.NonFinalMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonPublicMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonStaticMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.UnboundBeanParameterSql; import com.github.mjdbc.test.asset.sql.error.UnboundParameterSql; import com.github.mjdbc.test.asset.sql.error.WildcardParametrizedReturnTypeSql; import org.junit.Test;
/** * Check that missed Sql bean parameter triggers IllegalArgumentException. */ @Test(expected = IllegalArgumentException.class) public void missedBeanParameterThrowsException() { db.attachSql(MissedParameterSql.class); } /** * Check that unbound parameter type in Sql triggers IllegalArgumentException. */ @Test(expected = IllegalArgumentException.class) public void unboundParameterThrowsException() { db.attachSql(UnboundParameterSql.class); } /** * Check that unbound bean parameter type in Sql triggers IllegalArgumentException. */ @Test(expected = IllegalArgumentException.class) public void unboundBeanParameterThrowsException() { db.attachSql(UnboundBeanParameterSql.class); } /** * Check that duplicate parameter names in @Bind triggers IllegalArgumentException. */ @Test(expected = IllegalArgumentException.class) public void duplicateParameterNamesThrowsException() {
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/BeanWithStaticFieldMapperSql.java // public interface BeanWithStaticFieldMapperSql { // // @Sql("SELECT 1") // BeanWithStaticFieldMapper select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptyQuerySql.java // public interface EmptyQuerySql { // // @Sql // void updateFirstNameWithReader(); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptySql.java // public interface EmptySql { // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/BeanWithNullMapperSql.java // public interface BeanWithNullMapperSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/DuplicateParametersSql.java // public interface DuplicateParametersSql { // // @Sql("SELECT login FROM users WHERE id = :val AND login = :val") // void update(@Bind("val") UserId id, @Bind("val") String login); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/IllegalParametersSql3.java // public interface IllegalParametersSql3 { // // @Sql("SELECT login FROM users WHERE id = :?val") // void update(@Bind("?val") UserId id); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java // public interface NonFinalMapperBeanSql { // // @Sql("SELECT 1") // NonFinalMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java // public interface NonPublicMapperBeanSql { // // @Sql("SELECT 1") // NonPublicMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonStaticMapperBeanSql.java // public interface NonStaticMapperBeanSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/UnboundParameterSql.java // public interface UnboundParameterSql { // // @Sql("SELECT 1") // void update(@Bind("p") Class c); // } // Path: src/test/java/com/github/mjdbc/test/DbAttachSqlTest.java import com.github.mjdbc.DbImpl; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.ValidBean; import com.github.mjdbc.test.asset.model.error.MultipleMappersBean; import com.github.mjdbc.test.asset.sql.BeanWithStaticFieldMapperSql; import com.github.mjdbc.test.asset.sql.EmptyQuerySql; import com.github.mjdbc.test.asset.sql.EmptySql; import com.github.mjdbc.test.asset.sql.ValidBeansSql; import com.github.mjdbc.test.asset.sql.error.BeanWithNullMapperSql; import com.github.mjdbc.test.asset.sql.error.DuplicateParametersSql; import com.github.mjdbc.test.asset.sql.error.FakeGettersBeanSql; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql1; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql2; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql3; import com.github.mjdbc.test.asset.sql.error.MissedParameterSql; import com.github.mjdbc.test.asset.sql.error.MultipleMappersBean1Sql; import com.github.mjdbc.test.asset.sql.error.NonFinalMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonPublicMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonStaticMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.UnboundBeanParameterSql; import com.github.mjdbc.test.asset.sql.error.UnboundParameterSql; import com.github.mjdbc.test.asset.sql.error.WildcardParametrizedReturnTypeSql; import org.junit.Test; /** * Check that missed Sql bean parameter triggers IllegalArgumentException. */ @Test(expected = IllegalArgumentException.class) public void missedBeanParameterThrowsException() { db.attachSql(MissedParameterSql.class); } /** * Check that unbound parameter type in Sql triggers IllegalArgumentException. */ @Test(expected = IllegalArgumentException.class) public void unboundParameterThrowsException() { db.attachSql(UnboundParameterSql.class); } /** * Check that unbound bean parameter type in Sql triggers IllegalArgumentException. */ @Test(expected = IllegalArgumentException.class) public void unboundBeanParameterThrowsException() { db.attachSql(UnboundBeanParameterSql.class); } /** * Check that duplicate parameter names in @Bind triggers IllegalArgumentException. */ @Test(expected = IllegalArgumentException.class) public void duplicateParameterNamesThrowsException() {
db.attachSql(DuplicateParametersSql.class);
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/DbAttachSqlTest.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/BeanWithStaticFieldMapperSql.java // public interface BeanWithStaticFieldMapperSql { // // @Sql("SELECT 1") // BeanWithStaticFieldMapper select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptyQuerySql.java // public interface EmptyQuerySql { // // @Sql // void updateFirstNameWithReader(); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptySql.java // public interface EmptySql { // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/BeanWithNullMapperSql.java // public interface BeanWithNullMapperSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/DuplicateParametersSql.java // public interface DuplicateParametersSql { // // @Sql("SELECT login FROM users WHERE id = :val AND login = :val") // void update(@Bind("val") UserId id, @Bind("val") String login); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/IllegalParametersSql3.java // public interface IllegalParametersSql3 { // // @Sql("SELECT login FROM users WHERE id = :?val") // void update(@Bind("?val") UserId id); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java // public interface NonFinalMapperBeanSql { // // @Sql("SELECT 1") // NonFinalMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java // public interface NonPublicMapperBeanSql { // // @Sql("SELECT 1") // NonPublicMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonStaticMapperBeanSql.java // public interface NonStaticMapperBeanSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/UnboundParameterSql.java // public interface UnboundParameterSql { // // @Sql("SELECT 1") // void update(@Bind("p") Class c); // }
import com.github.mjdbc.DbImpl; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.ValidBean; import com.github.mjdbc.test.asset.model.error.MultipleMappersBean; import com.github.mjdbc.test.asset.sql.BeanWithStaticFieldMapperSql; import com.github.mjdbc.test.asset.sql.EmptyQuerySql; import com.github.mjdbc.test.asset.sql.EmptySql; import com.github.mjdbc.test.asset.sql.ValidBeansSql; import com.github.mjdbc.test.asset.sql.error.BeanWithNullMapperSql; import com.github.mjdbc.test.asset.sql.error.DuplicateParametersSql; import com.github.mjdbc.test.asset.sql.error.FakeGettersBeanSql; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql1; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql2; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql3; import com.github.mjdbc.test.asset.sql.error.MissedParameterSql; import com.github.mjdbc.test.asset.sql.error.MultipleMappersBean1Sql; import com.github.mjdbc.test.asset.sql.error.NonFinalMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonPublicMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonStaticMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.UnboundBeanParameterSql; import com.github.mjdbc.test.asset.sql.error.UnboundParameterSql; import com.github.mjdbc.test.asset.sql.error.WildcardParametrizedReturnTypeSql; import org.junit.Test;
*/ @Test(expected = IllegalArgumentException.class) public void unboundBeanParameterThrowsException() { db.attachSql(UnboundBeanParameterSql.class); } /** * Check that duplicate parameter names in @Bind triggers IllegalArgumentException. */ @Test(expected = IllegalArgumentException.class) public void duplicateParameterNamesThrowsException() { db.attachSql(DuplicateParametersSql.class); } /** * Check that parameter names are checked to be valid Java identifiers */ @Test public void illegalNamesThrowsException() { try { db.attachSql(IllegalParametersSql1.class); fail(); } catch (IllegalArgumentException ignored) { } try { db.attachSql(IllegalParametersSql2.class); fail(); } catch (IllegalArgumentException ignored) { } try {
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/BeanWithStaticFieldMapperSql.java // public interface BeanWithStaticFieldMapperSql { // // @Sql("SELECT 1") // BeanWithStaticFieldMapper select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptyQuerySql.java // public interface EmptyQuerySql { // // @Sql // void updateFirstNameWithReader(); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptySql.java // public interface EmptySql { // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/BeanWithNullMapperSql.java // public interface BeanWithNullMapperSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/DuplicateParametersSql.java // public interface DuplicateParametersSql { // // @Sql("SELECT login FROM users WHERE id = :val AND login = :val") // void update(@Bind("val") UserId id, @Bind("val") String login); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/IllegalParametersSql3.java // public interface IllegalParametersSql3 { // // @Sql("SELECT login FROM users WHERE id = :?val") // void update(@Bind("?val") UserId id); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java // public interface NonFinalMapperBeanSql { // // @Sql("SELECT 1") // NonFinalMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java // public interface NonPublicMapperBeanSql { // // @Sql("SELECT 1") // NonPublicMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonStaticMapperBeanSql.java // public interface NonStaticMapperBeanSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/UnboundParameterSql.java // public interface UnboundParameterSql { // // @Sql("SELECT 1") // void update(@Bind("p") Class c); // } // Path: src/test/java/com/github/mjdbc/test/DbAttachSqlTest.java import com.github.mjdbc.DbImpl; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.ValidBean; import com.github.mjdbc.test.asset.model.error.MultipleMappersBean; import com.github.mjdbc.test.asset.sql.BeanWithStaticFieldMapperSql; import com.github.mjdbc.test.asset.sql.EmptyQuerySql; import com.github.mjdbc.test.asset.sql.EmptySql; import com.github.mjdbc.test.asset.sql.ValidBeansSql; import com.github.mjdbc.test.asset.sql.error.BeanWithNullMapperSql; import com.github.mjdbc.test.asset.sql.error.DuplicateParametersSql; import com.github.mjdbc.test.asset.sql.error.FakeGettersBeanSql; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql1; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql2; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql3; import com.github.mjdbc.test.asset.sql.error.MissedParameterSql; import com.github.mjdbc.test.asset.sql.error.MultipleMappersBean1Sql; import com.github.mjdbc.test.asset.sql.error.NonFinalMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonPublicMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonStaticMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.UnboundBeanParameterSql; import com.github.mjdbc.test.asset.sql.error.UnboundParameterSql; import com.github.mjdbc.test.asset.sql.error.WildcardParametrizedReturnTypeSql; import org.junit.Test; */ @Test(expected = IllegalArgumentException.class) public void unboundBeanParameterThrowsException() { db.attachSql(UnboundBeanParameterSql.class); } /** * Check that duplicate parameter names in @Bind triggers IllegalArgumentException. */ @Test(expected = IllegalArgumentException.class) public void duplicateParameterNamesThrowsException() { db.attachSql(DuplicateParametersSql.class); } /** * Check that parameter names are checked to be valid Java identifiers */ @Test public void illegalNamesThrowsException() { try { db.attachSql(IllegalParametersSql1.class); fail(); } catch (IllegalArgumentException ignored) { } try { db.attachSql(IllegalParametersSql2.class); fail(); } catch (IllegalArgumentException ignored) { } try {
db.attachSql(IllegalParametersSql3.class);
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/DbAttachSqlTest.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/BeanWithStaticFieldMapperSql.java // public interface BeanWithStaticFieldMapperSql { // // @Sql("SELECT 1") // BeanWithStaticFieldMapper select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptyQuerySql.java // public interface EmptyQuerySql { // // @Sql // void updateFirstNameWithReader(); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptySql.java // public interface EmptySql { // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/BeanWithNullMapperSql.java // public interface BeanWithNullMapperSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/DuplicateParametersSql.java // public interface DuplicateParametersSql { // // @Sql("SELECT login FROM users WHERE id = :val AND login = :val") // void update(@Bind("val") UserId id, @Bind("val") String login); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/IllegalParametersSql3.java // public interface IllegalParametersSql3 { // // @Sql("SELECT login FROM users WHERE id = :?val") // void update(@Bind("?val") UserId id); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java // public interface NonFinalMapperBeanSql { // // @Sql("SELECT 1") // NonFinalMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java // public interface NonPublicMapperBeanSql { // // @Sql("SELECT 1") // NonPublicMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonStaticMapperBeanSql.java // public interface NonStaticMapperBeanSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/UnboundParameterSql.java // public interface UnboundParameterSql { // // @Sql("SELECT 1") // void update(@Bind("p") Class c); // }
import com.github.mjdbc.DbImpl; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.ValidBean; import com.github.mjdbc.test.asset.model.error.MultipleMappersBean; import com.github.mjdbc.test.asset.sql.BeanWithStaticFieldMapperSql; import com.github.mjdbc.test.asset.sql.EmptyQuerySql; import com.github.mjdbc.test.asset.sql.EmptySql; import com.github.mjdbc.test.asset.sql.ValidBeansSql; import com.github.mjdbc.test.asset.sql.error.BeanWithNullMapperSql; import com.github.mjdbc.test.asset.sql.error.DuplicateParametersSql; import com.github.mjdbc.test.asset.sql.error.FakeGettersBeanSql; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql1; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql2; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql3; import com.github.mjdbc.test.asset.sql.error.MissedParameterSql; import com.github.mjdbc.test.asset.sql.error.MultipleMappersBean1Sql; import com.github.mjdbc.test.asset.sql.error.NonFinalMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonPublicMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonStaticMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.UnboundBeanParameterSql; import com.github.mjdbc.test.asset.sql.error.UnboundParameterSql; import com.github.mjdbc.test.asset.sql.error.WildcardParametrizedReturnTypeSql; import org.junit.Test;
} /** * Check that multiple mapper variants triggers error */ @Test(expected = IllegalArgumentException.class) public void multipleMappersThrowsException1() { db.attachSql(MultipleMappersBean1Sql.class); } /** * Check that manual mapper registration does not trigger error for a bean with multiple mappers */ @Test public void multipleMappersThrowsException3() { db.registerMapper(MultipleMappersBean.class, MultipleMappersBean.SOME_MAPPER1); MultipleMappersBean bean = db.attachSql(MultipleMappersBean1Sql.class).selectABean(); assertEquals(1, bean.value); } @Test(expected = IllegalArgumentException.class) public void fakeGettersThrowException() { db.attachSql(FakeGettersBeanSql.class); } @Test public void checkBeanWithStaticFieldMapperByAnnotation() { DbImpl dbImpl = (DbImpl) this.db;
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/BeanWithStaticFieldMapperSql.java // public interface BeanWithStaticFieldMapperSql { // // @Sql("SELECT 1") // BeanWithStaticFieldMapper select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptyQuerySql.java // public interface EmptyQuerySql { // // @Sql // void updateFirstNameWithReader(); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptySql.java // public interface EmptySql { // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/BeanWithNullMapperSql.java // public interface BeanWithNullMapperSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/DuplicateParametersSql.java // public interface DuplicateParametersSql { // // @Sql("SELECT login FROM users WHERE id = :val AND login = :val") // void update(@Bind("val") UserId id, @Bind("val") String login); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/IllegalParametersSql3.java // public interface IllegalParametersSql3 { // // @Sql("SELECT login FROM users WHERE id = :?val") // void update(@Bind("?val") UserId id); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java // public interface NonFinalMapperBeanSql { // // @Sql("SELECT 1") // NonFinalMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java // public interface NonPublicMapperBeanSql { // // @Sql("SELECT 1") // NonPublicMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonStaticMapperBeanSql.java // public interface NonStaticMapperBeanSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/UnboundParameterSql.java // public interface UnboundParameterSql { // // @Sql("SELECT 1") // void update(@Bind("p") Class c); // } // Path: src/test/java/com/github/mjdbc/test/DbAttachSqlTest.java import com.github.mjdbc.DbImpl; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.ValidBean; import com.github.mjdbc.test.asset.model.error.MultipleMappersBean; import com.github.mjdbc.test.asset.sql.BeanWithStaticFieldMapperSql; import com.github.mjdbc.test.asset.sql.EmptyQuerySql; import com.github.mjdbc.test.asset.sql.EmptySql; import com.github.mjdbc.test.asset.sql.ValidBeansSql; import com.github.mjdbc.test.asset.sql.error.BeanWithNullMapperSql; import com.github.mjdbc.test.asset.sql.error.DuplicateParametersSql; import com.github.mjdbc.test.asset.sql.error.FakeGettersBeanSql; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql1; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql2; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql3; import com.github.mjdbc.test.asset.sql.error.MissedParameterSql; import com.github.mjdbc.test.asset.sql.error.MultipleMappersBean1Sql; import com.github.mjdbc.test.asset.sql.error.NonFinalMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonPublicMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonStaticMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.UnboundBeanParameterSql; import com.github.mjdbc.test.asset.sql.error.UnboundParameterSql; import com.github.mjdbc.test.asset.sql.error.WildcardParametrizedReturnTypeSql; import org.junit.Test; } /** * Check that multiple mapper variants triggers error */ @Test(expected = IllegalArgumentException.class) public void multipleMappersThrowsException1() { db.attachSql(MultipleMappersBean1Sql.class); } /** * Check that manual mapper registration does not trigger error for a bean with multiple mappers */ @Test public void multipleMappersThrowsException3() { db.registerMapper(MultipleMappersBean.class, MultipleMappersBean.SOME_MAPPER1); MultipleMappersBean bean = db.attachSql(MultipleMappersBean1Sql.class).selectABean(); assertEquals(1, bean.value); } @Test(expected = IllegalArgumentException.class) public void fakeGettersThrowException() { db.attachSql(FakeGettersBeanSql.class); } @Test public void checkBeanWithStaticFieldMapperByAnnotation() { DbImpl dbImpl = (DbImpl) this.db;
assertNull(dbImpl.getRegisteredMapperByType(BeanWithStaticFieldMapper.class));
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/DbAttachSqlTest.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/BeanWithStaticFieldMapperSql.java // public interface BeanWithStaticFieldMapperSql { // // @Sql("SELECT 1") // BeanWithStaticFieldMapper select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptyQuerySql.java // public interface EmptyQuerySql { // // @Sql // void updateFirstNameWithReader(); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptySql.java // public interface EmptySql { // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/BeanWithNullMapperSql.java // public interface BeanWithNullMapperSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/DuplicateParametersSql.java // public interface DuplicateParametersSql { // // @Sql("SELECT login FROM users WHERE id = :val AND login = :val") // void update(@Bind("val") UserId id, @Bind("val") String login); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/IllegalParametersSql3.java // public interface IllegalParametersSql3 { // // @Sql("SELECT login FROM users WHERE id = :?val") // void update(@Bind("?val") UserId id); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java // public interface NonFinalMapperBeanSql { // // @Sql("SELECT 1") // NonFinalMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java // public interface NonPublicMapperBeanSql { // // @Sql("SELECT 1") // NonPublicMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonStaticMapperBeanSql.java // public interface NonStaticMapperBeanSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/UnboundParameterSql.java // public interface UnboundParameterSql { // // @Sql("SELECT 1") // void update(@Bind("p") Class c); // }
import com.github.mjdbc.DbImpl; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.ValidBean; import com.github.mjdbc.test.asset.model.error.MultipleMappersBean; import com.github.mjdbc.test.asset.sql.BeanWithStaticFieldMapperSql; import com.github.mjdbc.test.asset.sql.EmptyQuerySql; import com.github.mjdbc.test.asset.sql.EmptySql; import com.github.mjdbc.test.asset.sql.ValidBeansSql; import com.github.mjdbc.test.asset.sql.error.BeanWithNullMapperSql; import com.github.mjdbc.test.asset.sql.error.DuplicateParametersSql; import com.github.mjdbc.test.asset.sql.error.FakeGettersBeanSql; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql1; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql2; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql3; import com.github.mjdbc.test.asset.sql.error.MissedParameterSql; import com.github.mjdbc.test.asset.sql.error.MultipleMappersBean1Sql; import com.github.mjdbc.test.asset.sql.error.NonFinalMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonPublicMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonStaticMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.UnboundBeanParameterSql; import com.github.mjdbc.test.asset.sql.error.UnboundParameterSql; import com.github.mjdbc.test.asset.sql.error.WildcardParametrizedReturnTypeSql; import org.junit.Test;
/** * Check that multiple mapper variants triggers error */ @Test(expected = IllegalArgumentException.class) public void multipleMappersThrowsException1() { db.attachSql(MultipleMappersBean1Sql.class); } /** * Check that manual mapper registration does not trigger error for a bean with multiple mappers */ @Test public void multipleMappersThrowsException3() { db.registerMapper(MultipleMappersBean.class, MultipleMappersBean.SOME_MAPPER1); MultipleMappersBean bean = db.attachSql(MultipleMappersBean1Sql.class).selectABean(); assertEquals(1, bean.value); } @Test(expected = IllegalArgumentException.class) public void fakeGettersThrowException() { db.attachSql(FakeGettersBeanSql.class); } @Test public void checkBeanWithStaticFieldMapperByAnnotation() { DbImpl dbImpl = (DbImpl) this.db; assertNull(dbImpl.getRegisteredMapperByType(BeanWithStaticFieldMapper.class));
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/BeanWithStaticFieldMapperSql.java // public interface BeanWithStaticFieldMapperSql { // // @Sql("SELECT 1") // BeanWithStaticFieldMapper select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptyQuerySql.java // public interface EmptyQuerySql { // // @Sql // void updateFirstNameWithReader(); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptySql.java // public interface EmptySql { // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/BeanWithNullMapperSql.java // public interface BeanWithNullMapperSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/DuplicateParametersSql.java // public interface DuplicateParametersSql { // // @Sql("SELECT login FROM users WHERE id = :val AND login = :val") // void update(@Bind("val") UserId id, @Bind("val") String login); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/IllegalParametersSql3.java // public interface IllegalParametersSql3 { // // @Sql("SELECT login FROM users WHERE id = :?val") // void update(@Bind("?val") UserId id); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java // public interface NonFinalMapperBeanSql { // // @Sql("SELECT 1") // NonFinalMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java // public interface NonPublicMapperBeanSql { // // @Sql("SELECT 1") // NonPublicMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonStaticMapperBeanSql.java // public interface NonStaticMapperBeanSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/UnboundParameterSql.java // public interface UnboundParameterSql { // // @Sql("SELECT 1") // void update(@Bind("p") Class c); // } // Path: src/test/java/com/github/mjdbc/test/DbAttachSqlTest.java import com.github.mjdbc.DbImpl; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.ValidBean; import com.github.mjdbc.test.asset.model.error.MultipleMappersBean; import com.github.mjdbc.test.asset.sql.BeanWithStaticFieldMapperSql; import com.github.mjdbc.test.asset.sql.EmptyQuerySql; import com.github.mjdbc.test.asset.sql.EmptySql; import com.github.mjdbc.test.asset.sql.ValidBeansSql; import com.github.mjdbc.test.asset.sql.error.BeanWithNullMapperSql; import com.github.mjdbc.test.asset.sql.error.DuplicateParametersSql; import com.github.mjdbc.test.asset.sql.error.FakeGettersBeanSql; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql1; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql2; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql3; import com.github.mjdbc.test.asset.sql.error.MissedParameterSql; import com.github.mjdbc.test.asset.sql.error.MultipleMappersBean1Sql; import com.github.mjdbc.test.asset.sql.error.NonFinalMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonPublicMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonStaticMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.UnboundBeanParameterSql; import com.github.mjdbc.test.asset.sql.error.UnboundParameterSql; import com.github.mjdbc.test.asset.sql.error.WildcardParametrizedReturnTypeSql; import org.junit.Test; /** * Check that multiple mapper variants triggers error */ @Test(expected = IllegalArgumentException.class) public void multipleMappersThrowsException1() { db.attachSql(MultipleMappersBean1Sql.class); } /** * Check that manual mapper registration does not trigger error for a bean with multiple mappers */ @Test public void multipleMappersThrowsException3() { db.registerMapper(MultipleMappersBean.class, MultipleMappersBean.SOME_MAPPER1); MultipleMappersBean bean = db.attachSql(MultipleMappersBean1Sql.class).selectABean(); assertEquals(1, bean.value); } @Test(expected = IllegalArgumentException.class) public void fakeGettersThrowException() { db.attachSql(FakeGettersBeanSql.class); } @Test public void checkBeanWithStaticFieldMapperByAnnotation() { DbImpl dbImpl = (DbImpl) this.db; assertNull(dbImpl.getRegisteredMapperByType(BeanWithStaticFieldMapper.class));
this.db.attachSql(BeanWithStaticFieldMapperSql.class);
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/DbAttachSqlTest.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/BeanWithStaticFieldMapperSql.java // public interface BeanWithStaticFieldMapperSql { // // @Sql("SELECT 1") // BeanWithStaticFieldMapper select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptyQuerySql.java // public interface EmptyQuerySql { // // @Sql // void updateFirstNameWithReader(); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptySql.java // public interface EmptySql { // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/BeanWithNullMapperSql.java // public interface BeanWithNullMapperSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/DuplicateParametersSql.java // public interface DuplicateParametersSql { // // @Sql("SELECT login FROM users WHERE id = :val AND login = :val") // void update(@Bind("val") UserId id, @Bind("val") String login); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/IllegalParametersSql3.java // public interface IllegalParametersSql3 { // // @Sql("SELECT login FROM users WHERE id = :?val") // void update(@Bind("?val") UserId id); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java // public interface NonFinalMapperBeanSql { // // @Sql("SELECT 1") // NonFinalMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java // public interface NonPublicMapperBeanSql { // // @Sql("SELECT 1") // NonPublicMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonStaticMapperBeanSql.java // public interface NonStaticMapperBeanSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/UnboundParameterSql.java // public interface UnboundParameterSql { // // @Sql("SELECT 1") // void update(@Bind("p") Class c); // }
import com.github.mjdbc.DbImpl; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.ValidBean; import com.github.mjdbc.test.asset.model.error.MultipleMappersBean; import com.github.mjdbc.test.asset.sql.BeanWithStaticFieldMapperSql; import com.github.mjdbc.test.asset.sql.EmptyQuerySql; import com.github.mjdbc.test.asset.sql.EmptySql; import com.github.mjdbc.test.asset.sql.ValidBeansSql; import com.github.mjdbc.test.asset.sql.error.BeanWithNullMapperSql; import com.github.mjdbc.test.asset.sql.error.DuplicateParametersSql; import com.github.mjdbc.test.asset.sql.error.FakeGettersBeanSql; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql1; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql2; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql3; import com.github.mjdbc.test.asset.sql.error.MissedParameterSql; import com.github.mjdbc.test.asset.sql.error.MultipleMappersBean1Sql; import com.github.mjdbc.test.asset.sql.error.NonFinalMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonPublicMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonStaticMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.UnboundBeanParameterSql; import com.github.mjdbc.test.asset.sql.error.UnboundParameterSql; import com.github.mjdbc.test.asset.sql.error.WildcardParametrizedReturnTypeSql; import org.junit.Test;
db.attachSql(MultipleMappersBean1Sql.class); } /** * Check that manual mapper registration does not trigger error for a bean with multiple mappers */ @Test public void multipleMappersThrowsException3() { db.registerMapper(MultipleMappersBean.class, MultipleMappersBean.SOME_MAPPER1); MultipleMappersBean bean = db.attachSql(MultipleMappersBean1Sql.class).selectABean(); assertEquals(1, bean.value); } @Test(expected = IllegalArgumentException.class) public void fakeGettersThrowException() { db.attachSql(FakeGettersBeanSql.class); } @Test public void checkBeanWithStaticFieldMapperByAnnotation() { DbImpl dbImpl = (DbImpl) this.db; assertNull(dbImpl.getRegisteredMapperByType(BeanWithStaticFieldMapper.class)); this.db.attachSql(BeanWithStaticFieldMapperSql.class); assertNotNull(dbImpl.getRegisteredMapperByType(BeanWithStaticFieldMapper.class)); } @Test(expected = IllegalArgumentException.class) public void checkBeanNonPublicMapper() {
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/BeanWithStaticFieldMapperSql.java // public interface BeanWithStaticFieldMapperSql { // // @Sql("SELECT 1") // BeanWithStaticFieldMapper select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptyQuerySql.java // public interface EmptyQuerySql { // // @Sql // void updateFirstNameWithReader(); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptySql.java // public interface EmptySql { // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/BeanWithNullMapperSql.java // public interface BeanWithNullMapperSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/DuplicateParametersSql.java // public interface DuplicateParametersSql { // // @Sql("SELECT login FROM users WHERE id = :val AND login = :val") // void update(@Bind("val") UserId id, @Bind("val") String login); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/IllegalParametersSql3.java // public interface IllegalParametersSql3 { // // @Sql("SELECT login FROM users WHERE id = :?val") // void update(@Bind("?val") UserId id); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java // public interface NonFinalMapperBeanSql { // // @Sql("SELECT 1") // NonFinalMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java // public interface NonPublicMapperBeanSql { // // @Sql("SELECT 1") // NonPublicMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonStaticMapperBeanSql.java // public interface NonStaticMapperBeanSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/UnboundParameterSql.java // public interface UnboundParameterSql { // // @Sql("SELECT 1") // void update(@Bind("p") Class c); // } // Path: src/test/java/com/github/mjdbc/test/DbAttachSqlTest.java import com.github.mjdbc.DbImpl; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.ValidBean; import com.github.mjdbc.test.asset.model.error.MultipleMappersBean; import com.github.mjdbc.test.asset.sql.BeanWithStaticFieldMapperSql; import com.github.mjdbc.test.asset.sql.EmptyQuerySql; import com.github.mjdbc.test.asset.sql.EmptySql; import com.github.mjdbc.test.asset.sql.ValidBeansSql; import com.github.mjdbc.test.asset.sql.error.BeanWithNullMapperSql; import com.github.mjdbc.test.asset.sql.error.DuplicateParametersSql; import com.github.mjdbc.test.asset.sql.error.FakeGettersBeanSql; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql1; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql2; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql3; import com.github.mjdbc.test.asset.sql.error.MissedParameterSql; import com.github.mjdbc.test.asset.sql.error.MultipleMappersBean1Sql; import com.github.mjdbc.test.asset.sql.error.NonFinalMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonPublicMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonStaticMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.UnboundBeanParameterSql; import com.github.mjdbc.test.asset.sql.error.UnboundParameterSql; import com.github.mjdbc.test.asset.sql.error.WildcardParametrizedReturnTypeSql; import org.junit.Test; db.attachSql(MultipleMappersBean1Sql.class); } /** * Check that manual mapper registration does not trigger error for a bean with multiple mappers */ @Test public void multipleMappersThrowsException3() { db.registerMapper(MultipleMappersBean.class, MultipleMappersBean.SOME_MAPPER1); MultipleMappersBean bean = db.attachSql(MultipleMappersBean1Sql.class).selectABean(); assertEquals(1, bean.value); } @Test(expected = IllegalArgumentException.class) public void fakeGettersThrowException() { db.attachSql(FakeGettersBeanSql.class); } @Test public void checkBeanWithStaticFieldMapperByAnnotation() { DbImpl dbImpl = (DbImpl) this.db; assertNull(dbImpl.getRegisteredMapperByType(BeanWithStaticFieldMapper.class)); this.db.attachSql(BeanWithStaticFieldMapperSql.class); assertNotNull(dbImpl.getRegisteredMapperByType(BeanWithStaticFieldMapper.class)); } @Test(expected = IllegalArgumentException.class) public void checkBeanNonPublicMapper() {
db.attachSql(NonPublicMapperBeanSql.class);
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/DbAttachSqlTest.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/BeanWithStaticFieldMapperSql.java // public interface BeanWithStaticFieldMapperSql { // // @Sql("SELECT 1") // BeanWithStaticFieldMapper select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptyQuerySql.java // public interface EmptyQuerySql { // // @Sql // void updateFirstNameWithReader(); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptySql.java // public interface EmptySql { // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/BeanWithNullMapperSql.java // public interface BeanWithNullMapperSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/DuplicateParametersSql.java // public interface DuplicateParametersSql { // // @Sql("SELECT login FROM users WHERE id = :val AND login = :val") // void update(@Bind("val") UserId id, @Bind("val") String login); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/IllegalParametersSql3.java // public interface IllegalParametersSql3 { // // @Sql("SELECT login FROM users WHERE id = :?val") // void update(@Bind("?val") UserId id); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java // public interface NonFinalMapperBeanSql { // // @Sql("SELECT 1") // NonFinalMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java // public interface NonPublicMapperBeanSql { // // @Sql("SELECT 1") // NonPublicMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonStaticMapperBeanSql.java // public interface NonStaticMapperBeanSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/UnboundParameterSql.java // public interface UnboundParameterSql { // // @Sql("SELECT 1") // void update(@Bind("p") Class c); // }
import com.github.mjdbc.DbImpl; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.ValidBean; import com.github.mjdbc.test.asset.model.error.MultipleMappersBean; import com.github.mjdbc.test.asset.sql.BeanWithStaticFieldMapperSql; import com.github.mjdbc.test.asset.sql.EmptyQuerySql; import com.github.mjdbc.test.asset.sql.EmptySql; import com.github.mjdbc.test.asset.sql.ValidBeansSql; import com.github.mjdbc.test.asset.sql.error.BeanWithNullMapperSql; import com.github.mjdbc.test.asset.sql.error.DuplicateParametersSql; import com.github.mjdbc.test.asset.sql.error.FakeGettersBeanSql; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql1; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql2; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql3; import com.github.mjdbc.test.asset.sql.error.MissedParameterSql; import com.github.mjdbc.test.asset.sql.error.MultipleMappersBean1Sql; import com.github.mjdbc.test.asset.sql.error.NonFinalMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonPublicMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonStaticMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.UnboundBeanParameterSql; import com.github.mjdbc.test.asset.sql.error.UnboundParameterSql; import com.github.mjdbc.test.asset.sql.error.WildcardParametrizedReturnTypeSql; import org.junit.Test;
* Check that manual mapper registration does not trigger error for a bean with multiple mappers */ @Test public void multipleMappersThrowsException3() { db.registerMapper(MultipleMappersBean.class, MultipleMappersBean.SOME_MAPPER1); MultipleMappersBean bean = db.attachSql(MultipleMappersBean1Sql.class).selectABean(); assertEquals(1, bean.value); } @Test(expected = IllegalArgumentException.class) public void fakeGettersThrowException() { db.attachSql(FakeGettersBeanSql.class); } @Test public void checkBeanWithStaticFieldMapperByAnnotation() { DbImpl dbImpl = (DbImpl) this.db; assertNull(dbImpl.getRegisteredMapperByType(BeanWithStaticFieldMapper.class)); this.db.attachSql(BeanWithStaticFieldMapperSql.class); assertNotNull(dbImpl.getRegisteredMapperByType(BeanWithStaticFieldMapper.class)); } @Test(expected = IllegalArgumentException.class) public void checkBeanNonPublicMapper() { db.attachSql(NonPublicMapperBeanSql.class); } @Test(expected = IllegalArgumentException.class) public void checkBeanNonStaticMapper() {
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/BeanWithStaticFieldMapperSql.java // public interface BeanWithStaticFieldMapperSql { // // @Sql("SELECT 1") // BeanWithStaticFieldMapper select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptyQuerySql.java // public interface EmptyQuerySql { // // @Sql // void updateFirstNameWithReader(); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptySql.java // public interface EmptySql { // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/BeanWithNullMapperSql.java // public interface BeanWithNullMapperSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/DuplicateParametersSql.java // public interface DuplicateParametersSql { // // @Sql("SELECT login FROM users WHERE id = :val AND login = :val") // void update(@Bind("val") UserId id, @Bind("val") String login); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/IllegalParametersSql3.java // public interface IllegalParametersSql3 { // // @Sql("SELECT login FROM users WHERE id = :?val") // void update(@Bind("?val") UserId id); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java // public interface NonFinalMapperBeanSql { // // @Sql("SELECT 1") // NonFinalMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java // public interface NonPublicMapperBeanSql { // // @Sql("SELECT 1") // NonPublicMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonStaticMapperBeanSql.java // public interface NonStaticMapperBeanSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/UnboundParameterSql.java // public interface UnboundParameterSql { // // @Sql("SELECT 1") // void update(@Bind("p") Class c); // } // Path: src/test/java/com/github/mjdbc/test/DbAttachSqlTest.java import com.github.mjdbc.DbImpl; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.ValidBean; import com.github.mjdbc.test.asset.model.error.MultipleMappersBean; import com.github.mjdbc.test.asset.sql.BeanWithStaticFieldMapperSql; import com.github.mjdbc.test.asset.sql.EmptyQuerySql; import com.github.mjdbc.test.asset.sql.EmptySql; import com.github.mjdbc.test.asset.sql.ValidBeansSql; import com.github.mjdbc.test.asset.sql.error.BeanWithNullMapperSql; import com.github.mjdbc.test.asset.sql.error.DuplicateParametersSql; import com.github.mjdbc.test.asset.sql.error.FakeGettersBeanSql; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql1; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql2; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql3; import com.github.mjdbc.test.asset.sql.error.MissedParameterSql; import com.github.mjdbc.test.asset.sql.error.MultipleMappersBean1Sql; import com.github.mjdbc.test.asset.sql.error.NonFinalMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonPublicMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonStaticMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.UnboundBeanParameterSql; import com.github.mjdbc.test.asset.sql.error.UnboundParameterSql; import com.github.mjdbc.test.asset.sql.error.WildcardParametrizedReturnTypeSql; import org.junit.Test; * Check that manual mapper registration does not trigger error for a bean with multiple mappers */ @Test public void multipleMappersThrowsException3() { db.registerMapper(MultipleMappersBean.class, MultipleMappersBean.SOME_MAPPER1); MultipleMappersBean bean = db.attachSql(MultipleMappersBean1Sql.class).selectABean(); assertEquals(1, bean.value); } @Test(expected = IllegalArgumentException.class) public void fakeGettersThrowException() { db.attachSql(FakeGettersBeanSql.class); } @Test public void checkBeanWithStaticFieldMapperByAnnotation() { DbImpl dbImpl = (DbImpl) this.db; assertNull(dbImpl.getRegisteredMapperByType(BeanWithStaticFieldMapper.class)); this.db.attachSql(BeanWithStaticFieldMapperSql.class); assertNotNull(dbImpl.getRegisteredMapperByType(BeanWithStaticFieldMapper.class)); } @Test(expected = IllegalArgumentException.class) public void checkBeanNonPublicMapper() { db.attachSql(NonPublicMapperBeanSql.class); } @Test(expected = IllegalArgumentException.class) public void checkBeanNonStaticMapper() {
db.attachSql(NonStaticMapperBeanSql.class);
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/DbAttachSqlTest.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/BeanWithStaticFieldMapperSql.java // public interface BeanWithStaticFieldMapperSql { // // @Sql("SELECT 1") // BeanWithStaticFieldMapper select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptyQuerySql.java // public interface EmptyQuerySql { // // @Sql // void updateFirstNameWithReader(); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptySql.java // public interface EmptySql { // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/BeanWithNullMapperSql.java // public interface BeanWithNullMapperSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/DuplicateParametersSql.java // public interface DuplicateParametersSql { // // @Sql("SELECT login FROM users WHERE id = :val AND login = :val") // void update(@Bind("val") UserId id, @Bind("val") String login); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/IllegalParametersSql3.java // public interface IllegalParametersSql3 { // // @Sql("SELECT login FROM users WHERE id = :?val") // void update(@Bind("?val") UserId id); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java // public interface NonFinalMapperBeanSql { // // @Sql("SELECT 1") // NonFinalMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java // public interface NonPublicMapperBeanSql { // // @Sql("SELECT 1") // NonPublicMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonStaticMapperBeanSql.java // public interface NonStaticMapperBeanSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/UnboundParameterSql.java // public interface UnboundParameterSql { // // @Sql("SELECT 1") // void update(@Bind("p") Class c); // }
import com.github.mjdbc.DbImpl; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.ValidBean; import com.github.mjdbc.test.asset.model.error.MultipleMappersBean; import com.github.mjdbc.test.asset.sql.BeanWithStaticFieldMapperSql; import com.github.mjdbc.test.asset.sql.EmptyQuerySql; import com.github.mjdbc.test.asset.sql.EmptySql; import com.github.mjdbc.test.asset.sql.ValidBeansSql; import com.github.mjdbc.test.asset.sql.error.BeanWithNullMapperSql; import com.github.mjdbc.test.asset.sql.error.DuplicateParametersSql; import com.github.mjdbc.test.asset.sql.error.FakeGettersBeanSql; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql1; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql2; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql3; import com.github.mjdbc.test.asset.sql.error.MissedParameterSql; import com.github.mjdbc.test.asset.sql.error.MultipleMappersBean1Sql; import com.github.mjdbc.test.asset.sql.error.NonFinalMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonPublicMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonStaticMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.UnboundBeanParameterSql; import com.github.mjdbc.test.asset.sql.error.UnboundParameterSql; import com.github.mjdbc.test.asset.sql.error.WildcardParametrizedReturnTypeSql; import org.junit.Test;
MultipleMappersBean bean = db.attachSql(MultipleMappersBean1Sql.class).selectABean(); assertEquals(1, bean.value); } @Test(expected = IllegalArgumentException.class) public void fakeGettersThrowException() { db.attachSql(FakeGettersBeanSql.class); } @Test public void checkBeanWithStaticFieldMapperByAnnotation() { DbImpl dbImpl = (DbImpl) this.db; assertNull(dbImpl.getRegisteredMapperByType(BeanWithStaticFieldMapper.class)); this.db.attachSql(BeanWithStaticFieldMapperSql.class); assertNotNull(dbImpl.getRegisteredMapperByType(BeanWithStaticFieldMapper.class)); } @Test(expected = IllegalArgumentException.class) public void checkBeanNonPublicMapper() { db.attachSql(NonPublicMapperBeanSql.class); } @Test(expected = IllegalArgumentException.class) public void checkBeanNonStaticMapper() { db.attachSql(NonStaticMapperBeanSql.class); } @Test(expected = IllegalArgumentException.class) public void checkBeanNonFinalMapper() {
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/BeanWithStaticFieldMapperSql.java // public interface BeanWithStaticFieldMapperSql { // // @Sql("SELECT 1") // BeanWithStaticFieldMapper select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptyQuerySql.java // public interface EmptyQuerySql { // // @Sql // void updateFirstNameWithReader(); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptySql.java // public interface EmptySql { // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/BeanWithNullMapperSql.java // public interface BeanWithNullMapperSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/DuplicateParametersSql.java // public interface DuplicateParametersSql { // // @Sql("SELECT login FROM users WHERE id = :val AND login = :val") // void update(@Bind("val") UserId id, @Bind("val") String login); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/IllegalParametersSql3.java // public interface IllegalParametersSql3 { // // @Sql("SELECT login FROM users WHERE id = :?val") // void update(@Bind("?val") UserId id); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java // public interface NonFinalMapperBeanSql { // // @Sql("SELECT 1") // NonFinalMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java // public interface NonPublicMapperBeanSql { // // @Sql("SELECT 1") // NonPublicMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonStaticMapperBeanSql.java // public interface NonStaticMapperBeanSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/UnboundParameterSql.java // public interface UnboundParameterSql { // // @Sql("SELECT 1") // void update(@Bind("p") Class c); // } // Path: src/test/java/com/github/mjdbc/test/DbAttachSqlTest.java import com.github.mjdbc.DbImpl; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.ValidBean; import com.github.mjdbc.test.asset.model.error.MultipleMappersBean; import com.github.mjdbc.test.asset.sql.BeanWithStaticFieldMapperSql; import com.github.mjdbc.test.asset.sql.EmptyQuerySql; import com.github.mjdbc.test.asset.sql.EmptySql; import com.github.mjdbc.test.asset.sql.ValidBeansSql; import com.github.mjdbc.test.asset.sql.error.BeanWithNullMapperSql; import com.github.mjdbc.test.asset.sql.error.DuplicateParametersSql; import com.github.mjdbc.test.asset.sql.error.FakeGettersBeanSql; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql1; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql2; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql3; import com.github.mjdbc.test.asset.sql.error.MissedParameterSql; import com.github.mjdbc.test.asset.sql.error.MultipleMappersBean1Sql; import com.github.mjdbc.test.asset.sql.error.NonFinalMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonPublicMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonStaticMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.UnboundBeanParameterSql; import com.github.mjdbc.test.asset.sql.error.UnboundParameterSql; import com.github.mjdbc.test.asset.sql.error.WildcardParametrizedReturnTypeSql; import org.junit.Test; MultipleMappersBean bean = db.attachSql(MultipleMappersBean1Sql.class).selectABean(); assertEquals(1, bean.value); } @Test(expected = IllegalArgumentException.class) public void fakeGettersThrowException() { db.attachSql(FakeGettersBeanSql.class); } @Test public void checkBeanWithStaticFieldMapperByAnnotation() { DbImpl dbImpl = (DbImpl) this.db; assertNull(dbImpl.getRegisteredMapperByType(BeanWithStaticFieldMapper.class)); this.db.attachSql(BeanWithStaticFieldMapperSql.class); assertNotNull(dbImpl.getRegisteredMapperByType(BeanWithStaticFieldMapper.class)); } @Test(expected = IllegalArgumentException.class) public void checkBeanNonPublicMapper() { db.attachSql(NonPublicMapperBeanSql.class); } @Test(expected = IllegalArgumentException.class) public void checkBeanNonStaticMapper() { db.attachSql(NonStaticMapperBeanSql.class); } @Test(expected = IllegalArgumentException.class) public void checkBeanNonFinalMapper() {
db.attachSql(NonFinalMapperBeanSql.class);
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/DbAttachSqlTest.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/BeanWithStaticFieldMapperSql.java // public interface BeanWithStaticFieldMapperSql { // // @Sql("SELECT 1") // BeanWithStaticFieldMapper select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptyQuerySql.java // public interface EmptyQuerySql { // // @Sql // void updateFirstNameWithReader(); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptySql.java // public interface EmptySql { // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/BeanWithNullMapperSql.java // public interface BeanWithNullMapperSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/DuplicateParametersSql.java // public interface DuplicateParametersSql { // // @Sql("SELECT login FROM users WHERE id = :val AND login = :val") // void update(@Bind("val") UserId id, @Bind("val") String login); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/IllegalParametersSql3.java // public interface IllegalParametersSql3 { // // @Sql("SELECT login FROM users WHERE id = :?val") // void update(@Bind("?val") UserId id); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java // public interface NonFinalMapperBeanSql { // // @Sql("SELECT 1") // NonFinalMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java // public interface NonPublicMapperBeanSql { // // @Sql("SELECT 1") // NonPublicMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonStaticMapperBeanSql.java // public interface NonStaticMapperBeanSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/UnboundParameterSql.java // public interface UnboundParameterSql { // // @Sql("SELECT 1") // void update(@Bind("p") Class c); // }
import com.github.mjdbc.DbImpl; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.ValidBean; import com.github.mjdbc.test.asset.model.error.MultipleMappersBean; import com.github.mjdbc.test.asset.sql.BeanWithStaticFieldMapperSql; import com.github.mjdbc.test.asset.sql.EmptyQuerySql; import com.github.mjdbc.test.asset.sql.EmptySql; import com.github.mjdbc.test.asset.sql.ValidBeansSql; import com.github.mjdbc.test.asset.sql.error.BeanWithNullMapperSql; import com.github.mjdbc.test.asset.sql.error.DuplicateParametersSql; import com.github.mjdbc.test.asset.sql.error.FakeGettersBeanSql; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql1; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql2; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql3; import com.github.mjdbc.test.asset.sql.error.MissedParameterSql; import com.github.mjdbc.test.asset.sql.error.MultipleMappersBean1Sql; import com.github.mjdbc.test.asset.sql.error.NonFinalMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonPublicMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonStaticMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.UnboundBeanParameterSql; import com.github.mjdbc.test.asset.sql.error.UnboundParameterSql; import com.github.mjdbc.test.asset.sql.error.WildcardParametrizedReturnTypeSql; import org.junit.Test;
public void fakeGettersThrowException() { db.attachSql(FakeGettersBeanSql.class); } @Test public void checkBeanWithStaticFieldMapperByAnnotation() { DbImpl dbImpl = (DbImpl) this.db; assertNull(dbImpl.getRegisteredMapperByType(BeanWithStaticFieldMapper.class)); this.db.attachSql(BeanWithStaticFieldMapperSql.class); assertNotNull(dbImpl.getRegisteredMapperByType(BeanWithStaticFieldMapper.class)); } @Test(expected = IllegalArgumentException.class) public void checkBeanNonPublicMapper() { db.attachSql(NonPublicMapperBeanSql.class); } @Test(expected = IllegalArgumentException.class) public void checkBeanNonStaticMapper() { db.attachSql(NonStaticMapperBeanSql.class); } @Test(expected = IllegalArgumentException.class) public void checkBeanNonFinalMapper() { db.attachSql(NonFinalMapperBeanSql.class); } @Test(expected = IllegalArgumentException.class) public void checkBeanNullMapper() {
// Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java // public class BeanWithStaticFieldMapper { // // @Mapper // public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null; // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/BeanWithStaticFieldMapperSql.java // public interface BeanWithStaticFieldMapperSql { // // @Sql("SELECT 1") // BeanWithStaticFieldMapper select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptyQuerySql.java // public interface EmptyQuerySql { // // @Sql // void updateFirstNameWithReader(); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/EmptySql.java // public interface EmptySql { // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/BeanWithNullMapperSql.java // public interface BeanWithNullMapperSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/DuplicateParametersSql.java // public interface DuplicateParametersSql { // // @Sql("SELECT login FROM users WHERE id = :val AND login = :val") // void update(@Bind("val") UserId id, @Bind("val") String login); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/IllegalParametersSql3.java // public interface IllegalParametersSql3 { // // @Sql("SELECT login FROM users WHERE id = :?val") // void update(@Bind("?val") UserId id); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonFinalMapperBeanSql.java // public interface NonFinalMapperBeanSql { // // @Sql("SELECT 1") // NonFinalMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java // public interface NonPublicMapperBeanSql { // // @Sql("SELECT 1") // NonPublicMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonStaticMapperBeanSql.java // public interface NonStaticMapperBeanSql { // // @Sql("SELECT 1") // NonStaticMapperBean select(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/UnboundParameterSql.java // public interface UnboundParameterSql { // // @Sql("SELECT 1") // void update(@Bind("p") Class c); // } // Path: src/test/java/com/github/mjdbc/test/DbAttachSqlTest.java import com.github.mjdbc.DbImpl; import com.github.mjdbc.test.asset.model.BeanWithStaticFieldMapper; import com.github.mjdbc.test.asset.model.ValidBean; import com.github.mjdbc.test.asset.model.error.MultipleMappersBean; import com.github.mjdbc.test.asset.sql.BeanWithStaticFieldMapperSql; import com.github.mjdbc.test.asset.sql.EmptyQuerySql; import com.github.mjdbc.test.asset.sql.EmptySql; import com.github.mjdbc.test.asset.sql.ValidBeansSql; import com.github.mjdbc.test.asset.sql.error.BeanWithNullMapperSql; import com.github.mjdbc.test.asset.sql.error.DuplicateParametersSql; import com.github.mjdbc.test.asset.sql.error.FakeGettersBeanSql; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql1; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql2; import com.github.mjdbc.test.asset.sql.error.IllegalParametersSql3; import com.github.mjdbc.test.asset.sql.error.MissedParameterSql; import com.github.mjdbc.test.asset.sql.error.MultipleMappersBean1Sql; import com.github.mjdbc.test.asset.sql.error.NonFinalMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonPublicMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.NonStaticMapperBeanSql; import com.github.mjdbc.test.asset.sql.error.UnboundBeanParameterSql; import com.github.mjdbc.test.asset.sql.error.UnboundParameterSql; import com.github.mjdbc.test.asset.sql.error.WildcardParametrizedReturnTypeSql; import org.junit.Test; public void fakeGettersThrowException() { db.attachSql(FakeGettersBeanSql.class); } @Test public void checkBeanWithStaticFieldMapperByAnnotation() { DbImpl dbImpl = (DbImpl) this.db; assertNull(dbImpl.getRegisteredMapperByType(BeanWithStaticFieldMapper.class)); this.db.attachSql(BeanWithStaticFieldMapperSql.class); assertNotNull(dbImpl.getRegisteredMapperByType(BeanWithStaticFieldMapper.class)); } @Test(expected = IllegalArgumentException.class) public void checkBeanNonPublicMapper() { db.attachSql(NonPublicMapperBeanSql.class); } @Test(expected = IllegalArgumentException.class) public void checkBeanNonStaticMapper() { db.attachSql(NonStaticMapperBeanSql.class); } @Test(expected = IllegalArgumentException.class) public void checkBeanNonFinalMapper() { db.attachSql(NonFinalMapperBeanSql.class); } @Test(expected = IllegalArgumentException.class) public void checkBeanNullMapper() {
db.attachSql(BeanWithNullMapperSql.class);
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/MapperLookupTest.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/User.java // public final class User { // /** // * It is recommended to have type safe IDs. // */ // public UserId id; // public String login; // public String firstName; // public String lastName; // public Gender gender; // public long score; // public Timestamp registrationDate; // // /** // * Class to create User object from result set. // */ // @Mapper // public static final DbMapper<User> MAPPER = (r) -> { // User user = new User(); // user.id = new UserId(r.getInt("id")); // user.login = r.getString("login"); // user.firstName = r.getString("first_name"); // user.lastName = r.getString("last_name"); // user.gender = Gender.fromDbValue(r.getInt("gender")); // user.score = r.getLong("score"); // user.registrationDate = r.getTimestamp("reg_date"); // return user; // }; // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // User user = (User) o; // return score == user.score && // Objects.equals(id, user.id) && // Objects.equals(login, user.login) && // Objects.equals(firstName, user.firstName) && // Objects.equals(lastName, user.lastName) && // gender == user.gender && // Objects.equals(registrationDate, user.registrationDate); // } // // @Override // public int hashCode() { // return Objects.hash(id, login, firstName, lastName, gender, score, registrationDate); // } // }
import com.github.mjdbc.test.asset.model.User; import com.github.mjdbc.test.asset.model.UserId; import com.github.mjdbc.test.asset.sql.UserSql; import com.github.mjdbc.test.asset.sql.error.InvalidMapperSql; import java.util.List; import org.junit.Before; import org.junit.Test;
package com.github.mjdbc.test; /** * Tests for DbValue (Int,Long..) support. */ public class MapperLookupTest extends DbTest { private UserSql sql; @Before public void setUp() { super.setUp(); sql = db.attachSql(UserSql.class); } @Test public void checkUserRegistered() {
// Path: src/test/java/com/github/mjdbc/test/asset/model/User.java // public final class User { // /** // * It is recommended to have type safe IDs. // */ // public UserId id; // public String login; // public String firstName; // public String lastName; // public Gender gender; // public long score; // public Timestamp registrationDate; // // /** // * Class to create User object from result set. // */ // @Mapper // public static final DbMapper<User> MAPPER = (r) -> { // User user = new User(); // user.id = new UserId(r.getInt("id")); // user.login = r.getString("login"); // user.firstName = r.getString("first_name"); // user.lastName = r.getString("last_name"); // user.gender = Gender.fromDbValue(r.getInt("gender")); // user.score = r.getLong("score"); // user.registrationDate = r.getTimestamp("reg_date"); // return user; // }; // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // User user = (User) o; // return score == user.score && // Objects.equals(id, user.id) && // Objects.equals(login, user.login) && // Objects.equals(firstName, user.firstName) && // Objects.equals(lastName, user.lastName) && // gender == user.gender && // Objects.equals(registrationDate, user.registrationDate); // } // // @Override // public int hashCode() { // return Objects.hash(id, login, firstName, lastName, gender, score, registrationDate); // } // } // Path: src/test/java/com/github/mjdbc/test/MapperLookupTest.java import com.github.mjdbc.test.asset.model.User; import com.github.mjdbc.test.asset.model.UserId; import com.github.mjdbc.test.asset.sql.UserSql; import com.github.mjdbc.test.asset.sql.error.InvalidMapperSql; import java.util.List; import org.junit.Before; import org.junit.Test; package com.github.mjdbc.test; /** * Tests for DbValue (Int,Long..) support. */ public class MapperLookupTest extends DbTest { private UserSql sql; @Before public void setUp() { super.setUp(); sql = db.attachSql(UserSql.class); } @Test public void checkUserRegistered() {
User u = sql.getUserByLogin("u1");
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/GetterBeanTest.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/GetterBean.java // public class GetterBean { // // private long id; // // private boolean booleanField; // // private int intField; // // private String stringField; // // private DbIntValue intValueField; // // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public boolean isBooleanField() { // return booleanField; // } // // public void setBooleanField(boolean booleanField) { // this.booleanField = booleanField; // } // // public int getIntField() { // return intField; // } // // public void setIntField(int intField) { // this.intField = intField; // } // // public String getStringField() { // return stringField; // } // // public void setStringField(String stringField) { // this.stringField = stringField; // } // // public DbIntValue getIntValueField() { // return intValueField; // } // // public void setIntValueField(DbIntValue intValueField) { // this.intValueField = intValueField; // } // // /** // * Class to create User object from result set. // */ // @Mapper // public static final DbMapper<GetterBean> MAPPER = (r) -> { // GetterBean res = new GetterBean(); // res.id = r.getInt("id"); // res.booleanField = r.getBoolean("boolean_field"); // res.intField = r.getInt("int_field"); // res.stringField = r.getString("string_field"); // res.intValueField = new DbIntValue(r.getInt("int_value_field")); // return res; // }; // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/GetterBeanSql.java // public interface GetterBeanSql { // // @Sql("INSERT INTO bean(boolean_field, int_field, string_field, int_value_field) " + // "VALUES(:booleanField, :intField, :stringField, :intValueField)") // @GetGeneratedKeys // long insert(@BindBean GetterBean bean); // // @Sql("UPDATE bean SET boolean_field = :booleanField, int_field = :intField, string_field = :stringField, int_value_field = :intValueField " + // "WHERE id = :id") // void update(@BindBean GetterBean bean); // // @Sql("SELECT * FROM bean WHERE id = :id") // GetterBean get(@Bind("id") long id); // } // // Path: src/test/java/com/github/mjdbc/test/asset/types/DbIntValue.java // public class DbIntValue extends AbstractDbInt { // protected int value; // // public DbIntValue(int value) { // this.value = value; // } // // public final int getDbValue() { // return value; // } // // public String toString() { // return getClass().getSimpleName() + "[" + value + "]"; // } // }
import com.github.mjdbc.test.asset.model.GetterBean; import com.github.mjdbc.test.asset.sql.GetterBeanSql; import com.github.mjdbc.test.asset.types.DbIntValue; import org.jetbrains.annotations.NotNull; import org.junit.Test;
package com.github.mjdbc.test; public class GetterBeanTest extends BaseSqlTest<GetterBeanSql> { public GetterBeanTest() { super(GetterBeanSql.class, "beans"); } @Test public void checkInsertWithGetter() {
// Path: src/test/java/com/github/mjdbc/test/asset/model/GetterBean.java // public class GetterBean { // // private long id; // // private boolean booleanField; // // private int intField; // // private String stringField; // // private DbIntValue intValueField; // // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public boolean isBooleanField() { // return booleanField; // } // // public void setBooleanField(boolean booleanField) { // this.booleanField = booleanField; // } // // public int getIntField() { // return intField; // } // // public void setIntField(int intField) { // this.intField = intField; // } // // public String getStringField() { // return stringField; // } // // public void setStringField(String stringField) { // this.stringField = stringField; // } // // public DbIntValue getIntValueField() { // return intValueField; // } // // public void setIntValueField(DbIntValue intValueField) { // this.intValueField = intValueField; // } // // /** // * Class to create User object from result set. // */ // @Mapper // public static final DbMapper<GetterBean> MAPPER = (r) -> { // GetterBean res = new GetterBean(); // res.id = r.getInt("id"); // res.booleanField = r.getBoolean("boolean_field"); // res.intField = r.getInt("int_field"); // res.stringField = r.getString("string_field"); // res.intValueField = new DbIntValue(r.getInt("int_value_field")); // return res; // }; // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/GetterBeanSql.java // public interface GetterBeanSql { // // @Sql("INSERT INTO bean(boolean_field, int_field, string_field, int_value_field) " + // "VALUES(:booleanField, :intField, :stringField, :intValueField)") // @GetGeneratedKeys // long insert(@BindBean GetterBean bean); // // @Sql("UPDATE bean SET boolean_field = :booleanField, int_field = :intField, string_field = :stringField, int_value_field = :intValueField " + // "WHERE id = :id") // void update(@BindBean GetterBean bean); // // @Sql("SELECT * FROM bean WHERE id = :id") // GetterBean get(@Bind("id") long id); // } // // Path: src/test/java/com/github/mjdbc/test/asset/types/DbIntValue.java // public class DbIntValue extends AbstractDbInt { // protected int value; // // public DbIntValue(int value) { // this.value = value; // } // // public final int getDbValue() { // return value; // } // // public String toString() { // return getClass().getSimpleName() + "[" + value + "]"; // } // } // Path: src/test/java/com/github/mjdbc/test/GetterBeanTest.java import com.github.mjdbc.test.asset.model.GetterBean; import com.github.mjdbc.test.asset.sql.GetterBeanSql; import com.github.mjdbc.test.asset.types.DbIntValue; import org.jetbrains.annotations.NotNull; import org.junit.Test; package com.github.mjdbc.test; public class GetterBeanTest extends BaseSqlTest<GetterBeanSql> { public GetterBeanTest() { super(GetterBeanSql.class, "beans"); } @Test public void checkInsertWithGetter() {
GetterBean original = createBean();
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/GetterBeanTest.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/GetterBean.java // public class GetterBean { // // private long id; // // private boolean booleanField; // // private int intField; // // private String stringField; // // private DbIntValue intValueField; // // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public boolean isBooleanField() { // return booleanField; // } // // public void setBooleanField(boolean booleanField) { // this.booleanField = booleanField; // } // // public int getIntField() { // return intField; // } // // public void setIntField(int intField) { // this.intField = intField; // } // // public String getStringField() { // return stringField; // } // // public void setStringField(String stringField) { // this.stringField = stringField; // } // // public DbIntValue getIntValueField() { // return intValueField; // } // // public void setIntValueField(DbIntValue intValueField) { // this.intValueField = intValueField; // } // // /** // * Class to create User object from result set. // */ // @Mapper // public static final DbMapper<GetterBean> MAPPER = (r) -> { // GetterBean res = new GetterBean(); // res.id = r.getInt("id"); // res.booleanField = r.getBoolean("boolean_field"); // res.intField = r.getInt("int_field"); // res.stringField = r.getString("string_field"); // res.intValueField = new DbIntValue(r.getInt("int_value_field")); // return res; // }; // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/GetterBeanSql.java // public interface GetterBeanSql { // // @Sql("INSERT INTO bean(boolean_field, int_field, string_field, int_value_field) " + // "VALUES(:booleanField, :intField, :stringField, :intValueField)") // @GetGeneratedKeys // long insert(@BindBean GetterBean bean); // // @Sql("UPDATE bean SET boolean_field = :booleanField, int_field = :intField, string_field = :stringField, int_value_field = :intValueField " + // "WHERE id = :id") // void update(@BindBean GetterBean bean); // // @Sql("SELECT * FROM bean WHERE id = :id") // GetterBean get(@Bind("id") long id); // } // // Path: src/test/java/com/github/mjdbc/test/asset/types/DbIntValue.java // public class DbIntValue extends AbstractDbInt { // protected int value; // // public DbIntValue(int value) { // this.value = value; // } // // public final int getDbValue() { // return value; // } // // public String toString() { // return getClass().getSimpleName() + "[" + value + "]"; // } // }
import com.github.mjdbc.test.asset.model.GetterBean; import com.github.mjdbc.test.asset.sql.GetterBeanSql; import com.github.mjdbc.test.asset.types.DbIntValue; import org.jetbrains.annotations.NotNull; import org.junit.Test;
package com.github.mjdbc.test; public class GetterBeanTest extends BaseSqlTest<GetterBeanSql> { public GetterBeanTest() { super(GetterBeanSql.class, "beans"); } @Test public void checkInsertWithGetter() { GetterBean original = createBean(); long id = sql.insert(original); assertTrue(id > 0); GetterBean fromDb = sql.get(id); assertEquals(original.isBooleanField(), fromDb.isBooleanField()); assertEquals(original.getIntField(), fromDb.getIntField()); assertEquals(original.getStringField(), fromDb.getStringField()); assertEquals(original.getIntValueField(), fromDb.getIntValueField()); } @NotNull private GetterBean createBean() { GetterBean original = new GetterBean(); original.setBooleanField(true); original.setIntField(10); original.setStringField("20");
// Path: src/test/java/com/github/mjdbc/test/asset/model/GetterBean.java // public class GetterBean { // // private long id; // // private boolean booleanField; // // private int intField; // // private String stringField; // // private DbIntValue intValueField; // // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public boolean isBooleanField() { // return booleanField; // } // // public void setBooleanField(boolean booleanField) { // this.booleanField = booleanField; // } // // public int getIntField() { // return intField; // } // // public void setIntField(int intField) { // this.intField = intField; // } // // public String getStringField() { // return stringField; // } // // public void setStringField(String stringField) { // this.stringField = stringField; // } // // public DbIntValue getIntValueField() { // return intValueField; // } // // public void setIntValueField(DbIntValue intValueField) { // this.intValueField = intValueField; // } // // /** // * Class to create User object from result set. // */ // @Mapper // public static final DbMapper<GetterBean> MAPPER = (r) -> { // GetterBean res = new GetterBean(); // res.id = r.getInt("id"); // res.booleanField = r.getBoolean("boolean_field"); // res.intField = r.getInt("int_field"); // res.stringField = r.getString("string_field"); // res.intValueField = new DbIntValue(r.getInt("int_value_field")); // return res; // }; // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/GetterBeanSql.java // public interface GetterBeanSql { // // @Sql("INSERT INTO bean(boolean_field, int_field, string_field, int_value_field) " + // "VALUES(:booleanField, :intField, :stringField, :intValueField)") // @GetGeneratedKeys // long insert(@BindBean GetterBean bean); // // @Sql("UPDATE bean SET boolean_field = :booleanField, int_field = :intField, string_field = :stringField, int_value_field = :intValueField " + // "WHERE id = :id") // void update(@BindBean GetterBean bean); // // @Sql("SELECT * FROM bean WHERE id = :id") // GetterBean get(@Bind("id") long id); // } // // Path: src/test/java/com/github/mjdbc/test/asset/types/DbIntValue.java // public class DbIntValue extends AbstractDbInt { // protected int value; // // public DbIntValue(int value) { // this.value = value; // } // // public final int getDbValue() { // return value; // } // // public String toString() { // return getClass().getSimpleName() + "[" + value + "]"; // } // } // Path: src/test/java/com/github/mjdbc/test/GetterBeanTest.java import com.github.mjdbc.test.asset.model.GetterBean; import com.github.mjdbc.test.asset.sql.GetterBeanSql; import com.github.mjdbc.test.asset.types.DbIntValue; import org.jetbrains.annotations.NotNull; import org.junit.Test; package com.github.mjdbc.test; public class GetterBeanTest extends BaseSqlTest<GetterBeanSql> { public GetterBeanTest() { super(GetterBeanSql.class, "beans"); } @Test public void checkInsertWithGetter() { GetterBean original = createBean(); long id = sql.insert(original); assertTrue(id > 0); GetterBean fromDb = sql.get(id); assertEquals(original.isBooleanField(), fromDb.isBooleanField()); assertEquals(original.getIntField(), fromDb.getIntField()); assertEquals(original.getStringField(), fromDb.getStringField()); assertEquals(original.getIntValueField(), fromDb.getIntValueField()); } @NotNull private GetterBean createBean() { GetterBean original = new GetterBean(); original.setBooleanField(true); original.setIntField(10); original.setStringField("20");
original.setIntValueField(new DbIntValue(30));
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/asset/model/error/FakeGettersBean.java
// Path: src/main/java/com/github/mjdbc/DbMapper.java // public interface DbMapper<T> { // // /** // * Maps a single row or all rows to the corresponding Java object. // * May return null for nullable primitive type fields (like nullable varchar field). // * Must never return null for complex java property objects (beans). // * // * @param r - open result set. // * @return Java object. // * @throws SQLException if SQLException occurs during the mapping process // */ // T map(@NotNull ResultSet r) throws SQLException; // } // // Path: src/test/java/com/github/mjdbc/test/asset/types/DbIntValue.java // public class DbIntValue extends AbstractDbInt { // protected int value; // // public DbIntValue(int value) { // this.value = value; // } // // public final int getDbValue() { // return value; // } // // public String toString() { // return getClass().getSimpleName() + "[" + value + "]"; // } // }
import com.github.mjdbc.DbMapper; import com.github.mjdbc.Mapper; import com.github.mjdbc.test.asset.types.DbIntValue;
package com.github.mjdbc.test.asset.model.error; /** * Bean with fake getters -> getters with parameters are not normal getters */ public class FakeGettersBean { private long id; private boolean booleanField; private int intField; private String stringField;
// Path: src/main/java/com/github/mjdbc/DbMapper.java // public interface DbMapper<T> { // // /** // * Maps a single row or all rows to the corresponding Java object. // * May return null for nullable primitive type fields (like nullable varchar field). // * Must never return null for complex java property objects (beans). // * // * @param r - open result set. // * @return Java object. // * @throws SQLException if SQLException occurs during the mapping process // */ // T map(@NotNull ResultSet r) throws SQLException; // } // // Path: src/test/java/com/github/mjdbc/test/asset/types/DbIntValue.java // public class DbIntValue extends AbstractDbInt { // protected int value; // // public DbIntValue(int value) { // this.value = value; // } // // public final int getDbValue() { // return value; // } // // public String toString() { // return getClass().getSimpleName() + "[" + value + "]"; // } // } // Path: src/test/java/com/github/mjdbc/test/asset/model/error/FakeGettersBean.java import com.github.mjdbc.DbMapper; import com.github.mjdbc.Mapper; import com.github.mjdbc.test.asset.types.DbIntValue; package com.github.mjdbc.test.asset.model.error; /** * Bean with fake getters -> getters with parameters are not normal getters */ public class FakeGettersBean { private long id; private boolean booleanField; private int intField; private String stringField;
private DbIntValue intValueField;
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/asset/model/error/FakeGettersBean.java
// Path: src/main/java/com/github/mjdbc/DbMapper.java // public interface DbMapper<T> { // // /** // * Maps a single row or all rows to the corresponding Java object. // * May return null for nullable primitive type fields (like nullable varchar field). // * Must never return null for complex java property objects (beans). // * // * @param r - open result set. // * @return Java object. // * @throws SQLException if SQLException occurs during the mapping process // */ // T map(@NotNull ResultSet r) throws SQLException; // } // // Path: src/test/java/com/github/mjdbc/test/asset/types/DbIntValue.java // public class DbIntValue extends AbstractDbInt { // protected int value; // // public DbIntValue(int value) { // this.value = value; // } // // public final int getDbValue() { // return value; // } // // public String toString() { // return getClass().getSimpleName() + "[" + value + "]"; // } // }
import com.github.mjdbc.DbMapper; import com.github.mjdbc.Mapper; import com.github.mjdbc.test.asset.types.DbIntValue;
} public int getIntField(int x) { return intField; } public void setIntField(int intField) { this.intField = intField; } public String getStringField(int x) { return stringField; } public void setStringField(String stringField) { this.stringField = stringField; } public DbIntValue getIntValueField(int x) { return intValueField; } public void setIntValueField(DbIntValue intValueField) { this.intValueField = intValueField; } /** * Class to create User object from result set. */ @Mapper
// Path: src/main/java/com/github/mjdbc/DbMapper.java // public interface DbMapper<T> { // // /** // * Maps a single row or all rows to the corresponding Java object. // * May return null for nullable primitive type fields (like nullable varchar field). // * Must never return null for complex java property objects (beans). // * // * @param r - open result set. // * @return Java object. // * @throws SQLException if SQLException occurs during the mapping process // */ // T map(@NotNull ResultSet r) throws SQLException; // } // // Path: src/test/java/com/github/mjdbc/test/asset/types/DbIntValue.java // public class DbIntValue extends AbstractDbInt { // protected int value; // // public DbIntValue(int value) { // this.value = value; // } // // public final int getDbValue() { // return value; // } // // public String toString() { // return getClass().getSimpleName() + "[" + value + "]"; // } // } // Path: src/test/java/com/github/mjdbc/test/asset/model/error/FakeGettersBean.java import com.github.mjdbc.DbMapper; import com.github.mjdbc.Mapper; import com.github.mjdbc.test.asset.types.DbIntValue; } public int getIntField(int x) { return intField; } public void setIntField(int intField) { this.intField = intField; } public String getStringField(int x) { return stringField; } public void setStringField(String stringField) { this.stringField = stringField; } public DbIntValue getIntValueField(int x) { return intValueField; } public void setIntValueField(DbIntValue intValueField) { this.intValueField = intValueField; } /** * Class to create User object from result set. */ @Mapper
public static final DbMapper<FakeGettersBean> MAPPER = (r) -> {
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/BaseSqlTest.java
// Path: src/main/java/com/github/mjdbc/Db.java // public interface Db { // // /** // * Registers result set mapper. See DbMapper class for details. // * // * @param mapperClass the result classes. Result set row will be mapped to the instance of this class. // * @param mapper mapper. This mapper will be used to map result set row to mapperClass instance. // * @param <T> result type. // */ // <T> void registerMapper(@NotNull Class<T> mapperClass, @NotNull DbMapper<T> mapper); // // /** // * Registers prepared statement parameter binder. // * A binder for parameter is looked up by matching class first, any superclass second or any interface third. // * The old binder for this type is removed. // * // * @param binderClass parameter class to be processed by this binder. // * @param binder binder implementation. // */ // <T> void registerBinder(@NotNull Class<? extends T> binderClass, @NotNull DbBinder<T> binder); // // /** // * Attaches Dbi (DB interfaces) implementation to the database. // * All methods will be wrapped to transaction. Transaction will be started when the first SQL statement // * is used inside of the method and closed on exit from the method. Transaction is committed // * on normal exit and rolled back if Exception is thrown. // * <p> // * If Dbi method is called from another Dbi method no new transaction will be started: the upper-stack transaction will be used. // * // * @param impl database interface implementation. // * @param dbiInterface database interface to wrap with transactions support. // * @param <T> type of the Dbi interface. // * @return wrapped instance of the @dbiInterface // */ // @NotNull // <T> T attachDbi(@NotNull T impl, @NotNull Class<T> dbiInterface); // // /** // * Attaches sql interface to the database. All sql queries are parsed and validated during this call. // * // * @param sqlInterface sql interface to attach. // * @param <T> type of the interface. // * @return interface implementation. // */ // @NotNull // <T> T attachSql(@NotNull Class<T> sqlInterface); // // /** // * Executes database query that produces Nullable result. // * // * @param op query types. // * @param <T> result type. // * @return query result. // */ // @Nullable // <T> T execute(@NotNull DbOp<T> op); // // /** // * Executes database query that produces NotNull result. // * // * @param op query types. // * @param <T> result type. // * @return query result. // */ // @NotNull // <T> T executeNN(@NotNull DbOpNN<T> op); // // /** // * Executes database operation that produces no result. // * // * @param op operation types. // */ // void executeV(@NotNull DbOpV op); // // // /** // * Returns per-method timers. // * Statistics is collected for all methods of attached Dbi interfaces // * and for all @Sql methods of attached query interfaces. // * // * @return per-method statistics. Note: This is direct access to the timers map. Timers are updated concurrently. // * If a timer is removed from the map: it will be restarted. // */ // @NotNull // Map<Method, DbTimer> getTimers(); // // // /** // * Returns active connection assigned to current thread or throws IllegalStateException if not within DBOp. // */ // @NotNull // DbConnection getActiveConnection(); // } // // Path: src/main/java/com/github/mjdbc/DbFactory.java // public class DbFactory { // // /** // * Creates new mjdbc Db wrapper for the given datasource. // */ // @NotNull // public static Db wrap(@NotNull DataSource dataSource) { // return new DbImpl(dataSource); // } // // } // // Path: src/test/java/com/github/mjdbc/test/util/ProfiledDataSource.java // public class ProfiledDataSource implements javax.sql.DataSource { // @NotNull // private final DataSource ds; // // public int nGetConnectionCalls; // // public ProfiledDataSource(@NotNull DataSource ds) { // this.ds = ds; // } // // @Override // public PrintWriter getLogWriter() throws SQLException { // return ds.getLogWriter(); // } // // @Override // public void setLogWriter(PrintWriter out) throws SQLException { // ds.setLogWriter(out); // } // // @Override // public void setLoginTimeout(int seconds) throws SQLException { // ds.setLoginTimeout(seconds); // } // // @Override // public int getLoginTimeout() throws SQLException { // return ds.getLoginTimeout(); // } // // @Override // public Logger getParentLogger() throws SQLFeatureNotSupportedException { // return ds.getParentLogger(); // } // // @Override // public <T> T unwrap(Class<T> c) throws SQLException { // return ds.unwrap(c); // } // // @Override // public boolean isWrapperFor(Class<?> c) throws SQLException { // return ds.isWrapperFor(c); // } // // @Override // public Connection getConnection() throws SQLException { // nGetConnectionCalls++; // return new ProfiledConnection(ds.getConnection()); // } // // @Override // public Connection getConnection(String username, String password) throws SQLException { // nGetConnectionCalls++; // return new ProfiledConnection(ds.getConnection(username, password)); // } // }
import com.github.mjdbc.Db; import com.github.mjdbc.DbFactory; import com.github.mjdbc.test.util.DbUtils; import com.github.mjdbc.test.util.ProfiledDataSource; import com.zaxxer.hikari.HikariDataSource; import org.jetbrains.annotations.NotNull; import org.junit.After; import org.junit.Assert; import org.junit.Before;
package com.github.mjdbc.test; public abstract class BaseSqlTest<S> extends Assert { /** * Low level connection pool. */ protected HikariDataSource ds;
// Path: src/main/java/com/github/mjdbc/Db.java // public interface Db { // // /** // * Registers result set mapper. See DbMapper class for details. // * // * @param mapperClass the result classes. Result set row will be mapped to the instance of this class. // * @param mapper mapper. This mapper will be used to map result set row to mapperClass instance. // * @param <T> result type. // */ // <T> void registerMapper(@NotNull Class<T> mapperClass, @NotNull DbMapper<T> mapper); // // /** // * Registers prepared statement parameter binder. // * A binder for parameter is looked up by matching class first, any superclass second or any interface third. // * The old binder for this type is removed. // * // * @param binderClass parameter class to be processed by this binder. // * @param binder binder implementation. // */ // <T> void registerBinder(@NotNull Class<? extends T> binderClass, @NotNull DbBinder<T> binder); // // /** // * Attaches Dbi (DB interfaces) implementation to the database. // * All methods will be wrapped to transaction. Transaction will be started when the first SQL statement // * is used inside of the method and closed on exit from the method. Transaction is committed // * on normal exit and rolled back if Exception is thrown. // * <p> // * If Dbi method is called from another Dbi method no new transaction will be started: the upper-stack transaction will be used. // * // * @param impl database interface implementation. // * @param dbiInterface database interface to wrap with transactions support. // * @param <T> type of the Dbi interface. // * @return wrapped instance of the @dbiInterface // */ // @NotNull // <T> T attachDbi(@NotNull T impl, @NotNull Class<T> dbiInterface); // // /** // * Attaches sql interface to the database. All sql queries are parsed and validated during this call. // * // * @param sqlInterface sql interface to attach. // * @param <T> type of the interface. // * @return interface implementation. // */ // @NotNull // <T> T attachSql(@NotNull Class<T> sqlInterface); // // /** // * Executes database query that produces Nullable result. // * // * @param op query types. // * @param <T> result type. // * @return query result. // */ // @Nullable // <T> T execute(@NotNull DbOp<T> op); // // /** // * Executes database query that produces NotNull result. // * // * @param op query types. // * @param <T> result type. // * @return query result. // */ // @NotNull // <T> T executeNN(@NotNull DbOpNN<T> op); // // /** // * Executes database operation that produces no result. // * // * @param op operation types. // */ // void executeV(@NotNull DbOpV op); // // // /** // * Returns per-method timers. // * Statistics is collected for all methods of attached Dbi interfaces // * and for all @Sql methods of attached query interfaces. // * // * @return per-method statistics. Note: This is direct access to the timers map. Timers are updated concurrently. // * If a timer is removed from the map: it will be restarted. // */ // @NotNull // Map<Method, DbTimer> getTimers(); // // // /** // * Returns active connection assigned to current thread or throws IllegalStateException if not within DBOp. // */ // @NotNull // DbConnection getActiveConnection(); // } // // Path: src/main/java/com/github/mjdbc/DbFactory.java // public class DbFactory { // // /** // * Creates new mjdbc Db wrapper for the given datasource. // */ // @NotNull // public static Db wrap(@NotNull DataSource dataSource) { // return new DbImpl(dataSource); // } // // } // // Path: src/test/java/com/github/mjdbc/test/util/ProfiledDataSource.java // public class ProfiledDataSource implements javax.sql.DataSource { // @NotNull // private final DataSource ds; // // public int nGetConnectionCalls; // // public ProfiledDataSource(@NotNull DataSource ds) { // this.ds = ds; // } // // @Override // public PrintWriter getLogWriter() throws SQLException { // return ds.getLogWriter(); // } // // @Override // public void setLogWriter(PrintWriter out) throws SQLException { // ds.setLogWriter(out); // } // // @Override // public void setLoginTimeout(int seconds) throws SQLException { // ds.setLoginTimeout(seconds); // } // // @Override // public int getLoginTimeout() throws SQLException { // return ds.getLoginTimeout(); // } // // @Override // public Logger getParentLogger() throws SQLFeatureNotSupportedException { // return ds.getParentLogger(); // } // // @Override // public <T> T unwrap(Class<T> c) throws SQLException { // return ds.unwrap(c); // } // // @Override // public boolean isWrapperFor(Class<?> c) throws SQLException { // return ds.isWrapperFor(c); // } // // @Override // public Connection getConnection() throws SQLException { // nGetConnectionCalls++; // return new ProfiledConnection(ds.getConnection()); // } // // @Override // public Connection getConnection(String username, String password) throws SQLException { // nGetConnectionCalls++; // return new ProfiledConnection(ds.getConnection(username, password)); // } // } // Path: src/test/java/com/github/mjdbc/test/BaseSqlTest.java import com.github.mjdbc.Db; import com.github.mjdbc.DbFactory; import com.github.mjdbc.test.util.DbUtils; import com.github.mjdbc.test.util.ProfiledDataSource; import com.zaxxer.hikari.HikariDataSource; import org.jetbrains.annotations.NotNull; import org.junit.After; import org.junit.Assert; import org.junit.Before; package com.github.mjdbc.test; public abstract class BaseSqlTest<S> extends Assert { /** * Low level connection pool. */ protected HikariDataSource ds;
protected ProfiledDataSource profiledDs;
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/BaseSqlTest.java
// Path: src/main/java/com/github/mjdbc/Db.java // public interface Db { // // /** // * Registers result set mapper. See DbMapper class for details. // * // * @param mapperClass the result classes. Result set row will be mapped to the instance of this class. // * @param mapper mapper. This mapper will be used to map result set row to mapperClass instance. // * @param <T> result type. // */ // <T> void registerMapper(@NotNull Class<T> mapperClass, @NotNull DbMapper<T> mapper); // // /** // * Registers prepared statement parameter binder. // * A binder for parameter is looked up by matching class first, any superclass second or any interface third. // * The old binder for this type is removed. // * // * @param binderClass parameter class to be processed by this binder. // * @param binder binder implementation. // */ // <T> void registerBinder(@NotNull Class<? extends T> binderClass, @NotNull DbBinder<T> binder); // // /** // * Attaches Dbi (DB interfaces) implementation to the database. // * All methods will be wrapped to transaction. Transaction will be started when the first SQL statement // * is used inside of the method and closed on exit from the method. Transaction is committed // * on normal exit and rolled back if Exception is thrown. // * <p> // * If Dbi method is called from another Dbi method no new transaction will be started: the upper-stack transaction will be used. // * // * @param impl database interface implementation. // * @param dbiInterface database interface to wrap with transactions support. // * @param <T> type of the Dbi interface. // * @return wrapped instance of the @dbiInterface // */ // @NotNull // <T> T attachDbi(@NotNull T impl, @NotNull Class<T> dbiInterface); // // /** // * Attaches sql interface to the database. All sql queries are parsed and validated during this call. // * // * @param sqlInterface sql interface to attach. // * @param <T> type of the interface. // * @return interface implementation. // */ // @NotNull // <T> T attachSql(@NotNull Class<T> sqlInterface); // // /** // * Executes database query that produces Nullable result. // * // * @param op query types. // * @param <T> result type. // * @return query result. // */ // @Nullable // <T> T execute(@NotNull DbOp<T> op); // // /** // * Executes database query that produces NotNull result. // * // * @param op query types. // * @param <T> result type. // * @return query result. // */ // @NotNull // <T> T executeNN(@NotNull DbOpNN<T> op); // // /** // * Executes database operation that produces no result. // * // * @param op operation types. // */ // void executeV(@NotNull DbOpV op); // // // /** // * Returns per-method timers. // * Statistics is collected for all methods of attached Dbi interfaces // * and for all @Sql methods of attached query interfaces. // * // * @return per-method statistics. Note: This is direct access to the timers map. Timers are updated concurrently. // * If a timer is removed from the map: it will be restarted. // */ // @NotNull // Map<Method, DbTimer> getTimers(); // // // /** // * Returns active connection assigned to current thread or throws IllegalStateException if not within DBOp. // */ // @NotNull // DbConnection getActiveConnection(); // } // // Path: src/main/java/com/github/mjdbc/DbFactory.java // public class DbFactory { // // /** // * Creates new mjdbc Db wrapper for the given datasource. // */ // @NotNull // public static Db wrap(@NotNull DataSource dataSource) { // return new DbImpl(dataSource); // } // // } // // Path: src/test/java/com/github/mjdbc/test/util/ProfiledDataSource.java // public class ProfiledDataSource implements javax.sql.DataSource { // @NotNull // private final DataSource ds; // // public int nGetConnectionCalls; // // public ProfiledDataSource(@NotNull DataSource ds) { // this.ds = ds; // } // // @Override // public PrintWriter getLogWriter() throws SQLException { // return ds.getLogWriter(); // } // // @Override // public void setLogWriter(PrintWriter out) throws SQLException { // ds.setLogWriter(out); // } // // @Override // public void setLoginTimeout(int seconds) throws SQLException { // ds.setLoginTimeout(seconds); // } // // @Override // public int getLoginTimeout() throws SQLException { // return ds.getLoginTimeout(); // } // // @Override // public Logger getParentLogger() throws SQLFeatureNotSupportedException { // return ds.getParentLogger(); // } // // @Override // public <T> T unwrap(Class<T> c) throws SQLException { // return ds.unwrap(c); // } // // @Override // public boolean isWrapperFor(Class<?> c) throws SQLException { // return ds.isWrapperFor(c); // } // // @Override // public Connection getConnection() throws SQLException { // nGetConnectionCalls++; // return new ProfiledConnection(ds.getConnection()); // } // // @Override // public Connection getConnection(String username, String password) throws SQLException { // nGetConnectionCalls++; // return new ProfiledConnection(ds.getConnection(username, password)); // } // }
import com.github.mjdbc.Db; import com.github.mjdbc.DbFactory; import com.github.mjdbc.test.util.DbUtils; import com.github.mjdbc.test.util.ProfiledDataSource; import com.zaxxer.hikari.HikariDataSource; import org.jetbrains.annotations.NotNull; import org.junit.After; import org.junit.Assert; import org.junit.Before;
package com.github.mjdbc.test; public abstract class BaseSqlTest<S> extends Assert { /** * Low level connection pool. */ protected HikariDataSource ds; protected ProfiledDataSource profiledDs;
// Path: src/main/java/com/github/mjdbc/Db.java // public interface Db { // // /** // * Registers result set mapper. See DbMapper class for details. // * // * @param mapperClass the result classes. Result set row will be mapped to the instance of this class. // * @param mapper mapper. This mapper will be used to map result set row to mapperClass instance. // * @param <T> result type. // */ // <T> void registerMapper(@NotNull Class<T> mapperClass, @NotNull DbMapper<T> mapper); // // /** // * Registers prepared statement parameter binder. // * A binder for parameter is looked up by matching class first, any superclass second or any interface third. // * The old binder for this type is removed. // * // * @param binderClass parameter class to be processed by this binder. // * @param binder binder implementation. // */ // <T> void registerBinder(@NotNull Class<? extends T> binderClass, @NotNull DbBinder<T> binder); // // /** // * Attaches Dbi (DB interfaces) implementation to the database. // * All methods will be wrapped to transaction. Transaction will be started when the first SQL statement // * is used inside of the method and closed on exit from the method. Transaction is committed // * on normal exit and rolled back if Exception is thrown. // * <p> // * If Dbi method is called from another Dbi method no new transaction will be started: the upper-stack transaction will be used. // * // * @param impl database interface implementation. // * @param dbiInterface database interface to wrap with transactions support. // * @param <T> type of the Dbi interface. // * @return wrapped instance of the @dbiInterface // */ // @NotNull // <T> T attachDbi(@NotNull T impl, @NotNull Class<T> dbiInterface); // // /** // * Attaches sql interface to the database. All sql queries are parsed and validated during this call. // * // * @param sqlInterface sql interface to attach. // * @param <T> type of the interface. // * @return interface implementation. // */ // @NotNull // <T> T attachSql(@NotNull Class<T> sqlInterface); // // /** // * Executes database query that produces Nullable result. // * // * @param op query types. // * @param <T> result type. // * @return query result. // */ // @Nullable // <T> T execute(@NotNull DbOp<T> op); // // /** // * Executes database query that produces NotNull result. // * // * @param op query types. // * @param <T> result type. // * @return query result. // */ // @NotNull // <T> T executeNN(@NotNull DbOpNN<T> op); // // /** // * Executes database operation that produces no result. // * // * @param op operation types. // */ // void executeV(@NotNull DbOpV op); // // // /** // * Returns per-method timers. // * Statistics is collected for all methods of attached Dbi interfaces // * and for all @Sql methods of attached query interfaces. // * // * @return per-method statistics. Note: This is direct access to the timers map. Timers are updated concurrently. // * If a timer is removed from the map: it will be restarted. // */ // @NotNull // Map<Method, DbTimer> getTimers(); // // // /** // * Returns active connection assigned to current thread or throws IllegalStateException if not within DBOp. // */ // @NotNull // DbConnection getActiveConnection(); // } // // Path: src/main/java/com/github/mjdbc/DbFactory.java // public class DbFactory { // // /** // * Creates new mjdbc Db wrapper for the given datasource. // */ // @NotNull // public static Db wrap(@NotNull DataSource dataSource) { // return new DbImpl(dataSource); // } // // } // // Path: src/test/java/com/github/mjdbc/test/util/ProfiledDataSource.java // public class ProfiledDataSource implements javax.sql.DataSource { // @NotNull // private final DataSource ds; // // public int nGetConnectionCalls; // // public ProfiledDataSource(@NotNull DataSource ds) { // this.ds = ds; // } // // @Override // public PrintWriter getLogWriter() throws SQLException { // return ds.getLogWriter(); // } // // @Override // public void setLogWriter(PrintWriter out) throws SQLException { // ds.setLogWriter(out); // } // // @Override // public void setLoginTimeout(int seconds) throws SQLException { // ds.setLoginTimeout(seconds); // } // // @Override // public int getLoginTimeout() throws SQLException { // return ds.getLoginTimeout(); // } // // @Override // public Logger getParentLogger() throws SQLFeatureNotSupportedException { // return ds.getParentLogger(); // } // // @Override // public <T> T unwrap(Class<T> c) throws SQLException { // return ds.unwrap(c); // } // // @Override // public boolean isWrapperFor(Class<?> c) throws SQLException { // return ds.isWrapperFor(c); // } // // @Override // public Connection getConnection() throws SQLException { // nGetConnectionCalls++; // return new ProfiledConnection(ds.getConnection()); // } // // @Override // public Connection getConnection(String username, String password) throws SQLException { // nGetConnectionCalls++; // return new ProfiledConnection(ds.getConnection(username, password)); // } // } // Path: src/test/java/com/github/mjdbc/test/BaseSqlTest.java import com.github.mjdbc.Db; import com.github.mjdbc.DbFactory; import com.github.mjdbc.test.util.DbUtils; import com.github.mjdbc.test.util.ProfiledDataSource; import com.zaxxer.hikari.HikariDataSource; import org.jetbrains.annotations.NotNull; import org.junit.After; import org.junit.Assert; import org.junit.Before; package com.github.mjdbc.test; public abstract class BaseSqlTest<S> extends Assert { /** * Low level connection pool. */ protected HikariDataSource ds; protected ProfiledDataSource profiledDs;
protected Db db;
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/asset/sql/GetterBeanSql.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/GetterBean.java // public class GetterBean { // // private long id; // // private boolean booleanField; // // private int intField; // // private String stringField; // // private DbIntValue intValueField; // // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public boolean isBooleanField() { // return booleanField; // } // // public void setBooleanField(boolean booleanField) { // this.booleanField = booleanField; // } // // public int getIntField() { // return intField; // } // // public void setIntField(int intField) { // this.intField = intField; // } // // public String getStringField() { // return stringField; // } // // public void setStringField(String stringField) { // this.stringField = stringField; // } // // public DbIntValue getIntValueField() { // return intValueField; // } // // public void setIntValueField(DbIntValue intValueField) { // this.intValueField = intValueField; // } // // /** // * Class to create User object from result set. // */ // @Mapper // public static final DbMapper<GetterBean> MAPPER = (r) -> { // GetterBean res = new GetterBean(); // res.id = r.getInt("id"); // res.booleanField = r.getBoolean("boolean_field"); // res.intField = r.getInt("int_field"); // res.stringField = r.getString("string_field"); // res.intValueField = new DbIntValue(r.getInt("int_value_field")); // return res; // }; // }
import com.github.mjdbc.Bind; import com.github.mjdbc.BindBean; import com.github.mjdbc.Sql; import com.github.mjdbc.GetGeneratedKeys; import com.github.mjdbc.test.asset.model.GetterBean;
package com.github.mjdbc.test.asset.sql; public interface GetterBeanSql { @Sql("INSERT INTO bean(boolean_field, int_field, string_field, int_value_field) " + "VALUES(:booleanField, :intField, :stringField, :intValueField)") @GetGeneratedKeys
// Path: src/test/java/com/github/mjdbc/test/asset/model/GetterBean.java // public class GetterBean { // // private long id; // // private boolean booleanField; // // private int intField; // // private String stringField; // // private DbIntValue intValueField; // // // public long getId() { // return id; // } // // public void setId(long id) { // this.id = id; // } // // public boolean isBooleanField() { // return booleanField; // } // // public void setBooleanField(boolean booleanField) { // this.booleanField = booleanField; // } // // public int getIntField() { // return intField; // } // // public void setIntField(int intField) { // this.intField = intField; // } // // public String getStringField() { // return stringField; // } // // public void setStringField(String stringField) { // this.stringField = stringField; // } // // public DbIntValue getIntValueField() { // return intValueField; // } // // public void setIntValueField(DbIntValue intValueField) { // this.intValueField = intValueField; // } // // /** // * Class to create User object from result set. // */ // @Mapper // public static final DbMapper<GetterBean> MAPPER = (r) -> { // GetterBean res = new GetterBean(); // res.id = r.getInt("id"); // res.booleanField = r.getBoolean("boolean_field"); // res.intField = r.getInt("int_field"); // res.stringField = r.getString("string_field"); // res.intValueField = new DbIntValue(r.getInt("int_value_field")); // return res; // }; // } // Path: src/test/java/com/github/mjdbc/test/asset/sql/GetterBeanSql.java import com.github.mjdbc.Bind; import com.github.mjdbc.BindBean; import com.github.mjdbc.Sql; import com.github.mjdbc.GetGeneratedKeys; import com.github.mjdbc.test.asset.model.GetterBean; package com.github.mjdbc.test.asset.sql; public interface GetterBeanSql { @Sql("INSERT INTO bean(boolean_field, int_field, string_field, int_value_field) " + "VALUES(:booleanField, :intField, :stringField, :intValueField)") @GetGeneratedKeys
long insert(@BindBean GetterBean bean);
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/asset/sql/error/AmbiguousTypeSql.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/error/AmbiguousTypeValue.java // public class AmbiguousTypeValue implements DbType1, DbType2 { // }
import com.github.mjdbc.Bind; import com.github.mjdbc.Sql; import com.github.mjdbc.test.asset.model.error.AmbiguousTypeValue;
package com.github.mjdbc.test.asset.sql.error; public interface AmbiguousTypeSql { @Sql("SELECT count(*) FROM users WHERE id = :id")
// Path: src/test/java/com/github/mjdbc/test/asset/model/error/AmbiguousTypeValue.java // public class AmbiguousTypeValue implements DbType1, DbType2 { // } // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/AmbiguousTypeSql.java import com.github.mjdbc.Bind; import com.github.mjdbc.Sql; import com.github.mjdbc.test.asset.model.error.AmbiguousTypeValue; package com.github.mjdbc.test.asset.sql.error; public interface AmbiguousTypeSql { @Sql("SELECT count(*) FROM users WHERE id = :id")
int call(@Bind("id") AmbiguousTypeValue value);
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/asset/sql/error/MissedBeanParameterSql.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/User.java // public final class User { // /** // * It is recommended to have type safe IDs. // */ // public UserId id; // public String login; // public String firstName; // public String lastName; // public Gender gender; // public long score; // public Timestamp registrationDate; // // /** // * Class to create User object from result set. // */ // @Mapper // public static final DbMapper<User> MAPPER = (r) -> { // User user = new User(); // user.id = new UserId(r.getInt("id")); // user.login = r.getString("login"); // user.firstName = r.getString("first_name"); // user.lastName = r.getString("last_name"); // user.gender = Gender.fromDbValue(r.getInt("gender")); // user.score = r.getLong("score"); // user.registrationDate = r.getTimestamp("reg_date"); // return user; // }; // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // User user = (User) o; // return score == user.score && // Objects.equals(id, user.id) && // Objects.equals(login, user.login) && // Objects.equals(firstName, user.firstName) && // Objects.equals(lastName, user.lastName) && // gender == user.gender && // Objects.equals(registrationDate, user.registrationDate); // } // // @Override // public int hashCode() { // return Objects.hash(id, login, firstName, lastName, gender, score, registrationDate); // } // }
import com.github.mjdbc.BindBean; import com.github.mjdbc.Sql; import com.github.mjdbc.test.asset.model.User;
package com.github.mjdbc.test.asset.sql.error; /** * Sql interface used to test missed bean-level parameters. */ public interface MissedBeanParameterSql { @Sql("SELECT * FROM users WHERE login = :loogin")
// Path: src/test/java/com/github/mjdbc/test/asset/model/User.java // public final class User { // /** // * It is recommended to have type safe IDs. // */ // public UserId id; // public String login; // public String firstName; // public String lastName; // public Gender gender; // public long score; // public Timestamp registrationDate; // // /** // * Class to create User object from result set. // */ // @Mapper // public static final DbMapper<User> MAPPER = (r) -> { // User user = new User(); // user.id = new UserId(r.getInt("id")); // user.login = r.getString("login"); // user.firstName = r.getString("first_name"); // user.lastName = r.getString("last_name"); // user.gender = Gender.fromDbValue(r.getInt("gender")); // user.score = r.getLong("score"); // user.registrationDate = r.getTimestamp("reg_date"); // return user; // }; // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // User user = (User) o; // return score == user.score && // Objects.equals(id, user.id) && // Objects.equals(login, user.login) && // Objects.equals(firstName, user.firstName) && // Objects.equals(lastName, user.lastName) && // gender == user.gender && // Objects.equals(registrationDate, user.registrationDate); // } // // @Override // public int hashCode() { // return Objects.hash(id, login, firstName, lastName, gender, score, registrationDate); // } // } // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/MissedBeanParameterSql.java import com.github.mjdbc.BindBean; import com.github.mjdbc.Sql; import com.github.mjdbc.test.asset.model.User; package com.github.mjdbc.test.asset.sql.error; /** * Sql interface used to test missed bean-level parameters. */ public interface MissedBeanParameterSql { @Sql("SELECT * FROM users WHERE login = :loogin")
void updateFirstNameWithReader(@BindBean User user);
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/asset/model/error/NonFinalMapperBean.java
// Path: src/main/java/com/github/mjdbc/DbMapper.java // public interface DbMapper<T> { // // /** // * Maps a single row or all rows to the corresponding Java object. // * May return null for nullable primitive type fields (like nullable varchar field). // * Must never return null for complex java property objects (beans). // * // * @param r - open result set. // * @return Java object. // * @throws SQLException if SQLException occurs during the mapping process // */ // T map(@NotNull ResultSet r) throws SQLException; // }
import com.github.mjdbc.DbMapper; import com.github.mjdbc.Mapper;
package com.github.mjdbc.test.asset.model.error; /** * Object mapped by field marked with annotation. */ public class NonFinalMapperBean { @Mapper
// Path: src/main/java/com/github/mjdbc/DbMapper.java // public interface DbMapper<T> { // // /** // * Maps a single row or all rows to the corresponding Java object. // * May return null for nullable primitive type fields (like nullable varchar field). // * Must never return null for complex java property objects (beans). // * // * @param r - open result set. // * @return Java object. // * @throws SQLException if SQLException occurs during the mapping process // */ // T map(@NotNull ResultSet r) throws SQLException; // } // Path: src/test/java/com/github/mjdbc/test/asset/model/error/NonFinalMapperBean.java import com.github.mjdbc.DbMapper; import com.github.mjdbc.Mapper; package com.github.mjdbc.test.asset.model.error; /** * Object mapped by field marked with annotation. */ public class NonFinalMapperBean { @Mapper
public static DbMapper<NonFinalMapperBean> M = (r) -> new NonFinalMapperBean();
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/DbRegisterBinderTest.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/User.java // public final class User { // /** // * It is recommended to have type safe IDs. // */ // public UserId id; // public String login; // public String firstName; // public String lastName; // public Gender gender; // public long score; // public Timestamp registrationDate; // // /** // * Class to create User object from result set. // */ // @Mapper // public static final DbMapper<User> MAPPER = (r) -> { // User user = new User(); // user.id = new UserId(r.getInt("id")); // user.login = r.getString("login"); // user.firstName = r.getString("first_name"); // user.lastName = r.getString("last_name"); // user.gender = Gender.fromDbValue(r.getInt("gender")); // user.score = r.getLong("score"); // user.registrationDate = r.getTimestamp("reg_date"); // return user; // }; // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // User user = (User) o; // return score == user.score && // Objects.equals(id, user.id) && // Objects.equals(login, user.login) && // Objects.equals(firstName, user.firstName) && // Objects.equals(lastName, user.lastName) && // gender == user.gender && // Objects.equals(registrationDate, user.registrationDate); // } // // @Override // public int hashCode() { // return Objects.hash(id, login, firstName, lastName, gender, score, registrationDate); // } // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/ReaderSql.java // public interface ReaderSql { // // @Sql("UPDATE users SET first_name = :firstName WHERE login = :login") // void updateFirstNameWithReader(@Bind("login") String login, @Bind("firstName") Reader r); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/AmbiguousTypeSql.java // public interface AmbiguousTypeSql { // @Sql("SELECT count(*) FROM users WHERE id = :id") // int call(@Bind("id") AmbiguousTypeValue value); // }
import com.github.mjdbc.test.asset.model.DbType1; import com.github.mjdbc.test.asset.model.DbType2; import com.github.mjdbc.test.asset.model.User; import com.github.mjdbc.test.asset.model.UserId; import com.github.mjdbc.test.asset.sql.ReaderSql; import com.github.mjdbc.test.asset.sql.UserSql; import com.github.mjdbc.test.asset.sql.error.AmbiguousTypeSql; import java.io.Reader; import java.io.StringReader; import java.sql.PreparedStatement; import org.junit.Before; import org.junit.Test;
package com.github.mjdbc.test; /** * Tests for Db::registerBinder method. */ public class DbRegisterBinderTest extends DbTest { @Before public void setUp() { super.setUp(); db.registerMapper(UserId.class, UserId.MAPPER);
// Path: src/test/java/com/github/mjdbc/test/asset/model/User.java // public final class User { // /** // * It is recommended to have type safe IDs. // */ // public UserId id; // public String login; // public String firstName; // public String lastName; // public Gender gender; // public long score; // public Timestamp registrationDate; // // /** // * Class to create User object from result set. // */ // @Mapper // public static final DbMapper<User> MAPPER = (r) -> { // User user = new User(); // user.id = new UserId(r.getInt("id")); // user.login = r.getString("login"); // user.firstName = r.getString("first_name"); // user.lastName = r.getString("last_name"); // user.gender = Gender.fromDbValue(r.getInt("gender")); // user.score = r.getLong("score"); // user.registrationDate = r.getTimestamp("reg_date"); // return user; // }; // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // User user = (User) o; // return score == user.score && // Objects.equals(id, user.id) && // Objects.equals(login, user.login) && // Objects.equals(firstName, user.firstName) && // Objects.equals(lastName, user.lastName) && // gender == user.gender && // Objects.equals(registrationDate, user.registrationDate); // } // // @Override // public int hashCode() { // return Objects.hash(id, login, firstName, lastName, gender, score, registrationDate); // } // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/ReaderSql.java // public interface ReaderSql { // // @Sql("UPDATE users SET first_name = :firstName WHERE login = :login") // void updateFirstNameWithReader(@Bind("login") String login, @Bind("firstName") Reader r); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/AmbiguousTypeSql.java // public interface AmbiguousTypeSql { // @Sql("SELECT count(*) FROM users WHERE id = :id") // int call(@Bind("id") AmbiguousTypeValue value); // } // Path: src/test/java/com/github/mjdbc/test/DbRegisterBinderTest.java import com.github.mjdbc.test.asset.model.DbType1; import com.github.mjdbc.test.asset.model.DbType2; import com.github.mjdbc.test.asset.model.User; import com.github.mjdbc.test.asset.model.UserId; import com.github.mjdbc.test.asset.sql.ReaderSql; import com.github.mjdbc.test.asset.sql.UserSql; import com.github.mjdbc.test.asset.sql.error.AmbiguousTypeSql; import java.io.Reader; import java.io.StringReader; import java.sql.PreparedStatement; import org.junit.Before; import org.junit.Test; package com.github.mjdbc.test; /** * Tests for Db::registerBinder method. */ public class DbRegisterBinderTest extends DbTest { @Before public void setUp() { super.setUp(); db.registerMapper(UserId.class, UserId.MAPPER);
db.registerMapper(User.class, User.MAPPER);
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/DbRegisterBinderTest.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/User.java // public final class User { // /** // * It is recommended to have type safe IDs. // */ // public UserId id; // public String login; // public String firstName; // public String lastName; // public Gender gender; // public long score; // public Timestamp registrationDate; // // /** // * Class to create User object from result set. // */ // @Mapper // public static final DbMapper<User> MAPPER = (r) -> { // User user = new User(); // user.id = new UserId(r.getInt("id")); // user.login = r.getString("login"); // user.firstName = r.getString("first_name"); // user.lastName = r.getString("last_name"); // user.gender = Gender.fromDbValue(r.getInt("gender")); // user.score = r.getLong("score"); // user.registrationDate = r.getTimestamp("reg_date"); // return user; // }; // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // User user = (User) o; // return score == user.score && // Objects.equals(id, user.id) && // Objects.equals(login, user.login) && // Objects.equals(firstName, user.firstName) && // Objects.equals(lastName, user.lastName) && // gender == user.gender && // Objects.equals(registrationDate, user.registrationDate); // } // // @Override // public int hashCode() { // return Objects.hash(id, login, firstName, lastName, gender, score, registrationDate); // } // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/ReaderSql.java // public interface ReaderSql { // // @Sql("UPDATE users SET first_name = :firstName WHERE login = :login") // void updateFirstNameWithReader(@Bind("login") String login, @Bind("firstName") Reader r); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/AmbiguousTypeSql.java // public interface AmbiguousTypeSql { // @Sql("SELECT count(*) FROM users WHERE id = :id") // int call(@Bind("id") AmbiguousTypeValue value); // }
import com.github.mjdbc.test.asset.model.DbType1; import com.github.mjdbc.test.asset.model.DbType2; import com.github.mjdbc.test.asset.model.User; import com.github.mjdbc.test.asset.model.UserId; import com.github.mjdbc.test.asset.sql.ReaderSql; import com.github.mjdbc.test.asset.sql.UserSql; import com.github.mjdbc.test.asset.sql.error.AmbiguousTypeSql; import java.io.Reader; import java.io.StringReader; import java.sql.PreparedStatement; import org.junit.Before; import org.junit.Test;
package com.github.mjdbc.test; /** * Tests for Db::registerBinder method. */ public class DbRegisterBinderTest extends DbTest { @Before public void setUp() { super.setUp(); db.registerMapper(UserId.class, UserId.MAPPER); db.registerMapper(User.class, User.MAPPER); } /** * Check that new binder class can be registered and used. */ @Test public void binderForUserClassIsRegisteredSuccessfully() { db.registerBinder(Reader.class, PreparedStatement::setCharacterStream);
// Path: src/test/java/com/github/mjdbc/test/asset/model/User.java // public final class User { // /** // * It is recommended to have type safe IDs. // */ // public UserId id; // public String login; // public String firstName; // public String lastName; // public Gender gender; // public long score; // public Timestamp registrationDate; // // /** // * Class to create User object from result set. // */ // @Mapper // public static final DbMapper<User> MAPPER = (r) -> { // User user = new User(); // user.id = new UserId(r.getInt("id")); // user.login = r.getString("login"); // user.firstName = r.getString("first_name"); // user.lastName = r.getString("last_name"); // user.gender = Gender.fromDbValue(r.getInt("gender")); // user.score = r.getLong("score"); // user.registrationDate = r.getTimestamp("reg_date"); // return user; // }; // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // User user = (User) o; // return score == user.score && // Objects.equals(id, user.id) && // Objects.equals(login, user.login) && // Objects.equals(firstName, user.firstName) && // Objects.equals(lastName, user.lastName) && // gender == user.gender && // Objects.equals(registrationDate, user.registrationDate); // } // // @Override // public int hashCode() { // return Objects.hash(id, login, firstName, lastName, gender, score, registrationDate); // } // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/ReaderSql.java // public interface ReaderSql { // // @Sql("UPDATE users SET first_name = :firstName WHERE login = :login") // void updateFirstNameWithReader(@Bind("login") String login, @Bind("firstName") Reader r); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/AmbiguousTypeSql.java // public interface AmbiguousTypeSql { // @Sql("SELECT count(*) FROM users WHERE id = :id") // int call(@Bind("id") AmbiguousTypeValue value); // } // Path: src/test/java/com/github/mjdbc/test/DbRegisterBinderTest.java import com.github.mjdbc.test.asset.model.DbType1; import com.github.mjdbc.test.asset.model.DbType2; import com.github.mjdbc.test.asset.model.User; import com.github.mjdbc.test.asset.model.UserId; import com.github.mjdbc.test.asset.sql.ReaderSql; import com.github.mjdbc.test.asset.sql.UserSql; import com.github.mjdbc.test.asset.sql.error.AmbiguousTypeSql; import java.io.Reader; import java.io.StringReader; import java.sql.PreparedStatement; import org.junit.Before; import org.junit.Test; package com.github.mjdbc.test; /** * Tests for Db::registerBinder method. */ public class DbRegisterBinderTest extends DbTest { @Before public void setUp() { super.setUp(); db.registerMapper(UserId.class, UserId.MAPPER); db.registerMapper(User.class, User.MAPPER); } /** * Check that new binder class can be registered and used. */ @Test public void binderForUserClassIsRegisteredSuccessfully() { db.registerBinder(Reader.class, PreparedStatement::setCharacterStream);
ReaderSql q1 = db.attachSql(ReaderSql.class);
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/DbRegisterBinderTest.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/User.java // public final class User { // /** // * It is recommended to have type safe IDs. // */ // public UserId id; // public String login; // public String firstName; // public String lastName; // public Gender gender; // public long score; // public Timestamp registrationDate; // // /** // * Class to create User object from result set. // */ // @Mapper // public static final DbMapper<User> MAPPER = (r) -> { // User user = new User(); // user.id = new UserId(r.getInt("id")); // user.login = r.getString("login"); // user.firstName = r.getString("first_name"); // user.lastName = r.getString("last_name"); // user.gender = Gender.fromDbValue(r.getInt("gender")); // user.score = r.getLong("score"); // user.registrationDate = r.getTimestamp("reg_date"); // return user; // }; // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // User user = (User) o; // return score == user.score && // Objects.equals(id, user.id) && // Objects.equals(login, user.login) && // Objects.equals(firstName, user.firstName) && // Objects.equals(lastName, user.lastName) && // gender == user.gender && // Objects.equals(registrationDate, user.registrationDate); // } // // @Override // public int hashCode() { // return Objects.hash(id, login, firstName, lastName, gender, score, registrationDate); // } // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/ReaderSql.java // public interface ReaderSql { // // @Sql("UPDATE users SET first_name = :firstName WHERE login = :login") // void updateFirstNameWithReader(@Bind("login") String login, @Bind("firstName") Reader r); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/AmbiguousTypeSql.java // public interface AmbiguousTypeSql { // @Sql("SELECT count(*) FROM users WHERE id = :id") // int call(@Bind("id") AmbiguousTypeValue value); // }
import com.github.mjdbc.test.asset.model.DbType1; import com.github.mjdbc.test.asset.model.DbType2; import com.github.mjdbc.test.asset.model.User; import com.github.mjdbc.test.asset.model.UserId; import com.github.mjdbc.test.asset.sql.ReaderSql; import com.github.mjdbc.test.asset.sql.UserSql; import com.github.mjdbc.test.asset.sql.error.AmbiguousTypeSql; import java.io.Reader; import java.io.StringReader; import java.sql.PreparedStatement; import org.junit.Before; import org.junit.Test;
ReaderSql q1 = db.attachSql(ReaderSql.class); q1.updateFirstNameWithReader("u1", new StringReader("x")); UserSql q2 = db.attachSql(UserSql.class); User u = q2.getUserByLogin("u1"); assertNotNull(u); assertEquals("x", u.firstName); } /** * Check that registration of null binder triggers IllegalArgumentException */ @Test(expected = NullPointerException.class) public void nullBinderTypeTriggersNullPointerException() { //noinspection ConstantConditions,RedundantCast db.registerBinder((Class<Reader>) null, PreparedStatement::setCharacterStream); } @Test(expected = NullPointerException.class) public void nullBinderFunctionTriggersNullPointerException() { //noinspection ConstantConditions db.registerBinder(Reader.class, null); } @Test(expected = IllegalArgumentException.class) public void multipleBindersForSameObjectThrowException() { db.registerBinder(DbType1.class, (statement, idx, value) -> { }); db.registerBinder(DbType2.class, (statement, idx, value) -> { });
// Path: src/test/java/com/github/mjdbc/test/asset/model/User.java // public final class User { // /** // * It is recommended to have type safe IDs. // */ // public UserId id; // public String login; // public String firstName; // public String lastName; // public Gender gender; // public long score; // public Timestamp registrationDate; // // /** // * Class to create User object from result set. // */ // @Mapper // public static final DbMapper<User> MAPPER = (r) -> { // User user = new User(); // user.id = new UserId(r.getInt("id")); // user.login = r.getString("login"); // user.firstName = r.getString("first_name"); // user.lastName = r.getString("last_name"); // user.gender = Gender.fromDbValue(r.getInt("gender")); // user.score = r.getLong("score"); // user.registrationDate = r.getTimestamp("reg_date"); // return user; // }; // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // User user = (User) o; // return score == user.score && // Objects.equals(id, user.id) && // Objects.equals(login, user.login) && // Objects.equals(firstName, user.firstName) && // Objects.equals(lastName, user.lastName) && // gender == user.gender && // Objects.equals(registrationDate, user.registrationDate); // } // // @Override // public int hashCode() { // return Objects.hash(id, login, firstName, lastName, gender, score, registrationDate); // } // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/ReaderSql.java // public interface ReaderSql { // // @Sql("UPDATE users SET first_name = :firstName WHERE login = :login") // void updateFirstNameWithReader(@Bind("login") String login, @Bind("firstName") Reader r); // } // // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/AmbiguousTypeSql.java // public interface AmbiguousTypeSql { // @Sql("SELECT count(*) FROM users WHERE id = :id") // int call(@Bind("id") AmbiguousTypeValue value); // } // Path: src/test/java/com/github/mjdbc/test/DbRegisterBinderTest.java import com.github.mjdbc.test.asset.model.DbType1; import com.github.mjdbc.test.asset.model.DbType2; import com.github.mjdbc.test.asset.model.User; import com.github.mjdbc.test.asset.model.UserId; import com.github.mjdbc.test.asset.sql.ReaderSql; import com.github.mjdbc.test.asset.sql.UserSql; import com.github.mjdbc.test.asset.sql.error.AmbiguousTypeSql; import java.io.Reader; import java.io.StringReader; import java.sql.PreparedStatement; import org.junit.Before; import org.junit.Test; ReaderSql q1 = db.attachSql(ReaderSql.class); q1.updateFirstNameWithReader("u1", new StringReader("x")); UserSql q2 = db.attachSql(UserSql.class); User u = q2.getUserByLogin("u1"); assertNotNull(u); assertEquals("x", u.firstName); } /** * Check that registration of null binder triggers IllegalArgumentException */ @Test(expected = NullPointerException.class) public void nullBinderTypeTriggersNullPointerException() { //noinspection ConstantConditions,RedundantCast db.registerBinder((Class<Reader>) null, PreparedStatement::setCharacterStream); } @Test(expected = NullPointerException.class) public void nullBinderFunctionTriggersNullPointerException() { //noinspection ConstantConditions db.registerBinder(Reader.class, null); } @Test(expected = IllegalArgumentException.class) public void multipleBindersForSameObjectThrowException() { db.registerBinder(DbType1.class, (statement, idx, value) -> { }); db.registerBinder(DbType2.class, (statement, idx, value) -> { });
db.attachSql(AmbiguousTypeSql.class);
mjdbc/mjdbc
src/main/java/com/github/mjdbc/DbPreparedStatement.java
// Path: src/main/java/com/github/mjdbc/type/DbInt.java // public interface DbInt { // /** // * @return database object representation. // */ // int getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbLong.java // public interface DbLong { // /** // * @return database object representation. // */ // long getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbString.java // public interface DbString { // /** // * @return database object representation. // */ // String getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbTimestamp.java // public interface DbTimestamp { // /** // * @return database object representation. // */ // Timestamp getDbValue(); // }
import com.github.mjdbc.DbImpl.BindInfo; import com.github.mjdbc.type.DbInt; import com.github.mjdbc.type.DbLong; import com.github.mjdbc.type.DbString; import com.github.mjdbc.type.DbTimestamp; import java.lang.reflect.InvocationTargetException; import java.math.BigDecimal; import java.sql.Connection; import java.sql.JDBCType; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.SQLType; import java.sql.Statement; import java.sql.Timestamp; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable;
} return this; } /** * Sets boolean value for all fields matched by name. */ @NotNull public DbPreparedStatement<T> set(@NotNull String name, boolean value) throws SQLException { for (int i : getIndexes(name)) { statement.setBoolean(i, value); } return this; } /** * Sets int value for all fields matched by name. */ @NotNull public DbPreparedStatement<T> set(@NotNull String name, int value) throws SQLException { for (int i : getIndexes(name)) { statement.setInt(i, value); } return this; } /** * Sets int value for all fields matched by name. If value is null calls setNull for all fields. */ @NotNull
// Path: src/main/java/com/github/mjdbc/type/DbInt.java // public interface DbInt { // /** // * @return database object representation. // */ // int getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbLong.java // public interface DbLong { // /** // * @return database object representation. // */ // long getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbString.java // public interface DbString { // /** // * @return database object representation. // */ // String getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbTimestamp.java // public interface DbTimestamp { // /** // * @return database object representation. // */ // Timestamp getDbValue(); // } // Path: src/main/java/com/github/mjdbc/DbPreparedStatement.java import com.github.mjdbc.DbImpl.BindInfo; import com.github.mjdbc.type.DbInt; import com.github.mjdbc.type.DbLong; import com.github.mjdbc.type.DbString; import com.github.mjdbc.type.DbTimestamp; import java.lang.reflect.InvocationTargetException; import java.math.BigDecimal; import java.sql.Connection; import java.sql.JDBCType; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.SQLType; import java.sql.Statement; import java.sql.Timestamp; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; } return this; } /** * Sets boolean value for all fields matched by name. */ @NotNull public DbPreparedStatement<T> set(@NotNull String name, boolean value) throws SQLException { for (int i : getIndexes(name)) { statement.setBoolean(i, value); } return this; } /** * Sets int value for all fields matched by name. */ @NotNull public DbPreparedStatement<T> set(@NotNull String name, int value) throws SQLException { for (int i : getIndexes(name)) { statement.setInt(i, value); } return this; } /** * Sets int value for all fields matched by name. If value is null calls setNull for all fields. */ @NotNull
public DbPreparedStatement<T> set(@NotNull String name, @Nullable DbInt value) throws SQLException {
mjdbc/mjdbc
src/main/java/com/github/mjdbc/DbPreparedStatement.java
// Path: src/main/java/com/github/mjdbc/type/DbInt.java // public interface DbInt { // /** // * @return database object representation. // */ // int getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbLong.java // public interface DbLong { // /** // * @return database object representation. // */ // long getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbString.java // public interface DbString { // /** // * @return database object representation. // */ // String getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbTimestamp.java // public interface DbTimestamp { // /** // * @return database object representation. // */ // Timestamp getDbValue(); // }
import com.github.mjdbc.DbImpl.BindInfo; import com.github.mjdbc.type.DbInt; import com.github.mjdbc.type.DbLong; import com.github.mjdbc.type.DbString; import com.github.mjdbc.type.DbTimestamp; import java.lang.reflect.InvocationTargetException; import java.math.BigDecimal; import java.sql.Connection; import java.sql.JDBCType; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.SQLType; import java.sql.Statement; import java.sql.Timestamp; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable;
public DbPreparedStatement<T> set(@NotNull String name, int value) throws SQLException { for (int i : getIndexes(name)) { statement.setInt(i, value); } return this; } /** * Sets int value for all fields matched by name. If value is null calls setNull for all fields. */ @NotNull public DbPreparedStatement<T> set(@NotNull String name, @Nullable DbInt value) throws SQLException { return value == null ? setNull(name, JDBCType.INTEGER) : set(name, value.getDbValue()); } /** * Sets long value for all fields matched by name. */ @NotNull public DbPreparedStatement<T> set(@NotNull String name, long value) throws SQLException { for (int i : getIndexes(name)) { statement.setLong(i, value); } return this; } /** * Sets long value for all fields matched by name. If value is null calls setNull for all fields. */ @NotNull
// Path: src/main/java/com/github/mjdbc/type/DbInt.java // public interface DbInt { // /** // * @return database object representation. // */ // int getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbLong.java // public interface DbLong { // /** // * @return database object representation. // */ // long getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbString.java // public interface DbString { // /** // * @return database object representation. // */ // String getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbTimestamp.java // public interface DbTimestamp { // /** // * @return database object representation. // */ // Timestamp getDbValue(); // } // Path: src/main/java/com/github/mjdbc/DbPreparedStatement.java import com.github.mjdbc.DbImpl.BindInfo; import com.github.mjdbc.type.DbInt; import com.github.mjdbc.type.DbLong; import com.github.mjdbc.type.DbString; import com.github.mjdbc.type.DbTimestamp; import java.lang.reflect.InvocationTargetException; import java.math.BigDecimal; import java.sql.Connection; import java.sql.JDBCType; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.SQLType; import java.sql.Statement; import java.sql.Timestamp; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public DbPreparedStatement<T> set(@NotNull String name, int value) throws SQLException { for (int i : getIndexes(name)) { statement.setInt(i, value); } return this; } /** * Sets int value for all fields matched by name. If value is null calls setNull for all fields. */ @NotNull public DbPreparedStatement<T> set(@NotNull String name, @Nullable DbInt value) throws SQLException { return value == null ? setNull(name, JDBCType.INTEGER) : set(name, value.getDbValue()); } /** * Sets long value for all fields matched by name. */ @NotNull public DbPreparedStatement<T> set(@NotNull String name, long value) throws SQLException { for (int i : getIndexes(name)) { statement.setLong(i, value); } return this; } /** * Sets long value for all fields matched by name. If value is null calls setNull for all fields. */ @NotNull
public DbPreparedStatement<T> set(@NotNull String name, @Nullable DbLong value) throws SQLException {
mjdbc/mjdbc
src/main/java/com/github/mjdbc/DbPreparedStatement.java
// Path: src/main/java/com/github/mjdbc/type/DbInt.java // public interface DbInt { // /** // * @return database object representation. // */ // int getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbLong.java // public interface DbLong { // /** // * @return database object representation. // */ // long getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbString.java // public interface DbString { // /** // * @return database object representation. // */ // String getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbTimestamp.java // public interface DbTimestamp { // /** // * @return database object representation. // */ // Timestamp getDbValue(); // }
import com.github.mjdbc.DbImpl.BindInfo; import com.github.mjdbc.type.DbInt; import com.github.mjdbc.type.DbLong; import com.github.mjdbc.type.DbString; import com.github.mjdbc.type.DbTimestamp; import java.lang.reflect.InvocationTargetException; import java.math.BigDecimal; import java.sql.Connection; import java.sql.JDBCType; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.SQLType; import java.sql.Statement; import java.sql.Timestamp; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable;
} return this; } /** * Sets BigDecimal value for all fields matched by name. */ @NotNull public DbPreparedStatement<T> set(@NotNull String name, @Nullable BigDecimal value) throws SQLException { for (int i : getIndexes(name)) { statement.setBigDecimal(i, value); } return this; } /** * Sets string value for all fields matched by name. */ @NotNull public DbPreparedStatement<T> set(@NotNull String name, @Nullable String value) throws SQLException { for (int i : getIndexes(name)) { statement.setString(i, value); } return this; } /** * Sets string value for all fields matched by name. If value is null - sets null. */ @NotNull
// Path: src/main/java/com/github/mjdbc/type/DbInt.java // public interface DbInt { // /** // * @return database object representation. // */ // int getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbLong.java // public interface DbLong { // /** // * @return database object representation. // */ // long getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbString.java // public interface DbString { // /** // * @return database object representation. // */ // String getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbTimestamp.java // public interface DbTimestamp { // /** // * @return database object representation. // */ // Timestamp getDbValue(); // } // Path: src/main/java/com/github/mjdbc/DbPreparedStatement.java import com.github.mjdbc.DbImpl.BindInfo; import com.github.mjdbc.type.DbInt; import com.github.mjdbc.type.DbLong; import com.github.mjdbc.type.DbString; import com.github.mjdbc.type.DbTimestamp; import java.lang.reflect.InvocationTargetException; import java.math.BigDecimal; import java.sql.Connection; import java.sql.JDBCType; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.SQLType; import java.sql.Statement; import java.sql.Timestamp; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; } return this; } /** * Sets BigDecimal value for all fields matched by name. */ @NotNull public DbPreparedStatement<T> set(@NotNull String name, @Nullable BigDecimal value) throws SQLException { for (int i : getIndexes(name)) { statement.setBigDecimal(i, value); } return this; } /** * Sets string value for all fields matched by name. */ @NotNull public DbPreparedStatement<T> set(@NotNull String name, @Nullable String value) throws SQLException { for (int i : getIndexes(name)) { statement.setString(i, value); } return this; } /** * Sets string value for all fields matched by name. If value is null - sets null. */ @NotNull
public DbPreparedStatement<T> set(@NotNull String name, @Nullable DbString value) throws SQLException {
mjdbc/mjdbc
src/main/java/com/github/mjdbc/DbPreparedStatement.java
// Path: src/main/java/com/github/mjdbc/type/DbInt.java // public interface DbInt { // /** // * @return database object representation. // */ // int getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbLong.java // public interface DbLong { // /** // * @return database object representation. // */ // long getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbString.java // public interface DbString { // /** // * @return database object representation. // */ // String getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbTimestamp.java // public interface DbTimestamp { // /** // * @return database object representation. // */ // Timestamp getDbValue(); // }
import com.github.mjdbc.DbImpl.BindInfo; import com.github.mjdbc.type.DbInt; import com.github.mjdbc.type.DbLong; import com.github.mjdbc.type.DbString; import com.github.mjdbc.type.DbTimestamp; import java.lang.reflect.InvocationTargetException; import java.math.BigDecimal; import java.sql.Connection; import java.sql.JDBCType; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.SQLType; import java.sql.Statement; import java.sql.Timestamp; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable;
public DbPreparedStatement<T> set(@NotNull String name, @Nullable DbString value) throws SQLException { return set(name, value == null ? null : value.getDbValue()); } /** * Sets byte[] value for all fields matched by name. */ @NotNull public DbPreparedStatement<T> set(@NotNull String name, @Nullable byte[] value) throws SQLException { for (int i : getIndexes(name)) { statement.setBytes(i, value); } return this; } /** * Sets Timestamp value for all fields matched by name. */ @NotNull public DbPreparedStatement<T> set(@NotNull String name, @Nullable Timestamp value) throws SQLException { for (int i : getIndexes(name)) { statement.setTimestamp(i, value); } return this; } /** * Sets Timestamp value for all fields matched by name. If value is null - sets null. */ @NotNull
// Path: src/main/java/com/github/mjdbc/type/DbInt.java // public interface DbInt { // /** // * @return database object representation. // */ // int getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbLong.java // public interface DbLong { // /** // * @return database object representation. // */ // long getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbString.java // public interface DbString { // /** // * @return database object representation. // */ // String getDbValue(); // } // // Path: src/main/java/com/github/mjdbc/type/DbTimestamp.java // public interface DbTimestamp { // /** // * @return database object representation. // */ // Timestamp getDbValue(); // } // Path: src/main/java/com/github/mjdbc/DbPreparedStatement.java import com.github.mjdbc.DbImpl.BindInfo; import com.github.mjdbc.type.DbInt; import com.github.mjdbc.type.DbLong; import com.github.mjdbc.type.DbString; import com.github.mjdbc.type.DbTimestamp; import java.lang.reflect.InvocationTargetException; import java.math.BigDecimal; import java.sql.Connection; import java.sql.JDBCType; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.SQLType; import java.sql.Statement; import java.sql.Timestamp; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public DbPreparedStatement<T> set(@NotNull String name, @Nullable DbString value) throws SQLException { return set(name, value == null ? null : value.getDbValue()); } /** * Sets byte[] value for all fields matched by name. */ @NotNull public DbPreparedStatement<T> set(@NotNull String name, @Nullable byte[] value) throws SQLException { for (int i : getIndexes(name)) { statement.setBytes(i, value); } return this; } /** * Sets Timestamp value for all fields matched by name. */ @NotNull public DbPreparedStatement<T> set(@NotNull String name, @Nullable Timestamp value) throws SQLException { for (int i : getIndexes(name)) { statement.setTimestamp(i, value); } return this; } /** * Sets Timestamp value for all fields matched by name. If value is null - sets null. */ @NotNull
public DbPreparedStatement<T> set(@NotNull String name, @Nullable DbTimestamp value) throws SQLException {
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java
// Path: src/main/java/com/github/mjdbc/DbMapper.java // public interface DbMapper<T> { // // /** // * Maps a single row or all rows to the corresponding Java object. // * May return null for nullable primitive type fields (like nullable varchar field). // * Must never return null for complex java property objects (beans). // * // * @param r - open result set. // * @return Java object. // * @throws SQLException if SQLException occurs during the mapping process // */ // T map(@NotNull ResultSet r) throws SQLException; // }
import com.github.mjdbc.DbMapper; import com.github.mjdbc.Mapper;
package com.github.mjdbc.test.asset.model; public class BeanWithStaticFieldMapper { @Mapper
// Path: src/main/java/com/github/mjdbc/DbMapper.java // public interface DbMapper<T> { // // /** // * Maps a single row or all rows to the corresponding Java object. // * May return null for nullable primitive type fields (like nullable varchar field). // * Must never return null for complex java property objects (beans). // * // * @param r - open result set. // * @return Java object. // * @throws SQLException if SQLException occurs during the mapping process // */ // T map(@NotNull ResultSet r) throws SQLException; // } // Path: src/test/java/com/github/mjdbc/test/asset/model/BeanWithStaticFieldMapper.java import com.github.mjdbc.DbMapper; import com.github.mjdbc.Mapper; package com.github.mjdbc.test.asset.model; public class BeanWithStaticFieldMapper { @Mapper
public static final DbMapper<BeanWithStaticFieldMapper> MAPPER_v1_1 = r -> null;
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/asset/model/User.java
// Path: src/main/java/com/github/mjdbc/DbMapper.java // public interface DbMapper<T> { // // /** // * Maps a single row or all rows to the corresponding Java object. // * May return null for nullable primitive type fields (like nullable varchar field). // * Must never return null for complex java property objects (beans). // * // * @param r - open result set. // * @return Java object. // * @throws SQLException if SQLException occurs during the mapping process // */ // T map(@NotNull ResultSet r) throws SQLException; // }
import com.github.mjdbc.DbMapper; import com.github.mjdbc.Mapper; import java.sql.Timestamp; import java.util.Objects;
package com.github.mjdbc.test.asset.model; /** * Sample class for user record in DB. * Fields are public because it's hard to find a reason to write both getters and setters. * Note: 'mjdbc' will work with getters too. */ public final class User { /** * It is recommended to have type safe IDs. */ public UserId id; public String login; public String firstName; public String lastName; public Gender gender; public long score; public Timestamp registrationDate; /** * Class to create User object from result set. */ @Mapper
// Path: src/main/java/com/github/mjdbc/DbMapper.java // public interface DbMapper<T> { // // /** // * Maps a single row or all rows to the corresponding Java object. // * May return null for nullable primitive type fields (like nullable varchar field). // * Must never return null for complex java property objects (beans). // * // * @param r - open result set. // * @return Java object. // * @throws SQLException if SQLException occurs during the mapping process // */ // T map(@NotNull ResultSet r) throws SQLException; // } // Path: src/test/java/com/github/mjdbc/test/asset/model/User.java import com.github.mjdbc.DbMapper; import com.github.mjdbc.Mapper; import java.sql.Timestamp; import java.util.Objects; package com.github.mjdbc.test.asset.model; /** * Sample class for user record in DB. * Fields are public because it's hard to find a reason to write both getters and setters. * Note: 'mjdbc' will work with getters too. */ public final class User { /** * It is recommended to have type safe IDs. */ public UserId id; public String login; public String firstName; public String lastName; public Gender gender; public long score; public Timestamp registrationDate; /** * Class to create User object from result set. */ @Mapper
public static final DbMapper<User> MAPPER = (r) -> {
mjdbc/mjdbc
src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java
// Path: src/test/java/com/github/mjdbc/test/asset/model/error/NonFinalMapperBean.java // public class NonFinalMapperBean { // // @Mapper // public static DbMapper<NonFinalMapperBean> M = (r) -> new NonFinalMapperBean(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/model/error/NonPublicMapperBean.java // public class NonPublicMapperBean { // // @Mapper // final static DbMapper<NonPublicMapperBean> M = (r) -> new NonPublicMapperBean(); // // }
import com.github.mjdbc.Sql; import com.github.mjdbc.test.asset.model.error.NonFinalMapperBean; import com.github.mjdbc.test.asset.model.error.NonPublicMapperBean;
package com.github.mjdbc.test.asset.sql.error; public interface NonPublicMapperBeanSql { @Sql("SELECT 1")
// Path: src/test/java/com/github/mjdbc/test/asset/model/error/NonFinalMapperBean.java // public class NonFinalMapperBean { // // @Mapper // public static DbMapper<NonFinalMapperBean> M = (r) -> new NonFinalMapperBean(); // // } // // Path: src/test/java/com/github/mjdbc/test/asset/model/error/NonPublicMapperBean.java // public class NonPublicMapperBean { // // @Mapper // final static DbMapper<NonPublicMapperBean> M = (r) -> new NonPublicMapperBean(); // // } // Path: src/test/java/com/github/mjdbc/test/asset/sql/error/NonPublicMapperBeanSql.java import com.github.mjdbc.Sql; import com.github.mjdbc.test.asset.model.error.NonFinalMapperBean; import com.github.mjdbc.test.asset.model.error.NonPublicMapperBean; package com.github.mjdbc.test.asset.sql.error; public interface NonPublicMapperBeanSql { @Sql("SELECT 1")
NonPublicMapperBean select();
operando/Garum
garum/src/main/java/com/os/operando/garum/annotations/DefaultStringSet.java
// Path: garum/src/main/java/com/os/operando/garum/ResId.java // public interface ResId { // int DEFAULT_VALUE = -1; // }
import com.os.operando.garum.ResId; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;
package com.os.operando.garum.annotations; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface DefaultStringSet { String[] value() default {};
// Path: garum/src/main/java/com/os/operando/garum/ResId.java // public interface ResId { // int DEFAULT_VALUE = -1; // } // Path: garum/src/main/java/com/os/operando/garum/annotations/DefaultStringSet.java import com.os.operando.garum.ResId; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; package com.os.operando.garum.annotations; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface DefaultStringSet { String[] value() default {};
int redId() default ResId.DEFAULT_VALUE;
operando/Garum
garum/src/main/java/com/os/operando/garum/Garum.java
// Path: garum/src/main/java/com/os/operando/garum/utils/Cache.java // public final class Cache { // // private static Context context; // private static ModelInfo modelInfo; // private static boolean isInitialized = false; // // private Cache() { // } // // public static synchronized void initialize(Configuration configuration) { // if (isInitialized) { // GarumLog.v("Garum already initialized."); // return; // } // context = configuration.getContext(); // try { // modelInfo = new ModelInfo(configuration); // } catch (IOException e) { // e.printStackTrace(); // } // isInitialized = true; // GarumLog.v("Garum initialized successfully."); // } // // // public static synchronized void dispose() { // modelInfo = null; // isInitialized = false; // GarumLog.v("Garum disposed. Call initialize to use library."); // } // // public static boolean isInitialized() { // return isInitialized; // } // // public static Context getContext() { // return context; // } // // public static synchronized Collection<PrefInfo> getPrefInfos() { // return modelInfo.getPrefInfos(); // } // // public static synchronized PrefInfo getPrefInfo(Class<? extends PrefModel> type) { // return modelInfo.getPrefInfo(type); // } // // public static synchronized String getPrefName(Class<? extends PrefModel> type) { // return modelInfo.getPrefInfo(type).getPrefName(); // } // // public static synchronized TypeSerializer getParserForType(Class<?> type) { // return modelInfo.getTypeSerializer(type); // } // } // // Path: garum/src/main/java/com/os/operando/garum/utils/GarumLog.java // public final class GarumLog { // // private static final String TGA = Garum.class.getSimpleName(); // private static boolean enabled = false; // // private GarumLog() { // } // // public static boolean isEnabled() { // return enabled; // } // // public static void setEnabled(boolean enabled) { // GarumLog.enabled = enabled; // } // // public static boolean isLoggingEnabled() { // return enabled; // } // // public static int v(String msg) { // return enabled ? Log.v(TGA, msg) : 0; // } // // public static int v(String tag, String msg) { // return enabled ? android.util.Log.v(tag, msg) : 0; // } // // public static int v(String msg, Throwable tr) { // return enabled ? Log.v(TGA, msg, tr) : 0; // } // // public static int v(String tag, String msg, Throwable tr) { // return enabled ? android.util.Log.v(tag, msg, tr) : 0; // } // // public static int d(String msg) { // return enabled ? android.util.Log.d(TGA, msg) : 0; // } // // public static int d(String tag, String msg) { // return enabled ? android.util.Log.d(tag, msg) : 0; // } // // public static int d(String msg, Throwable tr) { // return enabled ? android.util.Log.d(TGA, msg, tr) : 0; // } // // public static int d(String tag, String msg, Throwable tr) { // return enabled ? android.util.Log.d(tag, msg, tr) : 0; // } // // public static int i(String msg) { // return enabled ? android.util.Log.i(TGA, msg) : 0; // } // // public static int i(String tag, String msg) { // return enabled ? android.util.Log.i(tag, msg) : 0; // } // // public static int i(String msg, Throwable tr) { // return enabled ? android.util.Log.i(TGA, msg, tr) : 0; // } // // public static int i(String tag, String msg, Throwable tr) { // return enabled ? android.util.Log.i(tag, msg, tr) : 0; // } // // public static int w(String msg) { // return enabled ? android.util.Log.w(TGA, msg) : 0; // } // // public static int w(String tag, String msg) { // return enabled ? android.util.Log.w(tag, msg) : 0; // } // // public static int w(String msg, Throwable tr) { // return enabled ? android.util.Log.w(TGA, msg, tr) : 0; // } // // public static int w(String tag, String msg, Throwable tr) { // return enabled ? android.util.Log.w(tag, msg, tr) : 0; // } // // public static int e(String msg) { // return enabled ? android.util.Log.e(TGA, msg) : 0; // } // // public static int e(String tag, String msg) { // return enabled ? android.util.Log.e(tag, msg) : 0; // } // // public static int e(String msg, Throwable tr) { // return enabled ? android.util.Log.e(TGA, msg, tr) : 0; // } // // public static int e(String tag, String msg, Throwable tr) { // return enabled ? android.util.Log.e(tag, msg, tr) : 0; // } // // public static int t(String msg, Object... args) { // return enabled ? android.util.Log.v("test", String.format(msg, args)) : 0; // } // }
import com.os.operando.garum.utils.Cache; import com.os.operando.garum.utils.GarumLog;
package com.os.operando.garum; public class Garum { public static void initialize(Configuration configuration) { initialize(configuration, false); } public static void initialize(Configuration configuration, boolean loggingEnabled) { setLoggingEnabled(loggingEnabled);
// Path: garum/src/main/java/com/os/operando/garum/utils/Cache.java // public final class Cache { // // private static Context context; // private static ModelInfo modelInfo; // private static boolean isInitialized = false; // // private Cache() { // } // // public static synchronized void initialize(Configuration configuration) { // if (isInitialized) { // GarumLog.v("Garum already initialized."); // return; // } // context = configuration.getContext(); // try { // modelInfo = new ModelInfo(configuration); // } catch (IOException e) { // e.printStackTrace(); // } // isInitialized = true; // GarumLog.v("Garum initialized successfully."); // } // // // public static synchronized void dispose() { // modelInfo = null; // isInitialized = false; // GarumLog.v("Garum disposed. Call initialize to use library."); // } // // public static boolean isInitialized() { // return isInitialized; // } // // public static Context getContext() { // return context; // } // // public static synchronized Collection<PrefInfo> getPrefInfos() { // return modelInfo.getPrefInfos(); // } // // public static synchronized PrefInfo getPrefInfo(Class<? extends PrefModel> type) { // return modelInfo.getPrefInfo(type); // } // // public static synchronized String getPrefName(Class<? extends PrefModel> type) { // return modelInfo.getPrefInfo(type).getPrefName(); // } // // public static synchronized TypeSerializer getParserForType(Class<?> type) { // return modelInfo.getTypeSerializer(type); // } // } // // Path: garum/src/main/java/com/os/operando/garum/utils/GarumLog.java // public final class GarumLog { // // private static final String TGA = Garum.class.getSimpleName(); // private static boolean enabled = false; // // private GarumLog() { // } // // public static boolean isEnabled() { // return enabled; // } // // public static void setEnabled(boolean enabled) { // GarumLog.enabled = enabled; // } // // public static boolean isLoggingEnabled() { // return enabled; // } // // public static int v(String msg) { // return enabled ? Log.v(TGA, msg) : 0; // } // // public static int v(String tag, String msg) { // return enabled ? android.util.Log.v(tag, msg) : 0; // } // // public static int v(String msg, Throwable tr) { // return enabled ? Log.v(TGA, msg, tr) : 0; // } // // public static int v(String tag, String msg, Throwable tr) { // return enabled ? android.util.Log.v(tag, msg, tr) : 0; // } // // public static int d(String msg) { // return enabled ? android.util.Log.d(TGA, msg) : 0; // } // // public static int d(String tag, String msg) { // return enabled ? android.util.Log.d(tag, msg) : 0; // } // // public static int d(String msg, Throwable tr) { // return enabled ? android.util.Log.d(TGA, msg, tr) : 0; // } // // public static int d(String tag, String msg, Throwable tr) { // return enabled ? android.util.Log.d(tag, msg, tr) : 0; // } // // public static int i(String msg) { // return enabled ? android.util.Log.i(TGA, msg) : 0; // } // // public static int i(String tag, String msg) { // return enabled ? android.util.Log.i(tag, msg) : 0; // } // // public static int i(String msg, Throwable tr) { // return enabled ? android.util.Log.i(TGA, msg, tr) : 0; // } // // public static int i(String tag, String msg, Throwable tr) { // return enabled ? android.util.Log.i(tag, msg, tr) : 0; // } // // public static int w(String msg) { // return enabled ? android.util.Log.w(TGA, msg) : 0; // } // // public static int w(String tag, String msg) { // return enabled ? android.util.Log.w(tag, msg) : 0; // } // // public static int w(String msg, Throwable tr) { // return enabled ? android.util.Log.w(TGA, msg, tr) : 0; // } // // public static int w(String tag, String msg, Throwable tr) { // return enabled ? android.util.Log.w(tag, msg, tr) : 0; // } // // public static int e(String msg) { // return enabled ? android.util.Log.e(TGA, msg) : 0; // } // // public static int e(String tag, String msg) { // return enabled ? android.util.Log.e(tag, msg) : 0; // } // // public static int e(String msg, Throwable tr) { // return enabled ? android.util.Log.e(TGA, msg, tr) : 0; // } // // public static int e(String tag, String msg, Throwable tr) { // return enabled ? android.util.Log.e(tag, msg, tr) : 0; // } // // public static int t(String msg, Object... args) { // return enabled ? android.util.Log.v("test", String.format(msg, args)) : 0; // } // } // Path: garum/src/main/java/com/os/operando/garum/Garum.java import com.os.operando.garum.utils.Cache; import com.os.operando.garum.utils.GarumLog; package com.os.operando.garum; public class Garum { public static void initialize(Configuration configuration) { initialize(configuration, false); } public static void initialize(Configuration configuration, boolean loggingEnabled) { setLoggingEnabled(loggingEnabled);
Cache.initialize(configuration);
operando/Garum
garum/src/main/java/com/os/operando/garum/Garum.java
// Path: garum/src/main/java/com/os/operando/garum/utils/Cache.java // public final class Cache { // // private static Context context; // private static ModelInfo modelInfo; // private static boolean isInitialized = false; // // private Cache() { // } // // public static synchronized void initialize(Configuration configuration) { // if (isInitialized) { // GarumLog.v("Garum already initialized."); // return; // } // context = configuration.getContext(); // try { // modelInfo = new ModelInfo(configuration); // } catch (IOException e) { // e.printStackTrace(); // } // isInitialized = true; // GarumLog.v("Garum initialized successfully."); // } // // // public static synchronized void dispose() { // modelInfo = null; // isInitialized = false; // GarumLog.v("Garum disposed. Call initialize to use library."); // } // // public static boolean isInitialized() { // return isInitialized; // } // // public static Context getContext() { // return context; // } // // public static synchronized Collection<PrefInfo> getPrefInfos() { // return modelInfo.getPrefInfos(); // } // // public static synchronized PrefInfo getPrefInfo(Class<? extends PrefModel> type) { // return modelInfo.getPrefInfo(type); // } // // public static synchronized String getPrefName(Class<? extends PrefModel> type) { // return modelInfo.getPrefInfo(type).getPrefName(); // } // // public static synchronized TypeSerializer getParserForType(Class<?> type) { // return modelInfo.getTypeSerializer(type); // } // } // // Path: garum/src/main/java/com/os/operando/garum/utils/GarumLog.java // public final class GarumLog { // // private static final String TGA = Garum.class.getSimpleName(); // private static boolean enabled = false; // // private GarumLog() { // } // // public static boolean isEnabled() { // return enabled; // } // // public static void setEnabled(boolean enabled) { // GarumLog.enabled = enabled; // } // // public static boolean isLoggingEnabled() { // return enabled; // } // // public static int v(String msg) { // return enabled ? Log.v(TGA, msg) : 0; // } // // public static int v(String tag, String msg) { // return enabled ? android.util.Log.v(tag, msg) : 0; // } // // public static int v(String msg, Throwable tr) { // return enabled ? Log.v(TGA, msg, tr) : 0; // } // // public static int v(String tag, String msg, Throwable tr) { // return enabled ? android.util.Log.v(tag, msg, tr) : 0; // } // // public static int d(String msg) { // return enabled ? android.util.Log.d(TGA, msg) : 0; // } // // public static int d(String tag, String msg) { // return enabled ? android.util.Log.d(tag, msg) : 0; // } // // public static int d(String msg, Throwable tr) { // return enabled ? android.util.Log.d(TGA, msg, tr) : 0; // } // // public static int d(String tag, String msg, Throwable tr) { // return enabled ? android.util.Log.d(tag, msg, tr) : 0; // } // // public static int i(String msg) { // return enabled ? android.util.Log.i(TGA, msg) : 0; // } // // public static int i(String tag, String msg) { // return enabled ? android.util.Log.i(tag, msg) : 0; // } // // public static int i(String msg, Throwable tr) { // return enabled ? android.util.Log.i(TGA, msg, tr) : 0; // } // // public static int i(String tag, String msg, Throwable tr) { // return enabled ? android.util.Log.i(tag, msg, tr) : 0; // } // // public static int w(String msg) { // return enabled ? android.util.Log.w(TGA, msg) : 0; // } // // public static int w(String tag, String msg) { // return enabled ? android.util.Log.w(tag, msg) : 0; // } // // public static int w(String msg, Throwable tr) { // return enabled ? android.util.Log.w(TGA, msg, tr) : 0; // } // // public static int w(String tag, String msg, Throwable tr) { // return enabled ? android.util.Log.w(tag, msg, tr) : 0; // } // // public static int e(String msg) { // return enabled ? android.util.Log.e(TGA, msg) : 0; // } // // public static int e(String tag, String msg) { // return enabled ? android.util.Log.e(tag, msg) : 0; // } // // public static int e(String msg, Throwable tr) { // return enabled ? android.util.Log.e(TGA, msg, tr) : 0; // } // // public static int e(String tag, String msg, Throwable tr) { // return enabled ? android.util.Log.e(tag, msg, tr) : 0; // } // // public static int t(String msg, Object... args) { // return enabled ? android.util.Log.v("test", String.format(msg, args)) : 0; // } // }
import com.os.operando.garum.utils.Cache; import com.os.operando.garum.utils.GarumLog;
package com.os.operando.garum; public class Garum { public static void initialize(Configuration configuration) { initialize(configuration, false); } public static void initialize(Configuration configuration, boolean loggingEnabled) { setLoggingEnabled(loggingEnabled); Cache.initialize(configuration); } public static void setLoggingEnabled(boolean enabled) {
// Path: garum/src/main/java/com/os/operando/garum/utils/Cache.java // public final class Cache { // // private static Context context; // private static ModelInfo modelInfo; // private static boolean isInitialized = false; // // private Cache() { // } // // public static synchronized void initialize(Configuration configuration) { // if (isInitialized) { // GarumLog.v("Garum already initialized."); // return; // } // context = configuration.getContext(); // try { // modelInfo = new ModelInfo(configuration); // } catch (IOException e) { // e.printStackTrace(); // } // isInitialized = true; // GarumLog.v("Garum initialized successfully."); // } // // // public static synchronized void dispose() { // modelInfo = null; // isInitialized = false; // GarumLog.v("Garum disposed. Call initialize to use library."); // } // // public static boolean isInitialized() { // return isInitialized; // } // // public static Context getContext() { // return context; // } // // public static synchronized Collection<PrefInfo> getPrefInfos() { // return modelInfo.getPrefInfos(); // } // // public static synchronized PrefInfo getPrefInfo(Class<? extends PrefModel> type) { // return modelInfo.getPrefInfo(type); // } // // public static synchronized String getPrefName(Class<? extends PrefModel> type) { // return modelInfo.getPrefInfo(type).getPrefName(); // } // // public static synchronized TypeSerializer getParserForType(Class<?> type) { // return modelInfo.getTypeSerializer(type); // } // } // // Path: garum/src/main/java/com/os/operando/garum/utils/GarumLog.java // public final class GarumLog { // // private static final String TGA = Garum.class.getSimpleName(); // private static boolean enabled = false; // // private GarumLog() { // } // // public static boolean isEnabled() { // return enabled; // } // // public static void setEnabled(boolean enabled) { // GarumLog.enabled = enabled; // } // // public static boolean isLoggingEnabled() { // return enabled; // } // // public static int v(String msg) { // return enabled ? Log.v(TGA, msg) : 0; // } // // public static int v(String tag, String msg) { // return enabled ? android.util.Log.v(tag, msg) : 0; // } // // public static int v(String msg, Throwable tr) { // return enabled ? Log.v(TGA, msg, tr) : 0; // } // // public static int v(String tag, String msg, Throwable tr) { // return enabled ? android.util.Log.v(tag, msg, tr) : 0; // } // // public static int d(String msg) { // return enabled ? android.util.Log.d(TGA, msg) : 0; // } // // public static int d(String tag, String msg) { // return enabled ? android.util.Log.d(tag, msg) : 0; // } // // public static int d(String msg, Throwable tr) { // return enabled ? android.util.Log.d(TGA, msg, tr) : 0; // } // // public static int d(String tag, String msg, Throwable tr) { // return enabled ? android.util.Log.d(tag, msg, tr) : 0; // } // // public static int i(String msg) { // return enabled ? android.util.Log.i(TGA, msg) : 0; // } // // public static int i(String tag, String msg) { // return enabled ? android.util.Log.i(tag, msg) : 0; // } // // public static int i(String msg, Throwable tr) { // return enabled ? android.util.Log.i(TGA, msg, tr) : 0; // } // // public static int i(String tag, String msg, Throwable tr) { // return enabled ? android.util.Log.i(tag, msg, tr) : 0; // } // // public static int w(String msg) { // return enabled ? android.util.Log.w(TGA, msg) : 0; // } // // public static int w(String tag, String msg) { // return enabled ? android.util.Log.w(tag, msg) : 0; // } // // public static int w(String msg, Throwable tr) { // return enabled ? android.util.Log.w(TGA, msg, tr) : 0; // } // // public static int w(String tag, String msg, Throwable tr) { // return enabled ? android.util.Log.w(tag, msg, tr) : 0; // } // // public static int e(String msg) { // return enabled ? android.util.Log.e(TGA, msg) : 0; // } // // public static int e(String tag, String msg) { // return enabled ? android.util.Log.e(tag, msg) : 0; // } // // public static int e(String msg, Throwable tr) { // return enabled ? android.util.Log.e(TGA, msg, tr) : 0; // } // // public static int e(String tag, String msg, Throwable tr) { // return enabled ? android.util.Log.e(tag, msg, tr) : 0; // } // // public static int t(String msg, Object... args) { // return enabled ? android.util.Log.v("test", String.format(msg, args)) : 0; // } // } // Path: garum/src/main/java/com/os/operando/garum/Garum.java import com.os.operando.garum.utils.Cache; import com.os.operando.garum.utils.GarumLog; package com.os.operando.garum; public class Garum { public static void initialize(Configuration configuration) { initialize(configuration, false); } public static void initialize(Configuration configuration, boolean loggingEnabled) { setLoggingEnabled(loggingEnabled); Cache.initialize(configuration); } public static void setLoggingEnabled(boolean enabled) {
GarumLog.setEnabled(enabled);
operando/Garum
app/src/main/java/com/os/operando/garum/sample/MyApplication.java
// Path: garum/src/main/java/com/os/operando/garum/Garum.java // public class Garum { // // public static void initialize(Configuration configuration) { // initialize(configuration, false); // } // // public static void initialize(Configuration configuration, boolean loggingEnabled) { // setLoggingEnabled(loggingEnabled); // Cache.initialize(configuration); // } // // public static void setLoggingEnabled(boolean enabled) { // GarumLog.setEnabled(enabled); // } // }
import android.app.Application; import com.os.operando.garum.Garum;
package com.os.operando.garum.sample; public class MyApplication extends Application { @Override public void onCreate() { super.onCreate();
// Path: garum/src/main/java/com/os/operando/garum/Garum.java // public class Garum { // // public static void initialize(Configuration configuration) { // initialize(configuration, false); // } // // public static void initialize(Configuration configuration, boolean loggingEnabled) { // setLoggingEnabled(loggingEnabled); // Cache.initialize(configuration); // } // // public static void setLoggingEnabled(boolean enabled) { // GarumLog.setEnabled(enabled); // } // } // Path: app/src/main/java/com/os/operando/garum/sample/MyApplication.java import android.app.Application; import com.os.operando.garum.Garum; package com.os.operando.garum.sample; public class MyApplication extends Application { @Override public void onCreate() { super.onCreate();
Garum.initialize(getApplicationContext(), true);
operando/Garum
garum/src/main/java/com/os/operando/garum/annotations/DefaultString.java
// Path: garum/src/main/java/com/os/operando/garum/ResId.java // public interface ResId { // int DEFAULT_VALUE = -1; // }
import com.os.operando.garum.ResId; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;
package com.os.operando.garum.annotations; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface DefaultString { String value();
// Path: garum/src/main/java/com/os/operando/garum/ResId.java // public interface ResId { // int DEFAULT_VALUE = -1; // } // Path: garum/src/main/java/com/os/operando/garum/annotations/DefaultString.java import com.os.operando.garum.ResId; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; package com.os.operando.garum.annotations; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface DefaultString { String value();
int redId() default ResId.DEFAULT_VALUE;
operando/Garum
garum/src/main/java/com/os/operando/garum/annotations/DefaultInt.java
// Path: garum/src/main/java/com/os/operando/garum/ResId.java // public interface ResId { // int DEFAULT_VALUE = -1; // }
import com.os.operando.garum.ResId; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;
package com.os.operando.garum.annotations; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface DefaultInt { int value() default 0;
// Path: garum/src/main/java/com/os/operando/garum/ResId.java // public interface ResId { // int DEFAULT_VALUE = -1; // } // Path: garum/src/main/java/com/os/operando/garum/annotations/DefaultInt.java import com.os.operando.garum.ResId; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; package com.os.operando.garum.annotations; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface DefaultInt { int value() default 0;
int redId() default ResId.DEFAULT_VALUE;
operando/Garum
garum/src/main/java/com/os/operando/garum/utils/DefaultValueUtil.java
// Path: garum/src/main/java/com/os/operando/garum/ResId.java // public interface ResId { // int DEFAULT_VALUE = -1; // }
import android.content.res.Resources; import com.os.operando.garum.ResId; import com.os.operando.garum.annotations.DefaultBoolean; import com.os.operando.garum.annotations.DefaultFloat; import com.os.operando.garum.annotations.DefaultInt; import com.os.operando.garum.annotations.DefaultLong; import com.os.operando.garum.annotations.DefaultString; import com.os.operando.garum.annotations.DefaultStringSet; import java.util.Arrays; import java.util.HashSet; import java.util.Set;
} return resources.getBoolean(resId); } public static long getDefaultLongValue(DefaultLong defaultLong) { if (defaultLong == null) { return 0; } return defaultLong.value(); } public static float getDefaultFloatValue(DefaultFloat defaultFloat) { if (defaultFloat == null) { return 0.0f; } return defaultFloat.value(); } public static Set<String> getDefaultSetValue(DefaultStringSet defaultStringSet, Resources resources) { if (defaultStringSet == null) { return new HashSet<>(); } int resId = defaultStringSet.redId(); if (isResIdDefault(resId)) { return new HashSet<>(Arrays.asList(defaultStringSet.value())); } return new HashSet<>(Arrays.asList(resources.getStringArray(resId))); } private static boolean isResIdDefault(int resId) {
// Path: garum/src/main/java/com/os/operando/garum/ResId.java // public interface ResId { // int DEFAULT_VALUE = -1; // } // Path: garum/src/main/java/com/os/operando/garum/utils/DefaultValueUtil.java import android.content.res.Resources; import com.os.operando.garum.ResId; import com.os.operando.garum.annotations.DefaultBoolean; import com.os.operando.garum.annotations.DefaultFloat; import com.os.operando.garum.annotations.DefaultInt; import com.os.operando.garum.annotations.DefaultLong; import com.os.operando.garum.annotations.DefaultString; import com.os.operando.garum.annotations.DefaultStringSet; import java.util.Arrays; import java.util.HashSet; import java.util.Set; } return resources.getBoolean(resId); } public static long getDefaultLongValue(DefaultLong defaultLong) { if (defaultLong == null) { return 0; } return defaultLong.value(); } public static float getDefaultFloatValue(DefaultFloat defaultFloat) { if (defaultFloat == null) { return 0.0f; } return defaultFloat.value(); } public static Set<String> getDefaultSetValue(DefaultStringSet defaultStringSet, Resources resources) { if (defaultStringSet == null) { return new HashSet<>(); } int resId = defaultStringSet.redId(); if (isResIdDefault(resId)) { return new HashSet<>(Arrays.asList(defaultStringSet.value())); } return new HashSet<>(Arrays.asList(resources.getStringArray(resId))); } private static boolean isResIdDefault(int resId) {
return resId == ResId.DEFAULT_VALUE;
operando/Garum
app/src/main/java/com/os/operando/garum/sample/MainActivity.java
// Path: app/src/main/java/com/os/operando/garum/sample/models/EnumModel.java // @ToString // @Pref(name = "enum_model") // public class EnumModel extends PrefModel { // // @PrefKey // public ProgramLanguage programLanguage; // // } // // Path: app/src/main/java/com/os/operando/garum/sample/models/PrefTest.java // @Setter // @Getter // @ToString // @Pref(name = "pref_test") // public class PrefTest extends PrefModel { // // @PrefKey // @DefaultString("test") // private String str; // // @PrefKey // @DefaultInt(11111) // private int intValue; // // @PrefKey // private Integer integerValue; // // @PrefKey // @DefaultBoolean(true) // private boolean boolValue; // // // DefaultValue < redId < Save Value // @PrefKey // @DefaultString(value = "test", redId = R.string.hello_world) // private String strRes; // // @PrefKey // @DefaultStringSet(value = {"1", "2", "3"}, redId = R.array.test_string_array) // private Set<String> set; // // @PrefKey // private File file; // // @PrefKey // private Uri uri; // } // // Path: app/src/main/java/com/os/operando/garum/sample/models/UseStatus.java // @Setter // @Getter // @ToString // @Pref(name = "date_status") // public class UseStatus extends PrefModel { // // @PrefKey("last_used") // private Date lastUsed; // // @PrefKey // private Calendar calendar; // }
import android.net.Uri; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.util.Log; import android.view.View; import android.widget.TextView; import com.os.operando.garum.sample.enums.ProgramLanguage; import com.os.operando.garum.sample.models.AppStatus; import com.os.operando.garum.sample.models.EnumModel; import com.os.operando.garum.sample.models.JSONArrayTest; import com.os.operando.garum.sample.models.JSONObjectTest; import com.os.operando.garum.sample.models.PrefTest; import com.os.operando.garum.sample.models.UseStatus; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.util.Calendar; import java.util.Date;
package com.os.operando.garum.sample; public class MainActivity extends ActionBarActivity { private static final String TAG = MainActivity.class.getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
// Path: app/src/main/java/com/os/operando/garum/sample/models/EnumModel.java // @ToString // @Pref(name = "enum_model") // public class EnumModel extends PrefModel { // // @PrefKey // public ProgramLanguage programLanguage; // // } // // Path: app/src/main/java/com/os/operando/garum/sample/models/PrefTest.java // @Setter // @Getter // @ToString // @Pref(name = "pref_test") // public class PrefTest extends PrefModel { // // @PrefKey // @DefaultString("test") // private String str; // // @PrefKey // @DefaultInt(11111) // private int intValue; // // @PrefKey // private Integer integerValue; // // @PrefKey // @DefaultBoolean(true) // private boolean boolValue; // // // DefaultValue < redId < Save Value // @PrefKey // @DefaultString(value = "test", redId = R.string.hello_world) // private String strRes; // // @PrefKey // @DefaultStringSet(value = {"1", "2", "3"}, redId = R.array.test_string_array) // private Set<String> set; // // @PrefKey // private File file; // // @PrefKey // private Uri uri; // } // // Path: app/src/main/java/com/os/operando/garum/sample/models/UseStatus.java // @Setter // @Getter // @ToString // @Pref(name = "date_status") // public class UseStatus extends PrefModel { // // @PrefKey("last_used") // private Date lastUsed; // // @PrefKey // private Calendar calendar; // } // Path: app/src/main/java/com/os/operando/garum/sample/MainActivity.java import android.net.Uri; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.util.Log; import android.view.View; import android.widget.TextView; import com.os.operando.garum.sample.enums.ProgramLanguage; import com.os.operando.garum.sample.models.AppStatus; import com.os.operando.garum.sample.models.EnumModel; import com.os.operando.garum.sample.models.JSONArrayTest; import com.os.operando.garum.sample.models.JSONObjectTest; import com.os.operando.garum.sample.models.PrefTest; import com.os.operando.garum.sample.models.UseStatus; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.util.Calendar; import java.util.Date; package com.os.operando.garum.sample; public class MainActivity extends ActionBarActivity { private static final String TAG = MainActivity.class.getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
PrefTest prefTest = new PrefTest();
operando/Garum
app/src/main/java/com/os/operando/garum/sample/MainActivity.java
// Path: app/src/main/java/com/os/operando/garum/sample/models/EnumModel.java // @ToString // @Pref(name = "enum_model") // public class EnumModel extends PrefModel { // // @PrefKey // public ProgramLanguage programLanguage; // // } // // Path: app/src/main/java/com/os/operando/garum/sample/models/PrefTest.java // @Setter // @Getter // @ToString // @Pref(name = "pref_test") // public class PrefTest extends PrefModel { // // @PrefKey // @DefaultString("test") // private String str; // // @PrefKey // @DefaultInt(11111) // private int intValue; // // @PrefKey // private Integer integerValue; // // @PrefKey // @DefaultBoolean(true) // private boolean boolValue; // // // DefaultValue < redId < Save Value // @PrefKey // @DefaultString(value = "test", redId = R.string.hello_world) // private String strRes; // // @PrefKey // @DefaultStringSet(value = {"1", "2", "3"}, redId = R.array.test_string_array) // private Set<String> set; // // @PrefKey // private File file; // // @PrefKey // private Uri uri; // } // // Path: app/src/main/java/com/os/operando/garum/sample/models/UseStatus.java // @Setter // @Getter // @ToString // @Pref(name = "date_status") // public class UseStatus extends PrefModel { // // @PrefKey("last_used") // private Date lastUsed; // // @PrefKey // private Calendar calendar; // }
import android.net.Uri; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.util.Log; import android.view.View; import android.widget.TextView; import com.os.operando.garum.sample.enums.ProgramLanguage; import com.os.operando.garum.sample.models.AppStatus; import com.os.operando.garum.sample.models.EnumModel; import com.os.operando.garum.sample.models.JSONArrayTest; import com.os.operando.garum.sample.models.JSONObjectTest; import com.os.operando.garum.sample.models.PrefTest; import com.os.operando.garum.sample.models.UseStatus; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.util.Calendar; import java.util.Date;
package com.os.operando.garum.sample; public class MainActivity extends ActionBarActivity { private static final String TAG = MainActivity.class.getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); PrefTest prefTest = new PrefTest(); prefTest.setFile(new File("../test")); prefTest.setUri(Uri.parse("content://test/test")); prefTest.save(); PrefTest prefTest2 = new PrefTest(); Log.d(Tags.Garum, prefTest2.toString()); Log.d(Tags.Garum, prefTest2.getFile().toString());
// Path: app/src/main/java/com/os/operando/garum/sample/models/EnumModel.java // @ToString // @Pref(name = "enum_model") // public class EnumModel extends PrefModel { // // @PrefKey // public ProgramLanguage programLanguage; // // } // // Path: app/src/main/java/com/os/operando/garum/sample/models/PrefTest.java // @Setter // @Getter // @ToString // @Pref(name = "pref_test") // public class PrefTest extends PrefModel { // // @PrefKey // @DefaultString("test") // private String str; // // @PrefKey // @DefaultInt(11111) // private int intValue; // // @PrefKey // private Integer integerValue; // // @PrefKey // @DefaultBoolean(true) // private boolean boolValue; // // // DefaultValue < redId < Save Value // @PrefKey // @DefaultString(value = "test", redId = R.string.hello_world) // private String strRes; // // @PrefKey // @DefaultStringSet(value = {"1", "2", "3"}, redId = R.array.test_string_array) // private Set<String> set; // // @PrefKey // private File file; // // @PrefKey // private Uri uri; // } // // Path: app/src/main/java/com/os/operando/garum/sample/models/UseStatus.java // @Setter // @Getter // @ToString // @Pref(name = "date_status") // public class UseStatus extends PrefModel { // // @PrefKey("last_used") // private Date lastUsed; // // @PrefKey // private Calendar calendar; // } // Path: app/src/main/java/com/os/operando/garum/sample/MainActivity.java import android.net.Uri; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.util.Log; import android.view.View; import android.widget.TextView; import com.os.operando.garum.sample.enums.ProgramLanguage; import com.os.operando.garum.sample.models.AppStatus; import com.os.operando.garum.sample.models.EnumModel; import com.os.operando.garum.sample.models.JSONArrayTest; import com.os.operando.garum.sample.models.JSONObjectTest; import com.os.operando.garum.sample.models.PrefTest; import com.os.operando.garum.sample.models.UseStatus; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.util.Calendar; import java.util.Date; package com.os.operando.garum.sample; public class MainActivity extends ActionBarActivity { private static final String TAG = MainActivity.class.getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); PrefTest prefTest = new PrefTest(); prefTest.setFile(new File("../test")); prefTest.setUri(Uri.parse("content://test/test")); prefTest.save(); PrefTest prefTest2 = new PrefTest(); Log.d(Tags.Garum, prefTest2.toString()); Log.d(Tags.Garum, prefTest2.getFile().toString());
UseStatus s = new UseStatus();
operando/Garum
app/src/main/java/com/os/operando/garum/sample/MainActivity.java
// Path: app/src/main/java/com/os/operando/garum/sample/models/EnumModel.java // @ToString // @Pref(name = "enum_model") // public class EnumModel extends PrefModel { // // @PrefKey // public ProgramLanguage programLanguage; // // } // // Path: app/src/main/java/com/os/operando/garum/sample/models/PrefTest.java // @Setter // @Getter // @ToString // @Pref(name = "pref_test") // public class PrefTest extends PrefModel { // // @PrefKey // @DefaultString("test") // private String str; // // @PrefKey // @DefaultInt(11111) // private int intValue; // // @PrefKey // private Integer integerValue; // // @PrefKey // @DefaultBoolean(true) // private boolean boolValue; // // // DefaultValue < redId < Save Value // @PrefKey // @DefaultString(value = "test", redId = R.string.hello_world) // private String strRes; // // @PrefKey // @DefaultStringSet(value = {"1", "2", "3"}, redId = R.array.test_string_array) // private Set<String> set; // // @PrefKey // private File file; // // @PrefKey // private Uri uri; // } // // Path: app/src/main/java/com/os/operando/garum/sample/models/UseStatus.java // @Setter // @Getter // @ToString // @Pref(name = "date_status") // public class UseStatus extends PrefModel { // // @PrefKey("last_used") // private Date lastUsed; // // @PrefKey // private Calendar calendar; // }
import android.net.Uri; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.util.Log; import android.view.View; import android.widget.TextView; import com.os.operando.garum.sample.enums.ProgramLanguage; import com.os.operando.garum.sample.models.AppStatus; import com.os.operando.garum.sample.models.EnumModel; import com.os.operando.garum.sample.models.JSONArrayTest; import com.os.operando.garum.sample.models.JSONObjectTest; import com.os.operando.garum.sample.models.PrefTest; import com.os.operando.garum.sample.models.UseStatus; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.util.Calendar; import java.util.Date;
package com.os.operando.garum.sample; public class MainActivity extends ActionBarActivity { private static final String TAG = MainActivity.class.getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); PrefTest prefTest = new PrefTest(); prefTest.setFile(new File("../test")); prefTest.setUri(Uri.parse("content://test/test")); prefTest.save(); PrefTest prefTest2 = new PrefTest(); Log.d(Tags.Garum, prefTest2.toString()); Log.d(Tags.Garum, prefTest2.getFile().toString()); UseStatus s = new UseStatus(); Date date = s.getLastUsed(); if (date != null) { ((TextView) findViewById(R.id.last_used_date)).setText("last used : " + date.toString()); } else { ((TextView) findViewById(R.id.last_used_date)).setText("last used : null"); }
// Path: app/src/main/java/com/os/operando/garum/sample/models/EnumModel.java // @ToString // @Pref(name = "enum_model") // public class EnumModel extends PrefModel { // // @PrefKey // public ProgramLanguage programLanguage; // // } // // Path: app/src/main/java/com/os/operando/garum/sample/models/PrefTest.java // @Setter // @Getter // @ToString // @Pref(name = "pref_test") // public class PrefTest extends PrefModel { // // @PrefKey // @DefaultString("test") // private String str; // // @PrefKey // @DefaultInt(11111) // private int intValue; // // @PrefKey // private Integer integerValue; // // @PrefKey // @DefaultBoolean(true) // private boolean boolValue; // // // DefaultValue < redId < Save Value // @PrefKey // @DefaultString(value = "test", redId = R.string.hello_world) // private String strRes; // // @PrefKey // @DefaultStringSet(value = {"1", "2", "3"}, redId = R.array.test_string_array) // private Set<String> set; // // @PrefKey // private File file; // // @PrefKey // private Uri uri; // } // // Path: app/src/main/java/com/os/operando/garum/sample/models/UseStatus.java // @Setter // @Getter // @ToString // @Pref(name = "date_status") // public class UseStatus extends PrefModel { // // @PrefKey("last_used") // private Date lastUsed; // // @PrefKey // private Calendar calendar; // } // Path: app/src/main/java/com/os/operando/garum/sample/MainActivity.java import android.net.Uri; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.util.Log; import android.view.View; import android.widget.TextView; import com.os.operando.garum.sample.enums.ProgramLanguage; import com.os.operando.garum.sample.models.AppStatus; import com.os.operando.garum.sample.models.EnumModel; import com.os.operando.garum.sample.models.JSONArrayTest; import com.os.operando.garum.sample.models.JSONObjectTest; import com.os.operando.garum.sample.models.PrefTest; import com.os.operando.garum.sample.models.UseStatus; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.util.Calendar; import java.util.Date; package com.os.operando.garum.sample; public class MainActivity extends ActionBarActivity { private static final String TAG = MainActivity.class.getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); PrefTest prefTest = new PrefTest(); prefTest.setFile(new File("../test")); prefTest.setUri(Uri.parse("content://test/test")); prefTest.save(); PrefTest prefTest2 = new PrefTest(); Log.d(Tags.Garum, prefTest2.toString()); Log.d(Tags.Garum, prefTest2.getFile().toString()); UseStatus s = new UseStatus(); Date date = s.getLastUsed(); if (date != null) { ((TextView) findViewById(R.id.last_used_date)).setText("last used : " + date.toString()); } else { ((TextView) findViewById(R.id.last_used_date)).setText("last used : null"); }
EnumModel em = new EnumModel();
bwh-dope/pharmacoepi_toolbox
src/org/drugepi/hdps/db/HdpsDbPatientController.java
// Path: src/org/drugepi/util/DatabaseRowReader.java // public class DatabaseRowReader extends RowReader { // private Connection connection; // private Statement statement; // private ResultSet rs; // // private String query; // // /** // * DatabaseRowReader constructor. // * // * @throws Exception // */ // public DatabaseRowReader() // throws Exception // { // super(); // } // // /** // * DatabaseRowReader constructor. Opens a database connection using the specified parameters. // * // * @param driverClass Class of the JDBC driver for this database. // * @param url JDBC URL of the database. // * @param properties Properties for opening the database. // * @param query SQL query that will yield the data rows. // * @throws Exception // */ // public DatabaseRowReader(String driverClass, String url, Properties properties, String query) // throws Exception // { // this(); // this.open(driverClass, url, properties, query); // } // // /** // * DatabaseRowReader constructor. Opens a database connection using the specified parameters. // * // * @param driverClass Class of the JDBC driver for this database. // * @param url JDBC URL of the database. // * @param username Username for logging into the database. // * @param password Password for logging into the database. // * @param query SQL query that will yield the data rows. // * @throws Exception // */ // public DatabaseRowReader(String driverClass, String url, String username, String password, String query) // throws Exception // { // this(); // this.open(driverClass, url, username, password, query); // } // // /** // * Open a database connection and run the query that will yield the data rows. // * // * @param driverClass Class of the JDBC driver for this database. // * @param url JDBC URL of the database. // * @param username Username for logging into the database. // * @param password Password for logging into the database. // * @param query SQL query that will yield the data rows. // * @throws Exception // */ // public void open(String driverClass, String url, String username, String password, String query) // throws Exception // { // Properties properties = new Properties(); // properties.put("user", username); // properties.put("password", password); // // this.query = query; // // this.open(driverClass, url, properties, query); // } // // /** // * Open a database connection and run the query that will yield the data rows. // * // * @param driverClass Class of the JDBC driver for this database. // * @param url JDBC URL of the database. // * @param properties Properties for opening the database. // * @param query SQL query that will yield the data rows. // * @throws Exception // */ // public void open(String driverClass, String url, Properties properties, String query) // throws Exception // { // Class.forName(driverClass); // // this.connection = DriverManager.getConnection(url, properties); // this.statement = this.connection.createStatement(); // this.rs = this.statement.executeQuery(query); // // this.numColumns = this.rs.getMetaData().getColumnCount(); // } // // public void reset() // throws Exception // { // this.rs.first(); // } // // /* (non-Javadoc) // * @see org.drugepi.util.RowReader#close() // */ // public void close() throws Exception { // try { // if (this.statement != null) // this.statement.cancel(); // // if (this.rs != null) { // this.rs.clearWarnings(); // this.rs.close(); // } // // if (this.statement != null) // this.statement.close(); // // if (this.connection != null) // this.connection.close(); // } catch (Exception e) { // // do nothing -- this is OK. // } // } // // /* (non-Javadoc) // * @see org.drugepi.util.RowReader#getNextRow() // */ // public String[] getNextRow() throws Exception { // if (this.rs == null) // return null; // // if (! rs.next()) // return null; // // int numColumns = this.rs.getMetaData().getColumnCount(); // String[] row = new String[numColumns]; // for (int i = 0; i < numColumns; i++) { // row[i] = rs.getString(i + 1); // } // // return row; // } // // public String getQuery() { // return query; // } // }
import java.util.*; import org.drugepi.hdps.*; import org.drugepi.util.DatabaseRowReader; import java.sql.*;
/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.drugepi.hdps.db; public class HdpsDbPatientController extends HdpsPatientController { private HdpsDbController hdpsController; private Connection connection; public String patientViewName; public String patientIdFieldName; public String exposureFieldName; public String outcomeFieldName; public String personTimeFieldName; public HdpsDbPatientController(Hdps hdps, HdpsDbController hdpsController) { super(hdps); this.hdpsController = hdpsController; } public void readPatients() throws Exception { this.connection = HdpsDbController.connectionFactory(this.hdps); this.patientViewName = SqlUtils.getTableName("patients", this.hdpsController.randomSuffix); String sql; if (this.reader.getNumColumns() > 3) { sql = String.format( "CREATE VIEW %s AS %s", this.patientViewName,
// Path: src/org/drugepi/util/DatabaseRowReader.java // public class DatabaseRowReader extends RowReader { // private Connection connection; // private Statement statement; // private ResultSet rs; // // private String query; // // /** // * DatabaseRowReader constructor. // * // * @throws Exception // */ // public DatabaseRowReader() // throws Exception // { // super(); // } // // /** // * DatabaseRowReader constructor. Opens a database connection using the specified parameters. // * // * @param driverClass Class of the JDBC driver for this database. // * @param url JDBC URL of the database. // * @param properties Properties for opening the database. // * @param query SQL query that will yield the data rows. // * @throws Exception // */ // public DatabaseRowReader(String driverClass, String url, Properties properties, String query) // throws Exception // { // this(); // this.open(driverClass, url, properties, query); // } // // /** // * DatabaseRowReader constructor. Opens a database connection using the specified parameters. // * // * @param driverClass Class of the JDBC driver for this database. // * @param url JDBC URL of the database. // * @param username Username for logging into the database. // * @param password Password for logging into the database. // * @param query SQL query that will yield the data rows. // * @throws Exception // */ // public DatabaseRowReader(String driverClass, String url, String username, String password, String query) // throws Exception // { // this(); // this.open(driverClass, url, username, password, query); // } // // /** // * Open a database connection and run the query that will yield the data rows. // * // * @param driverClass Class of the JDBC driver for this database. // * @param url JDBC URL of the database. // * @param username Username for logging into the database. // * @param password Password for logging into the database. // * @param query SQL query that will yield the data rows. // * @throws Exception // */ // public void open(String driverClass, String url, String username, String password, String query) // throws Exception // { // Properties properties = new Properties(); // properties.put("user", username); // properties.put("password", password); // // this.query = query; // // this.open(driverClass, url, properties, query); // } // // /** // * Open a database connection and run the query that will yield the data rows. // * // * @param driverClass Class of the JDBC driver for this database. // * @param url JDBC URL of the database. // * @param properties Properties for opening the database. // * @param query SQL query that will yield the data rows. // * @throws Exception // */ // public void open(String driverClass, String url, Properties properties, String query) // throws Exception // { // Class.forName(driverClass); // // this.connection = DriverManager.getConnection(url, properties); // this.statement = this.connection.createStatement(); // this.rs = this.statement.executeQuery(query); // // this.numColumns = this.rs.getMetaData().getColumnCount(); // } // // public void reset() // throws Exception // { // this.rs.first(); // } // // /* (non-Javadoc) // * @see org.drugepi.util.RowReader#close() // */ // public void close() throws Exception { // try { // if (this.statement != null) // this.statement.cancel(); // // if (this.rs != null) { // this.rs.clearWarnings(); // this.rs.close(); // } // // if (this.statement != null) // this.statement.close(); // // if (this.connection != null) // this.connection.close(); // } catch (Exception e) { // // do nothing -- this is OK. // } // } // // /* (non-Javadoc) // * @see org.drugepi.util.RowReader#getNextRow() // */ // public String[] getNextRow() throws Exception { // if (this.rs == null) // return null; // // if (! rs.next()) // return null; // // int numColumns = this.rs.getMetaData().getColumnCount(); // String[] row = new String[numColumns]; // for (int i = 0; i < numColumns; i++) { // row[i] = rs.getString(i + 1); // } // // return row; // } // // public String getQuery() { // return query; // } // } // Path: src/org/drugepi/hdps/db/HdpsDbPatientController.java import java.util.*; import org.drugepi.hdps.*; import org.drugepi.util.DatabaseRowReader; import java.sql.*; /* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.drugepi.hdps.db; public class HdpsDbPatientController extends HdpsPatientController { private HdpsDbController hdpsController; private Connection connection; public String patientViewName; public String patientIdFieldName; public String exposureFieldName; public String outcomeFieldName; public String personTimeFieldName; public HdpsDbPatientController(Hdps hdps, HdpsDbController hdpsController) { super(hdps); this.hdpsController = hdpsController; } public void readPatients() throws Exception { this.connection = HdpsDbController.connectionFactory(this.hdps); this.patientViewName = SqlUtils.getTableName("patients", this.hdpsController.randomSuffix); String sql; if (this.reader.getNumColumns() > 3) { sql = String.format( "CREATE VIEW %s AS %s", this.patientViewName,
((DatabaseRowReader) this.reader).getQuery());
bwh-dope/pharmacoepi_toolbox
src/org/drugepi/table/TableCreator.java
// Path: src/org/drugepi/PharmacoepiTool.java // public abstract class PharmacoepiTool { // public static String description = "Pharamcoepi Toolbox"; // public static String version = "2.4.18"; // // private long startTime; // // public PharmacoepiTool() // { // // not implemented // } // // /** // * Add patient information, with patient data stored in a tab-delimited file. // * // * @param filePath Path of the patient data file. See the documentation on each // * subclass for the expected order of patient columns. // * @throws Exception // */ // public void addPatients(String filePath) // throws Exception // { // RowReader reader = new TabDelimitedFileReader(filePath); // this.addPatients(reader); // // // note: the implementing tool must close the reader // } // // /** // * Add patient information, with patient data stored in a string buffer. // * // * @param buf Patient data. See the documentation on each // * subclass for the expected order of patient columns. // * @throws Exception // */ // public void addPatientsFromBuffer(String buf) // throws Exception // { // RowReader reader = new StringBufferRowReader(buf); // this.addPatients(reader); // // // note: the implementing tool must close the reader // } // // /** // * Add patient information, with patient data stored in a database. // * // * @param dbDriverClass Name of the database driver. // * @param dbURL JDBC URL of the database // * @param dbUser Database user name. // * @param dbPassword Database user's password. // * @param dbQuery The query that will result in the patient data. See the documentation on each // * subclass for the expected order of patient columns. // * @throws Exception // */ // public void addPatients(String dbDriverClass, String dbURL, String dbUser, String dbPassword, // String dbQuery) // throws Exception // { // RowReader reader = new DatabaseRowReader(dbDriverClass, dbURL, dbUser, dbPassword, dbQuery); // this.addPatients(reader); // // // note: the implementing tool must close the reader // } // // /** // * Add patient information from specified row reader object. // * // * @param reader The row reader object. // * @throws Exception // */ // public void addPatients(RowReader reader) // throws Exception // { // // do nothing. override by subclass if desired. // } // // protected void startTool() // { // System.out.printf("NOTE: %s version %s starting at %s.\n", // description, version, new Date().toString()); // this.startTime = System.currentTimeMillis(); // } // // protected void endTool() // { // long eTime = System.currentTimeMillis() - startTime; // double minutes = Math.floor(eTime / (60 * 1000F)); // eTime -= minutes * 60 * 1000F; // double seconds = eTime / 1000F; // System.out.printf("NOTE: %s finished at %s. Run time: %02d:%02.3f.\n", // description, new Date().toString(), (int) minutes, seconds); // } // // /** // * @return the version // */ // public String getVersion() { // return version; // } // // /** // * @return the description // */ // public String getDescription() { // return description; // } // } // // Path: src/org/drugepi/table/TableRowCol.java // public enum RowColTypes { NORMAL, HEADER };
import java.io.*; import java.util.*; import org.apache.poi.ss.usermodel.*; import org.drugepi.PharmacoepiTool; import org.drugepi.table.TableRowCol.RowColTypes;
/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.drugepi.table; /** * Creation of basic tables for epidemiology. * * Tables are added using the {@link #addTable(String, String)} method. Rows and columns are then defined, * and values added to cells. Tables are then rendered to HTML using {@link #writeHtmlToFile(String, String)}. * * @author Jeremy A. Rassen * @version 1.0.0 * */ /** * @author jeremy * */ public class TableCreator extends PharmacoepiTool { Map<String, Table> tables; /** * Constructor for TableCreator. */ public TableCreator() { super(); this.tables = new HashMap<String, Table>(); } /** * Add a table definition. * * @param tableId Unique ID of this table. * @param description Description of this table, to print as the table header. */ public void addTable(String tableId, String description) { tableId = TableElement.makeId(tableId); Table t = new Table(tableId, description); tables.put(tableId, t); } /** * Add a header-style row to a table. * * @param tableId ID of the table. * @param parentId ID of the row's parent. * @param id Unique ID of the row. * @param description Description of the row, to print as the row's text in the table output. */ public void addHeaderRowToTable(String tableId, String parentId, String id, String description) {
// Path: src/org/drugepi/PharmacoepiTool.java // public abstract class PharmacoepiTool { // public static String description = "Pharamcoepi Toolbox"; // public static String version = "2.4.18"; // // private long startTime; // // public PharmacoepiTool() // { // // not implemented // } // // /** // * Add patient information, with patient data stored in a tab-delimited file. // * // * @param filePath Path of the patient data file. See the documentation on each // * subclass for the expected order of patient columns. // * @throws Exception // */ // public void addPatients(String filePath) // throws Exception // { // RowReader reader = new TabDelimitedFileReader(filePath); // this.addPatients(reader); // // // note: the implementing tool must close the reader // } // // /** // * Add patient information, with patient data stored in a string buffer. // * // * @param buf Patient data. See the documentation on each // * subclass for the expected order of patient columns. // * @throws Exception // */ // public void addPatientsFromBuffer(String buf) // throws Exception // { // RowReader reader = new StringBufferRowReader(buf); // this.addPatients(reader); // // // note: the implementing tool must close the reader // } // // /** // * Add patient information, with patient data stored in a database. // * // * @param dbDriverClass Name of the database driver. // * @param dbURL JDBC URL of the database // * @param dbUser Database user name. // * @param dbPassword Database user's password. // * @param dbQuery The query that will result in the patient data. See the documentation on each // * subclass for the expected order of patient columns. // * @throws Exception // */ // public void addPatients(String dbDriverClass, String dbURL, String dbUser, String dbPassword, // String dbQuery) // throws Exception // { // RowReader reader = new DatabaseRowReader(dbDriverClass, dbURL, dbUser, dbPassword, dbQuery); // this.addPatients(reader); // // // note: the implementing tool must close the reader // } // // /** // * Add patient information from specified row reader object. // * // * @param reader The row reader object. // * @throws Exception // */ // public void addPatients(RowReader reader) // throws Exception // { // // do nothing. override by subclass if desired. // } // // protected void startTool() // { // System.out.printf("NOTE: %s version %s starting at %s.\n", // description, version, new Date().toString()); // this.startTime = System.currentTimeMillis(); // } // // protected void endTool() // { // long eTime = System.currentTimeMillis() - startTime; // double minutes = Math.floor(eTime / (60 * 1000F)); // eTime -= minutes * 60 * 1000F; // double seconds = eTime / 1000F; // System.out.printf("NOTE: %s finished at %s. Run time: %02d:%02.3f.\n", // description, new Date().toString(), (int) minutes, seconds); // } // // /** // * @return the version // */ // public String getVersion() { // return version; // } // // /** // * @return the description // */ // public String getDescription() { // return description; // } // } // // Path: src/org/drugepi/table/TableRowCol.java // public enum RowColTypes { NORMAL, HEADER }; // Path: src/org/drugepi/table/TableCreator.java import java.io.*; import java.util.*; import org.apache.poi.ss.usermodel.*; import org.drugepi.PharmacoepiTool; import org.drugepi.table.TableRowCol.RowColTypes; /* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.drugepi.table; /** * Creation of basic tables for epidemiology. * * Tables are added using the {@link #addTable(String, String)} method. Rows and columns are then defined, * and values added to cells. Tables are then rendered to HTML using {@link #writeHtmlToFile(String, String)}. * * @author Jeremy A. Rassen * @version 1.0.0 * */ /** * @author jeremy * */ public class TableCreator extends PharmacoepiTool { Map<String, Table> tables; /** * Constructor for TableCreator. */ public TableCreator() { super(); this.tables = new HashMap<String, Table>(); } /** * Add a table definition. * * @param tableId Unique ID of this table. * @param description Description of this table, to print as the table header. */ public void addTable(String tableId, String description) { tableId = TableElement.makeId(tableId); Table t = new Table(tableId, description); tables.put(tableId, t); } /** * Add a header-style row to a table. * * @param tableId ID of the table. * @param parentId ID of the row's parent. * @param id Unique ID of the row. * @param description Description of the row, to print as the row's text in the table output. */ public void addHeaderRowToTable(String tableId, String parentId, String id, String description) {
this.addRowToTable(tableId, parentId, id, description, RowColTypes.HEADER);
bwh-dope/pharmacoepi_toolbox
src/org/drugepi/hdps/local/HdpsLocalPatientController.java
// Path: src/org/drugepi/hdps/storage/HdpsPatient.java // @Entity // public class HdpsPatient implements Comparable<HdpsPatient> { // @PrimaryKey // public String id; // public boolean exposed; // public boolean outcomeDichotomous; // public int outcomeCount; // public double outcomeContinuous; // public int followUpTime; // // public HdpsPatient() { // this(0); // } // // public HdpsPatient(int numDimensions) { // super(); // // // numCodes = new int[numDimensions]; // // numUniqueCodes = new int[numDimensions]; // } // // public int compareTo(HdpsPatient pat) { // return (id.compareTo(pat.id)); // } // // public String getId() { // return id; // } // // public boolean isExposed() { // return exposed; // } // // public boolean isOutcome() { // return outcomeDichotomous; // } // }
import org.drugepi.hdps.storage.HdpsPatient; import org.drugepi.hdps.*;
/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.drugepi.hdps.local; public class HdpsLocalPatientController extends HdpsPatientController { public HdpsLocalController hdpsController; public HdpsLocalPatientController(Hdps hdps, HdpsLocalController hdpsController) { super(hdps); this.hdpsController = hdpsController; } public void readPatients() throws Exception { // patientList = new HashMap<String, HdpsPatient>(); String[] row; nExposed = 0; nOutcome = 0; int n = 0; while ((row = reader.getNextRow()) != null) { String key = row[KEY_COLUMN_NUM];
// Path: src/org/drugepi/hdps/storage/HdpsPatient.java // @Entity // public class HdpsPatient implements Comparable<HdpsPatient> { // @PrimaryKey // public String id; // public boolean exposed; // public boolean outcomeDichotomous; // public int outcomeCount; // public double outcomeContinuous; // public int followUpTime; // // public HdpsPatient() { // this(0); // } // // public HdpsPatient(int numDimensions) { // super(); // // // numCodes = new int[numDimensions]; // // numUniqueCodes = new int[numDimensions]; // } // // public int compareTo(HdpsPatient pat) { // return (id.compareTo(pat.id)); // } // // public String getId() { // return id; // } // // public boolean isExposed() { // return exposed; // } // // public boolean isOutcome() { // return outcomeDichotomous; // } // } // Path: src/org/drugepi/hdps/local/HdpsLocalPatientController.java import org.drugepi.hdps.storage.HdpsPatient; import org.drugepi.hdps.*; /* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.drugepi.hdps.local; public class HdpsLocalPatientController extends HdpsPatientController { public HdpsLocalController hdpsController; public HdpsLocalPatientController(Hdps hdps, HdpsLocalController hdpsController) { super(hdps); this.hdpsController = hdpsController; } public void readPatients() throws Exception { // patientList = new HashMap<String, HdpsPatient>(); String[] row; nExposed = 0; nOutcome = 0; int n = 0; while ((row = reader.getNextRow()) != null) { String key = row[KEY_COLUMN_NUM];
HdpsPatient patient = this.hdpsController.getPatientDatabase().get(key);
bwh-dope/pharmacoepi_toolbox
src/org/drugepi/table/Table.java
// Path: src/org/drugepi/table/TableRowCol.java // public enum RowColTypes { NORMAL, HEADER };
import java.util.*; import org.drugepi.table.TableRowCol.RowColTypes; import java.io.InputStream;
public void addCell(TableCell cell) { cells.put(cell.id, cell); } public List<TableRowCol> getRowsColsAtLevel(List<TableRowCol> rcs, int level) { ArrayList<TableRowCol> rowsColsAtLevel = new ArrayList<TableRowCol>(); for (TableRowCol rc: rcs) { if (TableRowCol.getDepth(rc) == level) rowsColsAtLevel.add(rc); } return rowsColsAtLevel; } public String getRowHtml(List<TableRowCol> rows, List<TableRowCol> leafCols, int level, int maxRowDepth) { StringBuffer html = new StringBuffer(); ArrayList<TableRowCol> final_col_position = new ArrayList<TableRowCol>(); for (TableRowCol row: rows) { boolean printTr = false; if ((row.parent == null) || (row.parent.children.get(0) != row)) printTr = true; if (printTr) html.append("<tr>\n");
// Path: src/org/drugepi/table/TableRowCol.java // public enum RowColTypes { NORMAL, HEADER }; // Path: src/org/drugepi/table/Table.java import java.util.*; import org.drugepi.table.TableRowCol.RowColTypes; import java.io.InputStream; public void addCell(TableCell cell) { cells.put(cell.id, cell); } public List<TableRowCol> getRowsColsAtLevel(List<TableRowCol> rcs, int level) { ArrayList<TableRowCol> rowsColsAtLevel = new ArrayList<TableRowCol>(); for (TableRowCol rc: rcs) { if (TableRowCol.getDepth(rc) == level) rowsColsAtLevel.add(rc); } return rowsColsAtLevel; } public String getRowHtml(List<TableRowCol> rows, List<TableRowCol> leafCols, int level, int maxRowDepth) { StringBuffer html = new StringBuffer(); ArrayList<TableRowCol> final_col_position = new ArrayList<TableRowCol>(); for (TableRowCol row: rows) { boolean printTr = false; if ((row.parent == null) || (row.parent.children.get(0) != row)) printTr = true; if (printTr) html.append("<tr>\n");
String rowClass = (row.rcType == RowColTypes.NORMAL ? "row_normal" : "row_header");
bwh-dope/pharmacoepi_toolbox
src/org/drugepi/hdps/storage/HdpsVariable.java
// Path: src/org/drugepi/util/Utils.java // public class Utils { // /** // * Pick the top N items from the specified list. // * // * @param originalList The list to pick the top N items from. // * @param topN Number of items to pick. // * @param comparator Comparator with which to rank the items in the list. // * @return A new list containing the top N items. // */ // public static ArrayList<?> selectTopN(List<?> originalList, int topN, Comparator<Object> comparator) // { // ArrayList<Object> newList = new ArrayList<Object>(topN); // // int numIncluded = 0; // Object lastObject = null; // // for (Object o: originalList) { // if (numIncluded < topN) { // newList.add(o); // // // allow for ties // if (comparator.compare(o, lastObject) != 0) { // numIncluded++; // lastObject = o; // } // } // } // // return newList; // } // // /** // * Given a directory and a file name, construct a canonical file path. // * // * @param directory Directory name. // * @param fileName File name. // * @return File path combining directory name and file name. // */ // public static String getFilePath(String directory, String fileName) // { // File f = new File(directory, fileName); // return f.toString(); // } // // /** // * Join a collection using the specified delimiter. // * // * @param s The collection to join. // * @param delimiter The delimiter. // * @return // */ // public static String join(Collection<String> s, String delimiter) { // return Utils.join(s, delimiter, ""); // } // // /** // * Join a collection using the specified delimiter, enclosing each element in the // * specified enclosing string. // * // * @param s The collection to join. // * @param delimiter The delimiter. // * @return // */ // public static String join(Collection<String> s, String delimiter, final String enclosure) { // StringBuffer buffer = new StringBuffer(); // Iterator<String> iter = s.iterator(); // while (iter.hasNext()) { // buffer.append(enclosure + iter.next() + enclosure); // if (iter.hasNext()) { // buffer.append(delimiter); // } // } // return buffer.toString(); // } // // /** // * Formats a double for file output. Changes NaN to . // * // * @throws Exception // */ // public static String formatOutputDouble(double d) { // if ((Double.isNaN(d)) || // (Double.isInfinite(d)) || // (d == HdpsVariable.INVALID)) // return "."; // // // format for US, for easy SAS input // // !!! maybe this is a bad thing? // return String.format(Locale.US, "%.10f", d); // } // // /** // * Reads a double from an output file. Changes . to NaN. // * // * @throws Exception // */ // public static double parseInputDouble(String s) { // if (s.equals(".")) // return Double.NaN; // else // return Double.parseDouble(s); // } // // // /** // * Joins an array of strings into a single tab-delimited string. // * // * @throws Exception // */ // public static String tabJoin(String[] contents) // { // if (contents.length == 0) // return null; // // final String tab = "\t"; // // StringBuilder sb = new StringBuilder(contents[0]); // for (int i = 1; i < contents.length; i++) { // sb.append(tab + contents[i]); // } // sb.append("\n"); // // return sb.toString(); // } // }
import org.apache.commons.codec.digest.DigestUtils; import org.drugepi.util.Utils; import java.sql.ResultSet;
this.numEvents = r.getDouble("num_events"); this.c1NumEvents = r.getDouble("c1_num_events"); this.c0NumEvents = r.getDouble("c0_num_events"); this.pc_e0 = r.getDouble("pc_e0"); this.pc_e1 = r.getDouble("pc_e1"); this.rrCe = r.getDouble("rr_ce"); this.rrCd = r.getDouble("rr_cd"); this.cdRegressionBeta = r.getDouble("cd_regression_beta"); this.expAssocRankingVariable = r.getDouble("exp_assoc_ranking_var"); this.outcomeAssocRankingVariable = r.getDouble("outcome_assoc_ranking_var"); this.bias = r.getDouble("bias"); this.biasRankingVariable = r.getDouble("bias_ranking_var"); } public HdpsVariable(HdpsCode code, String[] s) throws Exception { this(); // hack, but a quick way to get a code where none exists if (code == null) this.code = new HdpsCode(s[1]); this.code.codeString = s[1]; this.varName = s[2]; this.selectedForPs = Boolean.parseBoolean(s[3]);
// Path: src/org/drugepi/util/Utils.java // public class Utils { // /** // * Pick the top N items from the specified list. // * // * @param originalList The list to pick the top N items from. // * @param topN Number of items to pick. // * @param comparator Comparator with which to rank the items in the list. // * @return A new list containing the top N items. // */ // public static ArrayList<?> selectTopN(List<?> originalList, int topN, Comparator<Object> comparator) // { // ArrayList<Object> newList = new ArrayList<Object>(topN); // // int numIncluded = 0; // Object lastObject = null; // // for (Object o: originalList) { // if (numIncluded < topN) { // newList.add(o); // // // allow for ties // if (comparator.compare(o, lastObject) != 0) { // numIncluded++; // lastObject = o; // } // } // } // // return newList; // } // // /** // * Given a directory and a file name, construct a canonical file path. // * // * @param directory Directory name. // * @param fileName File name. // * @return File path combining directory name and file name. // */ // public static String getFilePath(String directory, String fileName) // { // File f = new File(directory, fileName); // return f.toString(); // } // // /** // * Join a collection using the specified delimiter. // * // * @param s The collection to join. // * @param delimiter The delimiter. // * @return // */ // public static String join(Collection<String> s, String delimiter) { // return Utils.join(s, delimiter, ""); // } // // /** // * Join a collection using the specified delimiter, enclosing each element in the // * specified enclosing string. // * // * @param s The collection to join. // * @param delimiter The delimiter. // * @return // */ // public static String join(Collection<String> s, String delimiter, final String enclosure) { // StringBuffer buffer = new StringBuffer(); // Iterator<String> iter = s.iterator(); // while (iter.hasNext()) { // buffer.append(enclosure + iter.next() + enclosure); // if (iter.hasNext()) { // buffer.append(delimiter); // } // } // return buffer.toString(); // } // // /** // * Formats a double for file output. Changes NaN to . // * // * @throws Exception // */ // public static String formatOutputDouble(double d) { // if ((Double.isNaN(d)) || // (Double.isInfinite(d)) || // (d == HdpsVariable.INVALID)) // return "."; // // // format for US, for easy SAS input // // !!! maybe this is a bad thing? // return String.format(Locale.US, "%.10f", d); // } // // /** // * Reads a double from an output file. Changes . to NaN. // * // * @throws Exception // */ // public static double parseInputDouble(String s) { // if (s.equals(".")) // return Double.NaN; // else // return Double.parseDouble(s); // } // // // /** // * Joins an array of strings into a single tab-delimited string. // * // * @throws Exception // */ // public static String tabJoin(String[] contents) // { // if (contents.length == 0) // return null; // // final String tab = "\t"; // // StringBuilder sb = new StringBuilder(contents[0]); // for (int i = 1; i < contents.length; i++) { // sb.append(tab + contents[i]); // } // sb.append("\n"); // // return sb.toString(); // } // } // Path: src/org/drugepi/hdps/storage/HdpsVariable.java import org.apache.commons.codec.digest.DigestUtils; import org.drugepi.util.Utils; import java.sql.ResultSet; this.numEvents = r.getDouble("num_events"); this.c1NumEvents = r.getDouble("c1_num_events"); this.c0NumEvents = r.getDouble("c0_num_events"); this.pc_e0 = r.getDouble("pc_e0"); this.pc_e1 = r.getDouble("pc_e1"); this.rrCe = r.getDouble("rr_ce"); this.rrCd = r.getDouble("rr_cd"); this.cdRegressionBeta = r.getDouble("cd_regression_beta"); this.expAssocRankingVariable = r.getDouble("exp_assoc_ranking_var"); this.outcomeAssocRankingVariable = r.getDouble("outcome_assoc_ranking_var"); this.bias = r.getDouble("bias"); this.biasRankingVariable = r.getDouble("bias_ranking_var"); } public HdpsVariable(HdpsCode code, String[] s) throws Exception { this(); // hack, but a quick way to get a code where none exists if (code == null) this.code = new HdpsCode(s[1]); this.code.codeString = s[1]; this.varName = s[2]; this.selectedForPs = Boolean.parseBoolean(s[3]);
this.e1 = Utils.parseInputDouble(s[4]);
bwh-dope/pharmacoepi_toolbox
src/org/drugepi/match/TwoWayMatchTest.java
// Path: src/org/drugepi/match/Match.java // public enum MatchType { // NEAREST_NEIGHBOR, NN, BALANCED_NEAREST_NEIGHBOR, BALANCED_NN, // GREEDY_DIGIT, GREEDY_CALIPER, GREEDY, COMPLETE ; // // public static MatchType toMatchType(String s) { // if (s == null) // return null; // // try { // return(valueOf(s.toUpperCase())); // } catch (Exception e) { // return null; // } // } // } // // Path: src/org/drugepi/util/TabDelimitedFileReader.java // public class TabDelimitedFileReader extends RowReader { // private FileReader fr; // private BufferedReader br; // private String filePath; // // /** // * TabDelimitedFileReader constructor. // * // * @throws Exception // */ // public TabDelimitedFileReader() // throws Exception // { // super(); // fr = null; // br = null; // } // // /** // * TabDelimitedFileReader. Opens a file at the specified path. // * // * @param filePath Path of the tab-delimited file to be read. // * @throws Exception // */ // public TabDelimitedFileReader(String filePath) // throws Exception // { // this(); // // this.filePath = filePath; // // fr = new FileReader(filePath); // br = new BufferedReader(fr); // // // toss the first line // String line = br.readLine(); // if (line != null) { // String[] row = line.split("\\t"); // this.numColumns = row.length; // } // } // // /* (non-Javadoc) // * @see org.drugepi.util.RowReader#getNextRow() // */ // public String[] getNextRow() // throws Exception // { // String[] row = null; // // String line = br.readLine(); // if (line != null) { // row = line.split("\\t"); // } // // // // trim quotes around the string // // for (int i = 0; i < row.length; i++) { // // if ((row[i].startsWith("\"")) && // // (row[i].endsWith("\""))) // // row[i] = row[i].substring(1, row[i].length() - 1); // // } // // return row; // } // // public void reset() // throws Exception // { // this.close(); // // fr = new FileReader(this.filePath); // br = new BufferedReader(fr); // // // toss the first line // br.readLine(); // } // // /* (non-Javadoc) // * @see org.drugepi.util.RowReader#close() // */ // public void close() // throws Exception // { // br.close(); // fr.close(); // } // }
import org.drugepi.match.Match.MatchType; import org.drugepi.util.TabDelimitedFileReader; import org.junit.*; import static org.junit.Assert.*;
/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.drugepi.match; public class TwoWayMatchTest { private String outfilePath = String.format("/Users/jeremy/Desktop/match_output.txt"); @BeforeClass public static void setUpBeforeClass() throws Exception { } @AfterClass public static void tearDownAfterClass() throws Exception { } @Before public void setUp() throws Exception { } @After public void tearDown() throws Exception { } private void checkOutput(int caseNum) throws Exception {
// Path: src/org/drugepi/match/Match.java // public enum MatchType { // NEAREST_NEIGHBOR, NN, BALANCED_NEAREST_NEIGHBOR, BALANCED_NN, // GREEDY_DIGIT, GREEDY_CALIPER, GREEDY, COMPLETE ; // // public static MatchType toMatchType(String s) { // if (s == null) // return null; // // try { // return(valueOf(s.toUpperCase())); // } catch (Exception e) { // return null; // } // } // } // // Path: src/org/drugepi/util/TabDelimitedFileReader.java // public class TabDelimitedFileReader extends RowReader { // private FileReader fr; // private BufferedReader br; // private String filePath; // // /** // * TabDelimitedFileReader constructor. // * // * @throws Exception // */ // public TabDelimitedFileReader() // throws Exception // { // super(); // fr = null; // br = null; // } // // /** // * TabDelimitedFileReader. Opens a file at the specified path. // * // * @param filePath Path of the tab-delimited file to be read. // * @throws Exception // */ // public TabDelimitedFileReader(String filePath) // throws Exception // { // this(); // // this.filePath = filePath; // // fr = new FileReader(filePath); // br = new BufferedReader(fr); // // // toss the first line // String line = br.readLine(); // if (line != null) { // String[] row = line.split("\\t"); // this.numColumns = row.length; // } // } // // /* (non-Javadoc) // * @see org.drugepi.util.RowReader#getNextRow() // */ // public String[] getNextRow() // throws Exception // { // String[] row = null; // // String line = br.readLine(); // if (line != null) { // row = line.split("\\t"); // } // // // // trim quotes around the string // // for (int i = 0; i < row.length; i++) { // // if ((row[i].startsWith("\"")) && // // (row[i].endsWith("\""))) // // row[i] = row[i].substring(1, row[i].length() - 1); // // } // // return row; // } // // public void reset() // throws Exception // { // this.close(); // // fr = new FileReader(this.filePath); // br = new BufferedReader(fr); // // // toss the first line // br.readLine(); // } // // /* (non-Javadoc) // * @see org.drugepi.util.RowReader#close() // */ // public void close() // throws Exception // { // br.close(); // fr.close(); // } // } // Path: src/org/drugepi/match/TwoWayMatchTest.java import org.drugepi.match.Match.MatchType; import org.drugepi.util.TabDelimitedFileReader; import org.junit.*; import static org.junit.Assert.*; /* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.drugepi.match; public class TwoWayMatchTest { private String outfilePath = String.format("/Users/jeremy/Desktop/match_output.txt"); @BeforeClass public static void setUpBeforeClass() throws Exception { } @AfterClass public static void tearDownAfterClass() throws Exception { } @Before public void setUp() throws Exception { } @After public void tearDown() throws Exception { } private void checkOutput(int caseNum) throws Exception {
TabDelimitedFileReader matchOutputReader = new TabDelimitedFileReader(this.outfilePath);
bwh-dope/pharmacoepi_toolbox
src/org/drugepi/match/TwoWayMatchTest.java
// Path: src/org/drugepi/match/Match.java // public enum MatchType { // NEAREST_NEIGHBOR, NN, BALANCED_NEAREST_NEIGHBOR, BALANCED_NN, // GREEDY_DIGIT, GREEDY_CALIPER, GREEDY, COMPLETE ; // // public static MatchType toMatchType(String s) { // if (s == null) // return null; // // try { // return(valueOf(s.toUpperCase())); // } catch (Exception e) { // return null; // } // } // } // // Path: src/org/drugepi/util/TabDelimitedFileReader.java // public class TabDelimitedFileReader extends RowReader { // private FileReader fr; // private BufferedReader br; // private String filePath; // // /** // * TabDelimitedFileReader constructor. // * // * @throws Exception // */ // public TabDelimitedFileReader() // throws Exception // { // super(); // fr = null; // br = null; // } // // /** // * TabDelimitedFileReader. Opens a file at the specified path. // * // * @param filePath Path of the tab-delimited file to be read. // * @throws Exception // */ // public TabDelimitedFileReader(String filePath) // throws Exception // { // this(); // // this.filePath = filePath; // // fr = new FileReader(filePath); // br = new BufferedReader(fr); // // // toss the first line // String line = br.readLine(); // if (line != null) { // String[] row = line.split("\\t"); // this.numColumns = row.length; // } // } // // /* (non-Javadoc) // * @see org.drugepi.util.RowReader#getNextRow() // */ // public String[] getNextRow() // throws Exception // { // String[] row = null; // // String line = br.readLine(); // if (line != null) { // row = line.split("\\t"); // } // // // // trim quotes around the string // // for (int i = 0; i < row.length; i++) { // // if ((row[i].startsWith("\"")) && // // (row[i].endsWith("\""))) // // row[i] = row[i].substring(1, row[i].length() - 1); // // } // // return row; // } // // public void reset() // throws Exception // { // this.close(); // // fr = new FileReader(this.filePath); // br = new BufferedReader(fr); // // // toss the first line // br.readLine(); // } // // /* (non-Javadoc) // * @see org.drugepi.util.RowReader#close() // */ // public void close() // throws Exception // { // br.close(); // fr.close(); // } // }
import org.drugepi.match.Match.MatchType; import org.drugepi.util.TabDelimitedFileReader; import org.junit.*; import static org.junit.Assert.*;
@After public void tearDown() throws Exception { } private void checkOutput(int caseNum) throws Exception { TabDelimitedFileReader matchOutputReader = new TabDelimitedFileReader(this.outfilePath); TabDelimitedFileReader answerReader = new TabDelimitedFileReader("testing/match_test_2way_check.txt"); // toss the first rows answerReader.getNextRow(); matchOutputReader.getNextRow(); String[] answerRow; String[] outputRow; while ((answerRow = answerReader.getNextRow()) != null) { if (answerRow[0].equals(Integer.toString(caseNum))) { outputRow = matchOutputReader.getNextRow(); assertNotNull(outputRow); assertEquals(answerRow[1], outputRow[0]); assertEquals(answerRow[2], outputRow[1]); } } matchOutputReader.close(); answerReader.close(); }
// Path: src/org/drugepi/match/Match.java // public enum MatchType { // NEAREST_NEIGHBOR, NN, BALANCED_NEAREST_NEIGHBOR, BALANCED_NN, // GREEDY_DIGIT, GREEDY_CALIPER, GREEDY, COMPLETE ; // // public static MatchType toMatchType(String s) { // if (s == null) // return null; // // try { // return(valueOf(s.toUpperCase())); // } catch (Exception e) { // return null; // } // } // } // // Path: src/org/drugepi/util/TabDelimitedFileReader.java // public class TabDelimitedFileReader extends RowReader { // private FileReader fr; // private BufferedReader br; // private String filePath; // // /** // * TabDelimitedFileReader constructor. // * // * @throws Exception // */ // public TabDelimitedFileReader() // throws Exception // { // super(); // fr = null; // br = null; // } // // /** // * TabDelimitedFileReader. Opens a file at the specified path. // * // * @param filePath Path of the tab-delimited file to be read. // * @throws Exception // */ // public TabDelimitedFileReader(String filePath) // throws Exception // { // this(); // // this.filePath = filePath; // // fr = new FileReader(filePath); // br = new BufferedReader(fr); // // // toss the first line // String line = br.readLine(); // if (line != null) { // String[] row = line.split("\\t"); // this.numColumns = row.length; // } // } // // /* (non-Javadoc) // * @see org.drugepi.util.RowReader#getNextRow() // */ // public String[] getNextRow() // throws Exception // { // String[] row = null; // // String line = br.readLine(); // if (line != null) { // row = line.split("\\t"); // } // // // // trim quotes around the string // // for (int i = 0; i < row.length; i++) { // // if ((row[i].startsWith("\"")) && // // (row[i].endsWith("\""))) // // row[i] = row[i].substring(1, row[i].length() - 1); // // } // // return row; // } // // public void reset() // throws Exception // { // this.close(); // // fr = new FileReader(this.filePath); // br = new BufferedReader(fr); // // // toss the first line // br.readLine(); // } // // /* (non-Javadoc) // * @see org.drugepi.util.RowReader#close() // */ // public void close() // throws Exception // { // br.close(); // fr.close(); // } // } // Path: src/org/drugepi/match/TwoWayMatchTest.java import org.drugepi.match.Match.MatchType; import org.drugepi.util.TabDelimitedFileReader; import org.junit.*; import static org.junit.Assert.*; @After public void tearDown() throws Exception { } private void checkOutput(int caseNum) throws Exception { TabDelimitedFileReader matchOutputReader = new TabDelimitedFileReader(this.outfilePath); TabDelimitedFileReader answerReader = new TabDelimitedFileReader("testing/match_test_2way_check.txt"); // toss the first rows answerReader.getNextRow(); matchOutputReader.getNextRow(); String[] answerRow; String[] outputRow; while ((answerRow = answerReader.getNextRow()) != null) { if (answerRow[0].equals(Integer.toString(caseNum))) { outputRow = matchOutputReader.getNextRow(); assertNotNull(outputRow); assertEquals(answerRow[1], outputRow[0]); assertEquals(answerRow[2], outputRow[1]); } } matchOutputReader.close(); answerReader.close(); }
private void doTwoWayMatchingTest(MatchType matchType, int matchRatio, int fixedRatio, int parallel)
bwh-dope/pharmacoepi_toolbox
src/org/drugepi/hdps/HdpsPatientController.java
// Path: src/org/drugepi/util/RowReader.java // public abstract class RowReader { // protected int numColumns; // // /** // * RowReader constructor. // * // * @throws Exception // */ // public RowReader() // throws Exception // { // this.numColumns = -1; // } // // /** // * Read the next row from the data source and return elements as an array of strings. // * // * @return Elements read from the row. // * @throws Exception // */ // public abstract String[] getNextRow() // throws Exception; // // /** // * Reset the reader to the first row.. // * // * @return Elements read from the row. // * @throws Exception // */ // public abstract void reset() // throws Exception; // // // /** // * Close the reading source. // * // * @throws Exception // */ // public abstract void close() // throws Exception; // // // /** // * Gets the number of columns available in the data. // * // * @return Number of columns available. // * @throws Exception // */ // public int getNumColumns() // { // return this.numColumns; // } // // }
import org.drugepi.util.RowReader;
/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.drugepi.hdps; public abstract class HdpsPatientController { // VARIABLES WITH GETTERS AND SETTERS public Hdps hdps; protected static final int KEY_COLUMN_NUM = 0; protected static final int EXPOSED_COLUMN_NUM = 1; protected static final int OUTCOME_COLUMN_NUM = 2; protected static final int TIME_COLUMN_NUM = 3; public int nExposed; public int nOutcome; public int ptTotal = 0; public int ptExposed = 0; public double sumOfOutcomes = 0; public int numEvents = 0; private int numPatients;
// Path: src/org/drugepi/util/RowReader.java // public abstract class RowReader { // protected int numColumns; // // /** // * RowReader constructor. // * // * @throws Exception // */ // public RowReader() // throws Exception // { // this.numColumns = -1; // } // // /** // * Read the next row from the data source and return elements as an array of strings. // * // * @return Elements read from the row. // * @throws Exception // */ // public abstract String[] getNextRow() // throws Exception; // // /** // * Reset the reader to the first row.. // * // * @return Elements read from the row. // * @throws Exception // */ // public abstract void reset() // throws Exception; // // // /** // * Close the reading source. // * // * @throws Exception // */ // public abstract void close() // throws Exception; // // // /** // * Gets the number of columns available in the data. // * // * @return Number of columns available. // * @throws Exception // */ // public int getNumColumns() // { // return this.numColumns; // } // // } // Path: src/org/drugepi/hdps/HdpsPatientController.java import org.drugepi.util.RowReader; /* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.drugepi.hdps; public abstract class HdpsPatientController { // VARIABLES WITH GETTERS AND SETTERS public Hdps hdps; protected static final int KEY_COLUMN_NUM = 0; protected static final int EXPOSED_COLUMN_NUM = 1; protected static final int OUTCOME_COLUMN_NUM = 2; protected static final int TIME_COLUMN_NUM = 3; public int nExposed; public int nOutcome; public int ptTotal = 0; public int ptExposed = 0; public double sumOfOutcomes = 0; public int numEvents = 0; private int numPatients;
public RowReader reader;
bwh-dope/pharmacoepi_toolbox
src/org/drugepi/match/controllers/TwoWayMatchController.java
// Path: src/org/drugepi/match/Match.java // public enum MatchType { // NEAREST_NEIGHBOR, NN, BALANCED_NEAREST_NEIGHBOR, BALANCED_NN, // GREEDY_DIGIT, GREEDY_CALIPER, GREEDY, COMPLETE ; // // public static MatchType toMatchType(String s) { // if (s == null) // return null; // // try { // return(valueOf(s.toUpperCase())); // } catch (Exception e) { // return null; // } // } // }
import org.drugepi.match.*; import org.drugepi.match.Match.MatchType; import org.drugepi.match.storage.*; import java.util.*;
public void assignMatchGroups() { // set the treatment group to be the first-specified group this.treatmentGroup = this.matchGroupsList.get(0); // set the referent group to be the second-specified group this.referentGroup = this.matchGroupsList.get(1); this.treatmentGroupSize = treatmentGroup.size(); this.referentGroupSize = referentGroup.size(); } public void printPreMatchStatistics() { System.out.printf("%d:1 match beginning using the %s match method in %s ratio, %s mode\n", this.match.matchRatio, this.getClass().getSimpleName(), (this.match.fixedRatio == 0 ? "variable" : "fixed"), (this.match.parallelMatchingMode == 0 ? "sequential" : "parallel")); System.out.printf("%d items in the treatment (indicator=%s) group\n", this.treatmentGroup.size(), treatmentGroup.groupIndicator); System.out.printf("%d items in the referent (indicator=%s) group\n", this.referentGroup.size(), referentGroup.groupIndicator); } public void printPostMatchStatistics() { int[] matchedSetsPerLevel = new int[this.match.matchRatio + 1]; int numRefPatientsMatched = 0; int numTreatmentPatientsMatched = 0; double totalMatchDistance = 0;
// Path: src/org/drugepi/match/Match.java // public enum MatchType { // NEAREST_NEIGHBOR, NN, BALANCED_NEAREST_NEIGHBOR, BALANCED_NN, // GREEDY_DIGIT, GREEDY_CALIPER, GREEDY, COMPLETE ; // // public static MatchType toMatchType(String s) { // if (s == null) // return null; // // try { // return(valueOf(s.toUpperCase())); // } catch (Exception e) { // return null; // } // } // } // Path: src/org/drugepi/match/controllers/TwoWayMatchController.java import org.drugepi.match.*; import org.drugepi.match.Match.MatchType; import org.drugepi.match.storage.*; import java.util.*; public void assignMatchGroups() { // set the treatment group to be the first-specified group this.treatmentGroup = this.matchGroupsList.get(0); // set the referent group to be the second-specified group this.referentGroup = this.matchGroupsList.get(1); this.treatmentGroupSize = treatmentGroup.size(); this.referentGroupSize = referentGroup.size(); } public void printPreMatchStatistics() { System.out.printf("%d:1 match beginning using the %s match method in %s ratio, %s mode\n", this.match.matchRatio, this.getClass().getSimpleName(), (this.match.fixedRatio == 0 ? "variable" : "fixed"), (this.match.parallelMatchingMode == 0 ? "sequential" : "parallel")); System.out.printf("%d items in the treatment (indicator=%s) group\n", this.treatmentGroup.size(), treatmentGroup.groupIndicator); System.out.printf("%d items in the referent (indicator=%s) group\n", this.referentGroup.size(), referentGroup.groupIndicator); } public void printPostMatchStatistics() { int[] matchedSetsPerLevel = new int[this.match.matchRatio + 1]; int numRefPatientsMatched = 0; int numTreatmentPatientsMatched = 0; double totalMatchDistance = 0;
if (this.match.getMatchType() == MatchType.COMPLETE) {
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/validator/placeholdernamedetector/PlaceholderNameDetectorCommandTest.java
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // }
import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.ontology5.input.entities.person.NaturalInputPerson; import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue;
package org.nameapi.client.services.validator.placeholdernamedetector; /** * Service currently not available as public API. */ public class PlaceholderNameDetectorCommandTest extends AbstractTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); // @Test(dataProvider="people") public void people(String gn, String sn, int minIncl, int maxIncl, FakeType fakeType) throws Exception { PlaceholderNameDetectorCommand command = new PlaceholderNameDetectorCommand();
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // } // Path: src/test/functional/java/org/nameapi/client/services/validator/placeholdernamedetector/PlaceholderNameDetectorCommandTest.java import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.ontology5.input.entities.person.NaturalInputPerson; import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; package org.nameapi.client.services.validator.placeholdernamedetector; /** * Service currently not available as public API. */ public class PlaceholderNameDetectorCommandTest extends AbstractTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); // @Test(dataProvider="people") public void people(String gn, String sn, int minIncl, int maxIncl, FakeType fakeType) throws Exception { PlaceholderNameDetectorCommand command = new PlaceholderNameDetectorCommand();
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/nameparser/syntax/SyntaxBasedNameParserCommandTest.java
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/main/java/org/nameapi/client/services/nameparser/NameParserResult.java // @Immutable // public class NameParserResult { // // @NotNull // private final Optional<Match> bestMatch; // @NotNull // private final List<Match> matches; // private final int shortestItemCount; // // public NameParserResult(@Nullable Match bestMatch, @NotNull List<Match> matches, int shortestItemCount) { // this.bestMatch = Optional.fromNullable(bestMatch); // this.matches = matches; // this.shortestItemCount = shortestItemCount; // } // // @NotNull // public Optional<Match> getBestMatch() { // return bestMatch; // } // // @NotNull // public List<Match> getMatches() { // return matches; // } // // public int getShortestItemCount() { // return shortestItemCount; // } // // // @Override // public String toString() { // return "ParserResult{" + // "bestMatch=" + bestMatch + // ", matches=" + matches + // ", shortestItemCount=" + shortestItemCount + // '}'; // } // }
import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.nameparser.NameParserResult; import org.testng.annotations.Test; import java.util.List; import static org.testng.Assert.assertEquals;
package org.nameapi.client.services.nameparser.syntax; /** */ public class SyntaxBasedNameParserCommandTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); //Service currently not available as public API. // @Test public void testCall() throws Exception {
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/main/java/org/nameapi/client/services/nameparser/NameParserResult.java // @Immutable // public class NameParserResult { // // @NotNull // private final Optional<Match> bestMatch; // @NotNull // private final List<Match> matches; // private final int shortestItemCount; // // public NameParserResult(@Nullable Match bestMatch, @NotNull List<Match> matches, int shortestItemCount) { // this.bestMatch = Optional.fromNullable(bestMatch); // this.matches = matches; // this.shortestItemCount = shortestItemCount; // } // // @NotNull // public Optional<Match> getBestMatch() { // return bestMatch; // } // // @NotNull // public List<Match> getMatches() { // return matches; // } // // public int getShortestItemCount() { // return shortestItemCount; // } // // // @Override // public String toString() { // return "ParserResult{" + // "bestMatch=" + bestMatch + // ", matches=" + matches + // ", shortestItemCount=" + shortestItemCount + // '}'; // } // } // Path: src/test/functional/java/org/nameapi/client/services/nameparser/syntax/SyntaxBasedNameParserCommandTest.java import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.nameparser.NameParserResult; import org.testng.annotations.Test; import java.util.List; import static org.testng.Assert.assertEquals; package org.nameapi.client.services.nameparser.syntax; /** */ public class SyntaxBasedNameParserCommandTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); //Service currently not available as public API. // @Test public void testCall() throws Exception {
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/development/exceptionthrower/ExceptionThrowerCommandTest.java
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // }
import com.optimaize.anythingworks.common.fault.exceptions.AccessDeniedServiceException; import com.optimaize.anythingworks.common.fault.exceptions.BadRequestServiceException; import com.optimaize.anythingworks.common.fault.exceptions.InternalServerErrorServiceException; import com.optimaize.anythingworks.common.fault.faultinfo.Blame; import com.optimaize.anythingworks.common.fault.faultinfo.RetryType; import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.fail;
} catch (InternalServerErrorServiceException e) { assertEquals(e.getFaultInfo().getBlame(), Blame.SERVER); assertFalse(e.getFaultInfo().getRetrySameLocation().isPresent()); } } @Test public void testCall3() throws Exception { try { execute(ExceptionType.AccessDeniedNoSuchAccount); fail("Expected exception!"); } catch (AccessDeniedServiceException e) { assertEquals(e.getFaultInfo().getBlame(), Blame.CLIENT); assertEquals(e.getFaultInfo().getRetrySameLocation().get().getRetryType(), RetryType.NO); } } // @Test(expectedExceptions = AccessDeniedServiceException.class) // public void testCall4() throws Exception { // execute(ExceptionType.AccessDeniedRequestLimitExceeded); // } // // @Test(expectedExceptions = AccessDeniedServiceException.class) // public void testCall5() throws Exception { // execute(ExceptionType.AccessDeniedTooManyConcurrentRequests); // } private void execute(ExceptionType type) throws Exception { ExceptionThrowerCommand command = new ExceptionThrowerCommand();
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // Path: src/test/functional/java/org/nameapi/client/services/development/exceptionthrower/ExceptionThrowerCommandTest.java import com.optimaize.anythingworks.common.fault.exceptions.AccessDeniedServiceException; import com.optimaize.anythingworks.common.fault.exceptions.BadRequestServiceException; import com.optimaize.anythingworks.common.fault.exceptions.InternalServerErrorServiceException; import com.optimaize.anythingworks.common.fault.faultinfo.Blame; import com.optimaize.anythingworks.common.fault.faultinfo.RetryType; import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.fail; } catch (InternalServerErrorServiceException e) { assertEquals(e.getFaultInfo().getBlame(), Blame.SERVER); assertFalse(e.getFaultInfo().getRetrySameLocation().isPresent()); } } @Test public void testCall3() throws Exception { try { execute(ExceptionType.AccessDeniedNoSuchAccount); fail("Expected exception!"); } catch (AccessDeniedServiceException e) { assertEquals(e.getFaultInfo().getBlame(), Blame.CLIENT); assertEquals(e.getFaultInfo().getRetrySameLocation().get().getRetryType(), RetryType.NO); } } // @Test(expectedExceptions = AccessDeniedServiceException.class) // public void testCall4() throws Exception { // execute(ExceptionType.AccessDeniedRequestLimitExceeded); // } // // @Test(expectedExceptions = AccessDeniedServiceException.class) // public void testCall5() throws Exception { // execute(ExceptionType.AccessDeniedTooManyConcurrentRequests); // } private void execute(ExceptionType type) throws Exception { ExceptionThrowerCommand command = new ExceptionThrowerCommand();
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/validator/randomtyping/textfieldrandomtypingdetector/TextFieldRandomTypingDetectorCommandTest.java
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // }
import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.testng.Assert.assertTrue;
package org.nameapi.client.services.validator.randomtyping.textfieldrandomtypingdetector; /** * Service currently not available as public API. */ public class TextFieldRandomTypingDetectorCommandTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); // @Test(dataProvider="testSome") public void testSome(String name, int minIncl, int maxIncl) throws Exception { TextFieldRandomTypingDetectorCommand command = new TextFieldRandomTypingDetectorCommand();
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // Path: src/test/functional/java/org/nameapi/client/services/validator/randomtyping/textfieldrandomtypingdetector/TextFieldRandomTypingDetectorCommandTest.java import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.testng.Assert.assertTrue; package org.nameapi.client.services.validator.randomtyping.textfieldrandomtypingdetector; /** * Service currently not available as public API. */ public class TextFieldRandomTypingDetectorCommandTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); // @Test(dataProvider="testSome") public void testSome(String name, int minIncl, int maxIncl) throws Exception { TextFieldRandomTypingDetectorCommand command = new TextFieldRandomTypingDetectorCommand();
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/email/emailnameparser/EmailNameParserCommandTest.java
// Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // }
import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.ontology5.services.email.emailnameparser.EmailAddressParsingResultType; import org.nameapi.ontology5.services.email.emailnameparser.EmailNameParserResult; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals;
package org.nameapi.client.services.email.emailnameparser; /** */ public class EmailNameParserCommandTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); @Test public void testParse_John_Doe() throws Exception { EmailNameParserCommand command = new EmailNameParserCommand();
// Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // Path: src/test/functional/java/org/nameapi/client/services/email/emailnameparser/EmailNameParserCommandTest.java import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.ontology5.services.email.emailnameparser.EmailAddressParsingResultType; import org.nameapi.ontology5.services.email.emailnameparser.EmailNameParserResult; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; package org.nameapi.client.services.email.emailnameparser; /** */ public class EmailNameParserCommandTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); @Test public void testParse_John_Doe() throws Exception { EmailNameParserCommand command = new EmailNameParserCommand();
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/system/ping/PingCommandTest.java
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // }
import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals;
package org.nameapi.client.services.system.ping; /** */ public class PingCommandTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); @Test public void testCall() throws Exception { PingCommand command = new PingCommand();
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // Path: src/test/functional/java/org/nameapi/client/services/system/ping/PingCommandTest.java import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; package org.nameapi.client.services.system.ping; /** */ public class PingCommandTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); @Test public void testCall() throws Exception { PingCommand command = new PingCommand();
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/validator/famouspersondetector/FamousPersonDetectorCommandTest.java
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // }
import com.google.common.base.Optional; import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.ontology5.input.entities.person.NaturalInputPerson; import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue;
package org.nameapi.client.services.validator.famouspersondetector; /** * Service currently not available as public API. */ public class FamousPersonDetectorCommandTest extends AbstractTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); // @Test(dataProvider="people") public void people(String gn, String sn, Integer minIncl, Integer maxIncl) throws Exception { FamousPersonDetectorCommand command = new FamousPersonDetectorCommand();
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // } // Path: src/test/functional/java/org/nameapi/client/services/validator/famouspersondetector/FamousPersonDetectorCommandTest.java import com.google.common.base.Optional; import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.ontology5.input.entities.person.NaturalInputPerson; import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; package org.nameapi.client.services.validator.famouspersondetector; /** * Service currently not available as public API. */ public class FamousPersonDetectorCommandTest extends AbstractTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); // @Test(dataProvider="people") public void people(String gn, String sn, Integer minIncl, Integer maxIncl) throws Exception { FamousPersonDetectorCommand command = new FamousPersonDetectorCommand();
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/email/disposableemailaddressdetector/DisposableEmailAddressDetectorCommandTest.java
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // }
import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.ontology5.cremalang.lang.Maybe; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals;
package org.nameapi.client.services.email.disposableemailaddressdetector; /** */ public class DisposableEmailAddressDetectorCommandTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); @Test public void yes_1() throws Exception { DisposableEmailAddressDetectorCommand command = new DisposableEmailAddressDetectorCommand();
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // Path: src/test/functional/java/org/nameapi/client/services/email/disposableemailaddressdetector/DisposableEmailAddressDetectorCommandTest.java import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.ontology5.cremalang.lang.Maybe; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; package org.nameapi.client.services.email.disposableemailaddressdetector; /** */ public class DisposableEmailAddressDetectorCommandTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); @Test public void yes_1() throws Exception { DisposableEmailAddressDetectorCommand command = new DisposableEmailAddressDetectorCommand();
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/formatter/personnameformatter/PersonNameFormatterCommandTest.java
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // }
import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.ontology5.input.entities.person.NaturalInputPerson; import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder; import org.nameapi.ontology5.services.formatter.FormatterProperties; import org.nameapi.ontology5.services.formatter.FormatterResult; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals;
package org.nameapi.client.services.formatter.personnameformatter; /** */ public class PersonNameFormatterCommandTest extends AbstractTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); @Test public void testCall() throws Exception { PersonNameFormatterCommand command = new PersonNameFormatterCommand();
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // } // Path: src/test/functional/java/org/nameapi/client/services/formatter/personnameformatter/PersonNameFormatterCommandTest.java import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.ontology5.input.entities.person.NaturalInputPerson; import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder; import org.nameapi.ontology5.services.formatter.FormatterProperties; import org.nameapi.ontology5.services.formatter.FormatterResult; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; package org.nameapi.client.services.formatter.personnameformatter; /** */ public class PersonNameFormatterCommandTest extends AbstractTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); @Test public void testCall() throws Exception { PersonNameFormatterCommand command = new PersonNameFormatterCommand();
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/email/emaildomaintypeclassifier/EmailDomainTypeClassifierCommandTest.java
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // }
import com.optimaize.command4j.Mode; import com.optimaize.command4j.CommandExecutor; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import static org.testng.Assert.assertEquals;
package org.nameapi.client.services.email.emaildomaintypeclassifier; /** */ public class EmailDomainTypeClassifierCommandTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); //Service currently not available as public API. // @Test public void testCall() throws Exception { EmailDomainTypeClassifierCommand command = new EmailDomainTypeClassifierCommand();
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // Path: src/test/functional/java/org/nameapi/client/services/email/emaildomaintypeclassifier/EmailDomainTypeClassifierCommandTest.java import com.optimaize.command4j.Mode; import com.optimaize.command4j.CommandExecutor; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import static org.testng.Assert.assertEquals; package org.nameapi.client.services.email.emaildomaintypeclassifier; /** */ public class EmailDomainTypeClassifierCommandTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); //Service currently not available as public API. // @Test public void testCall() throws Exception { EmailDomainTypeClassifierCommand command = new EmailDomainTypeClassifierCommand();
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/validator/randomtyping/surnamerandomtypingdetector/SurnameRandomTypingDetectorCommandTest.java
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // }
import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.testng.Assert.assertTrue;
package org.nameapi.client.services.validator.randomtyping.surnamerandomtypingdetector; /** * Service currently not available as public API. */ public class SurnameRandomTypingDetectorCommandTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); // @Test(dataProvider="testSome") public void testSome(String name, int minIncl, int maxIncl) throws Exception { SurnameRandomTypingDetectorCommand command = new SurnameRandomTypingDetectorCommand();
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // Path: src/test/functional/java/org/nameapi/client/services/validator/randomtyping/surnamerandomtypingdetector/SurnameRandomTypingDetectorCommandTest.java import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.testng.Assert.assertTrue; package org.nameapi.client.services.validator.randomtyping.surnamerandomtypingdetector; /** * Service currently not available as public API. */ public class SurnameRandomTypingDetectorCommandTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); // @Test(dataProvider="testSome") public void testSome(String name, int minIncl, int maxIncl) throws Exception { SurnameRandomTypingDetectorCommand command = new SurnameRandomTypingDetectorCommand();
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
optimaize/nameapi-client-java
src/main/java/org/nameapi/client/services/NameApiBaseCommand.java
// Path: src/main/java/org/nameapi/client/lib/NameApiKeys.java // public interface NameApiKeys { // // /** // * The api key is required for any call to NameAPI services. // * You must supply a valid context with the {@code mode} argument. // */ // Key<String> API_KEY = Key.stringKey("apiKey"); // // /** // * The context is used as an optional argument by many of the NameApi services. // * You can supply a context with the {@code mode} argument. // */ // Key<Context> CONTEXT = Key.create("Context", Context.class); // // }
import com.optimaize.anythingworks.client.rest.RestBaseCommand; import com.optimaize.anythingworks.client.rest.http.RestHttpClient; import com.optimaize.anythingworks.client.rest.http.RestHttpClientImpl; import com.optimaize.command4j.ExecutionContext; import org.jetbrains.annotations.NotNull; import org.nameapi.client.lib.NameApiKeys; import org.nameapi.ontology5.input.context.Context; import java.net.URL;
package org.nameapi.client.services; /** * Adds NameAPI-specific functionality to the BaseCommand. * @param <T> The wsdl port type. */ public abstract class NameApiBaseCommand<T, A, R> extends RestBaseCommand<T, A, R> { protected static String CLIENT_VERSION = "NameAPI Java Client 5.0"; protected NameApiBaseCommand(@NotNull Class<T> wsdlPortType) { super(wsdlPortType); } @NotNull protected Context getContext(@NotNull ExecutionContext ec) {
// Path: src/main/java/org/nameapi/client/lib/NameApiKeys.java // public interface NameApiKeys { // // /** // * The api key is required for any call to NameAPI services. // * You must supply a valid context with the {@code mode} argument. // */ // Key<String> API_KEY = Key.stringKey("apiKey"); // // /** // * The context is used as an optional argument by many of the NameApi services. // * You can supply a context with the {@code mode} argument. // */ // Key<Context> CONTEXT = Key.create("Context", Context.class); // // } // Path: src/main/java/org/nameapi/client/services/NameApiBaseCommand.java import com.optimaize.anythingworks.client.rest.RestBaseCommand; import com.optimaize.anythingworks.client.rest.http.RestHttpClient; import com.optimaize.anythingworks.client.rest.http.RestHttpClientImpl; import com.optimaize.command4j.ExecutionContext; import org.jetbrains.annotations.NotNull; import org.nameapi.client.lib.NameApiKeys; import org.nameapi.ontology5.input.context.Context; import java.net.URL; package org.nameapi.client.services; /** * Adds NameAPI-specific functionality to the BaseCommand. * @param <T> The wsdl port type. */ public abstract class NameApiBaseCommand<T, A, R> extends RestBaseCommand<T, A, R> { protected static String CLIENT_VERSION = "NameAPI Java Client 5.0"; protected NameApiBaseCommand(@NotNull Class<T> wsdlPortType) { super(wsdlPortType); } @NotNull protected Context getContext(@NotNull ExecutionContext ec) {
return ec.getMode().get(NameApiKeys.CONTEXT).get();
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/riskdetector/person/PersonRiskDetectorCommandTest.java
// Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // }
import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.ontology5.input.entities.address.StructuredAddressBuilder; import org.nameapi.ontology5.input.entities.address.StructuredPlaceInfoBuilder; import org.nameapi.ontology5.input.entities.address.StructuredStreetInfoBuilder; import org.nameapi.ontology5.input.entities.contact.EmailAddressFactory; import org.nameapi.ontology5.input.entities.contact.TelNumberFactory; import org.nameapi.ontology5.input.entities.person.InputPerson; import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder; import org.nameapi.ontology5.input.entities.person.age.AgeInfo; import org.nameapi.ontology5.input.entities.person.age.AgeInfoFactory; import org.nameapi.ontology5.services.riskdetector.*; import org.testng.AssertJUnit; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.AssertJUnit.assertTrue;
.name(makeName("Peter Meyer")) .age(birthDate) .build(); RiskDetectorResult result = run(person); AssertJUnit.assertFalse(result.hasRisk()); } @DataProvider protected Object[][] birthDates_ok() { return new Object[][] { {AgeInfoFactory.forDate(1961, 1, 2)}, {AgeInfoFactory.forDate(1981, 1, 2)}, {AgeInfoFactory.forDate(1995, 12, 31)}, }; } @Test public void multipleResults() throws Exception { InputPerson person = new NaturalInputPersonBuilder() .name(makeName("John Doe")) .addEmail(EmailAddressFactory.forAddress("dqwdqw@dsds.sddsa")) .age(AgeInfoFactory.forDate(1861, 3, 3)) .build(); RiskDetectorResult result = run(person); assertTrue(result.getRisks().size() >= 3); } private RiskDetectorResult run(InputPerson person) throws Exception { PersonRiskDetectorCommand command = new PersonRiskDetectorCommand();
// Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // Path: src/test/functional/java/org/nameapi/client/services/riskdetector/person/PersonRiskDetectorCommandTest.java import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.ontology5.input.entities.address.StructuredAddressBuilder; import org.nameapi.ontology5.input.entities.address.StructuredPlaceInfoBuilder; import org.nameapi.ontology5.input.entities.address.StructuredStreetInfoBuilder; import org.nameapi.ontology5.input.entities.contact.EmailAddressFactory; import org.nameapi.ontology5.input.entities.contact.TelNumberFactory; import org.nameapi.ontology5.input.entities.person.InputPerson; import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder; import org.nameapi.ontology5.input.entities.person.age.AgeInfo; import org.nameapi.ontology5.input.entities.person.age.AgeInfoFactory; import org.nameapi.ontology5.services.riskdetector.*; import org.testng.AssertJUnit; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.AssertJUnit.assertTrue; .name(makeName("Peter Meyer")) .age(birthDate) .build(); RiskDetectorResult result = run(person); AssertJUnit.assertFalse(result.hasRisk()); } @DataProvider protected Object[][] birthDates_ok() { return new Object[][] { {AgeInfoFactory.forDate(1961, 1, 2)}, {AgeInfoFactory.forDate(1981, 1, 2)}, {AgeInfoFactory.forDate(1995, 12, 31)}, }; } @Test public void multipleResults() throws Exception { InputPerson person = new NaturalInputPersonBuilder() .name(makeName("John Doe")) .addEmail(EmailAddressFactory.forAddress("dqwdqw@dsds.sddsa")) .age(AgeInfoFactory.forDate(1861, 3, 3)) .build(); RiskDetectorResult result = run(person); assertTrue(result.getRisks().size() >= 3); } private RiskDetectorResult run(InputPerson person) throws Exception { PersonRiskDetectorCommand command = new PersonRiskDetectorCommand();
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/validator/randomtyping/givennamerandomtypingdetector/GivenNameRandomTypingDetectorCommandTest.java
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/main/java/org/nameapi/client/services/validator/randomtyping/RandomTypingResult.java // public class RandomTypingResult { // }
import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.validator.randomtyping.RandomTypingResult; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.testng.Assert.assertTrue;
package org.nameapi.client.services.validator.randomtyping.givennamerandomtypingdetector; /** * Service currently not available as public API. */ public class GivenNameRandomTypingDetectorCommandTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); // @Test(dataProvider="testSome") public void testSome(String name, int minIncl, int maxIncl) throws Exception { GivenNameRandomTypingDetectorCommand command = new GivenNameRandomTypingDetectorCommand();
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/main/java/org/nameapi/client/services/validator/randomtyping/RandomTypingResult.java // public class RandomTypingResult { // } // Path: src/test/functional/java/org/nameapi/client/services/validator/randomtyping/givennamerandomtypingdetector/GivenNameRandomTypingDetectorCommandTest.java import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.validator.randomtyping.RandomTypingResult; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.testng.Assert.assertTrue; package org.nameapi.client.services.validator.randomtyping.givennamerandomtypingdetector; /** * Service currently not available as public API. */ public class GivenNameRandomTypingDetectorCommandTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); // @Test(dataProvider="testSome") public void testSome(String name, int minIncl, int maxIncl) throws Exception { GivenNameRandomTypingDetectorCommand command = new GivenNameRandomTypingDetectorCommand();
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/validator/randomtyping/givennamerandomtypingdetector/GivenNameRandomTypingDetectorCommandTest.java
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/main/java/org/nameapi/client/services/validator/randomtyping/RandomTypingResult.java // public class RandomTypingResult { // }
import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.validator.randomtyping.RandomTypingResult; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.testng.Assert.assertTrue;
package org.nameapi.client.services.validator.randomtyping.givennamerandomtypingdetector; /** * Service currently not available as public API. */ public class GivenNameRandomTypingDetectorCommandTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); // @Test(dataProvider="testSome") public void testSome(String name, int minIncl, int maxIncl) throws Exception { GivenNameRandomTypingDetectorCommand command = new GivenNameRandomTypingDetectorCommand(); Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/main/java/org/nameapi/client/services/validator/randomtyping/RandomTypingResult.java // public class RandomTypingResult { // } // Path: src/test/functional/java/org/nameapi/client/services/validator/randomtyping/givennamerandomtypingdetector/GivenNameRandomTypingDetectorCommandTest.java import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.validator.randomtyping.RandomTypingResult; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.testng.Assert.assertTrue; package org.nameapi.client.services.validator.randomtyping.givennamerandomtypingdetector; /** * Service currently not available as public API. */ public class GivenNameRandomTypingDetectorCommandTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); // @Test(dataProvider="testSome") public void testSome(String name, int minIncl, int maxIncl) throws Exception { GivenNameRandomTypingDetectorCommand command = new GivenNameRandomTypingDetectorCommand(); Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
RandomTypingResult result = executor.execute(command, mode, name).get();
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/validator/gender/genericgendervalidator/GenericGenderValidatorCommandTest.java
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // }
import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.ontology5.input.entities.person.NaturalInputPerson; import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder; import org.nameapi.ontology5.input.entities.person.gender.StoragePersonGender; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals;
package org.nameapi.client.services.validator.gender.genericgendervalidator; /** * Service currently not available as public API. */ public class GenericGenderValidatorCommandTest extends AbstractTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); // @Test public void testCall() throws Exception { GenericGenderValidatorCommand command = new GenericGenderValidatorCommand();
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // } // Path: src/test/functional/java/org/nameapi/client/services/validator/gender/genericgendervalidator/GenericGenderValidatorCommandTest.java import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.ontology5.input.entities.person.NaturalInputPerson; import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder; import org.nameapi.ontology5.input.entities.person.gender.StoragePersonGender; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; package org.nameapi.client.services.validator.gender.genericgendervalidator; /** * Service currently not available as public API. */ public class GenericGenderValidatorCommandTest extends AbstractTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); // @Test public void testCall() throws Exception { GenericGenderValidatorCommand command = new GenericGenderValidatorCommand();
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/nameparser/personnameparser/PersonNameParserCommandTest.java
// Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/services/parser/personnameparser/PersonNameParserCommand.java // public class PersonNameParserCommand // extends NameApiBaseCommand<RestPort, InputPerson, PersonNameParserResult> // { // // // private static final String SERVICE_PATH = "/parser/personnameparser"; // // public PersonNameParserCommand() { // super(RestPort.class); // } // // @Override // public PersonNameParserResult call(@NotNull Optional<InputPerson> arg, @NotNull ExecutionContext ec) throws Exception { // return getPort(ec).call(getApiKey(ec), getContext(ec), arg.get()); // } // // @NotNull @Override // protected Callable<RestPort> createPort(@NotNull final ExecutionContext ec) { // return new Callable<RestPort>() { // @Override // public RestPort call() throws Exception { // return new RestPort(makeClient(ec), SERVICE_PATH); // } // }; // } // // }
import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.services.parser.personnameparser.PersonNameParserCommand; import org.nameapi.ontology5.input.entities.person.LegalInputPerson; import org.nameapi.ontology5.input.entities.person.LegalInputPersonBuilder; import org.nameapi.ontology5.input.entities.person.NaturalInputPerson; import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder; import org.nameapi.ontology5.input.entities.person.gender.ComputedPersonGender; import org.nameapi.ontology5.input.entities.person.gender.StoragePersonGender; import org.nameapi.ontology5.input.entities.person.name.builder.AmericanInputPersonNameBuilder; import org.nameapi.ontology5.input.entities.person.name.builder.NameBuilders; import org.nameapi.ontology5.input.entities.person.name.builder.WesternInputPersonNameBuilder; import org.nameapi.ontology5.output.entities.person.name.OutputPersonName; import org.nameapi.ontology5.output.entities.person.name.TermType; import org.nameapi.ontology5.services.parser.personnameparser.DisputeType; import org.nameapi.ontology5.services.parser.personnameparser.ParsedPerson; import org.nameapi.ontology5.services.parser.personnameparser.ParsedPersonMatch; import org.nameapi.ontology5.services.parser.personnameparser.PersonNameParserResult; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals;
package org.nameapi.client.services.nameparser.personnameparser; /** */ public class PersonNameParserCommandTest extends AbstractTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); @Test(dataProvider = "testNaturalPerson_1") public void testNaturalPerson_1(NaturalInputPerson inputPerson) throws Exception {
// Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/services/parser/personnameparser/PersonNameParserCommand.java // public class PersonNameParserCommand // extends NameApiBaseCommand<RestPort, InputPerson, PersonNameParserResult> // { // // // private static final String SERVICE_PATH = "/parser/personnameparser"; // // public PersonNameParserCommand() { // super(RestPort.class); // } // // @Override // public PersonNameParserResult call(@NotNull Optional<InputPerson> arg, @NotNull ExecutionContext ec) throws Exception { // return getPort(ec).call(getApiKey(ec), getContext(ec), arg.get()); // } // // @NotNull @Override // protected Callable<RestPort> createPort(@NotNull final ExecutionContext ec) { // return new Callable<RestPort>() { // @Override // public RestPort call() throws Exception { // return new RestPort(makeClient(ec), SERVICE_PATH); // } // }; // } // // } // Path: src/test/functional/java/org/nameapi/client/services/nameparser/personnameparser/PersonNameParserCommandTest.java import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.services.parser.personnameparser.PersonNameParserCommand; import org.nameapi.ontology5.input.entities.person.LegalInputPerson; import org.nameapi.ontology5.input.entities.person.LegalInputPersonBuilder; import org.nameapi.ontology5.input.entities.person.NaturalInputPerson; import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder; import org.nameapi.ontology5.input.entities.person.gender.ComputedPersonGender; import org.nameapi.ontology5.input.entities.person.gender.StoragePersonGender; import org.nameapi.ontology5.input.entities.person.name.builder.AmericanInputPersonNameBuilder; import org.nameapi.ontology5.input.entities.person.name.builder.NameBuilders; import org.nameapi.ontology5.input.entities.person.name.builder.WesternInputPersonNameBuilder; import org.nameapi.ontology5.output.entities.person.name.OutputPersonName; import org.nameapi.ontology5.output.entities.person.name.TermType; import org.nameapi.ontology5.services.parser.personnameparser.DisputeType; import org.nameapi.ontology5.services.parser.personnameparser.ParsedPerson; import org.nameapi.ontology5.services.parser.personnameparser.ParsedPersonMatch; import org.nameapi.ontology5.services.parser.personnameparser.PersonNameParserResult; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; package org.nameapi.client.services.nameparser.personnameparser; /** */ public class PersonNameParserCommandTest extends AbstractTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); @Test(dataProvider = "testNaturalPerson_1") public void testNaturalPerson_1(NaturalInputPerson inputPerson) throws Exception {
PersonNameParserCommand command = new PersonNameParserCommand();
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/nameparser/personnameparser/PersonNameParserCommandTest.java
// Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/services/parser/personnameparser/PersonNameParserCommand.java // public class PersonNameParserCommand // extends NameApiBaseCommand<RestPort, InputPerson, PersonNameParserResult> // { // // // private static final String SERVICE_PATH = "/parser/personnameparser"; // // public PersonNameParserCommand() { // super(RestPort.class); // } // // @Override // public PersonNameParserResult call(@NotNull Optional<InputPerson> arg, @NotNull ExecutionContext ec) throws Exception { // return getPort(ec).call(getApiKey(ec), getContext(ec), arg.get()); // } // // @NotNull @Override // protected Callable<RestPort> createPort(@NotNull final ExecutionContext ec) { // return new Callable<RestPort>() { // @Override // public RestPort call() throws Exception { // return new RestPort(makeClient(ec), SERVICE_PATH); // } // }; // } // // }
import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.services.parser.personnameparser.PersonNameParserCommand; import org.nameapi.ontology5.input.entities.person.LegalInputPerson; import org.nameapi.ontology5.input.entities.person.LegalInputPersonBuilder; import org.nameapi.ontology5.input.entities.person.NaturalInputPerson; import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder; import org.nameapi.ontology5.input.entities.person.gender.ComputedPersonGender; import org.nameapi.ontology5.input.entities.person.gender.StoragePersonGender; import org.nameapi.ontology5.input.entities.person.name.builder.AmericanInputPersonNameBuilder; import org.nameapi.ontology5.input.entities.person.name.builder.NameBuilders; import org.nameapi.ontology5.input.entities.person.name.builder.WesternInputPersonNameBuilder; import org.nameapi.ontology5.output.entities.person.name.OutputPersonName; import org.nameapi.ontology5.output.entities.person.name.TermType; import org.nameapi.ontology5.services.parser.personnameparser.DisputeType; import org.nameapi.ontology5.services.parser.personnameparser.ParsedPerson; import org.nameapi.ontology5.services.parser.personnameparser.ParsedPersonMatch; import org.nameapi.ontology5.services.parser.personnameparser.PersonNameParserResult; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals;
package org.nameapi.client.services.nameparser.personnameparser; /** */ public class PersonNameParserCommandTest extends AbstractTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); @Test(dataProvider = "testNaturalPerson_1") public void testNaturalPerson_1(NaturalInputPerson inputPerson) throws Exception { PersonNameParserCommand command = new PersonNameParserCommand();
// Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/services/parser/personnameparser/PersonNameParserCommand.java // public class PersonNameParserCommand // extends NameApiBaseCommand<RestPort, InputPerson, PersonNameParserResult> // { // // // private static final String SERVICE_PATH = "/parser/personnameparser"; // // public PersonNameParserCommand() { // super(RestPort.class); // } // // @Override // public PersonNameParserResult call(@NotNull Optional<InputPerson> arg, @NotNull ExecutionContext ec) throws Exception { // return getPort(ec).call(getApiKey(ec), getContext(ec), arg.get()); // } // // @NotNull @Override // protected Callable<RestPort> createPort(@NotNull final ExecutionContext ec) { // return new Callable<RestPort>() { // @Override // public RestPort call() throws Exception { // return new RestPort(makeClient(ec), SERVICE_PATH); // } // }; // } // // } // Path: src/test/functional/java/org/nameapi/client/services/nameparser/personnameparser/PersonNameParserCommandTest.java import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.services.parser.personnameparser.PersonNameParserCommand; import org.nameapi.ontology5.input.entities.person.LegalInputPerson; import org.nameapi.ontology5.input.entities.person.LegalInputPersonBuilder; import org.nameapi.ontology5.input.entities.person.NaturalInputPerson; import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder; import org.nameapi.ontology5.input.entities.person.gender.ComputedPersonGender; import org.nameapi.ontology5.input.entities.person.gender.StoragePersonGender; import org.nameapi.ontology5.input.entities.person.name.builder.AmericanInputPersonNameBuilder; import org.nameapi.ontology5.input.entities.person.name.builder.NameBuilders; import org.nameapi.ontology5.input.entities.person.name.builder.WesternInputPersonNameBuilder; import org.nameapi.ontology5.output.entities.person.name.OutputPersonName; import org.nameapi.ontology5.output.entities.person.name.TermType; import org.nameapi.ontology5.services.parser.personnameparser.DisputeType; import org.nameapi.ontology5.services.parser.personnameparser.ParsedPerson; import org.nameapi.ontology5.services.parser.personnameparser.ParsedPersonMatch; import org.nameapi.ontology5.services.parser.personnameparser.PersonNameParserResult; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; package org.nameapi.client.services.nameparser.personnameparser; /** */ public class PersonNameParserCommandTest extends AbstractTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); @Test(dataProvider = "testNaturalPerson_1") public void testNaturalPerson_1(NaturalInputPerson inputPerson) throws Exception { PersonNameParserCommand command = new PersonNameParserCommand();
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/matcher/personmatcher/PersonMatcherCommandTest.java
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // }
import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.ontology5.input.entities.person.NaturalInputPerson; import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder; import org.nameapi.ontology5.services.matcher.personmatcher.PersonMatchType; import org.nameapi.ontology5.services.matcher.personmatcher.PersonMatcherResult; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals;
package org.nameapi.client.services.matcher.personmatcher; /** */ public class PersonMatcherCommandTest extends AbstractTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); @Test public void test_equal() throws Exception { PersonMatcherCommand command = new PersonMatcherCommand();
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // } // Path: src/test/functional/java/org/nameapi/client/services/matcher/personmatcher/PersonMatcherCommandTest.java import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.ontology5.input.entities.person.NaturalInputPerson; import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder; import org.nameapi.ontology5.services.matcher.personmatcher.PersonMatchType; import org.nameapi.ontology5.services.matcher.personmatcher.PersonMatcherResult; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; package org.nameapi.client.services.matcher.personmatcher; /** */ public class PersonMatcherCommandTest extends AbstractTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); @Test public void test_equal() throws Exception { PersonMatcherCommand command = new PersonMatcherCommand();
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/validator/randomtyping/personrandomtypingdetector/PersonRandomTypingDetectorCommandTest.java
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // }
import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.ontology5.input.entities.person.NaturalInputPerson; import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.testng.Assert.assertTrue;
package org.nameapi.client.services.validator.randomtyping.personrandomtypingdetector; /** * Service currently not available as public API. */ public class PersonRandomTypingDetectorCommandTest extends AbstractTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); // @Test(dataProvider="testSome") public void testSome(String gn, String sn, int minIncl, int maxIncl) throws Exception { PersonRandomTypingDetectorCommand command = new PersonRandomTypingDetectorCommand();
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // } // Path: src/test/functional/java/org/nameapi/client/services/validator/randomtyping/personrandomtypingdetector/PersonRandomTypingDetectorCommandTest.java import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.ontology5.input.entities.person.NaturalInputPerson; import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.testng.Assert.assertTrue; package org.nameapi.client.services.validator.randomtyping.personrandomtypingdetector; /** * Service currently not available as public API. */ public class PersonRandomTypingDetectorCommandTest extends AbstractTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); // @Test(dataProvider="testSome") public void testSome(String gn, String sn, int minIncl, int maxIncl) throws Exception { PersonRandomTypingDetectorCommand command = new PersonRandomTypingDetectorCommand();
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/genderizer/persongenderizer/PersonGenderizerCommandTest.java
// Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // }
import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.ontology5.input.entities.address.StructuredAddressBuilder; import org.nameapi.ontology5.input.entities.address.StructuredPlaceInfoBuilder; import org.nameapi.ontology5.input.entities.address.StructuredStreetInfoBuilder; import org.nameapi.ontology5.input.entities.person.NaturalInputPerson; import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder; import org.nameapi.ontology5.input.entities.person.age.AgeInfoFactory; import org.nameapi.ontology5.input.entities.person.gender.ComputedPersonGender; import org.nameapi.ontology5.input.entities.person.gender.StoragePersonGender; import org.nameapi.ontology5.services.genderizer.GenderizerResult; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; import static org.testng.Assert.fail;
package org.nameapi.client.services.genderizer.persongenderizer; /** */ public class PersonGenderizerCommandTest extends AbstractTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); @Test public void testCall() throws Exception { PersonGenderizerCommand command = new PersonGenderizerCommand();
// Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // Path: src/test/functional/java/org/nameapi/client/services/genderizer/persongenderizer/PersonGenderizerCommandTest.java import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.ontology5.input.entities.address.StructuredAddressBuilder; import org.nameapi.ontology5.input.entities.address.StructuredPlaceInfoBuilder; import org.nameapi.ontology5.input.entities.address.StructuredStreetInfoBuilder; import org.nameapi.ontology5.input.entities.person.NaturalInputPerson; import org.nameapi.ontology5.input.entities.person.NaturalInputPersonBuilder; import org.nameapi.ontology5.input.entities.person.age.AgeInfoFactory; import org.nameapi.ontology5.input.entities.person.gender.ComputedPersonGender; import org.nameapi.ontology5.input.entities.person.gender.StoragePersonGender; import org.nameapi.ontology5.services.genderizer.GenderizerResult; import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; import static org.testng.Assert.fail; package org.nameapi.client.services.genderizer.persongenderizer; /** */ public class PersonGenderizerCommandTest extends AbstractTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); @Test public void testCall() throws Exception { PersonGenderizerCommand command = new PersonGenderizerCommand();
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/nameparser/fieldnameparser/FieldNameParserCommandTest.java
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // }
import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.ontology5.input.entities.person.name.NameField; import org.nameapi.ontology5.input.entities.person.name.types.CommonNameFieldType; import org.testng.annotations.Test; import static org.testng.Assert.assertFalse;
package org.nameapi.client.services.nameparser.fieldnameparser; /** * @author Fabian Kessler */ public class FieldNameParserCommandTest extends AbstractTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); //Service currently not available as public API. // @Test public void testCall() throws Exception { FieldNameParserCommand command = new FieldNameParserCommand();
// Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java // public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { // // //Developer: set your api key here. It looks something like this: // //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; // private static final String API_KEY = null; // // private static final Mode unitTestMode = withContext(API_KEY, makeContext(), // //the default and live server is "api.nameapi.org" // //we're using the latest release candidate with latest features here: // new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable()) // // //.with(TimeoutExtension.TIMEOUT, Duration.millis(5000)) // .with(StdoutLoggingExtension.enabled()) // ; // // private static Context makeContext() { // if (API_KEY==null) { // throw new RuntimeException("Set the api key variable to run the functional tests (get it from nameapi.org)!"); // } // return new ContextBuilder() // .priority(Priority.REALTIME) // .build(); // } // // @NotNull // public static Mode functionalTest() { // return unitTestMode; // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiRemoteExecutors.java // public final class NameApiRemoteExecutors { // // private static final CommandExecutor SAME = create(); // // public static CommandExecutor create() { // return new CommandExecutorBuilder() // .withExtension(new TimeoutExtension()) // .withExtension(new StdoutLoggingExtension()) // .withExtension(new ExceptionTranslationExtension()) // .withExtension(new AutoRetryExtension()) // .build(); // //could add name-api specific extensions here ... // } // // /** // * @return Always the same, immutable executor. // */ // public static CommandExecutor get() { // return SAME; // } // // } // // Path: src/test/functional/java/org/nameapi/client/services/AbstractTest.java // public class AbstractTest { // // @NotNull // protected InputPersonName makeName(@NotNull String gn, @NotNull String sn) { // return new WesternInputPersonNameBuilder().givenName(gn).surname(sn).build(); // } // // @NotNull // protected InputPersonName makeName(@NotNull String fullname) { // return NameBuilders.western().fullname(fullname).build(); // } // // } // Path: src/test/functional/java/org/nameapi/client/services/nameparser/fieldnameparser/FieldNameParserCommandTest.java import com.optimaize.command4j.CommandExecutor; import com.optimaize.command4j.Mode; import org.nameapi.client.services.FunctionalTestsNameApiModeFactory; import org.nameapi.client.lib.NameApiRemoteExecutors; import org.nameapi.client.services.AbstractTest; import org.nameapi.ontology5.input.entities.person.name.NameField; import org.nameapi.ontology5.input.entities.person.name.types.CommonNameFieldType; import org.testng.annotations.Test; import static org.testng.Assert.assertFalse; package org.nameapi.client.services.nameparser.fieldnameparser; /** * @author Fabian Kessler */ public class FieldNameParserCommandTest extends AbstractTest { private final CommandExecutor executor = NameApiRemoteExecutors.get(); //Service currently not available as public API. // @Test public void testCall() throws Exception { FieldNameParserCommand command = new FieldNameParserCommand();
Mode mode = FunctionalTestsNameApiModeFactory.functionalTest();
optimaize/nameapi-client-java
src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java
// Path: src/main/java/org/nameapi/client/lib/NameApiModeFactory.java // public class NameApiModeFactory { // // private static final Host DEFAULT_HOST = new Host("api.nameapi.org", 80); // private static final NameApiPortUrlFactory DEFAULT_PORT_FACTORY = NameApiPortUrlFactory.versionLatestStable(); // // // /** // * You can take this and extend for your setup if you need more. // * // * <p>Example: .with(StdoutLoggingExtension.enabled())</p> // * // * @param apiKey Your personal api key from registering with us. // * @param host for example {@code new Host("api.nameapi.org", 80)} // * @param portUrlFactory for example {@code NameApiPortUrlFactory.versionLatestStable()} // */ // @NotNull // public static Mode minimal(@NotNull String apiKey, @NotNull Host host, @NotNull RestPortUrlFactory portUrlFactory) { // return Mode.create() // .with(RestKeys.REST_PORT_URL_FACTORY, portUrlFactory) // // .with(ExceptionTranslationExtension.TRANSLATOR, new CombinedExceptionTranslator(new DefaultClientExceptionTranslator(), new SoapFaultExceptionTranslator())) // .with(Keys.HOST, host) // .with(NameApiKeys.API_KEY, apiKey); // } // // /** // * Overloaded method that uses // * for host: {@code new Host("api.nameapi.org", 80)} // * for port url: {@code NameApiPortUrlFactory.versionLatestStable()} // */ // @NotNull // public static Mode minimal(@NotNull String apiKey) { // return minimal(apiKey, DEFAULT_HOST, DEFAULT_PORT_FACTORY); // } // // // /** // * You can take this and extend for your setup if you need more. // * // * <p>Example: .with(StdoutLoggingExtension.enabled())</p> // * // * @param apiKey Your personal api key from registering with us. // * @param context for example {@code new ContextBuilder().priority(Priority.REALTIME).build()} // * @param host for example {@code new Host("api.nameapi.org", 80)} // * @param portUrlFactory for example {@code NameApiPortUrlFactory.versionLatestStable()} // */ // @NotNull // public static Mode withContext(@NotNull String apiKey, @NotNull Context context, @NotNull Host host, @NotNull RestPortUrlFactory portUrlFactory) { // return minimal(apiKey, host, portUrlFactory) // .with(NameApiKeys.CONTEXT, context); // } // // /** // * Overloaded method that uses // * for host: {@code new Host("api.nameapi.org", 80)} // * for port url: {@code NameApiPortUrlFactory.versionLatestStable()} // */ // @NotNull // public static Mode withContext(@NotNull String apiKey, @NotNull Context context) { // return withContext(apiKey, context, DEFAULT_HOST, DEFAULT_PORT_FACTORY); // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiPortUrlFactory.java // public class NameApiPortUrlFactory extends AbstractRestPortUrlFactory { // // private final String restPrefix; // // /** // * This is updated whenever the "latest stable" server api version changes. // * // * Currently this is version 5.0. // */ // public static NameApiPortUrlFactory versionLatestStable() { // return version5_0(); // } // // /** // * This is always set to the latest release candidate, that is the version right before it becomes the latest stable. // * Such a version does not always exist. After successful testing, it becomes the live version. // * // * Currently this is version 5.3. // */ // public static NameApiPortUrlFactory versionLatestReleaseCandidate() { // return version5_3(); // } // // /** // * This is always set to the current main development version. // * You do not necessarily have access to this. // * // * Currently this is version 5.3. // */ // public static NameApiPortUrlFactory versionLatestDevelopment() { // return version5_3(); // } // // public static NameApiPortUrlFactory version5_0() { // return new NameApiPortUrlFactory("5.0"); // } // public static NameApiPortUrlFactory version5_3() { // return new NameApiPortUrlFactory("5.3"); // } // // /** // * @param version for example "5.3". // */ // private NameApiPortUrlFactory(@NotNull String version) { // this.restPrefix = "/rest/v"+version; // } // // @NotNull @Override // public URL createUrl(@NotNull Host host) { // return createUrl(host, restPrefix); // } // }
import com.optimaize.anythingworks.common.host.Host; import com.optimaize.command4j.Mode; import com.optimaize.command4j.ext.extensions.logging.stdoutlogging.StdoutLoggingExtension; import org.jetbrains.annotations.NotNull; import org.nameapi.client.lib.NameApiModeFactory; import org.nameapi.client.lib.NameApiPortUrlFactory; import org.nameapi.ontology5.input.context.Context; import org.nameapi.ontology5.input.context.ContextBuilder; import org.nameapi.ontology5.input.context.Priority;
package org.nameapi.client.services; /** * @author Fabian Kessler */ public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { //Developer: set your api key here. It looks something like this: //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; private static final String API_KEY = null; private static final Mode unitTestMode = withContext(API_KEY, makeContext(), //the default and live server is "api.nameapi.org" //we're using the latest release candidate with latest features here:
// Path: src/main/java/org/nameapi/client/lib/NameApiModeFactory.java // public class NameApiModeFactory { // // private static final Host DEFAULT_HOST = new Host("api.nameapi.org", 80); // private static final NameApiPortUrlFactory DEFAULT_PORT_FACTORY = NameApiPortUrlFactory.versionLatestStable(); // // // /** // * You can take this and extend for your setup if you need more. // * // * <p>Example: .with(StdoutLoggingExtension.enabled())</p> // * // * @param apiKey Your personal api key from registering with us. // * @param host for example {@code new Host("api.nameapi.org", 80)} // * @param portUrlFactory for example {@code NameApiPortUrlFactory.versionLatestStable()} // */ // @NotNull // public static Mode minimal(@NotNull String apiKey, @NotNull Host host, @NotNull RestPortUrlFactory portUrlFactory) { // return Mode.create() // .with(RestKeys.REST_PORT_URL_FACTORY, portUrlFactory) // // .with(ExceptionTranslationExtension.TRANSLATOR, new CombinedExceptionTranslator(new DefaultClientExceptionTranslator(), new SoapFaultExceptionTranslator())) // .with(Keys.HOST, host) // .with(NameApiKeys.API_KEY, apiKey); // } // // /** // * Overloaded method that uses // * for host: {@code new Host("api.nameapi.org", 80)} // * for port url: {@code NameApiPortUrlFactory.versionLatestStable()} // */ // @NotNull // public static Mode minimal(@NotNull String apiKey) { // return minimal(apiKey, DEFAULT_HOST, DEFAULT_PORT_FACTORY); // } // // // /** // * You can take this and extend for your setup if you need more. // * // * <p>Example: .with(StdoutLoggingExtension.enabled())</p> // * // * @param apiKey Your personal api key from registering with us. // * @param context for example {@code new ContextBuilder().priority(Priority.REALTIME).build()} // * @param host for example {@code new Host("api.nameapi.org", 80)} // * @param portUrlFactory for example {@code NameApiPortUrlFactory.versionLatestStable()} // */ // @NotNull // public static Mode withContext(@NotNull String apiKey, @NotNull Context context, @NotNull Host host, @NotNull RestPortUrlFactory portUrlFactory) { // return minimal(apiKey, host, portUrlFactory) // .with(NameApiKeys.CONTEXT, context); // } // // /** // * Overloaded method that uses // * for host: {@code new Host("api.nameapi.org", 80)} // * for port url: {@code NameApiPortUrlFactory.versionLatestStable()} // */ // @NotNull // public static Mode withContext(@NotNull String apiKey, @NotNull Context context) { // return withContext(apiKey, context, DEFAULT_HOST, DEFAULT_PORT_FACTORY); // } // // } // // Path: src/main/java/org/nameapi/client/lib/NameApiPortUrlFactory.java // public class NameApiPortUrlFactory extends AbstractRestPortUrlFactory { // // private final String restPrefix; // // /** // * This is updated whenever the "latest stable" server api version changes. // * // * Currently this is version 5.0. // */ // public static NameApiPortUrlFactory versionLatestStable() { // return version5_0(); // } // // /** // * This is always set to the latest release candidate, that is the version right before it becomes the latest stable. // * Such a version does not always exist. After successful testing, it becomes the live version. // * // * Currently this is version 5.3. // */ // public static NameApiPortUrlFactory versionLatestReleaseCandidate() { // return version5_3(); // } // // /** // * This is always set to the current main development version. // * You do not necessarily have access to this. // * // * Currently this is version 5.3. // */ // public static NameApiPortUrlFactory versionLatestDevelopment() { // return version5_3(); // } // // public static NameApiPortUrlFactory version5_0() { // return new NameApiPortUrlFactory("5.0"); // } // public static NameApiPortUrlFactory version5_3() { // return new NameApiPortUrlFactory("5.3"); // } // // /** // * @param version for example "5.3". // */ // private NameApiPortUrlFactory(@NotNull String version) { // this.restPrefix = "/rest/v"+version; // } // // @NotNull @Override // public URL createUrl(@NotNull Host host) { // return createUrl(host, restPrefix); // } // } // Path: src/test/functional/java/org/nameapi/client/services/FunctionalTestsNameApiModeFactory.java import com.optimaize.anythingworks.common.host.Host; import com.optimaize.command4j.Mode; import com.optimaize.command4j.ext.extensions.logging.stdoutlogging.StdoutLoggingExtension; import org.jetbrains.annotations.NotNull; import org.nameapi.client.lib.NameApiModeFactory; import org.nameapi.client.lib.NameApiPortUrlFactory; import org.nameapi.ontology5.input.context.Context; import org.nameapi.ontology5.input.context.ContextBuilder; import org.nameapi.ontology5.input.context.Priority; package org.nameapi.client.services; /** * @author Fabian Kessler */ public class FunctionalTestsNameApiModeFactory extends NameApiModeFactory { //Developer: set your api key here. It looks something like this: //private static final String API_KEY = "32d21gc5071d7463ef6064c07ea98cb2-user1"; private static final String API_KEY = null; private static final Mode unitTestMode = withContext(API_KEY, makeContext(), //the default and live server is "api.nameapi.org" //we're using the latest release candidate with latest features here:
new Host("rc50-api.nameapi.org", 80), NameApiPortUrlFactory.versionLatestStable())
vaibhav-sinha/kong-java-client
src/main/java/com/github/vaibhavsinha/kong/impl/service/plugin/authentication/HmacAuthServiceImpl.java
// Path: src/main/java/com/github/vaibhavsinha/kong/api/plugin/authentication/HmacAuthService.java // public interface HmacAuthService { // void addCredentials(String consumerIdOrUsername, String username, String secret); // } // // Path: src/main/java/com/github/vaibhavsinha/kong/exception/KongClientException.java // public class KongClientException extends RuntimeException { // // private int code; // // private String error; // // public KongClientException(String message) { // super(message); // } // // public KongClientException(String message, int code, String error) { // super(message); // this.code = code; // this.error = error; // } // // public int getCode() { // return code; // } // // public String getError() { // return error; // } // }
import com.github.vaibhavsinha.kong.api.plugin.authentication.HmacAuthService; import com.github.vaibhavsinha.kong.exception.KongClientException; import com.github.vaibhavsinha.kong.internal.plugin.authentication.RetrofitHmacAuthService; import com.github.vaibhavsinha.kong.model.plugin.authentication.hmac.HmacAuthCredential; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; import java.io.IOException;
package com.github.vaibhavsinha.kong.impl.service.plugin.authentication; /** * Created by vaibhav on 15/06/17. * * Updated by fanhua on 2017-08-07. */ public class HmacAuthServiceImpl implements HmacAuthService { private RetrofitHmacAuthService retrofitHmacAuthService; public HmacAuthServiceImpl(RetrofitHmacAuthService retrofitHmacAuthService) { this.retrofitHmacAuthService = retrofitHmacAuthService; } @Override public void addCredentials(String consumerIdOrUsername, String username, String secret) { try { retrofitHmacAuthService.addCredentials(consumerIdOrUsername, new HmacAuthCredential(username, secret)).execute(); } catch (IOException e) {
// Path: src/main/java/com/github/vaibhavsinha/kong/api/plugin/authentication/HmacAuthService.java // public interface HmacAuthService { // void addCredentials(String consumerIdOrUsername, String username, String secret); // } // // Path: src/main/java/com/github/vaibhavsinha/kong/exception/KongClientException.java // public class KongClientException extends RuntimeException { // // private int code; // // private String error; // // public KongClientException(String message) { // super(message); // } // // public KongClientException(String message, int code, String error) { // super(message); // this.code = code; // this.error = error; // } // // public int getCode() { // return code; // } // // public String getError() { // return error; // } // } // Path: src/main/java/com/github/vaibhavsinha/kong/impl/service/plugin/authentication/HmacAuthServiceImpl.java import com.github.vaibhavsinha.kong.api.plugin.authentication.HmacAuthService; import com.github.vaibhavsinha.kong.exception.KongClientException; import com.github.vaibhavsinha.kong.internal.plugin.authentication.RetrofitHmacAuthService; import com.github.vaibhavsinha.kong.model.plugin.authentication.hmac.HmacAuthCredential; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; import java.io.IOException; package com.github.vaibhavsinha.kong.impl.service.plugin.authentication; /** * Created by vaibhav on 15/06/17. * * Updated by fanhua on 2017-08-07. */ public class HmacAuthServiceImpl implements HmacAuthService { private RetrofitHmacAuthService retrofitHmacAuthService; public HmacAuthServiceImpl(RetrofitHmacAuthService retrofitHmacAuthService) { this.retrofitHmacAuthService = retrofitHmacAuthService; } @Override public void addCredentials(String consumerIdOrUsername, String username, String secret) { try { retrofitHmacAuthService.addCredentials(consumerIdOrUsername, new HmacAuthCredential(username, secret)).execute(); } catch (IOException e) {
throw new KongClientException(e.getMessage());
vaibhav-sinha/kong-java-client
src/test/java/com/github/vaibhavsinha/kong/plugin/RetrofitOAuth2ManageServiceTest.java
// Path: src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/oauth2/Application.java // @Data // public class Application { // // @SerializedName("id") // private String id; // // @SerializedName("name") // private String name; // // @SerializedName("client_secret") // private String clientSecret; // // @SerializedName("client_id") // private String clientId; // // @SerializedName("redirect_uri") // private List<String> redirectUri; // // @SerializedName("created_at") // private Long createdAt; // // public Application(String name, List<String> redirectUri, String clientId, String clientSecret) { // this.name = name; // this.redirectUri = redirectUri; // this.clientId = clientId; // this.clientSecret = clientSecret; // } // // public Application(String name, List<String> redirectUri) { // this(name, redirectUri, null, null); // } // }
import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import com.github.vaibhavsinha.kong.BaseTest; import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.Application; import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.ApplicationList;
package com.github.vaibhavsinha.kong.plugin; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class RetrofitOAuth2ManageServiceTest extends BaseTest { private static String CONSUMER_ID = "53fe86c9-59d8-48c1-94ef-2e6142fadf85"; // ------------------------------------------------------------------------------------ private static String appName = "testApp-20170807113035732"; private static String appClientId = "dc80e4ebf33445faafad96c1b4701d48"; private static String appClientSecret = "22435791881e40dc97fd05f28eb86488"; private static List<String> appRedirectUrl = new ArrayList<>(); static { appRedirectUrl.add("http://10.5.227.17:3000/callback"); }
// Path: src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/oauth2/Application.java // @Data // public class Application { // // @SerializedName("id") // private String id; // // @SerializedName("name") // private String name; // // @SerializedName("client_secret") // private String clientSecret; // // @SerializedName("client_id") // private String clientId; // // @SerializedName("redirect_uri") // private List<String> redirectUri; // // @SerializedName("created_at") // private Long createdAt; // // public Application(String name, List<String> redirectUri, String clientId, String clientSecret) { // this.name = name; // this.redirectUri = redirectUri; // this.clientId = clientId; // this.clientSecret = clientSecret; // } // // public Application(String name, List<String> redirectUri) { // this(name, redirectUri, null, null); // } // } // Path: src/test/java/com/github/vaibhavsinha/kong/plugin/RetrofitOAuth2ManageServiceTest.java import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import com.github.vaibhavsinha.kong.BaseTest; import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.Application; import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.ApplicationList; package com.github.vaibhavsinha.kong.plugin; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class RetrofitOAuth2ManageServiceTest extends BaseTest { private static String CONSUMER_ID = "53fe86c9-59d8-48c1-94ef-2e6142fadf85"; // ------------------------------------------------------------------------------------ private static String appName = "testApp-20170807113035732"; private static String appClientId = "dc80e4ebf33445faafad96c1b4701d48"; private static String appClientSecret = "22435791881e40dc97fd05f28eb86488"; private static List<String> appRedirectUrl = new ArrayList<>(); static { appRedirectUrl.add("http://10.5.227.17:3000/callback"); }
private Application cachedApp;
vaibhav-sinha/kong-java-client
src/test/java/com/github/vaibhavsinha/kong/RetrofitApiPluginServiceTest.java
// Path: src/main/java/com/github/vaibhavsinha/kong/exception/KongClientException.java // public class KongClientException extends RuntimeException { // // private int code; // // private String error; // // public KongClientException(String message) { // super(message); // } // // public KongClientException(String message, int code, String error) { // super(message); // this.code = code; // this.error = error; // } // // public int getCode() { // return code; // } // // public String getError() { // return error; // } // }
import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.List; import com.github.vaibhavsinha.kong.model.admin.plugin.OAuth2Config; import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import com.github.vaibhavsinha.kong.exception.KongClientException; import com.github.vaibhavsinha.kong.model.admin.plugin.Plugin; import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList;
package com.github.vaibhavsinha.kong; /** * Created by fanhua on 2017-08-05. */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class RetrofitApiPluginServiceTest extends BaseTest { private String PLUGIN_ID = "3d3ee453-161c-449b-a468-42f06b7c0dc5"; private String PLUGIN_NAME = "oauth2"; private OAuth2Config OAUTH2_CONFIG = new OAuth2Config(); private String OAUTH2_PROVISION_KEY = "1f2b8d4baadb4b6f93c82b1599cad575"; private String API_NAME = "Test.V2.Api"; // ------------------------------------------------------------------------------- @Test public void test01_CreatePluginForApi() throws IOException { Plugin request = new Plugin(); request.setId(PLUGIN_ID); request.setName(PLUGIN_NAME); OAUTH2_CONFIG.setProvisionKey(OAUTH2_PROVISION_KEY); OAUTH2_CONFIG.setEnableAuthorizationCode(true); OAUTH2_CONFIG.setEnableImplicitGrant(true); OAUTH2_CONFIG.setEnablePasswordGrant(true); OAUTH2_CONFIG.setEnableClientCredentials(true); OAUTH2_CONFIG.setTokenExpiration(7200); request.setConfig(OAUTH2_CONFIG); Plugin response = kongClient.getApiPluginService().addPluginForApi(API_NAME, request); printJson(response); Assert.assertEquals(request.getName(), response.getName()); } @Test public void test02_GetPluginForApi() throws IOException { Plugin response = kongClient.getApiPluginService().getPluginForApi(API_NAME, PLUGIN_ID); printJson(response); Assert.assertEquals(PLUGIN_NAME, response.getName()); }
// Path: src/main/java/com/github/vaibhavsinha/kong/exception/KongClientException.java // public class KongClientException extends RuntimeException { // // private int code; // // private String error; // // public KongClientException(String message) { // super(message); // } // // public KongClientException(String message, int code, String error) { // super(message); // this.code = code; // this.error = error; // } // // public int getCode() { // return code; // } // // public String getError() { // return error; // } // } // Path: src/test/java/com/github/vaibhavsinha/kong/RetrofitApiPluginServiceTest.java import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.List; import com.github.vaibhavsinha.kong.model.admin.plugin.OAuth2Config; import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import com.github.vaibhavsinha.kong.exception.KongClientException; import com.github.vaibhavsinha.kong.model.admin.plugin.Plugin; import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList; package com.github.vaibhavsinha.kong; /** * Created by fanhua on 2017-08-05. */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class RetrofitApiPluginServiceTest extends BaseTest { private String PLUGIN_ID = "3d3ee453-161c-449b-a468-42f06b7c0dc5"; private String PLUGIN_NAME = "oauth2"; private OAuth2Config OAUTH2_CONFIG = new OAuth2Config(); private String OAUTH2_PROVISION_KEY = "1f2b8d4baadb4b6f93c82b1599cad575"; private String API_NAME = "Test.V2.Api"; // ------------------------------------------------------------------------------- @Test public void test01_CreatePluginForApi() throws IOException { Plugin request = new Plugin(); request.setId(PLUGIN_ID); request.setName(PLUGIN_NAME); OAUTH2_CONFIG.setProvisionKey(OAUTH2_PROVISION_KEY); OAUTH2_CONFIG.setEnableAuthorizationCode(true); OAUTH2_CONFIG.setEnableImplicitGrant(true); OAUTH2_CONFIG.setEnablePasswordGrant(true); OAUTH2_CONFIG.setEnableClientCredentials(true); OAUTH2_CONFIG.setTokenExpiration(7200); request.setConfig(OAUTH2_CONFIG); Plugin response = kongClient.getApiPluginService().addPluginForApi(API_NAME, request); printJson(response); Assert.assertEquals(request.getName(), response.getName()); } @Test public void test02_GetPluginForApi() throws IOException { Plugin response = kongClient.getApiPluginService().getPluginForApi(API_NAME, PLUGIN_ID); printJson(response); Assert.assertEquals(PLUGIN_NAME, response.getName()); }
@Test(expected = KongClientException.class)
vaibhav-sinha/kong-java-client
src/test/java/com/github/vaibhavsinha/kong/RetrofitApiServiceTest.java
// Path: src/main/java/com/github/vaibhavsinha/kong/exception/KongClientException.java // public class KongClientException extends RuntimeException { // // private int code; // // private String error; // // public KongClientException(String message) { // super(message); // } // // public KongClientException(String message, int code, String error) { // super(message); // this.code = code; // this.error = error; // } // // public int getCode() { // return code; // } // // public String getError() { // return error; // } // } // // Path: src/main/java/com/github/vaibhavsinha/kong/model/admin/api/ApiList.java // @Data // public class ApiList extends AbstractEntityList { // Long total; // String next; // List<Api> data; // }
import com.github.vaibhavsinha.kong.exception.KongClientException; import com.github.vaibhavsinha.kong.model.admin.api.Api; import com.github.vaibhavsinha.kong.model.admin.api.ApiList; import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List;
package com.github.vaibhavsinha.kong; /** * Created by vaibhav on 12/06/17. * * Updated by fanhua on 2017-08-04. */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class RetrofitApiServiceTest extends BaseTest { private String API_NAME_V1 = "Test_V1_Api"; // private String API_ID_V1 = "f813a66b-bac6-4951-831b-f04d53ae0bf0"; // not exist private String API_ID_V1 = "3a9fa5b9-5f99-4ab8-a949-d676becd30b3"; private String API_NAME_V2 = "Test_V2_Api"; private String API_NAME_V2_NEW = "Test.V2.Api"; private String API_ID_V2 = "f813a66b-bac6-4952-831b-f04d53ae0bf0"; private String API_UPSTREAM_URL = "http://httpbin.org"; private String[] API_HOSTS = new String[] {"example.com"}; private String[] API_URIS = new String[] {"/v1/example", "/v2/example"}; // ----------------------------------------------------------------------- @Test public void test01_CreateApi() throws IOException { Api request = new Api(); request.setId(API_ID_V2); request.setName(API_NAME_V2); request.setUpstreamUrl(API_UPSTREAM_URL); // request.setHosts(Arrays.asList(API_HOSTS)); request.setUris(Arrays.asList(API_URIS)); Api response = kongClient.getApiService().createApi(request); printJson(response); Assert.assertEquals(request.getName(), response.getName()); } @Test public void test02_GetApi() throws IOException { Api response = kongClient.getApiService().getApi(API_NAME_V2); printJson(response); Assert.assertEquals(API_NAME_V2, response.getName()); }
// Path: src/main/java/com/github/vaibhavsinha/kong/exception/KongClientException.java // public class KongClientException extends RuntimeException { // // private int code; // // private String error; // // public KongClientException(String message) { // super(message); // } // // public KongClientException(String message, int code, String error) { // super(message); // this.code = code; // this.error = error; // } // // public int getCode() { // return code; // } // // public String getError() { // return error; // } // } // // Path: src/main/java/com/github/vaibhavsinha/kong/model/admin/api/ApiList.java // @Data // public class ApiList extends AbstractEntityList { // Long total; // String next; // List<Api> data; // } // Path: src/test/java/com/github/vaibhavsinha/kong/RetrofitApiServiceTest.java import com.github.vaibhavsinha.kong.exception.KongClientException; import com.github.vaibhavsinha.kong.model.admin.api.Api; import com.github.vaibhavsinha.kong.model.admin.api.ApiList; import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; package com.github.vaibhavsinha.kong; /** * Created by vaibhav on 12/06/17. * * Updated by fanhua on 2017-08-04. */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class RetrofitApiServiceTest extends BaseTest { private String API_NAME_V1 = "Test_V1_Api"; // private String API_ID_V1 = "f813a66b-bac6-4951-831b-f04d53ae0bf0"; // not exist private String API_ID_V1 = "3a9fa5b9-5f99-4ab8-a949-d676becd30b3"; private String API_NAME_V2 = "Test_V2_Api"; private String API_NAME_V2_NEW = "Test.V2.Api"; private String API_ID_V2 = "f813a66b-bac6-4952-831b-f04d53ae0bf0"; private String API_UPSTREAM_URL = "http://httpbin.org"; private String[] API_HOSTS = new String[] {"example.com"}; private String[] API_URIS = new String[] {"/v1/example", "/v2/example"}; // ----------------------------------------------------------------------- @Test public void test01_CreateApi() throws IOException { Api request = new Api(); request.setId(API_ID_V2); request.setName(API_NAME_V2); request.setUpstreamUrl(API_UPSTREAM_URL); // request.setHosts(Arrays.asList(API_HOSTS)); request.setUris(Arrays.asList(API_URIS)); Api response = kongClient.getApiService().createApi(request); printJson(response); Assert.assertEquals(request.getName(), response.getName()); } @Test public void test02_GetApi() throws IOException { Api response = kongClient.getApiService().getApi(API_NAME_V2); printJson(response); Assert.assertEquals(API_NAME_V2, response.getName()); }
@Test(expected = KongClientException.class)
vaibhav-sinha/kong-java-client
src/test/java/com/github/vaibhavsinha/kong/RetrofitApiServiceTest.java
// Path: src/main/java/com/github/vaibhavsinha/kong/exception/KongClientException.java // public class KongClientException extends RuntimeException { // // private int code; // // private String error; // // public KongClientException(String message) { // super(message); // } // // public KongClientException(String message, int code, String error) { // super(message); // this.code = code; // this.error = error; // } // // public int getCode() { // return code; // } // // public String getError() { // return error; // } // } // // Path: src/main/java/com/github/vaibhavsinha/kong/model/admin/api/ApiList.java // @Data // public class ApiList extends AbstractEntityList { // Long total; // String next; // List<Api> data; // }
import com.github.vaibhavsinha.kong.exception.KongClientException; import com.github.vaibhavsinha.kong.model.admin.api.Api; import com.github.vaibhavsinha.kong.model.admin.api.ApiList; import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List;
// @Test public void test05_CreateOrUpdateApi() throws IOException { //Test by HTTP PUT method.... // API name is required, otherwise you will get exception. // if API id is not set, then Kong will add API by name. // if API id is set, the Kong will update API by id and name. // if API id is set, but the API is actually not exist, then Kong will response 200(OK), but the API won't be created!!! Api request = new Api(); request.setName(API_NAME_V1); // request.setId(API_ID_V1); request.setUpstreamUrl(API_UPSTREAM_URL); request.setUris(Arrays.asList(API_URIS)); request.setCreatedAt(System.currentTimeMillis()); Api response = kongClient.getApiService().createOrUpdateApi(request); Assert.assertNotNull(response); printJson(response); Assert.assertEquals(request.getName(), response.getName()); } @Test public void test09_testDeleteApi() throws IOException { kongClient.getApiService().deleteApi(API_ID_V2); } @Test public void test10_ListApis() throws IOException { List<Api> apis = new ArrayList<>();
// Path: src/main/java/com/github/vaibhavsinha/kong/exception/KongClientException.java // public class KongClientException extends RuntimeException { // // private int code; // // private String error; // // public KongClientException(String message) { // super(message); // } // // public KongClientException(String message, int code, String error) { // super(message); // this.code = code; // this.error = error; // } // // public int getCode() { // return code; // } // // public String getError() { // return error; // } // } // // Path: src/main/java/com/github/vaibhavsinha/kong/model/admin/api/ApiList.java // @Data // public class ApiList extends AbstractEntityList { // Long total; // String next; // List<Api> data; // } // Path: src/test/java/com/github/vaibhavsinha/kong/RetrofitApiServiceTest.java import com.github.vaibhavsinha.kong.exception.KongClientException; import com.github.vaibhavsinha.kong.model.admin.api.Api; import com.github.vaibhavsinha.kong.model.admin.api.ApiList; import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; // @Test public void test05_CreateOrUpdateApi() throws IOException { //Test by HTTP PUT method.... // API name is required, otherwise you will get exception. // if API id is not set, then Kong will add API by name. // if API id is set, the Kong will update API by id and name. // if API id is set, but the API is actually not exist, then Kong will response 200(OK), but the API won't be created!!! Api request = new Api(); request.setName(API_NAME_V1); // request.setId(API_ID_V1); request.setUpstreamUrl(API_UPSTREAM_URL); request.setUris(Arrays.asList(API_URIS)); request.setCreatedAt(System.currentTimeMillis()); Api response = kongClient.getApiService().createOrUpdateApi(request); Assert.assertNotNull(response); printJson(response); Assert.assertEquals(request.getName(), response.getName()); } @Test public void test09_testDeleteApi() throws IOException { kongClient.getApiService().deleteApi(API_ID_V2); } @Test public void test10_ListApis() throws IOException { List<Api> apis = new ArrayList<>();
ApiList apiList = kongClient.getApiService().listApis(null, null, null, null, 1L, null);
vaibhav-sinha/kong-java-client
src/main/java/com/github/vaibhavsinha/kong/api/plugin/authentication/KeyAuthService.java
// Path: src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/key/KeyAuthCredential.java // @Data // @NoArgsConstructor // public class KeyAuthCredential { // // @SerializedName("id") // private String id; // @SerializedName("key") // private String key; // @SerializedName("consumer_id") // private String consumerId; // @SerializedName("created_at") // private Long createdAt; // // public KeyAuthCredential(String key) { // this.key = key; // } // } // // Path: src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/key/KeyAuthCredentialList.java // @Data // public class KeyAuthCredentialList extends AbstractEntityList { // Long total; // List<KeyAuthCredential> data; // }
import com.github.vaibhavsinha.kong.model.plugin.authentication.key.KeyAuthCredential; import com.github.vaibhavsinha.kong.model.plugin.authentication.key.KeyAuthCredentialList;
package com.github.vaibhavsinha.kong.api.plugin.authentication; /** * Created by vaibhav on 15/06/17. * * Updated by dvilela on 17/10/17. */ public interface KeyAuthService { KeyAuthCredential addCredentials(String consumerIdOrUsername, String key);
// Path: src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/key/KeyAuthCredential.java // @Data // @NoArgsConstructor // public class KeyAuthCredential { // // @SerializedName("id") // private String id; // @SerializedName("key") // private String key; // @SerializedName("consumer_id") // private String consumerId; // @SerializedName("created_at") // private Long createdAt; // // public KeyAuthCredential(String key) { // this.key = key; // } // } // // Path: src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/key/KeyAuthCredentialList.java // @Data // public class KeyAuthCredentialList extends AbstractEntityList { // Long total; // List<KeyAuthCredential> data; // } // Path: src/main/java/com/github/vaibhavsinha/kong/api/plugin/authentication/KeyAuthService.java import com.github.vaibhavsinha.kong.model.plugin.authentication.key.KeyAuthCredential; import com.github.vaibhavsinha.kong.model.plugin.authentication.key.KeyAuthCredentialList; package com.github.vaibhavsinha.kong.api.plugin.authentication; /** * Created by vaibhav on 15/06/17. * * Updated by dvilela on 17/10/17. */ public interface KeyAuthService { KeyAuthCredential addCredentials(String consumerIdOrUsername, String key);
KeyAuthCredentialList listCredentials(String consumerIdOrUsername, Long size, String offset);
vaibhav-sinha/kong-java-client
src/main/java/com/github/vaibhavsinha/kong/api/admin/ApiService.java
// Path: src/main/java/com/github/vaibhavsinha/kong/model/admin/api/ApiList.java // @Data // public class ApiList extends AbstractEntityList { // Long total; // String next; // List<Api> data; // }
import com.github.vaibhavsinha.kong.model.admin.api.Api; import com.github.vaibhavsinha.kong.model.admin.api.ApiList; import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList;
package com.github.vaibhavsinha.kong.api.admin; /** * Created by vaibhav on 13/06/17. */ public interface ApiService { Api createApi(Api request); Api getApi(String nameOrId); Api updateApi(String nameOrId, Api request); /** * This interface has issue in Kong. * 1. Usually, when we put a API(which not exist in Kong) as a parameter, it should be added as a new one. * But it only take effect when API id is empty. * 2. When the API id input is not empty, it will consider to update the existing API. So, we can either * create a API (without id), or update a API (with id). * 3. When you try to create a API with name and id, it will become odd. Kong will give you the 200(ok) response, * but won't create the API that you wanted. (That's why we'd better not use this interface. * * */ @Deprecated Api createOrUpdateApi(Api request); void deleteApi(String nameOrId);
// Path: src/main/java/com/github/vaibhavsinha/kong/model/admin/api/ApiList.java // @Data // public class ApiList extends AbstractEntityList { // Long total; // String next; // List<Api> data; // } // Path: src/main/java/com/github/vaibhavsinha/kong/api/admin/ApiService.java import com.github.vaibhavsinha.kong.model.admin.api.Api; import com.github.vaibhavsinha.kong.model.admin.api.ApiList; import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList; package com.github.vaibhavsinha.kong.api.admin; /** * Created by vaibhav on 13/06/17. */ public interface ApiService { Api createApi(Api request); Api getApi(String nameOrId); Api updateApi(String nameOrId, Api request); /** * This interface has issue in Kong. * 1. Usually, when we put a API(which not exist in Kong) as a parameter, it should be added as a new one. * But it only take effect when API id is empty. * 2. When the API id input is not empty, it will consider to update the existing API. So, we can either * create a API (without id), or update a API (with id). * 3. When you try to create a API with name and id, it will become odd. Kong will give you the 200(ok) response, * but won't create the API that you wanted. (That's why we'd better not use this interface. * * */ @Deprecated Api createOrUpdateApi(Api request); void deleteApi(String nameOrId);
ApiList listApis(String id, String upstreamUrl, String name, Long retries, Long size, String offset);
vaibhav-sinha/kong-java-client
src/test/java/com/github/vaibhavsinha/kong/RetrofitPluginServiceTest.java
// Path: src/main/java/com/github/vaibhavsinha/kong/exception/KongClientException.java // public class KongClientException extends RuntimeException { // // private int code; // // private String error; // // public KongClientException(String message) { // super(message); // } // // public KongClientException(String message, int code, String error) { // super(message); // this.code = code; // this.error = error; // } // // public int getCode() { // return code; // } // // public String getError() { // return error; // } // }
import com.github.vaibhavsinha.kong.exception.KongClientException; import com.github.vaibhavsinha.kong.model.admin.plugin.Plugin; import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList; import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.List;
package com.github.vaibhavsinha.kong; /** * Created by vaibhav on 12/06/17. * * Updated by fanhua on 2017-08-04. */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class RetrofitPluginServiceTest extends BaseTest { private String PLUGIN_ID = "61e5b656-7b68-4761-aeae-d9c94a5782c8"; private String PLUGIN_NAME = "jwt"; private String API_ID = "3a9fa5b9-5f99-4ab8-a949-d676becd30b3"; @Test public void test11_CreatePlugin() throws IOException { Plugin request = new Plugin(); request.setId(PLUGIN_ID); request.setApiId(API_ID); // make sure you put the valid API_ID here, if you don't put API_ID, the the plugin will take effect on all APIs request.setName(PLUGIN_NAME); Plugin response = kongClient.getPluginService().addPlugin(request); printJson(response); Assert.assertEquals(request.getName(), response.getName()); } @Test public void test12_GetPlugin() throws IOException { Plugin response = kongClient.getPluginService().getPlugin(PLUGIN_ID); printJson(response); Assert.assertEquals(PLUGIN_NAME, response.getName()); }
// Path: src/main/java/com/github/vaibhavsinha/kong/exception/KongClientException.java // public class KongClientException extends RuntimeException { // // private int code; // // private String error; // // public KongClientException(String message) { // super(message); // } // // public KongClientException(String message, int code, String error) { // super(message); // this.code = code; // this.error = error; // } // // public int getCode() { // return code; // } // // public String getError() { // return error; // } // } // Path: src/test/java/com/github/vaibhavsinha/kong/RetrofitPluginServiceTest.java import com.github.vaibhavsinha.kong.exception.KongClientException; import com.github.vaibhavsinha.kong.model.admin.plugin.Plugin; import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList; import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.List; package com.github.vaibhavsinha.kong; /** * Created by vaibhav on 12/06/17. * * Updated by fanhua on 2017-08-04. */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class RetrofitPluginServiceTest extends BaseTest { private String PLUGIN_ID = "61e5b656-7b68-4761-aeae-d9c94a5782c8"; private String PLUGIN_NAME = "jwt"; private String API_ID = "3a9fa5b9-5f99-4ab8-a949-d676becd30b3"; @Test public void test11_CreatePlugin() throws IOException { Plugin request = new Plugin(); request.setId(PLUGIN_ID); request.setApiId(API_ID); // make sure you put the valid API_ID here, if you don't put API_ID, the the plugin will take effect on all APIs request.setName(PLUGIN_NAME); Plugin response = kongClient.getPluginService().addPlugin(request); printJson(response); Assert.assertEquals(request.getName(), response.getName()); } @Test public void test12_GetPlugin() throws IOException { Plugin response = kongClient.getPluginService().getPlugin(PLUGIN_ID); printJson(response); Assert.assertEquals(PLUGIN_NAME, response.getName()); }
@Test(expected = KongClientException.class)
vaibhav-sinha/kong-java-client
src/main/java/com/github/vaibhavsinha/kong/internal/admin/RetrofitApiService.java
// Path: src/main/java/com/github/vaibhavsinha/kong/model/admin/api/ApiList.java // @Data // public class ApiList extends AbstractEntityList { // Long total; // String next; // List<Api> data; // }
import com.github.vaibhavsinha.kong.model.admin.api.Api; import com.github.vaibhavsinha.kong.model.admin.api.ApiList; import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList; import retrofit2.Call; import retrofit2.http.*;
package com.github.vaibhavsinha.kong.internal.admin; /** * Created by vaibhav on 12/06/17. */ public interface RetrofitApiService { @POST("apis/") Call<Api> createApi(@Body Api request); @GET("apis/{id}") Call<Api> getApi(@Path("id") String nameOrId); @PATCH("apis/{id}") Call<Api> updateApi(@Path("id") String nameOrId, @Body Api request); @Deprecated @PUT("apis/") Call<Api> createOrUpdateApi(@Body Api request); @DELETE("apis/{id}") Call<Void> deleteApi(@Path("id") String nameOrId); @GET("apis/")
// Path: src/main/java/com/github/vaibhavsinha/kong/model/admin/api/ApiList.java // @Data // public class ApiList extends AbstractEntityList { // Long total; // String next; // List<Api> data; // } // Path: src/main/java/com/github/vaibhavsinha/kong/internal/admin/RetrofitApiService.java import com.github.vaibhavsinha.kong.model.admin.api.Api; import com.github.vaibhavsinha.kong.model.admin.api.ApiList; import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList; import retrofit2.Call; import retrofit2.http.*; package com.github.vaibhavsinha.kong.internal.admin; /** * Created by vaibhav on 12/06/17. */ public interface RetrofitApiService { @POST("apis/") Call<Api> createApi(@Body Api request); @GET("apis/{id}") Call<Api> getApi(@Path("id") String nameOrId); @PATCH("apis/{id}") Call<Api> updateApi(@Path("id") String nameOrId, @Body Api request); @Deprecated @PUT("apis/") Call<Api> createOrUpdateApi(@Body Api request); @DELETE("apis/{id}") Call<Void> deleteApi(@Path("id") String nameOrId); @GET("apis/")
Call<ApiList> listApis(@Query("id") String id, @Query("upstream_url") String upstreamUrl, @Query("name") String name, @Query("retries") Long retries, @Query("size") Long size, @Query("offset") String offset);
vaibhav-sinha/kong-java-client
src/main/java/com/github/vaibhavsinha/kong/api/admin/UpstreamService.java
// Path: src/main/java/com/github/vaibhavsinha/kong/model/admin/upstream/Upstream.java // @Data // public class Upstream { // // @SerializedName("id") // private String id; // @SerializedName("slots") // private Integer slots; // @SerializedName("name") // private String name; // @SerializedName("orderlist") // private List<Integer> orderList; // @SerializedName("created_at") // private Long createdAt; // }
import com.github.vaibhavsinha.kong.model.admin.upstream.Upstream; import com.github.vaibhavsinha.kong.model.admin.upstream.UpstreamList;
package com.github.vaibhavsinha.kong.api.admin; /** * Created by vaibhav on 13/06/17. */ @Deprecated public interface UpstreamService {
// Path: src/main/java/com/github/vaibhavsinha/kong/model/admin/upstream/Upstream.java // @Data // public class Upstream { // // @SerializedName("id") // private String id; // @SerializedName("slots") // private Integer slots; // @SerializedName("name") // private String name; // @SerializedName("orderlist") // private List<Integer> orderList; // @SerializedName("created_at") // private Long createdAt; // } // Path: src/main/java/com/github/vaibhavsinha/kong/api/admin/UpstreamService.java import com.github.vaibhavsinha.kong.model.admin.upstream.Upstream; import com.github.vaibhavsinha.kong.model.admin.upstream.UpstreamList; package com.github.vaibhavsinha.kong.api.admin; /** * Created by vaibhav on 13/06/17. */ @Deprecated public interface UpstreamService {
Upstream createUpstream(Upstream request);
vaibhav-sinha/kong-java-client
src/test/java/com/github/vaibhavsinha/kong/RetrofitTargetServiceTest.java
// Path: src/main/java/com/github/vaibhavsinha/kong/model/admin/target/Target.java // @Data // public class Target { // // @SerializedName("id") // private String id; // @SerializedName("target") // private String target; // @SerializedName("weight") // private Long weight; // @SerializedName("upstream_id") // private String upstreamId; // @SerializedName("created_at") // private Long createdAt; // }
import com.github.vaibhavsinha.kong.impl.KongClient; import com.github.vaibhavsinha.kong.model.admin.target.Target; import com.github.vaibhavsinha.kong.model.admin.target.TargetList; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import java.io.IOException; import java.util.ArrayList; import java.util.List;
package com.github.vaibhavsinha.kong; /** * Created by vaibhav on 12/06/17. */ public class RetrofitTargetServiceTest extends BaseTest { // @Test public void testCreateTarget() throws IOException {
// Path: src/main/java/com/github/vaibhavsinha/kong/model/admin/target/Target.java // @Data // public class Target { // // @SerializedName("id") // private String id; // @SerializedName("target") // private String target; // @SerializedName("weight") // private Long weight; // @SerializedName("upstream_id") // private String upstreamId; // @SerializedName("created_at") // private Long createdAt; // } // Path: src/test/java/com/github/vaibhavsinha/kong/RetrofitTargetServiceTest.java import com.github.vaibhavsinha.kong.impl.KongClient; import com.github.vaibhavsinha.kong.model.admin.target.Target; import com.github.vaibhavsinha.kong.model.admin.target.TargetList; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import java.io.IOException; import java.util.ArrayList; import java.util.List; package com.github.vaibhavsinha.kong; /** * Created by vaibhav on 12/06/17. */ public class RetrofitTargetServiceTest extends BaseTest { // @Test public void testCreateTarget() throws IOException {
Target request = new Target();
idega/is.idega.block.nationalregister
src/java/is/idega/block/nationalregister/data/NationalRegisterFateBMPBean.java
// Path: src/java/is/idega/block/nationalregister/business/NationalRegisterConstants.java // public class NationalRegisterConstants { // public static final String FATE_DECEASED = "deceased"; // LƒST // // public final static String FATE_CHANGE_PERSONAL_ID = "change_pid"; // "BRFD"; // // public final static String FATE_REMOVED = "removed"; // "BRFL"; // // private final static String FATE_CHANGE_OLD_ID = "BRNN"; // }
import java.util.Collection; import javax.ejb.FinderException; import is.idega.block.nationalregister.business.NationalRegisterConstants; import com.idega.data.GenericEntity; import com.idega.data.IDOLookup; import com.idega.data.IDOQuery;
package is.idega.block.nationalregister.data; public class NationalRegisterFateBMPBean extends GenericEntity implements NationalRegisterFate { protected final static String ENTITY_NAME = "reg_nat_is_fate"; protected final static String COLUMN_FATE_CODE = "fate_code"; protected final static String COLUMN_FATE_STRING = "fate_string"; public String getEntityName() { return ENTITY_NAME; } public void initializeAttributes() { addAttribute(getIDColumnName()); addAttribute(COLUMN_FATE_CODE, "fate code", String.class); addAttribute(COLUMN_FATE_STRING, "fate string", String.class); } public void insertStartData() throws Exception { try { NationalRegisterFate deceased = ((NationalRegisterFateHome) IDOLookup .getHome(NationalRegisterFate.class)).create();
// Path: src/java/is/idega/block/nationalregister/business/NationalRegisterConstants.java // public class NationalRegisterConstants { // public static final String FATE_DECEASED = "deceased"; // LƒST // // public final static String FATE_CHANGE_PERSONAL_ID = "change_pid"; // "BRFD"; // // public final static String FATE_REMOVED = "removed"; // "BRFL"; // // private final static String FATE_CHANGE_OLD_ID = "BRNN"; // } // Path: src/java/is/idega/block/nationalregister/data/NationalRegisterFateBMPBean.java import java.util.Collection; import javax.ejb.FinderException; import is.idega.block.nationalregister.business.NationalRegisterConstants; import com.idega.data.GenericEntity; import com.idega.data.IDOLookup; import com.idega.data.IDOQuery; package is.idega.block.nationalregister.data; public class NationalRegisterFateBMPBean extends GenericEntity implements NationalRegisterFate { protected final static String ENTITY_NAME = "reg_nat_is_fate"; protected final static String COLUMN_FATE_CODE = "fate_code"; protected final static String COLUMN_FATE_STRING = "fate_string"; public String getEntityName() { return ENTITY_NAME; } public void initializeAttributes() { addAttribute(getIDColumnName()); addAttribute(COLUMN_FATE_CODE, "fate code", String.class); addAttribute(COLUMN_FATE_STRING, "fate string", String.class); } public void insertStartData() throws Exception { try { NationalRegisterFate deceased = ((NationalRegisterFateHome) IDOLookup .getHome(NationalRegisterFate.class)).create();
deceased.setFateCode(NationalRegisterConstants.FATE_DECEASED);
idega/is.idega.block.nationalregister
src/java/is/idega/block/nationalregister/business/NationalRegisterDeceasedBusinessBean.java
// Path: src/java/is/idega/block/nationalregister/data/NationalRegisterDeceased.java // public interface NationalRegisterDeceased extends IDOEntity { // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#setSymbol // */ // public void setSymbol(String symbol); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#getSymbol // */ // public String getSymbol(); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#setSSN // */ // public void setSSN(String ssn); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#getSSN // */ // public String getSSN(); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#setDateOfDeath // */ // public void setDateOfDeath(String date); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#getDateOfDeath // */ // public String getDateOfDeath(); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#setName // */ // public void setName(String name); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#getName // */ // public String getName(); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#setCommune // */ // public void setCommune(String commune); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#getCommune // */ // public String getCommune(); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#setStreet // */ // public void setStreet(String street); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#getStreet // */ // public String getStreet(); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#setGender // */ // public void setGender(String gender); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#getGender // */ // public String getGender(); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#setMaritalStatus // */ // public void setMaritalStatus(String status); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#getMaritalStatus // */ // public String getMaritalStatus(); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#setSpouseSSN // */ // public void setSpouseSSN(String ssn); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#getSpouseSSN // */ // public String getSpouseSSN(); // } // // Path: src/java/is/idega/block/nationalregister/data/NationalRegisterDeceasedHome.java // public interface NationalRegisterDeceasedHome extends IDOHome { // // public NationalRegisterDeceased create() throws CreateException; // // public NationalRegisterDeceased findByPrimaryKey(Object pk) throws FinderException; // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#ejbFindAll // */ // public Collection findAll() throws FinderException, RemoteException; // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#ejbFindAllBySSN // */ // public Collection findAllBySSN(String ssn) throws FinderException, RemoteException; // // }
import is.idega.block.nationalregister.data.NationalRegisterDeceased; import is.idega.block.nationalregister.data.NationalRegisterDeceasedHome; import java.rmi.RemoteException; import java.util.Collection; import java.util.Iterator; import javax.ejb.CreateException; import javax.ejb.FinderException; import com.idega.business.IBOServiceBean; import com.idega.data.IDOLookup;
String gender, String maritialStatus, String spouseSSN) { try { NationalRegisterDeceased deceasedReg = getEntryBySSN(ssn); if (deceasedReg == null) { deceasedReg = getNationalRegisterDeceasedHome().create(); } deceasedReg.setSymbol(symbol); deceasedReg.setSSN(ssn); deceasedReg.setDateOfDeath(dateOfDeath); deceasedReg.setName(name); deceasedReg.setStreet(street); deceasedReg.setCommune(commune); deceasedReg.setGender(gender); deceasedReg.setMaritalStatus(maritialStatus); deceasedReg.setSpouseSSN(spouseSSN); deceasedReg.store(); } catch (CreateException e) { e.printStackTrace(); return false; } return true; }
// Path: src/java/is/idega/block/nationalregister/data/NationalRegisterDeceased.java // public interface NationalRegisterDeceased extends IDOEntity { // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#setSymbol // */ // public void setSymbol(String symbol); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#getSymbol // */ // public String getSymbol(); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#setSSN // */ // public void setSSN(String ssn); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#getSSN // */ // public String getSSN(); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#setDateOfDeath // */ // public void setDateOfDeath(String date); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#getDateOfDeath // */ // public String getDateOfDeath(); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#setName // */ // public void setName(String name); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#getName // */ // public String getName(); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#setCommune // */ // public void setCommune(String commune); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#getCommune // */ // public String getCommune(); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#setStreet // */ // public void setStreet(String street); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#getStreet // */ // public String getStreet(); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#setGender // */ // public void setGender(String gender); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#getGender // */ // public String getGender(); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#setMaritalStatus // */ // public void setMaritalStatus(String status); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#getMaritalStatus // */ // public String getMaritalStatus(); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#setSpouseSSN // */ // public void setSpouseSSN(String ssn); // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#getSpouseSSN // */ // public String getSpouseSSN(); // } // // Path: src/java/is/idega/block/nationalregister/data/NationalRegisterDeceasedHome.java // public interface NationalRegisterDeceasedHome extends IDOHome { // // public NationalRegisterDeceased create() throws CreateException; // // public NationalRegisterDeceased findByPrimaryKey(Object pk) throws FinderException; // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#ejbFindAll // */ // public Collection findAll() throws FinderException, RemoteException; // // /** // * @see is.idega.block.nationalregister.data.NationalRegisterDeceasedBMPBean#ejbFindAllBySSN // */ // public Collection findAllBySSN(String ssn) throws FinderException, RemoteException; // // } // Path: src/java/is/idega/block/nationalregister/business/NationalRegisterDeceasedBusinessBean.java import is.idega.block.nationalregister.data.NationalRegisterDeceased; import is.idega.block.nationalregister.data.NationalRegisterDeceasedHome; import java.rmi.RemoteException; import java.util.Collection; import java.util.Iterator; import javax.ejb.CreateException; import javax.ejb.FinderException; import com.idega.business.IBOServiceBean; import com.idega.data.IDOLookup; String gender, String maritialStatus, String spouseSSN) { try { NationalRegisterDeceased deceasedReg = getEntryBySSN(ssn); if (deceasedReg == null) { deceasedReg = getNationalRegisterDeceasedHome().create(); } deceasedReg.setSymbol(symbol); deceasedReg.setSSN(ssn); deceasedReg.setDateOfDeath(dateOfDeath); deceasedReg.setName(name); deceasedReg.setStreet(street); deceasedReg.setCommune(commune); deceasedReg.setGender(gender); deceasedReg.setMaritalStatus(maritialStatus); deceasedReg.setSpouseSSN(spouseSSN); deceasedReg.store(); } catch (CreateException e) { e.printStackTrace(); return false; } return true; }
protected NationalRegisterDeceasedHome getNationalRegisterDeceasedHome() {
GoogleCloudPlatform/runtime-builder-java
java-runtime-builder-app/src/test/java/com/google/cloud/runtimes/builder/config/AppYamlFinderTest.java
// Path: java-runtime-builder-app/src/test/java/com/google/cloud/runtimes/builder/TestUtils.java // public static class TestWorkspaceBuilder { // // private final Path workspaceDir; // // public TestWorkspaceBuilder() throws IOException { // this.workspaceDir = Files.createTempDirectory(null); // } // // public FileBuilder file(String path) { // return new FileBuilder(this, workspaceDir.resolve(path)); // } // // public Path build() { // return workspaceDir; // } // // public class FileBuilder { // private final Path path; // private final TestWorkspaceBuilder workspaceBuilder; // private String contents = ""; // private boolean isExecutable = false; // // private FileBuilder(TestWorkspaceBuilder workspaceBuilder, Path path) { // this.workspaceBuilder = workspaceBuilder; // this.path = path; // } // // public FileBuilder withContents(String contents) { // this.contents = contents; // return this; // } // // public FileBuilder setIsExecutable(boolean isExecutable) { // this.isExecutable = isExecutable; // return this; // } // // public TestWorkspaceBuilder build() throws IOException { // // mkdir -p // Files.createDirectories(path.getParent()); // // try (Writer out = Files.newBufferedWriter(path, Charset.defaultCharset())) { // out.write(contents); // } // // Set<PosixFilePermission> permissions = Sets.newHashSet( // PosixFilePermission.OWNER_READ, // PosixFilePermission.OWNER_WRITE); // if (isExecutable) { // permissions.add(PosixFilePermission.OWNER_EXECUTE); // } // // Files.setPosixFilePermissions(path, permissions); // return workspaceBuilder; // } // } // }
import static junit.framework.TestCase.assertFalse; import static org.junit.Assert.assertEquals; import com.google.cloud.runtimes.builder.TestUtils.TestWorkspaceBuilder; import org.junit.Test; import java.io.IOException; import java.nio.file.Path; import java.util.Optional;
package com.google.cloud.runtimes.builder.config; /** * Unit tests for {@link AppYamlFinder} */ public class AppYamlFinderTest { @Test public void testAppYamlAtRootNoEnvVar() throws IOException { String yamlPath = "app.yaml";
// Path: java-runtime-builder-app/src/test/java/com/google/cloud/runtimes/builder/TestUtils.java // public static class TestWorkspaceBuilder { // // private final Path workspaceDir; // // public TestWorkspaceBuilder() throws IOException { // this.workspaceDir = Files.createTempDirectory(null); // } // // public FileBuilder file(String path) { // return new FileBuilder(this, workspaceDir.resolve(path)); // } // // public Path build() { // return workspaceDir; // } // // public class FileBuilder { // private final Path path; // private final TestWorkspaceBuilder workspaceBuilder; // private String contents = ""; // private boolean isExecutable = false; // // private FileBuilder(TestWorkspaceBuilder workspaceBuilder, Path path) { // this.workspaceBuilder = workspaceBuilder; // this.path = path; // } // // public FileBuilder withContents(String contents) { // this.contents = contents; // return this; // } // // public FileBuilder setIsExecutable(boolean isExecutable) { // this.isExecutable = isExecutable; // return this; // } // // public TestWorkspaceBuilder build() throws IOException { // // mkdir -p // Files.createDirectories(path.getParent()); // // try (Writer out = Files.newBufferedWriter(path, Charset.defaultCharset())) { // out.write(contents); // } // // Set<PosixFilePermission> permissions = Sets.newHashSet( // PosixFilePermission.OWNER_READ, // PosixFilePermission.OWNER_WRITE); // if (isExecutable) { // permissions.add(PosixFilePermission.OWNER_EXECUTE); // } // // Files.setPosixFilePermissions(path, permissions); // return workspaceBuilder; // } // } // } // Path: java-runtime-builder-app/src/test/java/com/google/cloud/runtimes/builder/config/AppYamlFinderTest.java import static junit.framework.TestCase.assertFalse; import static org.junit.Assert.assertEquals; import com.google.cloud.runtimes.builder.TestUtils.TestWorkspaceBuilder; import org.junit.Test; import java.io.IOException; import java.nio.file.Path; import java.util.Optional; package com.google.cloud.runtimes.builder.config; /** * Unit tests for {@link AppYamlFinder} */ public class AppYamlFinderTest { @Test public void testAppYamlAtRootNoEnvVar() throws IOException { String yamlPath = "app.yaml";
Path workspace = new TestWorkspaceBuilder()
GoogleCloudPlatform/runtime-builder-java
java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/AppYamlParser.java
// Path: java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/domain/AppYaml.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class AppYaml { // // private RuntimeConfig runtimeConfig = new RuntimeConfig(); // private BetaSettings betaSettings = new BetaSettings(); // // /** // * Checks environment variables and overwrites any existing settings in this object. // * @param overrideSettings A map of the settings. // */ // public void applyOverrideSettings(Map<String, Object> overrideSettings) throws IOException { // runtimeConfig.applyOverrideSettings(overrideSettings); // betaSettings.applyOverrideSettings(overrideSettings); // } // // @JsonProperty("runtime_config") // public RuntimeConfig getRuntimeConfig() { // return runtimeConfig; // } // // public void setRuntimeConfig(RuntimeConfig runtimeConfig) { // this.runtimeConfig = runtimeConfig; // } // // @JsonProperty("beta_settings") // public BetaSettings getBetaSettings() { // return betaSettings; // } // // public void setBetaSettings(BetaSettings betaSettings) { // this.betaSettings = betaSettings; // } // } // // Path: java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/domain/BetaSettings.java // @JsonIgnoreProperties(ignoreUnknown = true) // public final class BetaSettings extends OverrideableSetting { // // private static final String ENABLE_APP_ENGINE_APIS_SETTING_NAME = "enable_app_engine_apis"; // // @OverrideSetting(ENABLE_APP_ENGINE_APIS_SETTING_NAME) // private boolean enableAppEngineApis = false; // // public boolean isEnableAppEngineApis() { // return enableAppEngineApis; // } // // @JsonProperty(ENABLE_APP_ENGINE_APIS_SETTING_NAME) // public void setEnableAppEngineApis(boolean enableAppEngineApis) { // this.enableAppEngineApis = enableAppEngineApis; // } // } // // Path: java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/domain/RuntimeConfig.java // @JsonIgnoreProperties(ignoreUnknown = true) // public final class RuntimeConfig extends OverrideableSetting { // // private static final String BUILD_SCRIPT_SETTING_NAME = "build_script"; // private static final String JETTY_QUICKSTART_SETTING_NAME = "jetty_quickstart"; // // @OverrideSetting // private String jdk; // // @OverrideSetting // private String server; // // @OverrideSetting(BUILD_SCRIPT_SETTING_NAME) // private String buildScript; // // @OverrideSetting // private String artifact; // // @OverrideSetting(JETTY_QUICKSTART_SETTING_NAME) // private boolean jettyQuickstart; // // public String getJdk() { // return jdk; // } // // public void setJdk(String jdk) { // this.jdk = jdk; // } // // public String getArtifact() { // return artifact; // } // // public void setArtifact(String artifact) { // this.artifact = artifact; // } // // public String getServer() { // return server; // } // // public void setServer(String server) { // this.server = server; // } // // public String getBuildScript() { // return buildScript; // } // // @JsonProperty(BUILD_SCRIPT_SETTING_NAME) // public void setBuildScript(String buildScript) { // this.buildScript = buildScript; // } // // public boolean getJettyQuickstart() { // return jettyQuickstart; // } // // @JsonProperty(JETTY_QUICKSTART_SETTING_NAME) // public void setJettyQuickstart(boolean jettyQuickstart) { // this.jettyQuickstart = jettyQuickstart; // } // }
import com.google.cloud.runtimes.builder.config.domain.AppYaml; import com.google.cloud.runtimes.builder.config.domain.BetaSettings; import com.google.cloud.runtimes.builder.config.domain.RuntimeConfig; import com.google.inject.Inject; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import java.io.IOException; import java.nio.file.Path;
/* * Copyright 2017 Google Inc. All Rights Reserved. * * 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 com.google.cloud.runtimes.builder.config; /** * YamlParser implementation that handles parsing of files in the {@link AppYaml} format. */ public class AppYamlParser implements YamlParser<AppYaml> { private final ObjectMapper objectMapper; /** * Constructs a new {@link AppYamlParser}. */ @Inject public AppYamlParser() { this.objectMapper = new ObjectMapper(new YAMLFactory()); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); } @Override public AppYaml parse(Path yamlFilePath) throws IOException { AppYaml appYaml = objectMapper.readValue(yamlFilePath.toFile(), AppYaml.class); if (appYaml.getBetaSettings() == null) {
// Path: java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/domain/AppYaml.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class AppYaml { // // private RuntimeConfig runtimeConfig = new RuntimeConfig(); // private BetaSettings betaSettings = new BetaSettings(); // // /** // * Checks environment variables and overwrites any existing settings in this object. // * @param overrideSettings A map of the settings. // */ // public void applyOverrideSettings(Map<String, Object> overrideSettings) throws IOException { // runtimeConfig.applyOverrideSettings(overrideSettings); // betaSettings.applyOverrideSettings(overrideSettings); // } // // @JsonProperty("runtime_config") // public RuntimeConfig getRuntimeConfig() { // return runtimeConfig; // } // // public void setRuntimeConfig(RuntimeConfig runtimeConfig) { // this.runtimeConfig = runtimeConfig; // } // // @JsonProperty("beta_settings") // public BetaSettings getBetaSettings() { // return betaSettings; // } // // public void setBetaSettings(BetaSettings betaSettings) { // this.betaSettings = betaSettings; // } // } // // Path: java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/domain/BetaSettings.java // @JsonIgnoreProperties(ignoreUnknown = true) // public final class BetaSettings extends OverrideableSetting { // // private static final String ENABLE_APP_ENGINE_APIS_SETTING_NAME = "enable_app_engine_apis"; // // @OverrideSetting(ENABLE_APP_ENGINE_APIS_SETTING_NAME) // private boolean enableAppEngineApis = false; // // public boolean isEnableAppEngineApis() { // return enableAppEngineApis; // } // // @JsonProperty(ENABLE_APP_ENGINE_APIS_SETTING_NAME) // public void setEnableAppEngineApis(boolean enableAppEngineApis) { // this.enableAppEngineApis = enableAppEngineApis; // } // } // // Path: java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/domain/RuntimeConfig.java // @JsonIgnoreProperties(ignoreUnknown = true) // public final class RuntimeConfig extends OverrideableSetting { // // private static final String BUILD_SCRIPT_SETTING_NAME = "build_script"; // private static final String JETTY_QUICKSTART_SETTING_NAME = "jetty_quickstart"; // // @OverrideSetting // private String jdk; // // @OverrideSetting // private String server; // // @OverrideSetting(BUILD_SCRIPT_SETTING_NAME) // private String buildScript; // // @OverrideSetting // private String artifact; // // @OverrideSetting(JETTY_QUICKSTART_SETTING_NAME) // private boolean jettyQuickstart; // // public String getJdk() { // return jdk; // } // // public void setJdk(String jdk) { // this.jdk = jdk; // } // // public String getArtifact() { // return artifact; // } // // public void setArtifact(String artifact) { // this.artifact = artifact; // } // // public String getServer() { // return server; // } // // public void setServer(String server) { // this.server = server; // } // // public String getBuildScript() { // return buildScript; // } // // @JsonProperty(BUILD_SCRIPT_SETTING_NAME) // public void setBuildScript(String buildScript) { // this.buildScript = buildScript; // } // // public boolean getJettyQuickstart() { // return jettyQuickstart; // } // // @JsonProperty(JETTY_QUICKSTART_SETTING_NAME) // public void setJettyQuickstart(boolean jettyQuickstart) { // this.jettyQuickstart = jettyQuickstart; // } // } // Path: java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/AppYamlParser.java import com.google.cloud.runtimes.builder.config.domain.AppYaml; import com.google.cloud.runtimes.builder.config.domain.BetaSettings; import com.google.cloud.runtimes.builder.config.domain.RuntimeConfig; import com.google.inject.Inject; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import java.io.IOException; import java.nio.file.Path; /* * Copyright 2017 Google Inc. All Rights Reserved. * * 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 com.google.cloud.runtimes.builder.config; /** * YamlParser implementation that handles parsing of files in the {@link AppYaml} format. */ public class AppYamlParser implements YamlParser<AppYaml> { private final ObjectMapper objectMapper; /** * Constructs a new {@link AppYamlParser}. */ @Inject public AppYamlParser() { this.objectMapper = new ObjectMapper(new YAMLFactory()); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); } @Override public AppYaml parse(Path yamlFilePath) throws IOException { AppYaml appYaml = objectMapper.readValue(yamlFilePath.toFile(), AppYaml.class); if (appYaml.getBetaSettings() == null) {
appYaml.setBetaSettings(new BetaSettings());
GoogleCloudPlatform/runtime-builder-java
java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/AppYamlParser.java
// Path: java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/domain/AppYaml.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class AppYaml { // // private RuntimeConfig runtimeConfig = new RuntimeConfig(); // private BetaSettings betaSettings = new BetaSettings(); // // /** // * Checks environment variables and overwrites any existing settings in this object. // * @param overrideSettings A map of the settings. // */ // public void applyOverrideSettings(Map<String, Object> overrideSettings) throws IOException { // runtimeConfig.applyOverrideSettings(overrideSettings); // betaSettings.applyOverrideSettings(overrideSettings); // } // // @JsonProperty("runtime_config") // public RuntimeConfig getRuntimeConfig() { // return runtimeConfig; // } // // public void setRuntimeConfig(RuntimeConfig runtimeConfig) { // this.runtimeConfig = runtimeConfig; // } // // @JsonProperty("beta_settings") // public BetaSettings getBetaSettings() { // return betaSettings; // } // // public void setBetaSettings(BetaSettings betaSettings) { // this.betaSettings = betaSettings; // } // } // // Path: java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/domain/BetaSettings.java // @JsonIgnoreProperties(ignoreUnknown = true) // public final class BetaSettings extends OverrideableSetting { // // private static final String ENABLE_APP_ENGINE_APIS_SETTING_NAME = "enable_app_engine_apis"; // // @OverrideSetting(ENABLE_APP_ENGINE_APIS_SETTING_NAME) // private boolean enableAppEngineApis = false; // // public boolean isEnableAppEngineApis() { // return enableAppEngineApis; // } // // @JsonProperty(ENABLE_APP_ENGINE_APIS_SETTING_NAME) // public void setEnableAppEngineApis(boolean enableAppEngineApis) { // this.enableAppEngineApis = enableAppEngineApis; // } // } // // Path: java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/domain/RuntimeConfig.java // @JsonIgnoreProperties(ignoreUnknown = true) // public final class RuntimeConfig extends OverrideableSetting { // // private static final String BUILD_SCRIPT_SETTING_NAME = "build_script"; // private static final String JETTY_QUICKSTART_SETTING_NAME = "jetty_quickstart"; // // @OverrideSetting // private String jdk; // // @OverrideSetting // private String server; // // @OverrideSetting(BUILD_SCRIPT_SETTING_NAME) // private String buildScript; // // @OverrideSetting // private String artifact; // // @OverrideSetting(JETTY_QUICKSTART_SETTING_NAME) // private boolean jettyQuickstart; // // public String getJdk() { // return jdk; // } // // public void setJdk(String jdk) { // this.jdk = jdk; // } // // public String getArtifact() { // return artifact; // } // // public void setArtifact(String artifact) { // this.artifact = artifact; // } // // public String getServer() { // return server; // } // // public void setServer(String server) { // this.server = server; // } // // public String getBuildScript() { // return buildScript; // } // // @JsonProperty(BUILD_SCRIPT_SETTING_NAME) // public void setBuildScript(String buildScript) { // this.buildScript = buildScript; // } // // public boolean getJettyQuickstart() { // return jettyQuickstart; // } // // @JsonProperty(JETTY_QUICKSTART_SETTING_NAME) // public void setJettyQuickstart(boolean jettyQuickstart) { // this.jettyQuickstart = jettyQuickstart; // } // }
import com.google.cloud.runtimes.builder.config.domain.AppYaml; import com.google.cloud.runtimes.builder.config.domain.BetaSettings; import com.google.cloud.runtimes.builder.config.domain.RuntimeConfig; import com.google.inject.Inject; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import java.io.IOException; import java.nio.file.Path;
/* * Copyright 2017 Google Inc. All Rights Reserved. * * 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 com.google.cloud.runtimes.builder.config; /** * YamlParser implementation that handles parsing of files in the {@link AppYaml} format. */ public class AppYamlParser implements YamlParser<AppYaml> { private final ObjectMapper objectMapper; /** * Constructs a new {@link AppYamlParser}. */ @Inject public AppYamlParser() { this.objectMapper = new ObjectMapper(new YAMLFactory()); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); } @Override public AppYaml parse(Path yamlFilePath) throws IOException { AppYaml appYaml = objectMapper.readValue(yamlFilePath.toFile(), AppYaml.class); if (appYaml.getBetaSettings() == null) { appYaml.setBetaSettings(new BetaSettings()); } if (appYaml.getRuntimeConfig() == null) {
// Path: java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/domain/AppYaml.java // @JsonIgnoreProperties(ignoreUnknown = true) // public class AppYaml { // // private RuntimeConfig runtimeConfig = new RuntimeConfig(); // private BetaSettings betaSettings = new BetaSettings(); // // /** // * Checks environment variables and overwrites any existing settings in this object. // * @param overrideSettings A map of the settings. // */ // public void applyOverrideSettings(Map<String, Object> overrideSettings) throws IOException { // runtimeConfig.applyOverrideSettings(overrideSettings); // betaSettings.applyOverrideSettings(overrideSettings); // } // // @JsonProperty("runtime_config") // public RuntimeConfig getRuntimeConfig() { // return runtimeConfig; // } // // public void setRuntimeConfig(RuntimeConfig runtimeConfig) { // this.runtimeConfig = runtimeConfig; // } // // @JsonProperty("beta_settings") // public BetaSettings getBetaSettings() { // return betaSettings; // } // // public void setBetaSettings(BetaSettings betaSettings) { // this.betaSettings = betaSettings; // } // } // // Path: java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/domain/BetaSettings.java // @JsonIgnoreProperties(ignoreUnknown = true) // public final class BetaSettings extends OverrideableSetting { // // private static final String ENABLE_APP_ENGINE_APIS_SETTING_NAME = "enable_app_engine_apis"; // // @OverrideSetting(ENABLE_APP_ENGINE_APIS_SETTING_NAME) // private boolean enableAppEngineApis = false; // // public boolean isEnableAppEngineApis() { // return enableAppEngineApis; // } // // @JsonProperty(ENABLE_APP_ENGINE_APIS_SETTING_NAME) // public void setEnableAppEngineApis(boolean enableAppEngineApis) { // this.enableAppEngineApis = enableAppEngineApis; // } // } // // Path: java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/domain/RuntimeConfig.java // @JsonIgnoreProperties(ignoreUnknown = true) // public final class RuntimeConfig extends OverrideableSetting { // // private static final String BUILD_SCRIPT_SETTING_NAME = "build_script"; // private static final String JETTY_QUICKSTART_SETTING_NAME = "jetty_quickstart"; // // @OverrideSetting // private String jdk; // // @OverrideSetting // private String server; // // @OverrideSetting(BUILD_SCRIPT_SETTING_NAME) // private String buildScript; // // @OverrideSetting // private String artifact; // // @OverrideSetting(JETTY_QUICKSTART_SETTING_NAME) // private boolean jettyQuickstart; // // public String getJdk() { // return jdk; // } // // public void setJdk(String jdk) { // this.jdk = jdk; // } // // public String getArtifact() { // return artifact; // } // // public void setArtifact(String artifact) { // this.artifact = artifact; // } // // public String getServer() { // return server; // } // // public void setServer(String server) { // this.server = server; // } // // public String getBuildScript() { // return buildScript; // } // // @JsonProperty(BUILD_SCRIPT_SETTING_NAME) // public void setBuildScript(String buildScript) { // this.buildScript = buildScript; // } // // public boolean getJettyQuickstart() { // return jettyQuickstart; // } // // @JsonProperty(JETTY_QUICKSTART_SETTING_NAME) // public void setJettyQuickstart(boolean jettyQuickstart) { // this.jettyQuickstart = jettyQuickstart; // } // } // Path: java-runtime-builder-app/src/main/java/com/google/cloud/runtimes/builder/config/AppYamlParser.java import com.google.cloud.runtimes.builder.config.domain.AppYaml; import com.google.cloud.runtimes.builder.config.domain.BetaSettings; import com.google.cloud.runtimes.builder.config.domain.RuntimeConfig; import com.google.inject.Inject; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import java.io.IOException; import java.nio.file.Path; /* * Copyright 2017 Google Inc. All Rights Reserved. * * 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 com.google.cloud.runtimes.builder.config; /** * YamlParser implementation that handles parsing of files in the {@link AppYaml} format. */ public class AppYamlParser implements YamlParser<AppYaml> { private final ObjectMapper objectMapper; /** * Constructs a new {@link AppYamlParser}. */ @Inject public AppYamlParser() { this.objectMapper = new ObjectMapper(new YAMLFactory()); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); } @Override public AppYaml parse(Path yamlFilePath) throws IOException { AppYaml appYaml = objectMapper.readValue(yamlFilePath.toFile(), AppYaml.class); if (appYaml.getBetaSettings() == null) { appYaml.setBetaSettings(new BetaSettings()); } if (appYaml.getRuntimeConfig() == null) {
appYaml.setRuntimeConfig(new RuntimeConfig());
GoogleCloudPlatform/runtime-builder-java
java-runtime-builder-app/src/test/java/com/google/cloud/runtimes/builder/config/domain/ArtifactTest.java
// Path: java-runtime-builder-app/src/test/java/com/google/cloud/runtimes/builder/TestUtils.java // public static class TestWorkspaceBuilder { // // private final Path workspaceDir; // // public TestWorkspaceBuilder() throws IOException { // this.workspaceDir = Files.createTempDirectory(null); // } // // public FileBuilder file(String path) { // return new FileBuilder(this, workspaceDir.resolve(path)); // } // // public Path build() { // return workspaceDir; // } // // public class FileBuilder { // private final Path path; // private final TestWorkspaceBuilder workspaceBuilder; // private String contents = ""; // private boolean isExecutable = false; // // private FileBuilder(TestWorkspaceBuilder workspaceBuilder, Path path) { // this.workspaceBuilder = workspaceBuilder; // this.path = path; // } // // public FileBuilder withContents(String contents) { // this.contents = contents; // return this; // } // // public FileBuilder setIsExecutable(boolean isExecutable) { // this.isExecutable = isExecutable; // return this; // } // // public TestWorkspaceBuilder build() throws IOException { // // mkdir -p // Files.createDirectories(path.getParent()); // // try (Writer out = Files.newBufferedWriter(path, Charset.defaultCharset())) { // out.write(contents); // } // // Set<PosixFilePermission> permissions = Sets.newHashSet( // PosixFilePermission.OWNER_READ, // PosixFilePermission.OWNER_WRITE); // if (isExecutable) { // permissions.add(PosixFilePermission.OWNER_EXECUTE); // } // // Files.setPosixFilePermissions(path, permissions); // return workspaceBuilder; // } // } // }
import static com.google.cloud.runtimes.builder.config.domain.Artifact.ArtifactType.COMPAT_EXPLODED_WAR; import static com.google.cloud.runtimes.builder.config.domain.Artifact.ArtifactType.EXPLODED_WAR; import static com.google.cloud.runtimes.builder.config.domain.Artifact.ArtifactType.JAR; import static com.google.cloud.runtimes.builder.config.domain.Artifact.ArtifactType.WAR; import static junit.framework.TestCase.assertFalse; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import com.google.cloud.runtimes.builder.TestUtils.TestWorkspaceBuilder; import com.google.common.collect.ImmutableList; import org.junit.Test; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List;
package com.google.cloud.runtimes.builder.config.domain; public class ArtifactTest { private List<Path> invalidArtifacts = ImmutableList.of( Paths.get("foo.txt"), Paths.get("foo.java"), Paths.get("some_dir/"), Paths.get("WEB-INF/appengine-web.xml"), Paths.get("WEB-INF/web.xml") ); @Test public void testNonExistentWar() { Path path = Paths.get("/foo/bar.war"); assertTrue(Artifact.isAnArtifact(path)); Artifact result = Artifact.fromPath(path); assertEquals(path, result.getPath()); assertEquals(WAR, result.getType()); } @Test public void testExistingWar() throws IOException {
// Path: java-runtime-builder-app/src/test/java/com/google/cloud/runtimes/builder/TestUtils.java // public static class TestWorkspaceBuilder { // // private final Path workspaceDir; // // public TestWorkspaceBuilder() throws IOException { // this.workspaceDir = Files.createTempDirectory(null); // } // // public FileBuilder file(String path) { // return new FileBuilder(this, workspaceDir.resolve(path)); // } // // public Path build() { // return workspaceDir; // } // // public class FileBuilder { // private final Path path; // private final TestWorkspaceBuilder workspaceBuilder; // private String contents = ""; // private boolean isExecutable = false; // // private FileBuilder(TestWorkspaceBuilder workspaceBuilder, Path path) { // this.workspaceBuilder = workspaceBuilder; // this.path = path; // } // // public FileBuilder withContents(String contents) { // this.contents = contents; // return this; // } // // public FileBuilder setIsExecutable(boolean isExecutable) { // this.isExecutable = isExecutable; // return this; // } // // public TestWorkspaceBuilder build() throws IOException { // // mkdir -p // Files.createDirectories(path.getParent()); // // try (Writer out = Files.newBufferedWriter(path, Charset.defaultCharset())) { // out.write(contents); // } // // Set<PosixFilePermission> permissions = Sets.newHashSet( // PosixFilePermission.OWNER_READ, // PosixFilePermission.OWNER_WRITE); // if (isExecutable) { // permissions.add(PosixFilePermission.OWNER_EXECUTE); // } // // Files.setPosixFilePermissions(path, permissions); // return workspaceBuilder; // } // } // } // Path: java-runtime-builder-app/src/test/java/com/google/cloud/runtimes/builder/config/domain/ArtifactTest.java import static com.google.cloud.runtimes.builder.config.domain.Artifact.ArtifactType.COMPAT_EXPLODED_WAR; import static com.google.cloud.runtimes.builder.config.domain.Artifact.ArtifactType.EXPLODED_WAR; import static com.google.cloud.runtimes.builder.config.domain.Artifact.ArtifactType.JAR; import static com.google.cloud.runtimes.builder.config.domain.Artifact.ArtifactType.WAR; import static junit.framework.TestCase.assertFalse; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import com.google.cloud.runtimes.builder.TestUtils.TestWorkspaceBuilder; import com.google.common.collect.ImmutableList; import org.junit.Test; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; package com.google.cloud.runtimes.builder.config.domain; public class ArtifactTest { private List<Path> invalidArtifacts = ImmutableList.of( Paths.get("foo.txt"), Paths.get("foo.java"), Paths.get("some_dir/"), Paths.get("WEB-INF/appengine-web.xml"), Paths.get("WEB-INF/web.xml") ); @Test public void testNonExistentWar() { Path path = Paths.get("/foo/bar.war"); assertTrue(Artifact.isAnArtifact(path)); Artifact result = Artifact.fromPath(path); assertEquals(path, result.getPath()); assertEquals(WAR, result.getType()); } @Test public void testExistingWar() throws IOException {
Path workspace = new TestWorkspaceBuilder()
GoogleCloudPlatform/runtime-builder-java
java-runtime-builder-app/src/test/java/com/google/cloud/runtimes/builder/config/domain/BuildContextTest.java
// Path: java-runtime-builder-app/src/test/java/com/google/cloud/runtimes/builder/TestUtils.java // public static class TestWorkspaceBuilder { // // private final Path workspaceDir; // // public TestWorkspaceBuilder() throws IOException { // this.workspaceDir = Files.createTempDirectory(null); // } // // public FileBuilder file(String path) { // return new FileBuilder(this, workspaceDir.resolve(path)); // } // // public Path build() { // return workspaceDir; // } // // public class FileBuilder { // private final Path path; // private final TestWorkspaceBuilder workspaceBuilder; // private String contents = ""; // private boolean isExecutable = false; // // private FileBuilder(TestWorkspaceBuilder workspaceBuilder, Path path) { // this.workspaceBuilder = workspaceBuilder; // this.path = path; // } // // public FileBuilder withContents(String contents) { // this.contents = contents; // return this; // } // // public FileBuilder setIsExecutable(boolean isExecutable) { // this.isExecutable = isExecutable; // return this; // } // // public TestWorkspaceBuilder build() throws IOException { // // mkdir -p // Files.createDirectories(path.getParent()); // // try (Writer out = Files.newBufferedWriter(path, Charset.defaultCharset())) { // out.write(contents); // } // // Set<PosixFilePermission> permissions = Sets.newHashSet( // PosixFilePermission.OWNER_READ, // PosixFilePermission.OWNER_WRITE); // if (isExecutable) { // permissions.add(PosixFilePermission.OWNER_EXECUTE); // } // // Files.setPosixFilePermissions(path, permissions); // return workspaceBuilder; // } // } // }
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import com.google.cloud.runtimes.builder.TestUtils.TestWorkspaceBuilder; import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import org.junit.Before; import org.junit.Test;
package com.google.cloud.runtimes.builder.config.domain; /** * Unit tests for {@link BuildContext}. */ public class BuildContextTest { private Path workspace; private RuntimeConfig runtimeConfig; private BetaSettings betaSettings; private boolean disableSourceBuild; private static final String DOCKER_IGNORE_PREAMBLE = "Dockerfile\n" + ".dockerignore\n"; @Before public void before() throws IOException { // initialize to empty dir
// Path: java-runtime-builder-app/src/test/java/com/google/cloud/runtimes/builder/TestUtils.java // public static class TestWorkspaceBuilder { // // private final Path workspaceDir; // // public TestWorkspaceBuilder() throws IOException { // this.workspaceDir = Files.createTempDirectory(null); // } // // public FileBuilder file(String path) { // return new FileBuilder(this, workspaceDir.resolve(path)); // } // // public Path build() { // return workspaceDir; // } // // public class FileBuilder { // private final Path path; // private final TestWorkspaceBuilder workspaceBuilder; // private String contents = ""; // private boolean isExecutable = false; // // private FileBuilder(TestWorkspaceBuilder workspaceBuilder, Path path) { // this.workspaceBuilder = workspaceBuilder; // this.path = path; // } // // public FileBuilder withContents(String contents) { // this.contents = contents; // return this; // } // // public FileBuilder setIsExecutable(boolean isExecutable) { // this.isExecutable = isExecutable; // return this; // } // // public TestWorkspaceBuilder build() throws IOException { // // mkdir -p // Files.createDirectories(path.getParent()); // // try (Writer out = Files.newBufferedWriter(path, Charset.defaultCharset())) { // out.write(contents); // } // // Set<PosixFilePermission> permissions = Sets.newHashSet( // PosixFilePermission.OWNER_READ, // PosixFilePermission.OWNER_WRITE); // if (isExecutable) { // permissions.add(PosixFilePermission.OWNER_EXECUTE); // } // // Files.setPosixFilePermissions(path, permissions); // return workspaceBuilder; // } // } // } // Path: java-runtime-builder-app/src/test/java/com/google/cloud/runtimes/builder/config/domain/BuildContextTest.java import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import com.google.cloud.runtimes.builder.TestUtils.TestWorkspaceBuilder; import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import org.junit.Before; import org.junit.Test; package com.google.cloud.runtimes.builder.config.domain; /** * Unit tests for {@link BuildContext}. */ public class BuildContextTest { private Path workspace; private RuntimeConfig runtimeConfig; private BetaSettings betaSettings; private boolean disableSourceBuild; private static final String DOCKER_IGNORE_PREAMBLE = "Dockerfile\n" + ".dockerignore\n"; @Before public void before() throws IOException { // initialize to empty dir
workspace = new TestWorkspaceBuilder().build();