Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

ActiveObjectsJUnitRunner - EntityManager is not injected into tests.

Hello everyone.
I am developing a plugin for Confluence and following this guide https://developer.atlassian.com/server/framework/atlassian-sdk/getting-started-with-active-objects/, but I am having trouble with testing.
The problem is that the ActiveObjectsJUnitRunner.class class doesn't inject EntityManager and throw NullPointerException at setUp () {} method. According to this guide ActiveObjectJUnitRunner.class should inject EntityManager.
Surely I do something wrong or something remains to be done.

Thanks in advance of your help.


Those are my pom test dependencies:

<!-- WIRED TEST RUNNER DEPENDENCIES -->
<dependency>
<groupId>com.atlassian.plugins</groupId>
<artifactId>atlassian-plugins-osgi-testrunner</artifactId>
<version>${plugin.testrunner.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.java.dev.activeobjects</groupId>
<artifactId>activeobjects-test</artifactId>
<version>${ao.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.atlassian.activeobjects</groupId>
<artifactId>activeobjects-test</artifactId>
<version>${ao.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.5</version>
<scope>test</scope>
</dependency>

 

and that is my test class:

package com.cis.confluence.plugins.persistence;

import com.atlassian.activeobjects.test.TestActiveObjects;
import net.java.ao.EntityManager;
import net.java.ao.test.jdbc.Data;
import net.java.ao.test.jdbc.DatabaseUpdater;
import net.java.ao.test.junit.ActiveObjectsJUnitRunner;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import static org.junit.jupiter.api.Assertions.*;


@RunWith(ActiveObjectsJUnitRunner.class)
@Data(ConfluencerPersistenceImplTest.ConfluencerPersistenceImplTestDatabaseUpdater.class)
//@Jdbc(DerbyEmbedded.class)
//@NameConverters
class ConfluencerPersistenceImplTest {

private ConfluencerPersistenceImpl objectToTest;

private EntityManager entityManager;

@Test
void getAll() {
}

@Test
void save() {
}

@Test
void remove() {
}

@BeforeEach
public void setUp() {
assertNotNull(entityManager);
objectToTest = new ConfluencerPersistenceImpl(new TestActiveObjects(entityManager));

}

public static final class ConfluencerPersistenceImplTestDatabaseUpdater implements DatabaseUpdater {
@Override
public void update(EntityManager entityManager) throws Exception {
entityManager.migrate(EventUserServ.class);
}
}
}

 

 

the error message: 

org.opentest4j.AssertionFailedError: expected: not <null>

 

1 answer

If someone have this problem , here is a solution. (although this should not be a solution, if there is a new version of junit)
I make it work with downgrading of junit. I have no problems with junit4 (org.junit.*), EntityManager was injected by ActiveObjectsJUnitRunner, but I don't understand why with junit5 (org.junit.jupiter.api.*) EntityManager is not injected.
Is there another way to test persistence with JUnit5?
Is there another way to inject the EntityManager with JUnit5 ?
All my tests are writed on junit5 , except this one.

worked test class:

 

package com.cis.confluence.plugins.persistence;

import com.atlassian.activeobjects.external.ActiveObjects;
import com.atlassian.activeobjects.test.TestActiveObjects;
import net.java.ao.EntityManager;
import net.java.ao.test.junit.ActiveObjectsJUnitRunner;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.jupiter.api.Assertions.*;


@RunWith(ActiveObjectsJUnitRunner.class)
public class ConfluencerPersistenceImplTest {

private ConfluencerPersistenceImpl objectToTest;

private EntityManager entityManager;

private ActiveObjects ao;

//changed from org.junit.jupiter.api.Test to org.junit.Test
@Test
public void getAll() {

}

//changed from org.junit.jupiter.api.Test to org.junit.Test
@Test
public void save() {
}

//changed from org.junit.jupiter.api.Test to org.junit.Test
@Test
public void remove() {
}

//changed from org.junit.jupiter.api.BeforeEach to org.junit.Before
@Before
public void setUp() {
assertNotNull(entityManager);

ao = new TestActiveObjects(entityManager);
objectToTest = new ConfluencerPersistenceImpl(ao);
}
}

 

Hello 
but it's not solved,throws same error..

i shared you screen-shot of error message along with code & maven dependency..

 

maven dependency :

<dependency>
<groupId>com.atlassian.plugins</groupId>
<artifactId>atlassian-plugins-osgi-testrunner</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>net.java.dev.activeobjects</groupId>
<artifactId>activeobjects-test</artifactId>
<version>${ao.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.atlassian.activeobjects</groupId>
<artifactId>activeobjects-test</artifactId>
<version>${ao.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
<scope>provided</scope>
</dependency>

 

code : 

import static org.junit.Assert.assertNotNull;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.atlassian.activeobjects.external.ActiveObjects;
import com.atlassian.activeobjects.test.TestActiveObjects;

import net.java.ao.EntityManager;
import net.java.ao.test.junit.ActiveObjectsJUnitRunner;

import net.java.ao.test.jdbc.Data; //added
import net.java.ao.test.jdbc.DatabaseUpdater; //added
import net.java.ao.test.jdbc.Hsql;
import net.java.ao.test.jdbc.Jdbc;

@RunWith(ActiveObjectsJUnitRunner.class)
@Data(SentinelGlobalSettingsTest.SentinelGlobalSettingsTestDataBaseUpdater.class) // added
@Jdbc(Hsql.class)
public class SentinelGlobalSettingsTest {

private SentinelGlobalSettings sentinelGlobalSettings;
private EntityManager entityManager;
private ActiveObjects ao;

@Before
public void setUp() {
System.out.println("setUpClass call");
assertNotNull(entityManager);
ao = new TestActiveObjects(entityManager);
System.out.println(ao);
sentinelGlobalSettings = new SentinelGlobalSettings(ao);
}

/**
* added
*/
public static final class SentinelGlobalSettingsTestDataBaseUpdater implements DatabaseUpdater {
@Override
public void update(EntityManager entityManager) throws Exception {
// you should migrade your entity interface to make tests
System.out.println("ok");
entityManager.migrate(ActiveObject.class);

}
}

@TEST
public void testAdd() {
System.out.println("testAdd");
}

}

 

another interface : 


import com.atlassian.activeobjects.external.ActiveObjects;

import net.java.ao.RawEntity;

public interface ActiveObject extends RawEntity<ActiveObjects>{

}Error.png

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

⚡️NEW Group for Confluence Cloud Admins

Calling all Confluence Cloud Admins!  We created a new Community Group to support your unique needs as Confluence admins. This is a group where you can ask questions, access resou...

144 views 2 10
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you