Last active
August 29, 2015 14:15
-
-
Save uklance/1dba84e5ee358beee3e9 to your computer and use it in GitHub Desktop.
sproc-unit thoughts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Events({Event.SCENARIO_THEN, Event.SCENARIO_AFTER}) | |
public class AssertCommand { | |
@Parameter(requiredGroup="value") | |
private String sql; | |
@Parameter(name="attribute", requiredGroup="value") | |
private String attributeName; | |
@Parameter(name="expected", required=true) | |
private String expectedString; | |
@Inject | |
private CommandContext commandContext; | |
@Inject | |
private ConnectionFactory connectionFactory; | |
@Command | |
public void doAssert() { | |
if (sql != null) { | |
... | |
} else if (attributeName != null) { | |
Object attribute = commandContext.getAttribute(attributeName); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface CommandBuilder<T extends Command> { | |
CommandBuilder<T> withField(String name, Object value); | |
T build(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface CommandBuilderSource { | |
<T extends Command> CommandBuilder<T> get(Class<T> type); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CommandJunitClassRunner extends ParentRunner<ScenarioGroup> { | |
public CommandJunitClassRunner(Class... moduleClasses) { | |
... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Events({Event.SCENARIO_GROUP_BEFORE, Event.SCENARIO_GIVEN, Event.SCENARIO_WHEN}) | |
public class InsertCommand { | |
@Parameter(required=true) | |
private String table; | |
// <insert randomize="firstName,birthDate" ... /> | |
@Parameter(defaultPrefix="csv") | |
private List<String> randomize; | |
// nested <insert><row /><insert> | |
@Parameter | |
private List<Row> rows; | |
@Inject | |
private ConnectionFactory connectionFactory; | |
@Command | |
public void doInsert() { | |
for (Row row : rows) { | |
... | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JdbcCommandJunitClassRunner extends CommandJunitClassRunner<ScenarioGroup> { | |
public JdbcCommandJunitClassRunner() { | |
super(JdbcCommandModule.class) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Row { | |
@WildParameters(pattern="*") | |
private Map<String, String> rows; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<scenarios> | |
<import path="some/other/scenarios.xml" /> | |
<before> | |
<!-- h2 sproc definitions --> | |
<execute>CREATE ALIAS DO_ADD FOR "foo.bar.TestUtils.doAdd";</execute> | |
<execute>CREATE ALIAS DO_MULTIPLY FOR "foo.bar.TestUtils.doMultiply";</execute> | |
<execute>CREATE ALIAS DO_CONCAT FOR "foo.bar.TestUtils.doConcat";</execute> | |
</before> | |
<after> | |
<execute>DROP ALIAS DO_ADD;</execute> | |
<execute>DROP ALIAS DO_MULTIPLY;</execute> | |
<execute>DROP ALIAS DO_CONCAT;</execute> | |
</after> | |
<scenario name="Testing DO_ADD"> | |
<when> | |
<attribute name="a1" sql="CALL DO_ADD(1, 2)" /> | |
<attribute name="a2" sql="CALL DO_ADD(2, 4)" /> | |
</when> | |
<then> | |
<assertEquals expected="3" sql="select ${a1}" /> | |
<assertEquals expected="6" sql="select ${a2}" /> | |
</then> | |
</scenario> | |
<scenario name="Testing DO_MULTIPLY"> | |
<when> | |
<attribute name="a1" sql="CALL DO_MULTIPLY(2, 4)" /> | |
<attribute name="a2" sql="CALL DO_MULTIPLY(3, 6)" /> | |
</when> | |
<then> | |
<assertEquals expected="8" sql="select ${a1}" /> | |
<assertEquals expected="18" sql="select ${a2}" /> | |
<assertEquals expected="20" sql="CALL DO_MULTIPLY(4, 5)" /> | |
<assertEquals expected="8" attribute="a1" /> | |
</then> | |
</scenario> | |
<scenario name="Testing DO_CONCAT"> | |
<when> | |
<attribute name="a1" sql="CALL DO_CONCAT('a', 'b')" /> | |
</when> | |
<then> | |
<assertEquals expected="ab" sql="select '${a1}'" /> | |
</then> | |
</scenario> | |
<scenario name="Wish List"> | |
<given> | |
<attribute name="empId1" sql="select EMPLOYEE_SEQ.nextval from dual;" /> | |
<attribute name="empId2" sql="select EMPLOYEE_SEQ.nextval from dual;" /> | |
<insert table="employees" randomize="birthDate,startDate"> | |
<row employeeId="${empId1}" firstName="Barney" surname="Rubble" /> | |
<row employeeId="${empId2}" firstName="Fred" surname="Flinstone" /> | |
</insert> | |
</given> | |
<when> | |
<resultSet name="employees" sql="select * from employees where employeeId = ${empId1}" /> | |
</when> | |
<then> | |
<assertEquals expected="1" attribute="employees.size()" /> | |
<assertEquals expected="Rubble" attribute="employees[0].surname" /> | |
</then> | |
<after> | |
<execute>delete from employees where employeeId in (${empId1}, ${empId2})</execute> | |
</after> | |
</scenario> | |
</scenarios> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SprocUnitModule { | |
public void contributeInjectionProviderSource(MappedConfiguration<String, InjectionProvider> config) { | |
config.addInstance("connectionFactory", ConnectionFactoryInjectionProvider.class); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment