Skip to content

Project Requirements

drsquidop edited this page Nov 10, 2013 · 3 revisions

Description

A program that demonstrates a Scala program calling a standard JRuby/Rails ActiveRecord model object which uses a postgres database. Implement unit tests on the scala program to test the functionality. The calling interface will be the java JSR 223 Scripting API’s.

Requirements

  1. Submission

    1. Work will start by forking the project

      1. post any questions as issues here
    2. Submit work by issuing a git pull request

    3. Requirements can be verified by following these steps on a test machine:

      1. install software prerequisites

      2. do a git clone/git pull

      3. (optionally) creating an empty database

      4. running ‘sbt publish-local’ or ‘mvn install’ to run all tests

      5. inspecting the code

    4. Submission is accepted by accepting the pull request

    5. Submission is rejected by opening a ticket in the developers fork on github

  2. Supported platforms

    1. Either of Apple OSX 10.8.2 or Ubuntu 12.04.3 LTS
  3. Software Versions

    1. Maven 3.0.3 or higher (if used)

    2. Java 1.7.0_x (Oracle java SE)

    3. Jruby 1.7.3 or higher

    4. Rails 4.0.1 or higher

    5. SBT 0.13.0 or higher

    6. Scala 2.10.2 or higher

    7. Postgresql 9.2.2.0 or higher

  4. Software Prerequisites

    1. Assume that the above software versions are already installed on the test machine

    2. Assume the default ‘empty’ postgresql user

  5. Directory Structure scala-jruby-activerecord/ .gitignore README.md pom.xml or sbt project/ (to build,test,package the whole project) model-gem/ (a gem following the ‘bundle gem’ convention) scala-client/ (a scala project following sbt or maven convention) .../resources/ config.__ - a config file holding the db credentials

  6. Packaging

    1. Project will package as:

      1. com.drsquidop.scala-jruby-activerecord:model-gem-1.0.SNAPSHOT:jar

        1. this gem will package as both a gem and a jar
      2. com.drsquidop.scala-jruby-activerecord:scala-client-1.0.SNAPSHOT:jar

        1. this jar will include a dependency on the model-gem jar
  7. General Requirements

    1. scala-client

      1. based on scala 2.10 maven or sbt convention

      2. depends on model-gem jar

      3. calls model-gem using JSR 223 Scripting API (see references)

      4. passes database configuration to model-gem

      5. contains MyModel case class with these fields

        1. id: Option[Int]

        2. name: String

      6. contains Client object with these methods

        1. new(MyModel): Try[MyModel] - returns with assigned id

        2. get(id:Int): Try[MyModel] - returns record with id

        3. all(): Try[List[MyModel]] - returns all records

      7. contains ValidationException extends Exception that contains ActiveRecord generated validation errors

    2. model-gem

      1. based on ‘bundle gem ’ convention

      2. based on rails ActiveRecord model object convention

      3. passed its database configuration from scala-client

      4. contains MyGemModel ActiveRecord object with

        1. id - autoassigned pk

        2. name - string

      5. ‘mvn package’ (or shell script) handles

        1. reloading db from migrations

        2. running rspec

        3. packaging as gem

        4. packaging as jar

        5. deploying jar to local repo

  8. Tests

    1. Scala tests will use ScalaTest or Specs2

    2. Unit Tests

      1. model-gem

        1. Configuration

          1. tests are implemented in rspec

          2. database configuration comes from gem/config/database.yml

        2. Test cases

          1. MyGemModel.new with (any string) creates a record in the database

          2. MyGemModel.new with (blank string) returns rails standard validation error

          3. MyGemModel.get(id) returns a valid object

          4. MyGemModel.all returns multiple entries

      2. scala-client

        1. Configuration

          1. model-gem is packaged as a jar

          2. scala-client includes model-gem jar as dependency

          3. tests run under scala-client using mvn or sbt

          4. tests are written in scalatest or specs2

          5. database config comes from scala-client/...config file

        2. Test cases

          1. Client.new(any string) returns Success(MyModel)

          2. Client.new(empty string) returns Failure(ValidationException) with ActiveRecord validation error map

          3. Client.get(valid id) returns Success(MyModel)

          4. Client.get(invalid id) returns Failure(Exception("MyModel not found"))

          5. Client.all returns Success(List[MyModel]) with several records

References

  1. JSR 223 - http://www.oracle.com/technetwork/articles/dsl/jruby-141877.html#ej

  2. Related examples:

    1. https://github.com/jruby/jruby/wiki/JRubyAndJavaCodeExamples

    2. https://kenai.com/projects/jruby/pages/WalkthroughsAndTutorials

    3. http://java.ociweb.com/mark/programming/ActiveRecord.html

Clone this wiki locally