Thanks Cristiano.
Your ideas helped me to implement a basic LoadFromJIRA.
I use the atlassian.jira.rest.client.
import java.net.URI;
import java.net.URISyntaxException;
import org.jbehave.core.io.ResourceLoader;
import org.jbehave.core.io.StoryLoader;
import com.atlassian.jira.rest.client.JiraRestClient;
import com.atlassian.jira.rest.client.NullProgressMonitor;
import com.atlassian.jira.rest.client.domain.Issue;
import com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClientFactory;
/**
private final String narrativeFieldName = "Narrative";
private final String scenariosFieldName = "Acceptance Criteria";
private String storyId;
private String location;
private String username;
private String password;
private JiraRestClient restClient = null;
final NullProgressMonitor pm = new NullProgressMonitor();
/**
- Configures the JIRA loader.
- @param location The jira url
- @param username The jira account username
- @param password The jira account password
- @param storyId The jira story id
*/
public LoadFromJIRA(String location, String username, String password, String storyId)
{
this.location = location;
this.password = password;
this.username = username;
this.storyId = storyId;
}
@Override
public String loadStoryAsText(String storyPath)
{
return loadFromJira(this.storyId);
}
@Override
public String loadResourceAsText(String resourcePath) {
return loadFromJira(this.storyId);
}
private JiraRestClient connect(String location, String username, String password) {
JerseyJiraRestClientFactory factory = new JerseyJiraRestClientFactory();
restClient = null;
try
{
restClient = factory.createWithBasicHttpAuthentication(new URI(location), username,
password);
}
catch (URISyntaxException e)
{
e.printStackTrace();
}
return restClient;
}
private String loadFromJira(String storyId) {
if(this.restClient == null)
{
this.restClient = connect(location, username, password);
}
final Issue issue = restClient.getIssueClient().getIssue(storyId, pm);
final String narrative = issue.getFieldByName(narrativeFieldName).getValue().toString();
final String scenarios = issue.getFieldByName(scenariosFieldName).getValue().toString();
StringBuilder sb = new StringBuilder();
sb.append("Narrative:");
sb.append(narrative);
sb.append(scenarios);
return sb.toString();
}
}
-----------------
Usage:
Configuration configuration = new MostUsefulConfiguration()
.useStoryLoader(new LoadFromJIRA("http://localhost/jira", "yourJiraUserName","yourJiraPassword", "JIRA-STORYID-112"))
.useStoryReporterBuilder(new StoryReporterBuilder().withFormats(HTML));
-----------------
Ressources:
jira rest client library
http://confluence.atlassian.com/display/DOCSPRINT/The+Simplest+Possible+JIRA+REST+Examples
https://studio.atlassian.com/wiki/display/JRJC/Tutorial
Hi, I did this couple years ago. Actually I've used the Confluence instead but it is the same.
But I don't think it is necessary anything more in Jbehave side other than the LoadFromURL.
You just need to create a plugin with the built-in REST support. This plugin will capture the calling parameters and process it. The result of your call will be a string (you can bring one story or a set of), so you don't need to worry in create a parser in the client side.
In client, you just need some abstract step class that connect to server calling the right http address with the right parameters.