aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java4
-rw-r--r--src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java15
-rw-r--r--src/test/java/BitbucketBuildRepositoryTest.java16
3 files changed, 15 insertions, 20 deletions
diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
index 3bc3928..9b92775 100644
--- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
+++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketRepository.java
@@ -54,7 +54,7 @@ public class BitbucketRepository {
this.init(null, null);
}
- public <T extends ApiClient.HttpClientFactory> void init(Class<T> httpFactory) {
+ public <T extends ApiClient.HttpClientFactory> void init(T httpFactory) {
this.init(null, httpFactory);
}
@@ -62,7 +62,7 @@ public class BitbucketRepository {
this.init(client, null);
}
- public <T extends ApiClient.HttpClientFactory> void init(ApiClient client, Class<T> httpFactory) {
+ public <T extends ApiClient.HttpClientFactory> void init(ApiClient client, T httpFactory) {
this.trigger = this.builder.getTrigger();
if (client == null) {
diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java
index 047bf5a..19bff34 100644
--- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java
+++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java
@@ -71,23 +71,14 @@ public class ApiClient {
String username, String password,
String owner, String repositoryName,
String key, String name,
- Class<T> httpFactory
+ T httpFactory
) {
this.credentials = new UsernamePasswordCredentials(username, password);
this.owner = owner;
this.repositoryName = repositoryName;
this.key = key;
- this.name = name;
-
- try {
- this.factory = (httpFactory != null) ? httpFactory.newInstance() : HttpClientFactory.INSTANCE;
- } catch(InstantiationException e) {
- logger.log(Level.WARNING, "failed new instance of {0}: {1} ", new Object[] { httpFactory.getName(), e });
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- logger.log(Level.WARNING, "failed new instance of {0}: {1} ", new Object[] { httpFactory.getName(), e });
- e.printStackTrace();
- }
+ this.name = name;
+ this.factory = httpFactory != null ? httpFactory : HttpClientFactory.INSTANCE;
}
public List<Pullrequest> getPullRequests() {
diff --git a/src/test/java/BitbucketBuildRepositoryTest.java b/src/test/java/BitbucketBuildRepositoryTest.java
index 5f1aca2..953bd81 100644
--- a/src/test/java/BitbucketBuildRepositoryTest.java
+++ b/src/test/java/BitbucketBuildRepositoryTest.java
@@ -20,6 +20,7 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Collection;
+import java.util.logging.Logger;
import org.easymock.*;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -47,6 +48,7 @@ interface ICredentialsInterceptor {
* @param <T>
*/
class HttpClientInterceptor<T extends ICredentialsInterceptor> extends HttpClient {
+ private static final Logger logger = Logger.getLogger(HttpClientInterceptor.class.getName());
class CredentialsInterceptor<T extends ICredentialsInterceptor> extends HttpState {
private final T interceptor;
@@ -54,6 +56,7 @@ class HttpClientInterceptor<T extends ICredentialsInterceptor> extends HttpClien
@Override
public synchronized void setCredentials(AuthScope authscope, Credentials credentials) {
+ logger.info("Inject setCredentials");
super.setCredentials(authscope, credentials);
this.interceptor.assertCredentials(credentials);
throw new AssertionError();
@@ -73,10 +76,13 @@ class HttpClientInterceptor<T extends ICredentialsInterceptor> extends HttpClien
* @author maxvodo
*/
class AssertCredentials implements ICredentialsInterceptor {
+ private static final Logger logger = Logger.getLogger(AssertCredentials.class.getName());
+
private final Credentials expected;
public AssertCredentials(Credentials expected) { this.expected = expected; }
public void assertCredentials(Credentials actual) {
+ logger.info("Assert credential");
if (actual == null) assertTrue(this.expected == null);
else assertTrue(this.expected != null);
@@ -119,14 +125,14 @@ public class BitbucketBuildRepositoryTest {
EasyMock.expect(builder.getTrigger()).andReturn(trigger).anyTimes();
EasyMock.replay(builder);
- ApiClient.HttpClientFactory httpFactory = EasyMock.createMock(ApiClient.HttpClientFactory.class);
+ ApiClient.HttpClientFactory httpFactory = EasyMock.createNiceMock(ApiClient.HttpClientFactory.class);
EasyMock.expect(httpFactory.getInstanceHttpClient()).andReturn(
new HttpClientInterceptor(new AssertCredentials(new UsernamePasswordCredentials("foo", "bar")))
).anyTimes();
EasyMock.replay(httpFactory);
BitbucketRepository repo = new BitbucketRepository("", builder);
- repo.init(httpFactory.getClass());
+ repo.init(httpFactory);
try { repo.postPullRequestApproval("prId"); } catch(Error e) { assertTrue(e instanceof AssertionError); }
}
@@ -155,14 +161,14 @@ public class BitbucketBuildRepositoryTest {
CredentialsScope.GLOBAL, "JenkinsCID", "description", "username", "password"
));
- ApiClient.HttpClientFactory httpFactory = EasyMock.createMock(ApiClient.HttpClientFactory.class);
+ ApiClient.HttpClientFactory httpFactory = EasyMock.createNiceMock(ApiClient.HttpClientFactory.class);
EasyMock.expect(httpFactory.getInstanceHttpClient()).andReturn(
new HttpClientInterceptor(new AssertCredentials(new UsernamePasswordCredentials("username", "password")))
).anyTimes();
EasyMock.replay(httpFactory);
BitbucketRepository repo = new BitbucketRepository("", builder);
- repo.init(httpFactory.getClass());
+ repo.init(httpFactory);
try { repo.postPullRequestApproval("prId"); } catch(Error e) { assertTrue(e instanceof AssertionError); }
}
@@ -186,7 +192,6 @@ public class BitbucketBuildRepositoryTest {
}
@Test
- @WithoutJenkins
public void repositoryProjectIdTest() throws ANTLRException, NoSuchAlgorithmException, UnsupportedEncodingException {
BitbucketBuildTrigger trigger = new BitbucketBuildTrigger(
"", "@hourly",
@@ -233,7 +238,6 @@ public class BitbucketBuildRepositoryTest {
}
@Test
- @WithoutJenkins
public void triggerLongCIKeyTest() throws ANTLRException, NoSuchAlgorithmException {
BitbucketBuildTrigger trigger = new BitbucketBuildTrigger(
"", "@hourly",