Has anyone else generated a post operation plugin module with the atlassian-plugin-sdk version 5.0.13 that created a test with the Jira-api-6.4.4 jar and tried to use IssueImpl in the test?
I used the atlas-create-jira-plugin-module to add a transition post operation plugin and the code that was generated for the test skeleton tries to create an IssueImpl object. Eclipse is saying that this class doesn't exist, and unpacking the jira-api-6.4.4 jar backs that up. The javadoc for the jar shows that this class should be present, the tutorials and documentation show that it should be there, and the code generator thought it should be there, but I am at a loss as to what I need to do.
Community moderators have prevented the ability to post new answers.
The IssueImpl
class is the raw implementing class for the issue and is intentionally not in the API.
The test's author doesn't really seem to understand what unit testing is, as you can't very well call this a "Unit test" if it's going to try to use a real IssueImpl
.
As for what you can do to move forward...
One way is to get the test access to this class by adding this to the pom.xml
:
<dependency> <groupId>com.atlassian.jira</groupId> <artifactId>jira-core</artifactId> <version>${jira.version}</version> <scope>test</scope> </dependency>
Unfortunately, the whole point of the API/core separation is to allow us to do things like change the constructors that internal implementations use, and that has happened here – the example no longer matches. You would also have to add an additional mock for JiraAuthenticationContext
and pass it into the IssueImpl
constructor as well:
JiraAuthenticationContext jiraAuthenticationContext = mock(JiraAuthenticationContext.class); return new IssueImpl(genericValue, issueManager, projectManager, versionManager, issueSecurityLevelManager, constantsManager, subTaskManager, attachmentManager, labelManager, projectComponentManager, userManager, jiraAuthenticationContext);
This works, but I want to reiterate that this is a terrible way to write a test and the example needs to be rewritten. I have opened AMPS-1252 to get it fixed.
A better answer, I think, is to actually fix the test to do what it should without using jira-core. This is what the test class should look like, with the MutableIssue
properly mocked and verified:
package ut.com.atlassian.example.jira.workflow; import java.util.Collections; import java.util.HashMap; import java.util.Map; import com.atlassian.example.jira.workflow.MyPostFunction; import com.atlassian.jira.exception.DataAccessException; import com.atlassian.jira.issue.MutableIssue; import org.junit.Before; import org.junit.Test; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.mockito.Mockito.verify; public class MyPostFunctionTest { public static final String MESSAGE = "my message"; protected MyPostFunction function; protected MutableIssue issue; @Before public void setup() { issue = mock(MutableIssue.class); when(issue.getDescription()).thenReturn(""); function = new MyPostFunction() { protected MutableIssue getIssue(Map transientVars) throws DataAccessException { return issue; } }; } @Test public void testNullMessage() throws Exception { Map transientVars = Collections.emptyMap(); function.execute(transientVars,null,null); verify(issue).setDescription(""); } @Test public void testEmptyMessage() throws Exception { Map transientVars = new HashMap(); transientVars.put("messageField",""); function.execute(transientVars,null,null); verify(issue).setDescription(""); } @Test public void testValidMessage() throws Exception { Map transientVars = new HashMap(); transientVars.put("messageField",MESSAGE); function.execute(transientVars,null,null); verify(issue).setDescription(MESSAGE); } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think you need to run:
atlas-mvn eclipse:eclipse
and then refresh your eclipse project.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I had run it before to generate the project, but I went ahead and tried it again. There was no change in the error.
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.