Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for creation/download of Support Zip #197

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/main/java/com/cdancy/bitbucket/rest/BitbucketApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@
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 {

@Delegate
AdminApi adminApi();

Expand Down Expand Up @@ -83,6 +81,9 @@ public interface BitbucketApi extends Closeable {
@Delegate
SystemApi systemApi();

@Delegate
SupportApi supportApi();

@Delegate
TagApi tagApi();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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<String> 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<String> warnings,
final String status) {
return new AutoValue_SupportZipDetails(taskId,
progressPercentage,
progressMessage,
warnings,
status);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 SupportZipStatus {
public abstract String taskId();

public abstract Integer progressPercentage();

@Nullable
public abstract String progressMessage();

@Nullable
public abstract List<String> 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<String> warnings,
final String status, final String fileName) {
return new AutoValue_SupportZipStatus(taskId,
progressPercentage,
progressMessage,
warnings,
status,
fileName);
}

}
49 changes: 49 additions & 0 deletions src/main/java/com/cdancy/bitbucket/rest/features/SupportApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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;
import com.cdancy.bitbucket.rest.domain.support.SupportZipDetails;
import com.cdancy.bitbucket.rest.filters.BitbucketAuthenticationFilter;
import org.jclouds.rest.annotations.RequestFilters;
import javax.inject.Named;
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)
@RequestFilters(BitbucketAuthenticationFilter.class)
@Path("/rest/troubleshooting/latest/support-zip")
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public interface SupportApi {
@Named("support-zip:create")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets put a line-break between the class name and this Named.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Consumes(MediaType.APPLICATION_JSON)
@Path("/local")
@POST
SupportZipDetails createSupportZip();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put a Documentation annotation here as we do elsewhere?

Copy link
Author

@padas2 padas2 Jun 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done though the lengths of links are very long(>= 210 chars long)


@Named("support-zip:status")
@Consumes(MediaType.APPLICATION_JSON)
@Path("/status/task/{taskId}")
@GET
SupportZipStatus getSupportZipStatus(@PathParam("taskId") String taskId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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;
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;

@Test(groups = "live", testName = "SupportApiLiveTest", singleThreaded = true)
public class SupportApiLiveTest extends BaseBitbucketApiLiveTest {
private SupportApi api() {
return api.supportApi();
}

@Test
public void testSupportZipCreation() {
final SupportZipDetails details = api().createSupportZip();
assertIntegrity(details);
}

@Test
public void testSupportZipStatus() {
final SupportZipDetails details = api().createSupportZip();
final SupportZipStatus supportZip = api().getSupportZipStatus(details.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) {
assertTaskId(supportZipTask.taskId());
assertTaskProgressPercentage(supportZipTask.progressPercentage());
assertTaskProgressMessage(supportZipTask.progressMessage());
assertTaskStatus(supportZipTask.status());
}

private void assertTaskProgressMessage(final String progressMessage) {
Assert.assertNotNull(progressMessage);
}

private void assertTaskStatus(final String status) {
Assert.assertTrue(!status.isEmpty());
}

private void assertTaskId(final String taskId) {
Assert.assertNotNull(taskId);
}

private void assertTaskProgressPercentage(final Integer progressPercentage) {
Assert.assertNotNull(progressPercentage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down