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

Paging api #19

Merged
merged 11 commits into from
Dec 9, 2016
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {
compile ('org.apache.jclouds:jclouds-core:1.9.2')
compile ('org.apache.jclouds.driver:jclouds-okhttp:1.9.2')
compile ('com.google.auto.service:auto-service:1.0-rc2')
compile ('com.google.auto.value:auto-value:1.1')
compile ('com.google.auto.value:auto-value:1.2')

testCompile ('org.apache.jclouds:jclouds-core:1.9.2:tests')
testCompile ('org.testng:testng:6.8.21')
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = com.cdancy
version = 0.0.10
version = 0.0.11-SNAPSHOT

artifactoryURL = http://127.0.0.1:8080/artifactory
artifactoryUser = admin
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.common;

import java.util.List;

import com.cdancy.bitbucket.rest.error.Error;

public interface ErrorsWrapper {

public abstract List<Error> errors();
}
35 changes: 35 additions & 0 deletions src/main/java/com/cdancy/bitbucket/rest/domain/common/Page.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.common;

import java.util.List;

public interface Page<T> {

public abstract int start();

public abstract int limit();

public abstract int size();

public abstract int nextPageStart();

public abstract boolean isLastPage();

public abstract List<T> values();
}
28 changes: 28 additions & 0 deletions src/main/java/com/cdancy/bitbucket/rest/domain/common/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.common;

import java.util.List;

import com.google.common.collect.ImmutableList;

public class Utils {
public static <T> List<T> nullToEmpty(Iterable<? extends T> input) {
return input == null ? ImmutableList.<T> of() : ImmutableList.copyOf(input);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.project;

import java.util.List;

import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;

import com.cdancy.bitbucket.rest.domain.common.ErrorsWrapper;
import com.cdancy.bitbucket.rest.domain.common.Page;
import com.cdancy.bitbucket.rest.domain.common.Utils;
import com.cdancy.bitbucket.rest.error.Error;
import com.google.auto.value.AutoValue;

@AutoValue
public abstract class ProjectPage implements Page<Project>, ErrorsWrapper {

@SerializedNames({ "start", "limit", "size", "nextPageStart", "isLastPage", "values", "errors" })
public static ProjectPage create(int start, int limit, int size, int nextPageStart, boolean isLastPage,
@Nullable List<Project> values, @Nullable List<Error> errors) {
return new AutoValue_ProjectPage(start, limit, size, nextPageStart, isLastPage,
Utils.nullToEmpty(values), Utils.nullToEmpty(errors));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.repository;

import java.util.List;

import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;

import com.cdancy.bitbucket.rest.domain.common.ErrorsWrapper;
import com.cdancy.bitbucket.rest.domain.common.Page;
import com.cdancy.bitbucket.rest.domain.common.Utils;
import com.cdancy.bitbucket.rest.error.Error;
import com.google.auto.value.AutoValue;

@AutoValue
public abstract class RepositoryPage implements Page<Repository>, ErrorsWrapper {

@SerializedNames({ "start", "limit", "size", "nextPageStart", "isLastPage", "values", "errors" })
public static RepositoryPage create(int start, int limit, int size, int nextPageStart, boolean isLastPage,
@Nullable List<Repository> values, @Nullable List<Error> errors) {
return new AutoValue_RepositoryPage(start, limit, size, nextPageStart, isLastPage,
Utils.nullToEmpty(values), Utils.nullToEmpty(errors));
}
}
34 changes: 22 additions & 12 deletions src/main/java/com/cdancy/bitbucket/rest/features/ProjectApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,29 @@

package com.cdancy.bitbucket.rest.features;

import com.cdancy.bitbucket.rest.domain.project.Project;
import com.cdancy.bitbucket.rest.domain.pullrequest.PullRequest;
import com.cdancy.bitbucket.rest.fallbacks.BitbucketFallbacks;
import com.cdancy.bitbucket.rest.filters.BitbucketAuthentication;
import com.cdancy.bitbucket.rest.options.CreateProject;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.binders.BindToJsonPayload;

import javax.inject.Named;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
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.QueryParam;
import javax.ws.rs.core.MediaType;

import org.jclouds.javax.annotation.Nullable;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.binders.BindToJsonPayload;

import com.cdancy.bitbucket.rest.domain.project.Project;
import com.cdancy.bitbucket.rest.domain.project.ProjectPage;
import com.cdancy.bitbucket.rest.fallbacks.BitbucketFallbacks;
import com.cdancy.bitbucket.rest.filters.BitbucketAuthentication;
import com.cdancy.bitbucket.rest.options.CreateProject;

@Produces(MediaType.APPLICATION_JSON)
@RequestFilters(BitbucketAuthentication.class)
@Path("/rest/api/{jclouds.api-version}/projects")
Expand All @@ -63,4 +64,13 @@ public interface ProjectApi {
@Fallback(BitbucketFallbacks.FalseOnError.class)
@DELETE
boolean delete(@PathParam("project") String project);

@GET
@Named("project:list")
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(BitbucketFallbacks.ProjectOnError.class)
ProjectPage list(@Nullable @QueryParam("start") Integer start,
@Nullable @QueryParam("limit") Integer limit,
@Nullable @QueryParam("name") String name,
@Nullable @QueryParam("permission") String permission);
}
33 changes: 22 additions & 11 deletions src/main/java/com/cdancy/bitbucket/rest/features/RepositoryApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,29 @@

package com.cdancy.bitbucket.rest.features;

import com.cdancy.bitbucket.rest.domain.repository.Repository;
import com.cdancy.bitbucket.rest.fallbacks.BitbucketFallbacks;
import com.cdancy.bitbucket.rest.filters.BitbucketAuthentication;
import com.cdancy.bitbucket.rest.options.CreateRepository;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.binders.BindToJsonPayload;

import javax.inject.Named;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
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.QueryParam;
import javax.ws.rs.core.MediaType;

import org.jclouds.javax.annotation.Nullable;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.binders.BindToJsonPayload;

import com.cdancy.bitbucket.rest.domain.repository.Repository;
import com.cdancy.bitbucket.rest.domain.repository.RepositoryPage;
import com.cdancy.bitbucket.rest.fallbacks.BitbucketFallbacks;
import com.cdancy.bitbucket.rest.filters.BitbucketAuthentication;
import com.cdancy.bitbucket.rest.options.CreateRepository;

@Produces(MediaType.APPLICATION_JSON)
@RequestFilters(BitbucketAuthentication.class)
@Path("/rest/api/{jclouds.api-version}/projects")
Expand Down Expand Up @@ -66,4 +68,13 @@ Repository get(@PathParam("project") String project,
@DELETE
boolean delete(@PathParam("project") String project,
@PathParam("repo") String repo);

@GET
@Named("repository:list")
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{project}/repos")
@Fallback(BitbucketFallbacks.RepositoryOnError.class)
RepositoryPage list(@PathParam("project") String project,
@Nullable @QueryParam("start") Integer start,
@Nullable @QueryParam("limit") Integer limit);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@

package com.cdancy.bitbucket.rest.features;

import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

import java.util.Map;

import org.testng.annotations.Test;

import com.cdancy.bitbucket.rest.BitbucketApi;
import com.cdancy.bitbucket.rest.BitbucketApiMetadata;
import com.cdancy.bitbucket.rest.domain.comment.Anchor;
import com.cdancy.bitbucket.rest.domain.comment.Comments;
import com.cdancy.bitbucket.rest.domain.comment.Parent;
import com.cdancy.bitbucket.rest.internal.BaseBitbucketMockTest;
import com.cdancy.bitbucket.rest.options.CreateComment;
import com.google.common.collect.ImmutableMap;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
import org.testng.annotations.Test;

import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

/**
* Mock tests for the {@link CommentsApi} class.
Expand Down Expand Up @@ -113,8 +116,10 @@ public void testDeleteComment() throws Exception {
boolean pr = api.delete("PRJ", "my-repo", 101, 1, 1);
assertNotNull(pr);
assertTrue(pr);

Map<String, ?> queryParams = ImmutableMap.of("version", 1);
assertSent(server, "DELETE", "/rest/api/" + BitbucketApiMetadata.API_VERSION
+ "/projects/PRJ/repos/my-repo/pull-requests/101/comments/1?version=1");
+ "/projects/PRJ/repos/my-repo/pull-requests/101/comments/1", queryParams);
} finally {
baseApi.close();
server.shutdown();
Expand Down
Loading