Play Framework run test in Codeship with database - postgresql

I need to run test for my Play app in Codeship. The problem is that my app cannot find the database to connect to, and this all tests are failing.
From the doc, I suppose that there are 3 different Postgres DBs (9.2, 9.3, 9.4) that I can use, so I configure my conf as below.
Please let me know where I got it wrong.

I finally found out why my test could not find the database. It was because running the test with sbt test -Dconfig.resource=test.application.conf is not a valid way to specify java option for test.
I have to go to the build.sbt file and add the following for test to load the correct config like illustrated below.

Related

Configuring PostgreSQL on Play! 2.6

I have a PostgreSQL(v9.6) instance running on my machine. The database is called 'postgres'. I've managed to open the application in pgAdmin 3 using localhost:5432. In my Play! application(v2.6.2) I have added the driver and the url to the application.conf file following the tutorial here and I have added the javaJdbc dependency to my build.sbt file. So I have the following:
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://localhost:5432/postgres"
db.default.username = "user"
db.default.password = "pass"
When I run the application though I get this error in the console:
Cannot connect to database [default]
Could somebody explain to me why this is the case? I can provide more information if I need to.
So after quite a bit of digging, it turns out the problem was actually me missing the postgres dependency. If anyone encounters this problem I would suggest checking your build.sbt file and adding the org.postgres dependency if you are missing it.
This documentation on the play website doesn't explain this step.

How to connect mongodb to neo4j

I am trying to connect mongodb data to neo4j.
I tried with this code "CALL apoc.mongodb.get('mongodb://localhost:27017','test','test',{name:'testDocument'})" in Neo4j.
But I get an error as
There is no procedure with the name apoc.mongodb.get registered for this database instance. Please ensure you've spelled the procedure name correctly and that the procedure is properly deployed.
I had added APOC jar files in Neo4j plugins and I gone through this link http://indexoutofrange.com/Neo4jStoredProceduresWindows/
still Iam unable to connect.
can someone please explain what shall i do to get this started.
Thanks
In addition to copying the APOC jar file to $NEO4J_HOME/plugins you'll also need to copy the mongo specific jar files into $NEO4J_HOME/plugins. For example:
mvn dependency:copy-dependencies
cp target/dependency/mongodb*.jar target/dependency/bson*.jar $NEO4J_HOME/plugins/
More information available in the docs here
I know this was made 5 years ago but this is for anyone else (like myself) who's looking for an answer.
The URI should look something like this:
CALL apoc.mongo.find("mongodb://localhost:port/databaseName.collectionName")

Unable to run Scala test as a suite in Eclipse

I am running Scala (and Spark) tests using FunSuite in Eclipse (Kepler). I have been able to successfully run the tests. I then created a new package (in the same source folder and project) and am running into a problem.
When I select run as:
I am able to successfully run my tests using both the 1st (ScalaTest – File) and 3rd (ScalaTest – Test) options. However, when I try and run method 2 (ScalaTest – Suite), I get:
***RUN ABORTED ***
java.lang.ClassNotFoundException: com.domain.gotime.rdd.Test1
Why is that I am getting this error for the Suite only? I am planning on this being run automatically with Jenkins – and want to know if I need to fix this, and if so how?
I have looked over this page but am still confused as to why it isn't working.
Please check that com.domain.gotime.rdd.Test1 is in the classpath of the auto-created Run Configuration.

How to keep separate dev, test, and prod databases in Play! 2 Framework?

In particular, for test-cases, I want to keep the test database separate so that the test cases don't interfere with development or production databases.
What are some good practices for separating development, test and production environments?
EDIT1: Some context
In Ruby On Rails, there are different configuration files by convention for different environments. So does Play! 2 also support that ?
Or, do I have to cook the configuration files, and then write some glue code that selects the appropriate configuration files ?
At the moment if I run sbt test it uses development database ( configured as "default" in conf/application.conf ). However I would like Play!2 to use a different test database.
EDIT2: On commands that play provides
For Play! 2 framework, I observed this.
$ help play
Welcome to Play 2.2.2!
These commands are available:
-----------------------------
...OUTPUT SKIPPED...
run <port> Run the current application in DEV mode.
test Run Junit tests and/or Specs from the command line
start <port> Start the current application in another JVM in PROD mode.
...OUTPUT SKIPPED...
There are three well defined commands for "test", "development" and "production" instances which are:
test: This runs the test cases. So it should automatically select test configuration.
run <port>: this runs the development instance on the specified port. So this command should automatically select development configuration.
start <port>: this runs the production instance on the specified port. So this should automatically select production configuration.
However, all these commands select the values that are provided in conf/application.conf. I feel there is some gap to be filled here.
Please do correct me if I am wrong.
EDIT3: Best approach is using Global.scala
Described here: How to manage application.conf in several environments with play 2.0?
Good practice is keeping separate instances of the application in separate folders and synching them i.e. via git repo.
When you want to keep single instance you can use alternative configuration file for each environment.
In your application.conf file there is an entry (or entries) for your database, e.g. db.default.url=jdbc:mysql://127.0.0.1:3306/devdb
The conf file can read environment variables using ${?ENV_VAR_NAME} syntax, so change that to something like db.default.url=${?DB_URL} and use environment variables.
A simpler way to get this done and manage your configuration easier is via GlobalSettings. There is a method you can override and that its name is "onLoadConfig". Try check its api at API_LINK
Basically on your conf/ project folder, you'll setup similar to below:
conf/application.conf --> configurations common for all environment
conf/dev/application.conf --> configurations for development environment
conf/test/application.conf --> configurations for testing environment
conf/prod/application.conf --> configurations for production environment
So with this, your application knows which configuration to run for your specific environment mode. For a code snippet of my implementation on onLoadConfig try check my article at my blog post
I hope this is helpful.

deploying a scala app built using IDEA

I developed a simple scala app that uses casbah to query the DB for the command line argument passed to it. For example
$ querydb.scala execution 10
it will run a casbah query to find 10 records matching execution in mongo. Now i have two questions.
1) How do i test this in my local. If i click execute in intellij it is just running the program, i am not able to pass command line arguments to my program.
2) How do i deploy it to run on my server, it is just going to used as console app in my ubuntu server, but im not sure how i should deploy this, which files i should put up on the server and how do i execute it in server, and stuff like that.
Any pointers would be useful for me.
or try to use sbt, IDEA has a plugin with sbt, the wiki of it has an explanation on how to use it.
I usually use sbt directly in Terminal instead of running in IDE.
1) First you need to find "Select Run/Debug Configuration" button at the top of your screen
Click on it and choose edit
Create new one, if you haven't got it yet.
Your program parameters should be written in "Program parameters" field
2) Compile your .scala files with scalac and you'll got .class files.
Then deploy it, as you usually do with java code. Hence you don't need to install scala on target machine - all you need is JDK.