Skip to content

Commit

Permalink
ADDED: endpoint BranchApi.model
Browse files Browse the repository at this point in the history
  • Loading branch information
cdancy committed Jun 26, 2016
1 parent 68338ac commit 057d68f
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.branch;

import com.cdancy.bitbucket.rest.error.Error;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;

import java.util.List;

@AutoValue
public abstract class BranchModel {

@Nullable
public abstract Branch development();

@Nullable
public abstract Branch production();

@Nullable
public abstract List<Type> types();

@Nullable
public abstract List<Error> errors();

BranchModel() {
}

@SerializedNames({ "development", "production", "types", "errors" })
public static BranchModel create(Branch development, Branch production, List<Type> types, List<Error> errors) {
return new AutoValue_BranchModel(development, production,
types != null ? ImmutableList.copyOf(types) : ImmutableList.<Type> of(),
errors != null ? ImmutableList.copyOf(errors) : ImmutableList.<Error> of());
}
}
44 changes: 44 additions & 0 deletions src/main/java/com/cdancy/bitbucket/rest/domain/branch/Type.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.branch;

import com.cdancy.bitbucket.rest.error.Error;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;

import java.util.List;

@AutoValue
public abstract class Type {

public abstract String id();

public abstract String displayName();

public abstract String prefix();

Type() {
}

@SerializedNames({ "id", "displayName", "prefix" })
public static Type create(String id, String displayName, String prefix) {
return new AutoValue_Type(id, displayName, prefix);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.cdancy.bitbucket.rest.features;

import com.cdancy.bitbucket.rest.domain.branch.Branch;
import com.cdancy.bitbucket.rest.domain.branch.BranchModel;
import com.cdancy.bitbucket.rest.fallbacks.BitbucketFallbacks;
import com.cdancy.bitbucket.rest.filters.BitbucketAuthentication;
import com.cdancy.bitbucket.rest.options.CreateBranch;
Expand Down Expand Up @@ -77,4 +78,12 @@ boolean updateDefault(@PathParam("project") String project,
@GET
Branch getDefault(@PathParam("project") String project,
@PathParam("repo") String repo);

@Named("branch:model")
@Consumes(MediaType.APPLICATION_JSON)
@Path("/branch-utils/{jclouds.api-version}/projects/{project}/repos/{repo}/branchmodel")
@Fallback(BitbucketFallbacks.BranchOnError.class)
@GET
BranchModel model(@PathParam("project") String project,
@PathParam("repo") String repo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.cdancy.bitbucket.rest.BaseBitbucketApiLiveTest;
import com.cdancy.bitbucket.rest.domain.branch.Branch;
import com.cdancy.bitbucket.rest.domain.branch.BranchModel;
import com.cdancy.bitbucket.rest.options.CreateBranch;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
Expand All @@ -37,10 +38,10 @@ public class BranchApiLiveTest extends BaseBitbucketApiLiveTest {
String commitHash = "";
*/

String projectKey = "TEST";
String repoKey = "dev";
String projectKey = "BUILD";
String repoKey = "dancc-test";
String branchName = randomStringLettersOnly();
String commitHash = "d90ca08fa076e2e4c076592fce3832aba80a494f";
String commitHash = "5284b6cec569346855710b535dafb915423110c2";

String defaultBranchId = "refs/heads/master";

Expand All @@ -63,6 +64,13 @@ public void testCreateBranch() {
}

@Test (dependsOnMethods = "testCreateBranch")
public void testGetBranchModel() {
BranchModel branchModel = api().model(projectKey, repoKey);
assertNotNull(branchModel);
assertTrue(branchModel.errors().size() == 0);
}

@Test (dependsOnMethods = "testGetBranchModel")
public void testUpdateDefaultBranch() {
boolean success = api().updateDefault(projectKey, repoKey, "refs/heads/" + branchName);
assertTrue(success);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.cdancy.bitbucket.rest.BitbucketApi;
import com.cdancy.bitbucket.rest.BitbucketApiMetadata;
import com.cdancy.bitbucket.rest.domain.branch.Branch;
import com.cdancy.bitbucket.rest.domain.branch.BranchModel;
import com.cdancy.bitbucket.rest.domain.tags.Tag;
import com.cdancy.bitbucket.rest.internal.BaseBitbucketMockTest;
import com.cdancy.bitbucket.rest.options.CreateBranch;
Expand Down Expand Up @@ -63,6 +64,27 @@ public void testCreateBranch() throws Exception {
}
}

public void testGetBranchModel() throws Exception {
MockWebServer server = mockEtcdJavaWebServer();

server.enqueue(new MockResponse().setBody(payloadFromResource("/branch-model.json")).setResponseCode(200));
BitbucketApi baseApi = api(server.getUrl("/"));
BranchApi api = baseApi.branchApi();
try {
String projectKey = "PRJ";
String repoKey = "myrepo";
BranchModel branchModel = api.model(projectKey, repoKey);
assertNotNull(branchModel);
assertTrue(branchModel.errors().size() == 0);
assertTrue(branchModel.types().size() > 0);
assertSent(server, "GET", "/rest/branch-utils/" + BitbucketApiMetadata.API_VERSION
+ "/projects/" + projectKey + "/repos/" + repoKey + "/branchmodel");
} finally {
baseApi.close();
server.shutdown();
}
}

public void testDeleteBranch() throws Exception {
MockWebServer server = mockEtcdJavaWebServer();

Expand Down
32 changes: 32 additions & 0 deletions src/test/resources/branch-model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"development":{
"id":"refs/heads/master",
"displayId":"master",
"type":"BRANCH",
"latestCommit":"d90ca08fa076e2e4c076592fce3832aba80a494f",
"latestChangeset":"d90ca08fa076e2e4c076592fce3832aba80a494f",
"isDefault":true
},
"types":[
{
"id":"BUGFIX",
"displayName":"Bugfix",
"prefix":"bugfix/"
},
{
"id":"FEATURE",
"displayName":"Feature",
"prefix":"feature/"
},
{
"id":"HOTFIX",
"displayName":"Hotfix",
"prefix":"hotfix/"
},
{
"id":"RELEASE",
"displayName":"Release",
"prefix":"release/"
}
]
}

0 comments on commit 057d68f

Please sign in to comment.