From 65a3d8f86aa222206b09082d0c8da5ec0813011d Mon Sep 17 00:00:00 2001 From: padas2 Date: Sat, 8 Jun 2019 23:49:42 +0530 Subject: [PATCH 01/19] Added SupportApi to create Support Zip, Added Live test for supportApi as well, Need to create Mock Test and in-line supportApi tests --- .../cdancy/bitbucket/rest/BitbucketApi.java | 20 ++------ .../rest/domain/support/SupportZipTask.java | 34 +++++++++++++ .../bitbucket/rest/features/SupportApi.java | 22 +++++++++ .../rest/features/SupportApiLiveTest.java | 49 +++++++++++++++++++ .../rest/features/SystemApiLiveTest.java | 1 - 5 files changed, 109 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipTask.java create mode 100644 src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java create mode 100644 src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java diff --git a/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java b/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java index 2c0aae47..2f7c5626 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java @@ -19,22 +19,7 @@ import java.io.Closeable; -import com.cdancy.bitbucket.rest.features.AdminApi; -import com.cdancy.bitbucket.rest.features.BuildStatusApi; -import com.cdancy.bitbucket.rest.features.BranchApi; -import com.cdancy.bitbucket.rest.features.CommentsApi; -import com.cdancy.bitbucket.rest.features.CommitsApi; -import com.cdancy.bitbucket.rest.features.DefaultReviewersApi; -import com.cdancy.bitbucket.rest.features.FileApi; -import com.cdancy.bitbucket.rest.features.HookApi; -import com.cdancy.bitbucket.rest.features.ProjectApi; -import com.cdancy.bitbucket.rest.features.PullRequestApi; -import com.cdancy.bitbucket.rest.features.RepositoryApi; -import com.cdancy.bitbucket.rest.features.SyncApi; -import com.cdancy.bitbucket.rest.features.SystemApi; -import com.cdancy.bitbucket.rest.features.TagApi; -import com.cdancy.bitbucket.rest.features.TasksApi; -import com.cdancy.bitbucket.rest.features.WebHookApi; +import com.cdancy.bitbucket.rest.features.*; import org.jclouds.rest.annotations.Delegate; @@ -83,6 +68,9 @@ public interface BitbucketApi extends Closeable { @Delegate SystemApi systemApi(); + @Delegate + SupportApi supportApi(); + @Delegate TagApi tagApi(); diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipTask.java b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipTask.java new file mode 100644 index 00000000..5b9e1ca1 --- /dev/null +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipTask.java @@ -0,0 +1,34 @@ +package com.cdancy.bitbucket.rest.domain.support; + +import com.google.auto.value.AutoValue; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.json.SerializedNames; +import java.util.List; + +@AutoValue +public abstract class SupportZipTask { + public abstract String taskId(); + + public abstract Integer progressPercentage(); + + @Nullable + public abstract String progressMessage(); + + @Nullable + public abstract List warnings(); + + public abstract String status(); + + @SerializedNames({"taskId", "progressPercentage", "progressMessage", "warnings", "status"}) + public static SupportZipTask create(final String taskId, + final Integer progressPercentage, + final String progressMessage, + final List warnings, + final String status) { + return new AutoValue_SupportZipTask(taskId, + progressPercentage, + progressMessage, + warnings, + status); + } +} diff --git a/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java b/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java new file mode 100644 index 00000000..3d7f14b2 --- /dev/null +++ b/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java @@ -0,0 +1,22 @@ +package com.cdancy.bitbucket.rest.features; + +import com.cdancy.bitbucket.rest.domain.support.SupportZipTask; +import com.cdancy.bitbucket.rest.fallbacks.BitbucketFallbacks; +import com.cdancy.bitbucket.rest.filters.BitbucketAuthenticationFilter; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.RequestFilters; +import javax.inject.Named; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; + +@Produces(MediaType.APPLICATION_JSON) +@RequestFilters(BitbucketAuthenticationFilter.class) +@Path("/rest/troubleshooting/latest/support-zip") +@SuppressWarnings("PMD.AvoidDuplicateLiterals") +public interface SupportApi { + @Named("support-zip:create") + @Consumes(MediaType.APPLICATION_JSON) + @Path("/local") + @POST + SupportZipTask createSupportZip(); +} diff --git a/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java new file mode 100644 index 00000000..67ff3e9f --- /dev/null +++ b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java @@ -0,0 +1,49 @@ +package com.cdancy.bitbucket.rest.features; + +import com.cdancy.bitbucket.rest.BitbucketClient; +import com.cdancy.bitbucket.rest.domain.support.SupportZipTask; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +@Test(groups = "live", testName = "SupportApiLiveTest", singleThreaded = true) +public class SupportApiLiveTest { + @BeforeClass + private SupportApi api() { + BitbucketClient client = BitbucketClient.builder() + .endPoint("http://127.0.0.1:7990") + .credentials("engadmin:Pega2014") + .build(); + + return client.api().supportApi(); + } + + @Test + public void testSupportZipCreation() { + SupportZipTask supportZipTask = api().createSupportZip(); + assertIntegrity(supportZipTask); + } + + private void assertIntegrity(SupportZipTask supportZipTask) { + assertTaskId(supportZipTask.taskId()); + assertTaskProgressPercentage(supportZipTask.progressPercentage()); + assertTaskProgressMessage(supportZipTask.progressMessage()); + assertTaskStatus(supportZipTask.status()); + } + + private void assertTaskProgressMessage(String progressMessage) { + Assert.assertNotNull(progressMessage); + } + + private void assertTaskStatus(String status) { + Assert.assertTrue(!status.isEmpty()); + } + + private void assertTaskId(String taskId) { + Assert.assertNotNull(taskId); + } + + private void assertTaskProgressPercentage(Integer progressPercentage) { + Assert.assertNotNull(progressPercentage); + } +} diff --git a/src/test/java/com/cdancy/bitbucket/rest/features/SystemApiLiveTest.java b/src/test/java/com/cdancy/bitbucket/rest/features/SystemApiLiveTest.java index 9d1f7865..b7074dfc 100644 --- a/src/test/java/com/cdancy/bitbucket/rest/features/SystemApiLiveTest.java +++ b/src/test/java/com/cdancy/bitbucket/rest/features/SystemApiLiveTest.java @@ -20,7 +20,6 @@ import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.Test; - import com.cdancy.bitbucket.rest.BaseBitbucketApiLiveTest; import com.cdancy.bitbucket.rest.domain.system.Version; From 76890627ce0080868e7493c6576274b7850e0fd4 Mon Sep 17 00:00:00 2001 From: padas2 Date: Sat, 8 Jun 2019 23:53:34 +0530 Subject: [PATCH 02/19] Adding back unintentionally removed imports --- .../cdancy/bitbucket/rest/BitbucketApi.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java b/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java index 2f7c5626..039564b9 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java @@ -18,10 +18,22 @@ package com.cdancy.bitbucket.rest; import java.io.Closeable; - -import com.cdancy.bitbucket.rest.features.*; - - +import com.cdancy.bitbucket.rest.features.AdminApi; +import com.cdancy.bitbucket.rest.features.BuildStatusApi; +import com.cdancy.bitbucket.rest.features.BranchApi; +import com.cdancy.bitbucket.rest.features.CommentsApi; +import com.cdancy.bitbucket.rest.features.CommitsApi; +import com.cdancy.bitbucket.rest.features.DefaultReviewersApi; +import com.cdancy.bitbucket.rest.features.FileApi; +import com.cdancy.bitbucket.rest.features.HookApi; +import com.cdancy.bitbucket.rest.features.ProjectApi; +import com.cdancy.bitbucket.rest.features.PullRequestApi; +import com.cdancy.bitbucket.rest.features.RepositoryApi; +import com.cdancy.bitbucket.rest.features.SyncApi; +import com.cdancy.bitbucket.rest.features.SystemApi; +import com.cdancy.bitbucket.rest.features.TagApi; +import com.cdancy.bitbucket.rest.features.TasksApi; +import com.cdancy.bitbucket.rest.features.WebHookApi; import org.jclouds.rest.annotations.Delegate; public interface BitbucketApi extends Closeable { From 39c70d1b8c520dd76433922509cd25cac4763939 Mon Sep 17 00:00:00 2001 From: padas2 Date: Sat, 8 Jun 2019 23:54:36 +0530 Subject: [PATCH 03/19] Removing custom credentials --- .../com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java index 67ff3e9f..0d660b8e 100644 --- a/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java +++ b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java @@ -12,7 +12,7 @@ public class SupportApiLiveTest { private SupportApi api() { BitbucketClient client = BitbucketClient.builder() .endPoint("http://127.0.0.1:7990") - .credentials("engadmin:Pega2014") + .credentials("admin-user:admin-pwd") .build(); return client.api().supportApi(); From bf3a0f8f30ad338d39a48e14ed87ba56dc08b97b Mon Sep 17 00:00:00 2001 From: padas2 Date: Sun, 9 Jun 2019 00:49:23 +0530 Subject: [PATCH 04/19] Started work on getting task status --- .../cdancy/bitbucket/rest/BitbucketApi.java | 18 +-------- .../rest/domain/support/SupportZip.java | 40 +++++++++++++++++++ .../bitbucket/rest/features/SupportApi.java | 7 ++++ .../rest/features/SupportApiLiveTest.java | 18 ++++++++- 4 files changed, 66 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java diff --git a/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java b/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java index 039564b9..9bd1e4ea 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java @@ -18,22 +18,8 @@ package com.cdancy.bitbucket.rest; import java.io.Closeable; -import com.cdancy.bitbucket.rest.features.AdminApi; -import com.cdancy.bitbucket.rest.features.BuildStatusApi; -import com.cdancy.bitbucket.rest.features.BranchApi; -import com.cdancy.bitbucket.rest.features.CommentsApi; -import com.cdancy.bitbucket.rest.features.CommitsApi; -import com.cdancy.bitbucket.rest.features.DefaultReviewersApi; -import com.cdancy.bitbucket.rest.features.FileApi; -import com.cdancy.bitbucket.rest.features.HookApi; -import com.cdancy.bitbucket.rest.features.ProjectApi; -import com.cdancy.bitbucket.rest.features.PullRequestApi; -import com.cdancy.bitbucket.rest.features.RepositoryApi; -import com.cdancy.bitbucket.rest.features.SyncApi; -import com.cdancy.bitbucket.rest.features.SystemApi; -import com.cdancy.bitbucket.rest.features.TagApi; -import com.cdancy.bitbucket.rest.features.TasksApi; -import com.cdancy.bitbucket.rest.features.WebHookApi; + +import com.cdancy.bitbucket.rest.features.*; import org.jclouds.rest.annotations.Delegate; public interface BitbucketApi extends Closeable { diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java new file mode 100644 index 00000000..85ddda25 --- /dev/null +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java @@ -0,0 +1,40 @@ +package com.cdancy.bitbucket.rest.domain.support; + +import com.google.auto.value.AutoValue; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.json.SerializedNames; + +import java.util.List; + +@AutoValue +public abstract class SupportZip { + public abstract String taskId(); + + public abstract Integer progressPercentage(); + + @Nullable + public abstract String progressMessage(); + + @Nullable + public abstract List warnings(); + + public abstract String status(); + + public abstract String fileName(); + + @SerializedNames({"taskId", "progressPercentage", "progressMessage", "warnings", "status", "fileName"}) + public static SupportZip create(final String taskId, + final Integer progressPercentage, + final String progressMessage, + final List warnings, + final String status, + final String fileName) { + return new AutoValue_SupportZip(taskId, + progressPercentage, + progressMessage, + warnings, + status, + fileName); + } + +} diff --git a/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java b/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java index 3d7f14b2..15cbe604 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java @@ -1,5 +1,6 @@ package com.cdancy.bitbucket.rest.features; +import com.cdancy.bitbucket.rest.domain.support.SupportZip; import com.cdancy.bitbucket.rest.domain.support.SupportZipTask; import com.cdancy.bitbucket.rest.fallbacks.BitbucketFallbacks; import com.cdancy.bitbucket.rest.filters.BitbucketAuthenticationFilter; @@ -19,4 +20,10 @@ public interface SupportApi { @Path("/local") @POST SupportZipTask createSupportZip(); + + @Named("support-zip:status") + @Consumes(MediaType.APPLICATION_JSON) + @Path("/status/task/{taskId}") + @GET + SupportZip getSupportZip(final String taskId); } diff --git a/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java index 0d660b8e..e99c7a9e 100644 --- a/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java +++ b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java @@ -1,6 +1,7 @@ package com.cdancy.bitbucket.rest.features; import com.cdancy.bitbucket.rest.BitbucketClient; +import com.cdancy.bitbucket.rest.domain.support.SupportZip; import com.cdancy.bitbucket.rest.domain.support.SupportZipTask; import org.testng.Assert; import org.testng.annotations.BeforeClass; @@ -12,7 +13,7 @@ public class SupportApiLiveTest { private SupportApi api() { BitbucketClient client = BitbucketClient.builder() .endPoint("http://127.0.0.1:7990") - .credentials("admin-user:admin-pwd") + .credentials("engadmin:Pega2014") .build(); return client.api().supportApi(); @@ -24,6 +25,21 @@ public void testSupportZipCreation() { assertIntegrity(supportZipTask); } + @Test + public void testSupportZip() { + SupportZipTask supportZipTask = api().createSupportZip(); + SupportZip supportZip = api().getSupportZip(supportZipTask.taskId()); + assertIntegrity(supportZip); + } + + private void assertIntegrity(SupportZip supportZip) { + assertTaskId(supportZip.taskId()); + assertTaskProgressMessage(supportZip.progressMessage()); + assertTaskProgressPercentage(supportZip.progressPercentage()); + assertTaskStatus(supportZip.status()); + Assert.assertNotNull(supportZip.fileName()); + } + private void assertIntegrity(SupportZipTask supportZipTask) { assertTaskId(supportZipTask.taskId()); assertTaskProgressPercentage(supportZipTask.progressPercentage()); From 3d2f99f535a84eef400a2701376bc47be2385ea4 Mon Sep 17 00:00:00 2001 From: padas2 Date: Mon, 10 Jun 2019 11:07:21 +0530 Subject: [PATCH 05/19] Renaming SupportZipTask to SupportZipDetails, refactoring code to follow HAS-A pattern to avoid duplication --- .../rest/domain/support/SupportZip.java | 33 +++---------------- ...ortZipTask.java => SupportZipDetails.java} | 14 ++++---- .../bitbucket/rest/features/SupportApi.java | 8 ++--- .../rest/features/SupportApiLiveTest.java | 33 ++++++++----------- 4 files changed, 28 insertions(+), 60 deletions(-) rename src/main/java/com/cdancy/bitbucket/rest/domain/support/{SupportZipTask.java => SupportZipDetails.java} (63%) diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java index 85ddda25..63b203ab 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java @@ -1,40 +1,17 @@ package com.cdancy.bitbucket.rest.domain.support; import com.google.auto.value.AutoValue; -import org.jclouds.javax.annotation.Nullable; import org.jclouds.json.SerializedNames; -import java.util.List; - @AutoValue public abstract class SupportZip { - public abstract String taskId(); - - public abstract Integer progressPercentage(); - - @Nullable - public abstract String progressMessage(); - - @Nullable - public abstract List warnings(); - - public abstract String status(); - public abstract String fileName(); - @SerializedNames({"taskId", "progressPercentage", "progressMessage", "warnings", "status", "fileName"}) - public static SupportZip create(final String taskId, - final Integer progressPercentage, - final String progressMessage, - final List warnings, - final String status, - final String fileName) { - return new AutoValue_SupportZip(taskId, - progressPercentage, - progressMessage, - warnings, - status, - fileName); + //public abstract SupportZipDetails details(); + + @SerializedNames({"fileName"}) + public static SupportZip create(final String fileName) { + return new AutoValue_SupportZip(fileName); } } diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipTask.java b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipDetails.java similarity index 63% rename from src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipTask.java rename to src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipDetails.java index 5b9e1ca1..9f538a30 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipTask.java +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipDetails.java @@ -6,7 +6,7 @@ import java.util.List; @AutoValue -public abstract class SupportZipTask { +public abstract class SupportZipDetails { public abstract String taskId(); public abstract Integer progressPercentage(); @@ -20,12 +20,12 @@ public abstract class SupportZipTask { public abstract String status(); @SerializedNames({"taskId", "progressPercentage", "progressMessage", "warnings", "status"}) - public static SupportZipTask create(final String taskId, - final Integer progressPercentage, - final String progressMessage, - final List warnings, - final String status) { - return new AutoValue_SupportZipTask(taskId, + public static SupportZipDetails create(final String taskId, + final Integer progressPercentage, + final String progressMessage, + final List warnings, + final String status) { + return new AutoValue_SupportZipDetails(taskId, progressPercentage, progressMessage, warnings, diff --git a/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java b/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java index 15cbe604..67edb787 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java @@ -1,10 +1,8 @@ package com.cdancy.bitbucket.rest.features; import com.cdancy.bitbucket.rest.domain.support.SupportZip; -import com.cdancy.bitbucket.rest.domain.support.SupportZipTask; -import com.cdancy.bitbucket.rest.fallbacks.BitbucketFallbacks; +import com.cdancy.bitbucket.rest.domain.support.SupportZipDetails; import com.cdancy.bitbucket.rest.filters.BitbucketAuthenticationFilter; -import org.jclouds.rest.annotations.Fallback; import org.jclouds.rest.annotations.RequestFilters; import javax.inject.Named; import javax.ws.rs.*; @@ -19,11 +17,11 @@ public interface SupportApi { @Consumes(MediaType.APPLICATION_JSON) @Path("/local") @POST - SupportZipTask createSupportZip(); + SupportZipDetails createSupportZip(); @Named("support-zip:status") @Consumes(MediaType.APPLICATION_JSON) @Path("/status/task/{taskId}") @GET - SupportZip getSupportZip(final String taskId); + SupportZip getSupportZip(@PathParam("taskId") String taskId); } diff --git a/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java index e99c7a9e..8831e167 100644 --- a/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java +++ b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java @@ -1,46 +1,39 @@ package com.cdancy.bitbucket.rest.features; -import com.cdancy.bitbucket.rest.BitbucketClient; +import com.cdancy.bitbucket.rest.BaseBitbucketApiLiveTest; import com.cdancy.bitbucket.rest.domain.support.SupportZip; -import com.cdancy.bitbucket.rest.domain.support.SupportZipTask; +import com.cdancy.bitbucket.rest.domain.support.SupportZipDetails; import org.testng.Assert; -import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @Test(groups = "live", testName = "SupportApiLiveTest", singleThreaded = true) -public class SupportApiLiveTest { - @BeforeClass +public class SupportApiLiveTest extends BaseBitbucketApiLiveTest{ private SupportApi api() { - BitbucketClient client = BitbucketClient.builder() - .endPoint("http://127.0.0.1:7990") - .credentials("engadmin:Pega2014") - .build(); - - return client.api().supportApi(); + return api.supportApi(); } @Test public void testSupportZipCreation() { - SupportZipTask supportZipTask = api().createSupportZip(); - assertIntegrity(supportZipTask); + SupportZipDetails supportZipDetails = api().createSupportZip(); + assertIntegrity(supportZipDetails); } @Test public void testSupportZip() { - SupportZipTask supportZipTask = api().createSupportZip(); - SupportZip supportZip = api().getSupportZip(supportZipTask.taskId()); + SupportZipDetails supportZipDetails = api().createSupportZip(); + SupportZip supportZip = api().getSupportZip(supportZipDetails.taskId()); assertIntegrity(supportZip); } private void assertIntegrity(SupportZip supportZip) { - assertTaskId(supportZip.taskId()); - assertTaskProgressMessage(supportZip.progressMessage()); - assertTaskProgressPercentage(supportZip.progressPercentage()); - assertTaskStatus(supportZip.status()); + /*assertTaskId(supportZip.details().taskId()); + assertTaskProgressMessage(supportZip.details().progressMessage()); + assertTaskProgressPercentage(supportZip.details().progressPercentage()); + assertTaskStatus(supportZip.details().status());*/ Assert.assertNotNull(supportZip.fileName()); } - private void assertIntegrity(SupportZipTask supportZipTask) { + private void assertIntegrity(SupportZipDetails supportZipTask) { assertTaskId(supportZipTask.taskId()); assertTaskProgressPercentage(supportZipTask.progressPercentage()); assertTaskProgressMessage(supportZipTask.progressMessage()); From a97730d39e62e5be4d6c0096a42c9d886eab1fb4 Mon Sep 17 00:00:00 2001 From: padas2 Date: Mon, 10 Jun 2019 11:55:25 +0530 Subject: [PATCH 06/19] Renaming SupportZip to SupportZipStatus, tried to use HAS-A pattern, but looks like autovalue does not allow it, need to investigate more --- .../rest/domain/support/SupportZip.java | 17 -------- .../rest/domain/support/SupportZipStatus.java | 39 +++++++++++++++++++ .../bitbucket/rest/features/SupportApi.java | 4 +- .../rest/features/SupportApiLiveTest.java | 22 +++++------ 4 files changed, 52 insertions(+), 30 deletions(-) delete mode 100644 src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java create mode 100644 src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipStatus.java diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java deleted file mode 100644 index 63b203ab..00000000 --- a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.cdancy.bitbucket.rest.domain.support; - -import com.google.auto.value.AutoValue; -import org.jclouds.json.SerializedNames; - -@AutoValue -public abstract class SupportZip { - public abstract String fileName(); - - //public abstract SupportZipDetails details(); - - @SerializedNames({"fileName"}) - public static SupportZip create(final String fileName) { - return new AutoValue_SupportZip(fileName); - } - -} diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipStatus.java b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipStatus.java new file mode 100644 index 00000000..46dac607 --- /dev/null +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipStatus.java @@ -0,0 +1,39 @@ +package com.cdancy.bitbucket.rest.domain.support; + +import com.google.auto.value.AutoValue; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.json.SerializedNames; + +import java.util.List; + +@AutoValue +public abstract class SupportZipStatus { + public abstract String taskId(); + + public abstract Integer progressPercentage(); + + @Nullable + public abstract String progressMessage(); + + @Nullable + public abstract List warnings(); + + public abstract String status(); + + public abstract String fileName(); + + @SerializedNames({"taskId", "progressPercentage", "progressMessage", "warnings", "status", "fileName"}) + public static SupportZipStatus create(final String taskId, + final Integer progressPercentage, + final String progressMessage, + final List warnings, + final String status, final String fileName) { + return new AutoValue_SupportZipStatus(taskId, + progressPercentage, + progressMessage, + warnings, + status, + fileName); + } + +} diff --git a/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java b/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java index 67edb787..48638c8d 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java @@ -1,6 +1,6 @@ package com.cdancy.bitbucket.rest.features; -import com.cdancy.bitbucket.rest.domain.support.SupportZip; +import com.cdancy.bitbucket.rest.domain.support.SupportZipStatus; import com.cdancy.bitbucket.rest.domain.support.SupportZipDetails; import com.cdancy.bitbucket.rest.filters.BitbucketAuthenticationFilter; import org.jclouds.rest.annotations.RequestFilters; @@ -23,5 +23,5 @@ public interface SupportApi { @Consumes(MediaType.APPLICATION_JSON) @Path("/status/task/{taskId}") @GET - SupportZip getSupportZip(@PathParam("taskId") String taskId); + SupportZipStatus getSupportZipStatus(@PathParam("taskId") String taskId); } diff --git a/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java index 8831e167..438a29f1 100644 --- a/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java +++ b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java @@ -1,7 +1,7 @@ package com.cdancy.bitbucket.rest.features; import com.cdancy.bitbucket.rest.BaseBitbucketApiLiveTest; -import com.cdancy.bitbucket.rest.domain.support.SupportZip; +import com.cdancy.bitbucket.rest.domain.support.SupportZipStatus; import com.cdancy.bitbucket.rest.domain.support.SupportZipDetails; import org.testng.Assert; import org.testng.annotations.Test; @@ -14,22 +14,22 @@ private SupportApi api() { @Test public void testSupportZipCreation() { - SupportZipDetails supportZipDetails = api().createSupportZip(); - assertIntegrity(supportZipDetails); + SupportZipDetails details = api().createSupportZip(); + assertIntegrity(details); } @Test - public void testSupportZip() { - SupportZipDetails supportZipDetails = api().createSupportZip(); - SupportZip supportZip = api().getSupportZip(supportZipDetails.taskId()); + public void testSupportZipStatus() { + SupportZipDetails details = api().createSupportZip(); + SupportZipStatus supportZip = api().getSupportZipStatus(details.taskId()); assertIntegrity(supportZip); } - private void assertIntegrity(SupportZip supportZip) { - /*assertTaskId(supportZip.details().taskId()); - assertTaskProgressMessage(supportZip.details().progressMessage()); - assertTaskProgressPercentage(supportZip.details().progressPercentage()); - assertTaskStatus(supportZip.details().status());*/ + private void assertIntegrity(SupportZipStatus supportZip) { + assertTaskId(supportZip.taskId()); + assertTaskProgressMessage(supportZip.progressMessage()); + assertTaskProgressPercentage(supportZip.progressPercentage()); + assertTaskStatus(supportZip.status()); Assert.assertNotNull(supportZip.fileName()); } From 39707c400b60c696648cc0048c368bf4935a65ff Mon Sep 17 00:00:00 2001 From: padas2 Date: Mon, 10 Jun 2019 11:58:37 +0530 Subject: [PATCH 07/19] Removing changes introduced by IDE --- .../cdancy/bitbucket/rest/BitbucketApi.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java b/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java index 9bd1e4ea..74104974 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java @@ -18,12 +18,25 @@ package com.cdancy.bitbucket.rest; import java.io.Closeable; - -import com.cdancy.bitbucket.rest.features.*; +import com.cdancy.bitbucket.rest.features.AdminApi; +import com.cdancy.bitbucket.rest.features.BuildStatusApi; +import com.cdancy.bitbucket.rest.features.BranchApi; +import com.cdancy.bitbucket.rest.features.CommentsApi; +import com.cdancy.bitbucket.rest.features.CommitsApi; +import com.cdancy.bitbucket.rest.features.DefaultReviewersApi; +import com.cdancy.bitbucket.rest.features.FileApi; +import com.cdancy.bitbucket.rest.features.HookApi; +import com.cdancy.bitbucket.rest.features.ProjectApi; +import com.cdancy.bitbucket.rest.features.PullRequestApi; +import com.cdancy.bitbucket.rest.features.RepositoryApi; +import com.cdancy.bitbucket.rest.features.SyncApi; +import com.cdancy.bitbucket.rest.features.SystemApi; +import com.cdancy.bitbucket.rest.features.TagApi; +import com.cdancy.bitbucket.rest.features.TasksApi; +import com.cdancy.bitbucket.rest.features.WebHookApi; import org.jclouds.rest.annotations.Delegate; public interface BitbucketApi extends Closeable { - @Delegate AdminApi adminApi(); From d3d2c8baff1833c5d7105741bcbe75e43dfba4cf Mon Sep 17 00:00:00 2001 From: padas2 Date: Mon, 10 Jun 2019 12:00:02 +0530 Subject: [PATCH 08/19] Removing unecessary empty lines --- .../cdancy/bitbucket/rest/domain/support/SupportZipStatus.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipStatus.java b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipStatus.java index 46dac607..a4f30e77 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipStatus.java +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipStatus.java @@ -3,7 +3,6 @@ import com.google.auto.value.AutoValue; import org.jclouds.javax.annotation.Nullable; import org.jclouds.json.SerializedNames; - import java.util.List; @AutoValue From 931361213a96eda9a0bb7d9129c28c448ee1449b Mon Sep 17 00:00:00 2001 From: padas2 Date: Mon, 10 Jun 2019 12:16:50 +0530 Subject: [PATCH 09/19] Again adding code removed by IDE --- .../cdancy/bitbucket/rest/BitbucketApi.java | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java b/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java index 74104974..d35fdf37 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java @@ -18,22 +18,8 @@ package com.cdancy.bitbucket.rest; import java.io.Closeable; -import com.cdancy.bitbucket.rest.features.AdminApi; -import com.cdancy.bitbucket.rest.features.BuildStatusApi; -import com.cdancy.bitbucket.rest.features.BranchApi; -import com.cdancy.bitbucket.rest.features.CommentsApi; -import com.cdancy.bitbucket.rest.features.CommitsApi; -import com.cdancy.bitbucket.rest.features.DefaultReviewersApi; -import com.cdancy.bitbucket.rest.features.FileApi; -import com.cdancy.bitbucket.rest.features.HookApi; -import com.cdancy.bitbucket.rest.features.ProjectApi; -import com.cdancy.bitbucket.rest.features.PullRequestApi; -import com.cdancy.bitbucket.rest.features.RepositoryApi; -import com.cdancy.bitbucket.rest.features.SyncApi; -import com.cdancy.bitbucket.rest.features.SystemApi; -import com.cdancy.bitbucket.rest.features.TagApi; -import com.cdancy.bitbucket.rest.features.TasksApi; -import com.cdancy.bitbucket.rest.features.WebHookApi; + +import com.cdancy.bitbucket.rest.features.*; import org.jclouds.rest.annotations.Delegate; public interface BitbucketApi extends Closeable { From e96591f576a63b207da3d2da391c7f6ada64c9d0 Mon Sep 17 00:00:00 2001 From: padas2 Date: Mon, 10 Jun 2019 12:38:25 +0530 Subject: [PATCH 10/19] Removed all windows line endings --- .../com/cdancy/bitbucket/rest/features/SupportApi.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java b/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java index 48638c8d..1a5043c0 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java @@ -5,7 +5,12 @@ import com.cdancy.bitbucket.rest.filters.BitbucketAuthenticationFilter; import org.jclouds.rest.annotations.RequestFilters; import javax.inject.Named; -import javax.ws.rs.*; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; @Produces(MediaType.APPLICATION_JSON) From 611d00c2fe4ab383fd52edbf186991adaf964fae Mon Sep 17 00:00:00 2001 From: padas2 Date: Mon, 10 Jun 2019 12:42:03 +0530 Subject: [PATCH 11/19] restoring ide removed commits --- .../cdancy/bitbucket/rest/BitbucketApi.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java b/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java index d35fdf37..c6272f7a 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java @@ -19,7 +19,23 @@ import java.io.Closeable; -import com.cdancy.bitbucket.rest.features.*; +import com.cdancy.bitbucket.rest.features.AdminApi; +import com.cdancy.bitbucket.rest.features.BuildStatusApi; +import com.cdancy.bitbucket.rest.features.BranchApi; +import com.cdancy.bitbucket.rest.features.CommentsApi; +import com.cdancy.bitbucket.rest.features.CommitsApi; +import com.cdancy.bitbucket.rest.features.DefaultReviewersApi; +import com.cdancy.bitbucket.rest.features.FileApi; +import com.cdancy.bitbucket.rest.features.HookApi; +import com.cdancy.bitbucket.rest.features.ProjectApi; +import com.cdancy.bitbucket.rest.features.PullRequestApi; +import com.cdancy.bitbucket.rest.features.RepositoryApi; +import com.cdancy.bitbucket.rest.features.SyncApi; +import com.cdancy.bitbucket.rest.features.SystemApi; +import com.cdancy.bitbucket.rest.features.TagApi; +import com.cdancy.bitbucket.rest.features.TasksApi; +import com.cdancy.bitbucket.rest.features.WebHookApi; +import com.cdancy.bitbucket.rest.features.SupportApi; import org.jclouds.rest.annotations.Delegate; public interface BitbucketApi extends Closeable { From b40793db225784c6f4d28bfdf04464f3b779107c Mon Sep 17 00:00:00 2001 From: padas2 Date: Mon, 10 Jun 2019 12:45:21 +0530 Subject: [PATCH 12/19] Adding licensing info --- .../rest/domain/support/SupportZipDetails.java | 17 +++++++++++++++++ .../rest/domain/support/SupportZipStatus.java | 17 +++++++++++++++++ .../bitbucket/rest/features/SupportApi.java | 17 +++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipDetails.java b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipDetails.java index 9f538a30..89ee9382 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipDetails.java +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipDetails.java @@ -1,3 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.cdancy.bitbucket.rest.domain.support; import com.google.auto.value.AutoValue; diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipStatus.java b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipStatus.java index a4f30e77..1e708ba2 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipStatus.java +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipStatus.java @@ -1,3 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.cdancy.bitbucket.rest.domain.support; import com.google.auto.value.AutoValue; diff --git a/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java b/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java index 1a5043c0..0b8051e0 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java @@ -1,3 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.cdancy.bitbucket.rest.features; import com.cdancy.bitbucket.rest.domain.support.SupportZipStatus; From eca9dcdd09f6b71b8aee8a71e466e1490ad68843 Mon Sep 17 00:00:00 2001 From: padas2 Date: Mon, 10 Jun 2019 13:15:00 +0530 Subject: [PATCH 13/19] Fixing PMD violations --- .../rest/features/SupportApiLiveTest.java | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java index 438a29f1..0380a06f 100644 --- a/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java +++ b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java @@ -1,3 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.cdancy.bitbucket.rest.features; import com.cdancy.bitbucket.rest.BaseBitbucketApiLiveTest; @@ -7,25 +24,25 @@ import org.testng.annotations.Test; @Test(groups = "live", testName = "SupportApiLiveTest", singleThreaded = true) -public class SupportApiLiveTest extends BaseBitbucketApiLiveTest{ +public class SupportApiLiveTest extends BaseBitbucketApiLiveTest { private SupportApi api() { return api.supportApi(); } @Test public void testSupportZipCreation() { - SupportZipDetails details = api().createSupportZip(); + final SupportZipDetails details = api().createSupportZip(); assertIntegrity(details); } @Test public void testSupportZipStatus() { - SupportZipDetails details = api().createSupportZip(); - SupportZipStatus supportZip = api().getSupportZipStatus(details.taskId()); + final SupportZipDetails details = api().createSupportZip(); + final SupportZipStatus supportZip = api().getSupportZipStatus(details.taskId()); assertIntegrity(supportZip); } - private void assertIntegrity(SupportZipStatus supportZip) { + private void assertIntegrity(final SupportZipStatus supportZip) { assertTaskId(supportZip.taskId()); assertTaskProgressMessage(supportZip.progressMessage()); assertTaskProgressPercentage(supportZip.progressPercentage()); @@ -33,26 +50,26 @@ private void assertIntegrity(SupportZipStatus supportZip) { Assert.assertNotNull(supportZip.fileName()); } - private void assertIntegrity(SupportZipDetails supportZipTask) { + private void assertIntegrity(final SupportZipDetails supportZipTask) { assertTaskId(supportZipTask.taskId()); assertTaskProgressPercentage(supportZipTask.progressPercentage()); assertTaskProgressMessage(supportZipTask.progressMessage()); assertTaskStatus(supportZipTask.status()); } - private void assertTaskProgressMessage(String progressMessage) { + private void assertTaskProgressMessage(final String progressMessage) { Assert.assertNotNull(progressMessage); } - private void assertTaskStatus(String status) { + private void assertTaskStatus(final String status) { Assert.assertTrue(!status.isEmpty()); } - private void assertTaskId(String taskId) { + private void assertTaskId(final String taskId) { Assert.assertNotNull(taskId); } - private void assertTaskProgressPercentage(Integer progressPercentage) { + private void assertTaskProgressPercentage(final Integer progressPercentage) { Assert.assertNotNull(progressPercentage); } } From a3726ae9e320a7ef6980eb3343cc1a0882ab7b74 Mon Sep 17 00:00:00 2001 From: padas2 Date: Wed, 12 Jun 2019 11:43:14 +0530 Subject: [PATCH 14/19] Adding whitespace between class name and top most annotation, Adding documentation detail annotation tag --- .../java/com/cdancy/bitbucket/rest/features/SupportApi.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java b/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java index 0b8051e0..07450b60 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java @@ -17,6 +17,7 @@ package com.cdancy.bitbucket.rest.features; +import com.cdancy.bitbucket.rest.annotations.Documentation; import com.cdancy.bitbucket.rest.domain.support.SupportZipStatus; import com.cdancy.bitbucket.rest.domain.support.SupportZipDetails; import com.cdancy.bitbucket.rest.filters.BitbucketAuthenticationFilter; @@ -35,13 +36,16 @@ @Path("/rest/troubleshooting/latest/support-zip") @SuppressWarnings("PMD.AvoidDuplicateLiterals") public interface SupportApi { + @Named("support-zip:create") + @Documentation("https://confluence.atlassian.com/support/create-a-support-zip-using-the-rest-api-in-server-applications-947857090.html#CreateasupportzipusingtheRESTAPIinServerapplications-Generateasupportzip") @Consumes(MediaType.APPLICATION_JSON) @Path("/local") @POST SupportZipDetails createSupportZip(); @Named("support-zip:status") + @Documentation("https://confluence.atlassian.com/support/create-a-support-zip-using-the-rest-api-in-server-applications-947857090.html#CreateasupportzipusingtheRESTAPIinServerapplications-Checktheprogressofthetask") @Consumes(MediaType.APPLICATION_JSON) @Path("/status/task/{taskId}") @GET From 6d6b0966eba3a79da0e5b82f37db8f12394e2feb Mon Sep 17 00:00:00 2001 From: padas2 Date: Mon, 17 Jun 2019 01:45:18 +0530 Subject: [PATCH 15/19] A Rather big commit containing following changes: Changed SupportApi calls to use only one object type, Added mock tests for both Support Api calls, Added test resources as well --- ...{SupportZipStatus.java => SupportZip.java} | 9 ++- .../domain/support/SupportZipDetails.java | 51 ------------- .../bitbucket/rest/features/SupportApi.java | 7 +- .../rest/features/SupportApiLiveTest.java | 24 +++---- .../rest/features/SupportApiMockTest.java | 71 +++++++++++++++++++ src/test/resources/support-zip-create.json | 7 ++ .../resources/support-zip-request-status.json | 8 +++ 7 files changed, 103 insertions(+), 74 deletions(-) rename src/main/java/com/cdancy/bitbucket/rest/domain/support/{SupportZipStatus.java => SupportZip.java} (92%) delete mode 100644 src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipDetails.java create mode 100644 src/test/java/com/cdancy/bitbucket/rest/features/SupportApiMockTest.java create mode 100644 src/test/resources/support-zip-create.json create mode 100644 src/test/resources/support-zip-request-status.json diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipStatus.java b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java similarity index 92% rename from src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipStatus.java rename to src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java index 1e708ba2..81fa14dd 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipStatus.java +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java @@ -23,28 +23,27 @@ import java.util.List; @AutoValue -public abstract class SupportZipStatus { +public abstract class SupportZip { public abstract String taskId(); public abstract Integer progressPercentage(); - @Nullable public abstract String progressMessage(); - @Nullable public abstract List warnings(); public abstract String status(); + @Nullable public abstract String fileName(); @SerializedNames({"taskId", "progressPercentage", "progressMessage", "warnings", "status", "fileName"}) - public static SupportZipStatus create(final String taskId, + public static SupportZip create(final String taskId, final Integer progressPercentage, final String progressMessage, final List warnings, final String status, final String fileName) { - return new AutoValue_SupportZipStatus(taskId, + return new AutoValue_SupportZip(taskId, progressPercentage, progressMessage, warnings, diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipDetails.java b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipDetails.java deleted file mode 100644 index 89ee9382..00000000 --- a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZipDetails.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.cdancy.bitbucket.rest.domain.support; - -import com.google.auto.value.AutoValue; -import org.jclouds.javax.annotation.Nullable; -import org.jclouds.json.SerializedNames; -import java.util.List; - -@AutoValue -public abstract class SupportZipDetails { - public abstract String taskId(); - - public abstract Integer progressPercentage(); - - @Nullable - public abstract String progressMessage(); - - @Nullable - public abstract List warnings(); - - public abstract String status(); - - @SerializedNames({"taskId", "progressPercentage", "progressMessage", "warnings", "status"}) - public static SupportZipDetails create(final String taskId, - final Integer progressPercentage, - final String progressMessage, - final List warnings, - final String status) { - return new AutoValue_SupportZipDetails(taskId, - progressPercentage, - progressMessage, - warnings, - status); - } -} diff --git a/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java b/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java index 07450b60..f1694ff0 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java @@ -18,8 +18,7 @@ package com.cdancy.bitbucket.rest.features; import com.cdancy.bitbucket.rest.annotations.Documentation; -import com.cdancy.bitbucket.rest.domain.support.SupportZipStatus; -import com.cdancy.bitbucket.rest.domain.support.SupportZipDetails; +import com.cdancy.bitbucket.rest.domain.support.SupportZip; import com.cdancy.bitbucket.rest.filters.BitbucketAuthenticationFilter; import org.jclouds.rest.annotations.RequestFilters; import javax.inject.Named; @@ -42,12 +41,12 @@ public interface SupportApi { @Consumes(MediaType.APPLICATION_JSON) @Path("/local") @POST - SupportZipDetails createSupportZip(); + SupportZip createSupportZip(); @Named("support-zip:status") @Documentation("https://confluence.atlassian.com/support/create-a-support-zip-using-the-rest-api-in-server-applications-947857090.html#CreateasupportzipusingtheRESTAPIinServerapplications-Checktheprogressofthetask") @Consumes(MediaType.APPLICATION_JSON) @Path("/status/task/{taskId}") @GET - SupportZipStatus getSupportZipStatus(@PathParam("taskId") String taskId); + SupportZip getSupportZipStatus(@PathParam("taskId") String taskId); } diff --git a/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java index 0380a06f..7ad0d878 100644 --- a/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java +++ b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java @@ -17,40 +17,35 @@ package com.cdancy.bitbucket.rest.features; +import static org.assertj.core.api.Assertions.assertThat; import com.cdancy.bitbucket.rest.BaseBitbucketApiLiveTest; -import com.cdancy.bitbucket.rest.domain.support.SupportZipStatus; -import com.cdancy.bitbucket.rest.domain.support.SupportZipDetails; +import com.cdancy.bitbucket.rest.domain.support.SupportZip; import org.testng.Assert; import org.testng.annotations.Test; @Test(groups = "live", testName = "SupportApiLiveTest", singleThreaded = true) public class SupportApiLiveTest extends BaseBitbucketApiLiveTest { + private String taskIdRegex = "^\\w+\\-+\\w+\\-+\\w+\\-+\\w+\\-+\\w+$"; + private SupportApi api() { return api.supportApi(); } @Test public void testSupportZipCreation() { - final SupportZipDetails details = api().createSupportZip(); - assertIntegrity(details); + final SupportZip supportZip = api().createSupportZip(); + assertIntegrity(supportZip); } @Test public void testSupportZipStatus() { - final SupportZipDetails details = api().createSupportZip(); - final SupportZipStatus supportZip = api().getSupportZipStatus(details.taskId()); + SupportZip supportZip = api().createSupportZip(); + supportZip = api().getSupportZipStatus(supportZip.taskId()); assertIntegrity(supportZip); - } - - private void assertIntegrity(final SupportZipStatus supportZip) { - assertTaskId(supportZip.taskId()); - assertTaskProgressMessage(supportZip.progressMessage()); - assertTaskProgressPercentage(supportZip.progressPercentage()); - assertTaskStatus(supportZip.status()); Assert.assertNotNull(supportZip.fileName()); } - private void assertIntegrity(final SupportZipDetails supportZipTask) { + private void assertIntegrity(final SupportZip supportZipTask) { assertTaskId(supportZipTask.taskId()); assertTaskProgressPercentage(supportZipTask.progressPercentage()); assertTaskProgressMessage(supportZipTask.progressMessage()); @@ -67,6 +62,7 @@ private void assertTaskStatus(final String status) { private void assertTaskId(final String taskId) { Assert.assertNotNull(taskId); + assertThat(taskId.matches(taskIdRegex)).isTrue(); } private void assertTaskProgressPercentage(final Integer progressPercentage) { diff --git a/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiMockTest.java b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiMockTest.java new file mode 100644 index 00000000..87713036 --- /dev/null +++ b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiMockTest.java @@ -0,0 +1,71 @@ +package com.cdancy.bitbucket.rest.features; + +import static org.assertj.core.api.Assertions.assertThat; +import com.cdancy.bitbucket.rest.BaseBitbucketMockTest; +import com.cdancy.bitbucket.rest.domain.support.SupportZip; +import com.squareup.okhttp.mockwebserver.MockResponse; +import com.squareup.okhttp.mockwebserver.MockWebServer; +import org.testng.Assert; +import org.testng.annotations.Test; + +@Test(groups = "unit", testName = "SupportApiMockTest") +public class SupportApiMockTest extends BaseBitbucketMockTest{ + + private String taskIdRegex = "^\\w+\\-+\\w+\\-+\\w+\\-+\\w+\\-+\\w+$"; + private String supportZipRestApiPath = "/rest/troubleshooting/latest/support-zip" ; + + public void testSupportZipCreation() throws Exception{ + MockWebServer mockWebServer = mockWebServer(); + mockWebServer.enqueue(new MockResponse().setBody(payloadFromResource("/support-zip-create.json")).setResponseCode(200)); + + try { + final SupportApi supportApi = api(mockWebServer.getUrl("/")).supportApi() ; + final SupportZip supportZip = supportApi.createSupportZip(); + + assertSupportZipCreateRequest(mockWebServer); + assertIntegrity(supportZip); + } finally { + mockWebServer.shutdown(); + } + } + + public void testSupportZipStatus() throws Exception{ + MockWebServer mockWebServer = mockWebServer(); + mockWebServer.enqueue(new MockResponse().setBody(payloadFromResource("/support-zip-create.json")).setResponseCode(200)); + mockWebServer.enqueue(new MockResponse().setBody(payloadFromResource("/support-zip-request-status.json")).setResponseCode(200)); + + try { + final SupportApi supportApi = api(mockWebServer.getUrl("/")).supportApi() ; + SupportZip supportZip = supportApi.createSupportZip(); + supportZip = supportApi.getSupportZipStatus(supportZip.taskId()); + + assertSupportZipCreateRequest(mockWebServer); + assertIntegritySupportZipStatus(supportZip); + assertSupportZipStatusRequest(mockWebServer, supportZip.taskId()); + } finally { + mockWebServer.shutdown(); + } + } + + public void assertIntegritySupportZipStatus(final SupportZip supportZip) { + assertIntegrity(supportZip); + Assert.assertNotNull(supportZip.fileName()); + } + + public void assertIntegrity(final SupportZip supportZip) { + Assert.assertNotNull(supportZip.progressMessage()); + assertThat(supportZip.taskId().matches(taskIdRegex)).isTrue(); + Assert.assertNotNull(supportZip.progressPercentage()); + Assert.assertNotNull(supportZip.status()); + } + + public void assertSupportZipCreateRequest(final MockWebServer mockWebServer) + throws InterruptedException{ + assertSent(mockWebServer, "POST", supportZipRestApiPath + "/local"); + } + + public void assertSupportZipStatusRequest(final MockWebServer mockWebServer, + final String taskId) throws InterruptedException { + assertSent(mockWebServer, "GET", supportZipRestApiPath + "/status/task/" + taskId); + } +} diff --git a/src/test/resources/support-zip-create.json b/src/test/resources/support-zip-create.json new file mode 100644 index 00000000..50c2f529 --- /dev/null +++ b/src/test/resources/support-zip-create.json @@ -0,0 +1,7 @@ +{ + "taskId": "cf27e653-d3af-4202-bcc8-79d836432b0b", + "progressPercentage": 0, + "progressMessage": "", + "warnings": [], + "status": "IN_PROGRESS" +} \ No newline at end of file diff --git a/src/test/resources/support-zip-request-status.json b/src/test/resources/support-zip-request-status.json new file mode 100644 index 00000000..ec8291ee --- /dev/null +++ b/src/test/resources/support-zip-request-status.json @@ -0,0 +1,8 @@ +{ + "taskId": "cf27e653-d3af-4202-bcc8-79d836432b0b", + "progressPercentage": 100, + "progressMessage": "It was saved to C:\\Atlassian\\ApplicationData\\Bitbucket\\shared\\export\\Bitbucket_support_2019-06-17-00-23-13.zip.", + "fileName": "Bitbucket_support_2019-06-17-00-23-13.zip", + "warnings": [], + "status": "COMPLETE_WITH_WARNING" +} \ No newline at end of file From 81e8958ed701e92407c9c6ad8af81689ce9a26c1 Mon Sep 17 00:00:00 2001 From: padas2 Date: Mon, 17 Jun 2019 01:57:02 +0530 Subject: [PATCH 16/19] Fixed CheckStyle and Licensing errors --- .../rest/features/SupportApiMockTest.java | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiMockTest.java b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiMockTest.java index 87713036..4114def5 100644 --- a/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiMockTest.java +++ b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiMockTest.java @@ -1,3 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.cdancy.bitbucket.rest.features; import static org.assertj.core.api.Assertions.assertThat; @@ -8,13 +25,16 @@ import org.testng.Assert; import org.testng.annotations.Test; +/** + * Mock tests for the {@link SupportApi} class. + */ @Test(groups = "unit", testName = "SupportApiMockTest") -public class SupportApiMockTest extends BaseBitbucketMockTest{ +public class SupportApiMockTest extends BaseBitbucketMockTest { private String taskIdRegex = "^\\w+\\-+\\w+\\-+\\w+\\-+\\w+\\-+\\w+$"; private String supportZipRestApiPath = "/rest/troubleshooting/latest/support-zip" ; - public void testSupportZipCreation() throws Exception{ + public void testSupportZipCreation() throws Exception { MockWebServer mockWebServer = mockWebServer(); mockWebServer.enqueue(new MockResponse().setBody(payloadFromResource("/support-zip-create.json")).setResponseCode(200)); @@ -29,7 +49,7 @@ public void testSupportZipCreation() throws Exception{ } } - public void testSupportZipStatus() throws Exception{ + public void testSupportZipStatus() throws Exception { MockWebServer mockWebServer = mockWebServer(); mockWebServer.enqueue(new MockResponse().setBody(payloadFromResource("/support-zip-create.json")).setResponseCode(200)); mockWebServer.enqueue(new MockResponse().setBody(payloadFromResource("/support-zip-request-status.json")).setResponseCode(200)); @@ -47,24 +67,24 @@ public void testSupportZipStatus() throws Exception{ } } - public void assertIntegritySupportZipStatus(final SupportZip supportZip) { + private void assertIntegritySupportZipStatus(final SupportZip supportZip) { assertIntegrity(supportZip); Assert.assertNotNull(supportZip.fileName()); } - public void assertIntegrity(final SupportZip supportZip) { + private void assertIntegrity(final SupportZip supportZip) { Assert.assertNotNull(supportZip.progressMessage()); assertThat(supportZip.taskId().matches(taskIdRegex)).isTrue(); Assert.assertNotNull(supportZip.progressPercentage()); Assert.assertNotNull(supportZip.status()); } - public void assertSupportZipCreateRequest(final MockWebServer mockWebServer) - throws InterruptedException{ + private void assertSupportZipCreateRequest(final MockWebServer mockWebServer) + throws InterruptedException { assertSent(mockWebServer, "POST", supportZipRestApiPath + "/local"); } - public void assertSupportZipStatusRequest(final MockWebServer mockWebServer, + private void assertSupportZipStatusRequest(final MockWebServer mockWebServer, final String taskId) throws InterruptedException { assertSent(mockWebServer, "GET", supportZipRestApiPath + "/status/task/" + taskId); } From e237b19d50827b54d6cb6496300847a1cb64e065 Mon Sep 17 00:00:00 2001 From: padas2 Date: Mon, 17 Jun 2019 01:59:14 +0530 Subject: [PATCH 17/19] Fixed PMD rule violations --- .../bitbucket/rest/features/SupportApiMockTest.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiMockTest.java b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiMockTest.java index 4114def5..3551b61f 100644 --- a/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiMockTest.java +++ b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiMockTest.java @@ -35,9 +35,8 @@ public class SupportApiMockTest extends BaseBitbucketMockTest { private String supportZipRestApiPath = "/rest/troubleshooting/latest/support-zip" ; public void testSupportZipCreation() throws Exception { - MockWebServer mockWebServer = mockWebServer(); + final MockWebServer mockWebServer = mockWebServer(); mockWebServer.enqueue(new MockResponse().setBody(payloadFromResource("/support-zip-create.json")).setResponseCode(200)); - try { final SupportApi supportApi = api(mockWebServer.getUrl("/")).supportApi() ; final SupportZip supportZip = supportApi.createSupportZip(); @@ -50,10 +49,9 @@ public void testSupportZipCreation() throws Exception { } public void testSupportZipStatus() throws Exception { - MockWebServer mockWebServer = mockWebServer(); + final MockWebServer mockWebServer = mockWebServer(); mockWebServer.enqueue(new MockResponse().setBody(payloadFromResource("/support-zip-create.json")).setResponseCode(200)); mockWebServer.enqueue(new MockResponse().setBody(payloadFromResource("/support-zip-request-status.json")).setResponseCode(200)); - try { final SupportApi supportApi = api(mockWebServer.getUrl("/")).supportApi() ; SupportZip supportZip = supportApi.createSupportZip(); @@ -84,8 +82,8 @@ private void assertSupportZipCreateRequest(final MockWebServer mockWebServer) assertSent(mockWebServer, "POST", supportZipRestApiPath + "/local"); } - private void assertSupportZipStatusRequest(final MockWebServer mockWebServer, - final String taskId) throws InterruptedException { + private void assertSupportZipStatusRequest(final MockWebServer mockWebServer, final String taskId) + throws InterruptedException { assertSent(mockWebServer, "GET", supportZipRestApiPath + "/status/task/" + taskId); } } From b26abdf1e37dc74cca04ca6483f0b5172986c381 Mon Sep 17 00:00:00 2001 From: padas2 Date: Sat, 22 Jun 2019 00:00:45 +0530 Subject: [PATCH 18/19] Initial changes for introducing fallbacks for support zip failures --- .../rest/domain/support/SupportZip.java | 22 +++++++++++----- .../rest/fallbacks/BitbucketFallbacks.java | 16 ++++++++++++ .../bitbucket/rest/features/SupportApi.java | 4 +++ .../rest/features/SupportApiLiveTest.java | 26 +++++++++++-------- 4 files changed, 50 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java index 81fa14dd..1a849ee6 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java @@ -17,13 +17,16 @@ package com.cdancy.bitbucket.rest.domain.support; +import com.cdancy.bitbucket.rest.BitbucketUtils; +import com.cdancy.bitbucket.rest.domain.common.Error; +import com.cdancy.bitbucket.rest.domain.common.ErrorsHolder; import com.google.auto.value.AutoValue; import org.jclouds.javax.annotation.Nullable; import org.jclouds.json.SerializedNames; import java.util.List; @AutoValue -public abstract class SupportZip { +public abstract class SupportZip implements ErrorsHolder{ public abstract String taskId(); public abstract Integer progressPercentage(); @@ -37,13 +40,18 @@ public abstract class SupportZip { @Nullable public abstract String fileName(); - @SerializedNames({"taskId", "progressPercentage", "progressMessage", "warnings", "status", "fileName"}) + @SerializedNames({"taskId", "progressPercentage", "progressMessage", + "warnings", "status", "fileName", + "errors"}) public static SupportZip create(final String taskId, - final Integer progressPercentage, - final String progressMessage, - final List warnings, - final String status, final String fileName) { - return new AutoValue_SupportZip(taskId, + final Integer progressPercentage, + final String progressMessage, + final List warnings, + final String status, + final String fileName, + final List errors) { + return new AutoValue_SupportZip(BitbucketUtils.nullToEmpty(errors), + taskId, progressPercentage, progressMessage, warnings, diff --git a/src/main/java/com/cdancy/bitbucket/rest/fallbacks/BitbucketFallbacks.java b/src/main/java/com/cdancy/bitbucket/rest/fallbacks/BitbucketFallbacks.java index 99bd9c45..7582769a 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/fallbacks/BitbucketFallbacks.java +++ b/src/main/java/com/cdancy/bitbucket/rest/fallbacks/BitbucketFallbacks.java @@ -66,6 +66,7 @@ import com.cdancy.bitbucket.rest.domain.repository.RepositoryPage; import com.cdancy.bitbucket.rest.domain.repository.WebHook; import com.cdancy.bitbucket.rest.domain.repository.WebHookPage; +import com.cdancy.bitbucket.rest.domain.support.SupportZip; import com.cdancy.bitbucket.rest.domain.sync.SyncState; import com.cdancy.bitbucket.rest.domain.sync.SyncStatus; import com.cdancy.bitbucket.rest.domain.tags.Tag; @@ -361,6 +362,16 @@ public Object createOrPropagate(final Throwable throwable) throws Exception { } } + public static final class SupportZipOnError implements Fallback { + @Override + public Object createOrPropagate(final Throwable throwable) throws Exception { + if (checkNotNull(throwable, "throwable") != null) { + return createSupportZipFromErrors(getErrors(throwable.getMessage())); + } + throw propagate(throwable); + } + } + public static final class SyncStatusOnError implements Fallback { @Override public Object createOrPropagate(final Throwable throwable) throws Exception { @@ -663,6 +674,11 @@ public static PullRequest createPullRequestFromErrors(final List errors) null, null, errors); } + public static SupportZip createSupportZipFromErrors(final List errors) { + return SupportZip.create(null, 0, null, + null, null, null, errors); + } + public static SyncState createSyncStateFromErrors(final List errors) { return SyncState.create(null, null, null, null, errors); } diff --git a/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java b/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java index f1694ff0..7d6016a9 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java +++ b/src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java @@ -20,6 +20,8 @@ import com.cdancy.bitbucket.rest.annotations.Documentation; import com.cdancy.bitbucket.rest.domain.support.SupportZip; import com.cdancy.bitbucket.rest.filters.BitbucketAuthenticationFilter; +import com.cdancy.bitbucket.rest.fallbacks.BitbucketFallbacks.SupportZipOnError; +import org.jclouds.rest.annotations.Fallback; import org.jclouds.rest.annotations.RequestFilters; import javax.inject.Named; import javax.ws.rs.Consumes; @@ -40,6 +42,7 @@ public interface SupportApi { @Documentation("https://confluence.atlassian.com/support/create-a-support-zip-using-the-rest-api-in-server-applications-947857090.html#CreateasupportzipusingtheRESTAPIinServerapplications-Generateasupportzip") @Consumes(MediaType.APPLICATION_JSON) @Path("/local") + @Fallback(SupportZipOnError.class) @POST SupportZip createSupportZip(); @@ -47,6 +50,7 @@ public interface SupportApi { @Documentation("https://confluence.atlassian.com/support/create-a-support-zip-using-the-rest-api-in-server-applications-947857090.html#CreateasupportzipusingtheRESTAPIinServerapplications-Checktheprogressofthetask") @Consumes(MediaType.APPLICATION_JSON) @Path("/status/task/{taskId}") + @Fallback(SupportZipOnError.class) @GET SupportZip getSupportZipStatus(@PathParam("taskId") String taskId); } diff --git a/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java index 7ad0d878..66b1cf92 100644 --- a/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java +++ b/src/test/java/com/cdancy/bitbucket/rest/features/SupportApiLiveTest.java @@ -20,7 +20,6 @@ import static org.assertj.core.api.Assertions.assertThat; import com.cdancy.bitbucket.rest.BaseBitbucketApiLiveTest; import com.cdancy.bitbucket.rest.domain.support.SupportZip; -import org.testng.Assert; import org.testng.annotations.Test; @Test(groups = "live", testName = "SupportApiLiveTest", singleThreaded = true) @@ -33,16 +32,16 @@ private SupportApi api() { @Test public void testSupportZipCreation() { - final SupportZip supportZip = api().createSupportZip(); - assertIntegrity(supportZip); + final SupportZip supportZipTask = api().createSupportZip(); + assertIntegrity(supportZipTask); } @Test public void testSupportZipStatus() { - SupportZip supportZip = api().createSupportZip(); - supportZip = api().getSupportZipStatus(supportZip.taskId()); - assertIntegrity(supportZip); - Assert.assertNotNull(supportZip.fileName()); + SupportZip supportZipTask = api().createSupportZip(); + supportZipTask = api().getSupportZipStatus(supportZipTask.taskId()); + assertIntegrity(supportZipTask); + assertThat(supportZipTask.fileName()).isNotNull(); } private void assertIntegrity(final SupportZip supportZipTask) { @@ -50,22 +49,27 @@ private void assertIntegrity(final SupportZip supportZipTask) { assertTaskProgressPercentage(supportZipTask.progressPercentage()); assertTaskProgressMessage(supportZipTask.progressMessage()); assertTaskStatus(supportZipTask.status()); + assertErrors(supportZipTask); + } + + private void assertErrors(final SupportZip supportZip) { + assertThat(supportZip.errors().isEmpty()).isTrue(); } private void assertTaskProgressMessage(final String progressMessage) { - Assert.assertNotNull(progressMessage); + assertThat(progressMessage).isNotNull(); } private void assertTaskStatus(final String status) { - Assert.assertTrue(!status.isEmpty()); + assertThat(!status.isEmpty()).isTrue(); } private void assertTaskId(final String taskId) { - Assert.assertNotNull(taskId); + assertThat(taskId).isNotNull(); assertThat(taskId.matches(taskIdRegex)).isTrue(); } private void assertTaskProgressPercentage(final Integer progressPercentage) { - Assert.assertNotNull(progressPercentage); + assertThat(progressPercentage).isNotNull(); } } From b64e3f365c9ecd0ffbd6722cdb04bfc42488bd64 Mon Sep 17 00:00:00 2001 From: padas2 Date: Sat, 22 Jun 2019 00:18:49 +0530 Subject: [PATCH 19/19] Reverting accidental conversion of Line endings back to LF type and adding missing whitespace --- .../com/cdancy/bitbucket/rest/domain/support/SupportZip.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java index 1a849ee6..7106a81a 100644 --- a/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java +++ b/src/main/java/com/cdancy/bitbucket/rest/domain/support/SupportZip.java @@ -26,7 +26,7 @@ import java.util.List; @AutoValue -public abstract class SupportZip implements ErrorsHolder{ +public abstract class SupportZip implements ErrorsHolder { public abstract String taskId(); public abstract Integer progressPercentage();