private static final String DESTROY_URL = ROOT_URL + "/destroy";
private static final String SET_DEFAULT_URL = ROOT_URL + "/set_as_default";
private static final String UNSET_DEFAULT_URL = ROOT_URL + "/unset_default";
+ private static final String SELECT_URL = ROOT_URL + "/select";
+ private static final String DESELECT_URL = ROOT_URL + "/deselect";
private final HttpRequestFactory requestFactory;
requestFactory.post(UNSET_DEFAULT_URL, Collections.<String, Object> emptyMap());
}
+ @Override
+ public void selectProject(long qGateId, long projectId) {
+ requestFactory.post(SELECT_URL, selectionParams(qGateId, projectId));
+ }
+
+ @Override
+ public void deselectProject(long qGateId, long projectId) {
+ requestFactory.post(DESELECT_URL, selectionParams(qGateId, projectId));
+ }
+
+ private Map<String, Object> selectionParams(long qGateId, long projectId) {
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put("gateId", Long.toString(qGateId));
+ params.put("projectId", Long.toString(projectId));
+ return params;
+ }
+
+
@SuppressWarnings({"rawtypes", "unchecked"})
private QualityGate jsonToQualityGate(String json) {
Map jsonRoot = (Map) JSONValue.parse(json);
entry("id", "666")
);
}
+
+ @Test
+ public void should_select_project() {
+ HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url());
+
+ httpServer.stubStatusCode(HttpURLConnection.HTTP_NO_CONTENT);
+
+ QualityGateClient client = new DefaultQualityGateClient(requestFactory);
+ client.selectProject(666L, 999L);
+
+ assertThat(httpServer.requestedPath()).isEqualTo("/api/qualitygates/select");
+ assertThat(httpServer.requestParams()).includes(
+ entry("gateId", "666"),
+ entry("projectId", "999")
+ );
+ }
+
+ @Test
+ public void should_deselect_project() {
+ HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url());
+
+ httpServer.stubStatusCode(HttpURLConnection.HTTP_NO_CONTENT);
+
+ QualityGateClient client = new DefaultQualityGateClient(requestFactory);
+ client.deselectProject(666L, 999L);
+
+ assertThat(httpServer.requestedPath()).isEqualTo("/api/qualitygates/deselect");
+ assertThat(httpServer.requestParams()).includes(
+ entry("gateId", "666"),
+ entry("projectId", "999")
+ );
+ }
}