Hello!
I have a set of integration tests that work fine in the plugin test console, but fail when run with atlas-integration-test.
Steps to reproduce:
1. Create a new Confluence plugin project (has been tested with 5.4.4 and 5.5.2)
2. Use the following class for tests:
package it.com.example.integrationtest; import com.atlassian.confluence.spaces.Space; import com.atlassian.confluence.spaces.SpaceManager; import com.atlassian.confluence.user.ConfluenceUser; import com.atlassian.confluence.user.UserAccessor; import com.atlassian.plugins.osgi.test.AtlassianPluginsTestRunner; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import static org.junit.Assert.assertEquals; @RunWith(AtlassianPluginsTestRunner.class) public class ExampleWiredTest { private SpaceManager spaceManager; private UserAccessor userAccessor; private Space testSpace; public ExampleWiredTest(SpaceManager spaceManager, UserAccessor userAccessor) { this.spaceManager = spaceManager; this.userAccessor = userAccessor; } @BeforeClass public void setup() { ConfluenceUser user = userAccessor.getUserByName("admin"); testSpace = spaceManager.getSpace("TEST"); if (testSpace != null) { spaceManager.removeSpace(testSpace); } testSpace = spaceManager.createSpace("TEST", "Test space", "This is a test space", user); } @AfterClass public void teardown() { spaceManager.removeSpace(testSpace); } @Test public void testHasNewSpaceBeenCreatedWithCorrectName() { Space space = spaceManager.getSpace("TEST"); assertEquals("Test space", space.getName()); } }
Run this in the plugin test console and with atlas-integration-test. In the latter, it will fail with a NullPointerException. The output from Surefire is here:
Strangely enough, if I comment the spaceManager.removeSpace(testSpace) line from teardown(), it fails in setup() because it cannot find the admin user:
com.atlassian.confluence.security.InvalidOperationException: Must be the owner of the space or system administrator to create initial space permissions. User null tried to set permissions on space TEST owned by admin
(This was the result even after doing atlas-clean first. Full surefire output from that one here: http://pastebin.com/M6rSg6Xi)
Has anyone else encountered similar problems? Running the tests with atlas-integration-test always ends up in some strange failures here...
Best regards
Nicho
Community moderators have prevented the ability to post new answers.
I'm not an expert with these kinds of tests, but my guess is that in the Plugin Test Console, it runs the tests as the user you are logged in as, where in 'atlas-integration-test' you are running in an anonymous user context.
Try adding this to your setup method:
@BeforeClass public void setup() { ConfluenceUser user = userAccessor.getUserByName("admin"); if (AuthenticatedUserThreadLocal.get() == null) { AuthenticatedUserThreadLocal.set(user) } }
The reason that the exception message changes when you remove the code from your teardown method is because exceptions during the teardown will mask other failures from being reported by JUnit. The other exception is probably always happening, but then the failure that JUnit reports is being overwritten by the exception in your teardown method.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, I have tried with test fixtures as well, both the one you linked to and one I created myself. I even tried specifically creating extra users for the purpose of testing, e.g. an admin user named "fixtureadmin", but userAccessor will still return null for this user when run with atlas-integration-test (while the same test works in the Atlassian Plugin Test Console). The same strangeness with the space also occurs when trying to delete it, even if it is a space created by the fixture.
Best regards
Nicho
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.