Wired integration tests work in plugin test console but fails with atlas-integration-test

Nicholas June 2, 2014

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:

http://pastebin.com/YL9UgQaa

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

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 6, 2014

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.

Nicholas June 9, 2014

Thanks, this worked great! :)

0 votes
Steve Gerstner [bridgingIT]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 3, 2014
Can you create a dataset with a test data including your testspace? See here https://developer.atlassian.com/plugins/servlet/mobile#content/view/11927560
Nicholas June 4, 2014

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

TAGS
AUG Leaders

Atlassian Community Events