Add a test
This commit is contained in:
parent
116c6baf19
commit
d3c9cbce79
|
@ -37,7 +37,8 @@ public class HttpResponse {
|
|||
HttpEntity entity = response.getEntity();
|
||||
if(getStatus() >= 300){
|
||||
ErrorMessage errorMessage = new ErrorMessage(getStatus(), getStatusLine());
|
||||
if (StringUtils.isEmpty(errorMessage.message)) {
|
||||
// WireMock returns "Bad Request" for the status message; it's also pretty nondescript
|
||||
if (StringUtils.isEmpty(errorMessage.message) || "Bad Request".equals(errorMessage.message)) {
|
||||
String message;;
|
||||
List<ErrorMessage.Error> errors = new ArrayList<>();
|
||||
try {
|
||||
|
|
|
@ -146,6 +146,41 @@ public class BitbucketServerScmContentProviderTest extends BbServerWireMock {
|
|||
fail("Should have failed with PreConditionException");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleSaveErrorsWithEmptyStatusLine() throws UnirestException, IOException {
|
||||
String credentialId = createCredential(BitbucketServerScm.ID);
|
||||
StaplerRequest staplerRequest = mockStapler();
|
||||
MultiBranchProject mbp = mockMbp(credentialId);
|
||||
|
||||
// /rest/api/1.0/projects/PROJ/repos/with-jenkinsfile/browse/Jenkinsfile
|
||||
GitContent content = new GitContent.Builder().autoCreateBranch(true).base64Data("bm9kZXsKICBlY2hvICdoZWxsbyB3b3JsZCEnCn0K")
|
||||
.branch("master").message("new commit").owner("TESTP").path("Jenkinsfile").repo("pipeline-demo-test").build();
|
||||
|
||||
when(staplerRequest.bindJSON(Mockito.eq(BitbucketScmSaveFileRequest.class), Mockito.any(JSONObject.class))).thenReturn(new BitbucketScmSaveFileRequest(content));
|
||||
|
||||
String request = "{\n" +
|
||||
" \"content\" : {\n" +
|
||||
" \"message\" : \"new commit\",\n" +
|
||||
" \"path\" : \"Jenkinsfile\",\n" +
|
||||
" \"branch\" : \"master\",\n" +
|
||||
" \"repo\" : \"pipeline-demo-test\",\n" +
|
||||
" \"base64Data\" : " + "\"bm9kZXsKICBlY2hvICdoZWxsbyB3b3JsZCEnCn0K\"" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
when(staplerRequest.getReader()).thenReturn(new BufferedReader(new StringReader(request), request.length()));
|
||||
|
||||
try {
|
||||
// Should get mocked response from:
|
||||
// bitbucket_rest_api_10_projects_proj_repos_with-jenkinsfile_browse_jenkinsfile-7269cd83-1af6-4134-9161-82360d678dcc.json
|
||||
new BitbucketServerScmContentProvider()
|
||||
.saveContent(staplerRequest, mbp);
|
||||
} catch (ServiceException e) {
|
||||
assertEquals("File editing canceled for 'Jenkinsfile' on 'master'.", e.getMessage());
|
||||
return;
|
||||
}
|
||||
fail("Should have failed with message: File editing canceled for 'Jenkinsfile' on 'master'.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateContent() throws UnirestException, IOException {
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"id" : "7269cd83-1af6-4134-9161-82360d678dcc",
|
||||
"name" : "bitbucket_rest_api_10_projects_proj_repos_with-jenkinsfile_browse_jenkinsfile",
|
||||
"request" : {
|
||||
"url" : "/rest/api/1.0/projects/TESTP/repos/pipeline-demo-test/browse/Jenkinsfile",
|
||||
"method" : "PUT",
|
||||
"bodyPatterns" : [ {
|
||||
"anything" : "anything"
|
||||
} ]
|
||||
},
|
||||
"response" : {
|
||||
"status" : "400",
|
||||
"body" : "{\"errors\":[{\"context\":null,\"message\":\"File editing canceled for 'Jenkinsfile' on 'master'.\",\"exceptionName\":\"com.atlassian.bitbucket.hook.repository.RepositoryHookVetoedException\",\"details\":[\"Branch permissions canceled the editing of 'Jenkinsfile' on 'master'.\",\"Branch refs/heads/master can only be modified through pull requests.\\nCheck your branch permissions configuration with the project administrator.\"],\"trigger\":{\"id\":\"file-edit\",\"abortOnFirstVeto\":false}}]}",
|
||||
"headers" : {
|
||||
"X-AREQUESTID" : "@L72CV8x1069x1007x0",
|
||||
"X-AUSERID" : "2",
|
||||
"X-AUSERNAME" : "user",
|
||||
"Cache-Control" : "no-cache, no-transform",
|
||||
"Vary" : "X-AUSERNAME,Accept-Encoding",
|
||||
"X-Content-Type-Options" : "nosniff",
|
||||
"Content-Type" : "application/json;charset=UTF-8",
|
||||
"Date" : "Sun, 19 Aug 2018 21:49:54 GMT",
|
||||
"Connection" : "close"
|
||||
}
|
||||
},
|
||||
"uuid" : "7269cd83-1af6-4134-9161-82360d678dcc",
|
||||
"persistent" : true,
|
||||
"insertionIndex" : 68
|
||||
}
|
Loading…
Reference in New Issue