BitbucketCloudScm extends AbstractBitbucketScm { @Nonnull @Override public String getId() { return ID; } BitbucketCloudScm(Reachable parent); @Nonnull @Override String getId(); @Override ScmServerEndpointContainer getServers(); static final String ID; static final String API_URL; }
@Test public void getBitbucketScm() throws UnirestException { Map r = new RequestBuilder(baseUrl) .status(200) .jwtToken(getJwtToken(j.jenkins, authenticatedUser.getId(), authenticatedUser.getId())) .get("/organizations/jenkins/scm/"+ BitbucketCloudScm.ID+getApiUrlParam()) .build(Map.class); assertNotNull(r); assertEquals(BitbucketCloudScm.ID, r.get("id")); assertEquals(apiUrl, r.get("uri")); assertNull(r.get("credentialId")); }
@Test public void getOrganizationsWithCredentialId() throws IOException, UnirestException { String credentialId = createCredential(BitbucketCloudScm.ID); List orgs = new RequestBuilder(baseUrl) .status(200) .jwtToken(getJwtToken(j.jenkins, authenticatedUser.getId(), authenticatedUser.getId())) .get("/organizations/jenkins/scm/"+BitbucketCloudScm.ID+"/organizations/"+getApiUrlParam()+"&credentialId="+credentialId) .build(List.class); assertEquals(2, orgs.size()); assertEquals(BbCloudWireMock.USER_UUID, ((Map)orgs.get(0)).get("key")); assertEquals("Vivek Pandey", ((Map)orgs.get(0)).get("name")); assertEquals(BbCloudWireMock.TEAM_UUID, ((Map)orgs.get(1)).get("key")); assertEquals("Vivek's Team", ((Map)orgs.get(1)).get("name")); }
@Test public void getOrganizationsWithoutCredentialId() throws IOException, UnirestException { createCredential(BitbucketCloudScm.ID); List orgs = new RequestBuilder(baseUrl) .status(200) .jwtToken(getJwtToken(j.jenkins, authenticatedUser.getId(), authenticatedUser.getId())) .get("/organizations/jenkins/scm/"+BitbucketCloudScm.ID+"/organizations/"+getApiUrlParam()) .build(List.class); assertEquals(2, orgs.size()); assertEquals(BbCloudWireMock.USER_UUID, ((Map)orgs.get(0)).get("key")); assertEquals("Vivek Pandey", ((Map)orgs.get(0)).get("name")); assertEquals(BbCloudWireMock.TEAM_UUID, ((Map)orgs.get(1)).get("key")); assertEquals("Vivek's Team", ((Map)orgs.get(1)).get("name")); }
@Test public void getOrganizationsWithInvalidCredentialId() throws IOException, UnirestException { Map r = new RequestBuilder(baseUrl) .status(400) .jwtToken(getJwtToken(j.jenkins, authenticatedUser.getId(), authenticatedUser.getId())) .get("/organizations/jenkins/scm/"+ BitbucketCloudScm.ID+"/organizations/"+getApiUrlParam()+"&credentialId=foo") .build(Map.class); }
@Test public void getRepositoriesWithCredentialId() throws IOException, UnirestException { String credentialId = createCredential(BitbucketCloudScm.ID); Map repoResp = new RequestBuilder(baseUrl) .status(200) .jwtToken(getJwtToken(j.jenkins, authenticatedUser.getId(), authenticatedUser.getId())) .get("/organizations/jenkins/scm/"+BitbucketCloudScm.ID+"/organizations/" + BbCloudWireMock.TEAM_UUID + "/repositories/"+getApiUrlParam()+"&credentialId="+credentialId) .build(Map.class); List repos = (List) ((Map)repoResp.get("repositories")).get("items"); assertEquals("pipeline-demo-test", ((Map)repos.get(0)).get("name")); assertEquals("pipeline-demo-test", ((Map)repos.get(0)).get("description")); assertTrue((Boolean) ((Map)repos.get(0)).get("private")); assertEquals("master",((Map)repos.get(0)).get("defaultBranch")); assertEquals(2, repos.size()); assertEquals("emptyrepo", ((Map)repos.get(1)).get("name")); assertEquals("emptyrepo", ((Map)repos.get(1)).get("description")); assertTrue((Boolean) ((Map)repos.get(1)).get("private")); assertNull(((Map)repos.get(1)).get("defaultBranch")); }
@Test public void getRepositoriesWithoutCredentialId() throws IOException, UnirestException { createCredential(BitbucketCloudScm.ID); Map repoResp = new RequestBuilder(baseUrl) .status(200) .jwtToken(getJwtToken(j.jenkins, authenticatedUser.getId(), authenticatedUser.getId())) .get("/organizations/jenkins/scm/"+BitbucketCloudScm.ID+"/organizations/" + BbCloudWireMock.TEAM_UUID + "/repositories/"+getApiUrlParam()) .build(Map.class); List repos = (List) ((Map)repoResp.get("repositories")).get("items"); assertEquals("pipeline-demo-test", ((Map)repos.get(0)).get("name")); assertEquals("pipeline-demo-test", ((Map)repos.get(0)).get("description")); assertTrue((Boolean) ((Map)repos.get(0)).get("private")); assertEquals("master",((Map)repos.get(0)).get("defaultBranch")); assertEquals(2, repos.size()); assertEquals("emptyrepo", ((Map)repos.get(1)).get("name")); assertEquals("emptyrepo", ((Map)repos.get(1)).get("description")); assertTrue((Boolean) ((Map)repos.get(1)).get("private")); assertNull(((Map)repos.get(1)).get("defaultBranch")); }