Search in sources :

Example 11 with BitbucketPersonalAccessToken

use of org.eclipse.che.api.factory.server.bitbucket.server.BitbucketPersonalAccessToken in project devspaces-images by redhat-developer.

the class HttpBitbucketServerApiClientTest method shouldBeAbleToCreatePAT.

@Test
public void shouldBeAbleToCreatePAT() throws ScmCommunicationException, ScmBadRequestException, ScmUnauthorizedException {
    // given
    stubFor(put(urlPathEqualTo("/rest/access-tokens/1.0/users/ksmster")).withHeader(HttpHeaders.AUTHORIZATION, equalTo(AUTHORIZATION_TOKEN)).withHeader(HttpHeaders.ACCEPT, equalTo(MediaType.APPLICATION_JSON)).withHeader(HttpHeaders.CONTENT_TYPE, equalTo(MediaType.APPLICATION_JSON)).withHeader(HttpHeaders.CONTENT_LENGTH, equalTo("63")).willReturn(ok().withBodyFile("bitbucket/rest/access-tokens/1.0/users/ksmster/newtoken.json")));
    // when
    BitbucketPersonalAccessToken result = bitbucketServer.createPersonalAccessTokens("ksmster", "myToKen", ImmutableSet.of("PROJECT_WRITE", "REPO_WRITE"));
    // then
    assertNotNull(result);
    assertEquals(result.getToken(), "MTU4OTEwNTMyOTA5Ohc88HcY8k7gWOzl2mP5TtdtY5Qs");
}
Also used : BitbucketPersonalAccessToken(org.eclipse.che.api.factory.server.bitbucket.server.BitbucketPersonalAccessToken) Test(org.testng.annotations.Test)

Example 12 with BitbucketPersonalAccessToken

use of org.eclipse.che.api.factory.server.bitbucket.server.BitbucketPersonalAccessToken in project devspaces-images by redhat-developer.

the class HttpBitbucketServerApiClientTest method shouldBeAbleToGetExistedPAT.

@Test
public void shouldBeAbleToGetExistedPAT() throws ScmCommunicationException, ScmUnauthorizedException, ScmItemNotFoundException {
    // given
    stubFor(get(urlPathEqualTo("/rest/access-tokens/1.0/users/ksmster/5")).withHeader(HttpHeaders.AUTHORIZATION, equalTo(AUTHORIZATION_TOKEN)).withHeader(HttpHeaders.ACCEPT, equalTo(MediaType.APPLICATION_JSON)).willReturn(ok().withBodyFile("bitbucket/rest/access-tokens/1.0/users/ksmster/newtoken.json")));
    // when
    BitbucketPersonalAccessToken result = bitbucketServer.getPersonalAccessToken("ksmster", 5L);
    // then
    assertNotNull(result);
    assertEquals(result.getToken(), "MTU4OTEwNTMyOTA5Ohc88HcY8k7gWOzl2mP5TtdtY5Qs");
}
Also used : BitbucketPersonalAccessToken(org.eclipse.che.api.factory.server.bitbucket.server.BitbucketPersonalAccessToken) Test(org.testng.annotations.Test)

Aggregations

BitbucketPersonalAccessToken (org.eclipse.che.api.factory.server.bitbucket.server.BitbucketPersonalAccessToken)12 Test (org.testng.annotations.Test)8 PersonalAccessToken (org.eclipse.che.api.factory.server.scm.PersonalAccessToken)6 URL (java.net.URL)4 BitbucketUser (org.eclipse.che.api.factory.server.bitbucket.server.BitbucketUser)4 EnvironmentContext (org.eclipse.che.commons.env.EnvironmentContext)4 ImmutableSet (com.google.common.collect.ImmutableSet)2 String.format (java.lang.String.format)2 String.valueOf (java.lang.String.valueOf)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Named (javax.inject.Named)2 BitbucketServerApiClient (org.eclipse.che.api.factory.server.bitbucket.server.BitbucketServerApiClient)2 PersonalAccessTokenFetcher (org.eclipse.che.api.factory.server.scm.PersonalAccessTokenFetcher)2 ScmBadRequestException (org.eclipse.che.api.factory.server.scm.exception.ScmBadRequestException)2 ScmCommunicationException (org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException)2 ScmItemNotFoundException (org.eclipse.che.api.factory.server.scm.exception.ScmItemNotFoundException)2