Giter VIP home page Giter VIP logo

stu's Introduction

stu - Simple Test Utils

Build Status

The project contains simple test utils for JUnit and DBUnit. See documentation for more Details.

Use STU in your project

Use STU in a maven project

Repository needed in your project's pom.xml :

<repository>
  <id>sb-utils-bintray</id>
  <name>Seitenbau utils bintrayrepository</name>
  <url>http://dl.bintray.com/seitenbau/utils</url>
</repository>

Dependencies needed in your project's pom.xml :

<dependency>
  <groupId>com.seitenbau.stu</groupId>
  <artifactId>stu-common</artifactId>
  <version>0.2.0-RC4</version>
</dependency>
<dependency>
  <groupId>com.seitenbau.stu</groupId>
  <artifactId>stu-database</artifactId>
  <version>0.2.0-RC4</version>
</dependency>

Use STU in a gradle project

apply plugin: 'java'

repositories {
  mavenCentral()
  maven { url "http://dl.bintray.com/seitenbau/utils" }
}

dependencies {
  compile("com.seitenbau.stu:stu-common:0.2.0-RC4")
  compile("com.seitenbau.stu:stu-database:0.2.0-RC4")
}

Build STU

Either use provided gradlew or you need gradle (<2.0) 1.8 installed. STU currently only compiles with a JDK 1.7.

gradlew build

Build Documentation

To generate the documentation please invoke:

gradlew asciidoctor

The documentation is generated to stu/documentation/html/stu.html.

Eclipse

To import the project into eclipse invoke:

gradlew eclipse

Then the project can be imported as eclipse projects. Please be sure to use the code-conventions-sb-testing.xml file from src/eclipse folder.

IntelliJ

To import the project into IntelliJ IDEA invoke:

gradlew idea

Then the project can be open in IntelliJ.When you use IntelliJ version > 12, IntelliJ has build in gradle support then the project can direct be opened. When the workspace is ready the gradle task generateDataSetDsl should be invoked.

Documentation

The documentation can be found here. The asciidoc files are stored in the subproject stu-documentation.

stu's People

Contributors

chbaranowski avatar kaulbersch avatar kistenjunge avatar rainerw avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stu's Issues

Suggestion: Solution for getWhere/findWhere

Suggestion:

findWhere does not throw an exception if the list is empty. Instead, each public method from the row collection type (getters / setters) except the getRowCount method will throw the exception.

Further, a package private method like getSingleRow() might return an Optional and "replace" the getWhere-API. This method would throw an exception if more than one row is returned, return an absent value if no row is found.

Advantages:

  • Almost same behaviour like SB Testing DB
  • Combined the APIs getWhere/findWhere

The getSingleRow() method could be public as well if required...

DSL Table Model

The common classes should be part of the database project.

  • TableRowModel
  • ColumnBinding

Find a new name for "jetzt"

"jetzt" is used for a pseudo now time. It is a fixed value and depends on the instantiation time.

The new name should show the side-effect, that it does not change within a test.

Suggestions:

  • instantiationTime
  • steadyNow
  • uniformNow
  • constantNow
  • invariantNow

DataSet Composition Feature

DSL use:

   class ExtendedDemoGroovyDataSet extends PersonDatabaseBuilder
   {
      def extendsDataSet() { DemoGroovyDataSet } 

Internal Implementation:

 public void tables(Closure<?> table)
 {
    tables(this, table);
 }

 public void tables(PersonDatabaseBuilder delegate, Closure<?> table){
   DataSetIdentificator lastDataSet = DataSetRegistry.use(delegate);
   table.setDelegate(delegate);
   table.setResolveStrategy(Closure.DELEGATE_FIRST);
   table.call();
   DataSetRegistry.use(lastDataSet);
}

Database Testing Example improvements

Use Spring Data

The example for the TeamRepo, PersonRepo and JobRepo should use Spring Data instead of plain Spring JDBC.

Remove the Interface for the Person Service

Only use interfaces when there are more than one implementation.

Unique identifiers for generated foreign ref relation

Until now the method name of a foreign relation inside a generated reference class was created based on the foreign relation identifier only.
${foreignCol.relation.foreignName}
That could result in identical methodnames with identical signature, if multiple references of same type exist.

To avoid that problem the method (relation) name is now generated as tuple of foreign relation identifier and foreign relation identifier local name.
${foreignCol.relation.foreignName}_${foreignCol.relation.localName}

The fix works, but the "quality" of the created DSL is decreased.
QA.hasMembers(Mr.Tester) must now be referenced as QA.hasMembers_belongsTo(Mr.Tester).

The problem must be analysed and a better solution should be found.

findWhere and getWhere API

findWhere

Returns a list, should return an empty list when no element is found.

getWhere

Returns a Optional object guava google API will be used

Rename Table Classes in Package dsl

Actually, the table classes in the dsl package do not represent a table. They are a kind of table builder instead. The class name should express that..

Model DB Generator Flags

The builder API to describe the database model, should have a better way to define the meta information e.g. ID handling:

Is:

     addColumn("id", DataType.BIGINT, Flags.AutoInvokeNextIdMethod, Flags.IdentifierColumn)

Should:

     TableBuilder professorTable = 
        table("professor")
              .column("id", DataType.BIGINT)
                 .identifierColumn()
                 .autoIdHandling()
              .column("title", DataType.VARCHAR)
            .end();

Generator Package DSL and Model

The generator should generate the model and a DSL API.
And the DSL API depends on the model classes.

Comment can the DSL API code be plain Java source?

Default Reference Name and Attributes

IS:

    .column("professor_id", DataType.BIGINT)
      .references(professoren)
        .local("geleitetVon")
        .remote("leitet")
          .min(1)
          .max(1

SHOULD:

    .column("professor_id", DataType.BIGINT)
      .references(professoren)

The name of the reference is in this case the name and some postfix(suffix) like "To" or "From".

Add Clear() Method for each Table

Add a clear() method for each table in the DSL to remove all row data from the table. The clear method only removes the rows no magic is done.

Type-safe DataSet Identifier Interface

Remove general "Object" return type in IScope, rename class as well. DslIdentifier could be part of type information T

Is:

     public interface IScope
     {

       Object getDataSet();

       String getDslIdentifier();

     }

Should (or similar):

     public interface IScope<T>
     {

       T getDataSet();

     }

Problem:
Both the new Table Builder and the "classic" DataSet must represent the same Scope type (DSL identifer / T).
The class (DSL identifier) of the DataSet is used to distinguish different DSL types. But as the base DataSet class is abstract, the dataset's getClass() method will not return the type of the abstract DataSet class.

Add table class AssociationTable

There should be a special table class to represent associative tables. In the Model Builder, there should be a method associationTable() to add this kind of table.

Model code may look like:

    associationTable("besucht")
        .column("student_id", DataType.BIGINT)
          .references(studenten)
            .named("besucht")
            .multiplicities("1")
            .description("Gibt an, welche Lehrveranstaltungen ein Student besucht.")
        .column("lehrveranstaltung_id", DataType.BIGINT)
          .references(lehrveranstaltungen)
            .named("besuchtVon")
            .multiplicities("3..100")
            .description("Gibt an, welche Studenten eine Lehrveranstaltung besuchen.")
      .build();

Database-Model-Generator

Create a generator for STU Database Models, which generates a model from real database (e.g. via JDBC).

Reference Integrity Check

Allow to check the integrity of the used references in a data set. If a reference cannot be resolved, the check should fail.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.