You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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>
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);
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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>{
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.