play-neo4jplugin icon indicating copy to clipboard operation
play-neo4jplugin copied to clipboard

Add a sample test case

Open Brazo opened this issue 11 years ago • 6 comments

Hello guys,

thanks a lot for providing this neo4j plugin. It saves a lot of time configuring play correctly.

One thing I am missing is a sample test case. Could you provide a sample test case for the Galaxy example? Something simple that checks Neo4JServiceProvider.get() actually returns a non-null Neo4jServiceProvider, e.g. a non-null galaxyService?

This worked for me using your plugin: @Test public void serviceIsCorrectlyRegistered() { running(fakeApplication(), new Runnable() { public void run() { Neo4JServiceProvider nsp = Neo4JServiceProvider.get(); assertNotNull("Neo4jService is not correctly wired by Spring", nsp); GalaxyService ms = nsp.galaxyService; assertNotNull("GalaxyService is not correctly wired by Spring", ms); } }); }

Thanks Patrick

Brazo avatar Feb 04 '14 21:02 Brazo

Hi @Brazo,

thanks for the feedback. I will write some test cases

tuxBurner avatar Feb 05 '14 08:02 tuxBurner

Ups wrong button :) Coffee is still not working.

tuxBurner avatar Feb 05 '14 08:02 tuxBurner

Thanks for providing this plugin. When using the same test provided by @Brazo,i am getting a nullexception below. Anyideas on what could be wrong?

java.lang.NullPointerException at neo4jplugin.Neo4JPlugin.get(Neo4JPlugin.java:105)

Code: running(fakeApplication(), new Runnable() { public void run() { Neo4JServiceProvider nsp = Neo4JServiceProvider.get(); assertNotNull("Neo4jService is not correctly wired by Spring", nsp); } });

Update: Hi Sepp, The tests provided by @Brazo are working when run from prompt with "play test" ,there is no issue now . Earlier i was trying to run from eclipse ,where it was failing with the NullPointer exception.

Thanks, Kishore

pkishore avatar May 09 '14 04:05 pkishore

Ups okay i will try to check this at the weekend

tuxBurner avatar May 09 '14 09:05 tuxBurner

I found a simple solution to enable us to write unit test. The test will take long tho because it require starting the application. It is not a perfect solution because the test will break if simply the application break(because it need to start the app to enable us to use the plugin), which make the test not isolated.

So basically the test class need to extends play.test.WithApplication And we add Service as a field, then add a setUp method to start the application, get the service before we start the testing. After that we will be able to use the Service object.

@Before
public void setUp() throws Exception {
    this.startPlay();
    this.citationService = Neo4JServiceProvider.get().citationService;
}

haimingzhao avatar Jan 07 '15 03:01 haimingzhao

Woaaah cool one @mirahmz thx a lot :)

tuxBurner avatar Jan 07 '15 18:01 tuxBurner