-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Konrad Biedowicz
committed
Jun 25, 2019
1 parent
9980dbd
commit 2c158e7
Showing
3 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/jira_rest_essentials/DisabledOptionsResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package jira_rest_essentials; | ||
|
||
import static java.util.stream.Collectors.toList; | ||
|
||
import java.util.List; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import com.atlassian.jira.component.ComponentAccessor; | ||
import com.atlassian.jira.issue.customfields.manager.OptionsManager; | ||
import com.atlassian.jira.issue.customfields.option.Option; | ||
|
||
@Path("/disabled-options") | ||
public class DisabledOptionsResource { | ||
|
||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response getDisabledOptions() { | ||
|
||
final List<Option> allOptions = options().getAllOptions(); | ||
|
||
final List<Long> disabledOptions = allOptions.stream() | ||
.filter(Option::getDisabled) | ||
.map(Option::getOptionId) | ||
.collect(toList()); | ||
|
||
return Response.ok(disabledOptions).build(); | ||
} | ||
|
||
private OptionsManager options() { | ||
return ComponentAccessor.getOptionsManager(); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/test/java/jira_rest_essentials/DisabledOptionsResourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package jira_rest_essentials; | ||
|
||
import static com.github.jenspiegsa.restassuredextension.PostConstructPojoResourceFactory.wired; | ||
import static io.restassured.RestAssured.given; | ||
import static javax.ws.rs.core.Response.Status.OK; | ||
import static org.hamcrest.Matchers.containsInAnyOrder; | ||
import static org.mockito.BDDMockito.given; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.jboss.resteasy.spi.ResourceFactory; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import com.atlassian.jira.action.issue.customfields.option.MockOption; | ||
import com.atlassian.jira.component.ComponentAccessor; | ||
import com.atlassian.jira.issue.customfields.manager.OptionsManager; | ||
import com.atlassian.jira.issue.customfields.option.Option; | ||
import com.atlassian.jira.mock.component.MockComponentWorker; | ||
import com.github.jenspiegsa.restassuredextension.ConfigureRestAssured; | ||
import com.github.jenspiegsa.restassuredextension.RestAssuredExtension; | ||
|
||
import io.restassured.http.ContentType; | ||
|
||
/** | ||
* @author Konrad Biedowicz | ||
*/ | ||
@DisplayName("DisabledOptionsResource") | ||
@ExtendWith(MockitoExtension.class) | ||
@ExtendWith(RestAssuredExtension.class) | ||
class DisabledOptionsResourceTest { | ||
|
||
private static final boolean ENABLED = false; | ||
private static final boolean DISABLED = true; | ||
|
||
private static final String SIMPLE_JSON_ARRAY = "$"; | ||
|
||
@ConfigureRestAssured(contextPath = "/jira/rest/essentials/1.0", port = 8989) | ||
ResourceFactory[] resourceFactory = { wired(DisabledOptionsResource.class, nop -> { | ||
}) }; | ||
|
||
@Mock OptionsManager optionsManager; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
|
||
ComponentAccessor.initialiseWorker( | ||
new MockComponentWorker() | ||
.addMock(OptionsManager.class, optionsManager) | ||
); | ||
} | ||
|
||
@Test | ||
@DisplayName("HTTP GET /disabled-options") | ||
void testGet() { | ||
|
||
final List<Option> allOptions = new ArrayList<>(); | ||
allOptions.add(makeOption(1L, "enabledValue A", ENABLED)); | ||
allOptions.add(makeOption(2L, "disabledValue B", DISABLED)); | ||
allOptions.add(makeOption(3L, "disabledValue C", DISABLED)); | ||
|
||
given(optionsManager.getAllOptions()).willReturn(allOptions); | ||
|
||
given() | ||
.accept(ContentType.JSON) | ||
.when() | ||
.get("/jira/rest/essentials/1.0/disabled-options") | ||
.then() | ||
.statusCode(OK.getStatusCode()) | ||
.body(SIMPLE_JSON_ARRAY, containsInAnyOrder(2, 3)); // assert json response: [2,3] | ||
} | ||
|
||
private static Option makeOption(final long optionId, final String optionValue, final boolean disabled) { | ||
final Option option = new MockOption(null, null, null, optionValue, null, optionId); | ||
option.setDisabled(disabled); | ||
return option; | ||
} | ||
} |