-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
297 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/test/java/jenkins/plugins/slack/CloseableHttpClientStub.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package jenkins.plugins.slack; | ||
|
||
import org.apache.commons.httpclient.HttpStatus; | ||
import org.apache.http.HttpHost; | ||
import org.apache.http.HttpRequest; | ||
import org.apache.http.client.ClientProtocolException; | ||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
import org.apache.http.client.methods.HttpUriRequest; | ||
import org.apache.http.conn.ClientConnectionManager; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.params.HttpParams; | ||
import org.apache.http.protocol.HttpContext; | ||
|
||
import java.io.IOException; | ||
|
||
public class CloseableHttpClientStub extends CloseableHttpClient { | ||
|
||
private int numberOfCallsToExecuteMethod; | ||
private int httpStatus; | ||
private boolean failAlternateResponses = false; | ||
|
||
public CloseableHttpResponse execute(HttpUriRequest post) { | ||
numberOfCallsToExecuteMethod++; | ||
if (failAlternateResponses && (numberOfCallsToExecuteMethod % 2 == 0)) { | ||
return new CloseableHttpResponseStub(HttpStatus.SC_NOT_FOUND); | ||
} else { | ||
return new CloseableHttpResponseStub(httpStatus); | ||
} | ||
} | ||
|
||
@Override | ||
public ClientConnectionManager getConnectionManager() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
|
||
} | ||
|
||
@Override | ||
public HttpParams getParams() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected CloseableHttpResponse doExecute(HttpHost httpHost, HttpRequest httpRequest, HttpContext httpContext) throws IOException, ClientProtocolException { | ||
return null; | ||
} | ||
|
||
public int getNumberOfCallsToExecuteMethod() { | ||
return numberOfCallsToExecuteMethod; | ||
} | ||
|
||
public void setHttpStatus(int httpStatus) { | ||
this.httpStatus = httpStatus; | ||
} | ||
|
||
public void setFailAlternateResponses(boolean failAlternateResponses) { | ||
this.failAlternateResponses = failAlternateResponses; | ||
} | ||
} |
Oops, something went wrong.