@@ -0,0 +1,2827 @@
+package jft.rest;%0A%0Aimport com.google.gson.Gson;%0Aimport com.google.gson.JsonArray;%0Aimport com.google.gson.JsonElement;%0Aimport com.google.gson.JsonParser;%0Aimport com.google.gson.reflect.TypeToken;%0Aimport org.apache.http.client.fluent.Executor;%0Aimport org.apache.http.client.fluent.Request;%0Aimport org.apache.http.message.BasicNameValuePair;%0Aimport org.testng.Assert;%0Aimport org.testng.SkipException;%0Aimport org.testng.annotations.Test;%0A%0Aimport java.io.IOException;%0Aimport java.util.Set;%0A%0A/**%0A * Created by Anna on 14.06.16.%0A */%0Apublic class RestTests %7B%0A%0A    @Test%0A    public void testCreateIssue() throws IOException %7B%0A        Set%3CIssue%3E oldIssues= getIssues();%0A        Issue newIssue = new Issue().withSubject(%22test subject%22).withDescription(%22test description%22);%0A        int id = createIssue(newIssue);%0A        Set%3CIssue%3E newIssues= getIssues();%0A        oldIssues.add(newIssue.withId(id));%0A        Assert.assertEquals(newIssues, oldIssues);%0A    %7D%0A%0A    private int createIssue(Issue newIssue) throws IOException %7B%0A        String json = getExecutor().execute(Request.Post(%22http://demo.bugify.com/api/issues.json%22)%0A                .bodyForm(new BasicNameValuePair(%22subject%22, newIssue.getSubject()),%0A                        new BasicNameValuePair(%22description%22, newIssue.getDescription())))%0A                .returnContent().asString();%0A        JsonElement parsed = new JsonParser().parse(json);%0A        return parsed.getAsJsonObject().get(%22issue_id%22).getAsInt();%0A    %7D%0A%0A    private Set%3CIssue%3E getIssues() throws IOException %7B%0A        String json = getExecutor().execute(Request.Get(%22http://demo.bugify.com/api/issues.json%22)).returnContent().asString();%0A        JsonElement parsed = new JsonParser().parse(json);%0A        JsonElement issues = parsed.getAsJsonObject().get(%22issues%22);%0A        return new Gson().fromJson(issues, new TypeToken%3CSet%3CIssue%3E%3E()%7B%7D.getType());%0A    %7D%0A%0A    private Executor getExecutor()%7B%0A        return Executor.newInstance().auth(%22LSGjeU4yP1X493ud1hNniA==%22, %22%22);%0A    %7D%0A%0A%0A    public void skipIfNotFixed(int issueId) throws IOException %7B%0A        if (isIssueOpen(issueId)) %7B%0A            throw new SkipException(%22Ignored because of issue %22 + issueId);%0A        %7D%0A    %7D%0A%0A    public boolean isIssueOpen(int issueId) throws IOException %7B%0A%0A        String json = getExecutor().execute(Request.Get(%22http://demo.bugify.com/api/issues/%22 + issueId + %22.json%22))%0A                .returnContent().asString();%0A        JsonElement parsed = new JsonParser().parse(json);%0A        JsonArray issues = parsed.getAsJsonObject().get(%22issues%22).getAsJsonArray();%0A        String status = issues.get(0).getAsJsonObject().get(%22state_name%22).getAsString();%0A        return (status.equals(%22Open%22));%0A    %7D%0A%0A    @Test%0A    public void testSkipping() throws IOException %7B%0A        skipIfNotFixed(1);%0A        System.out.println(%22not skipped%22);%0A    %7D%0A%7D%0A

Test for verifying if bug was fixed