diff --git a/self-core-impl/src/main/java/com/selfxdsd/core/EmptyIssues.java b/self-core-impl/src/main/java/com/selfxdsd/core/EmptyIssues.java deleted file mode 100644 index 884a6da0..00000000 --- a/self-core-impl/src/main/java/com/selfxdsd/core/EmptyIssues.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Copyright (c) 2020-2021, Self XDSD Contributors - * All rights reserved. - *
- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), - * to read the Software only. Permission is hereby NOT GRANTED to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software. - *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
- * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package com.selfxdsd.core;
-
-import com.selfxdsd.api.Issue;
-import com.selfxdsd.api.Issues;
-
-import javax.json.JsonObject;
-import java.util.Collections;
-import java.util.Iterator;
-
-/**
- * Empty issues representation.
- * @author criske
- * @version $Id$
- * @since 0.0.95
- */
-final class EmptyIssues implements Issues {
-
- @Override
- public Issue getById(final String issueId) {
- return null;
- }
-
- @Override
- public Issue received(final JsonObject issue) {
- return null;
- }
-
- @Override
- public Issue open(final String title,
- final String body,
- final String... labels) {
- return null;
- }
-
- @Override
- public Issues search(final String text, final String... labels) {
- return null;
- }
-
- @Override
- public Iterator
+ * Gitlab doc: link
+ */
@Override
public Issues enableIssues() {
- LOG.warn("Gitlab doesn't support enabling issues...");
- return new EmptyIssues();
+ final Resource response = this.resources().put(
+ this.repoUri(),
+ Json.createObjectBuilder()
+ .add("issues_access_level", "enabled")
+ .build()
+ );
+ if(response.statusCode() == HttpURLConnection.HTTP_OK) {
+ return this.issues();
+ } else {
+ throw new IllegalStateException(
+ "Could not enable Issues for Repo ["
+ + this.repoUri() + "]. Received Status is "
+ + response.statusCode() + ", while Status 200 OK"
+ + " was expected."
+ );
+ }
}
@Override
diff --git a/self-core-impl/src/test/java/com/selfxdsd/core/GitlabRepoTestCase.java b/self-core-impl/src/test/java/com/selfxdsd/core/GitlabRepoTestCase.java
index b99cc0a2..68d3601c 100644
--- a/self-core-impl/src/test/java/com/selfxdsd/core/GitlabRepoTestCase.java
+++ b/self-core-impl/src/test/java/com/selfxdsd/core/GitlabRepoTestCase.java
@@ -11,6 +11,7 @@
import org.mockito.Mockito;
import javax.json.Json;
+import javax.json.JsonValue;
import java.math.BigDecimal;
import java.net.URI;
@@ -240,19 +241,65 @@ public void returnsCommits() {
}
/**
- * Gitlab doesn't support enabling issues.
+ * GitlabRepo can enable issues.
*/
@Test
- public void doesNotSupportEnableIssues(){
+ public void canEnableIssues(){
+ final MockJsonResources res = new MockJsonResources(
+ request -> new MockJsonResources.MockResource(
+ 200,
+ Json.createObjectBuilder().build()
+ )
+ );
final Repo repo = new GitlabRepo(
- Mockito.mock(JsonResources.class),
+ res,
URI.create("https://gitlab.com/api/v4/projects/1"),
Mockito.mock(User.class),
Mockito.mock(Storage.class)
);
+
MatcherAssert.assertThat(
repo.enableIssues(),
- Matchers.instanceOf(EmptyIssues.class)
+ Matchers.instanceOf(Issues.class)
+ );
+
+ final MockJsonResources.MockRequest request = res.requests().first();
+ MatcherAssert.assertThat(
+ request.getUri(),
+ Matchers.equalTo(URI.create("https://gitlab.com/api/v4/projects/1"))
+ );
+ MatcherAssert.assertThat(
+ request.getMethod(),
+ Matchers.equalTo("PUT")
+ );
+ MatcherAssert.assertThat(
+ request.getBody(),
+ Matchers.equalTo(
+ Json.createObjectBuilder()
+ .add("issues_access_level", "enabled")
+ .build()
+ )
+ );
+ }
+
+ /**
+ * GitlabRepo throws IllegalStateException if enableIssues returns status
+ * != 200 OK.
+ */
+ @Test(expected = IllegalStateException.class)
+ public void throwsIllegalStateExceptionIfEnableIssueNotOk() {
+ final JsonResources res = new MockJsonResources(
+ request -> new MockJsonResources.MockResource(
+ 410,
+ JsonValue.EMPTY_JSON_OBJECT
+ )
+ );
+ final Repo repo = new GitlabRepo(
+ res,
+ URI.create("https://gitlab.com/api/v4/projects/1"),
+ Mockito.mock(User.class),
+ Mockito.mock(Storage.class)
);
+ repo.enableIssues();
}
}