Skip to content

Commit d83b983

Browse files
authored
Bugfix - build retention service sends an empty body (#504)
1 parent a93f400 commit d83b983

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

Diff for: build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/client/artifactory/services/SendBuildRetention.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.apache.http.client.methods.HttpPost;
44
import org.apache.http.client.methods.HttpRequestBase;
5+
import org.apache.http.entity.StringEntity;
56
import org.jfrog.build.api.BuildRetention;
67
import org.jfrog.build.api.util.Log;
78
import org.jfrog.build.extractor.clientConfiguration.client.VoidJFrogService;
@@ -29,9 +30,14 @@ public SendBuildRetention(BuildRetention buildRetention, String buildName, Strin
2930
@Override
3031
public HttpRequestBase createRequest() throws IOException {
3132
log.info(createBuildRetentionLogMsg(buildRetention, async));
32-
log.debug(toJsonString(buildRetention));
33+
String buildRetentionString = toJsonString(buildRetention);
34+
log.debug(buildRetentionString);
3335
String url = RETENTION_REST_URL + buildName + "?async=" + async + getProjectQueryParam(project, "&project=");
34-
return new HttpPost(url);
36+
StringEntity stringEntity = new StringEntity(buildRetentionString, "UTF-8");
37+
stringEntity.setContentType("application/json");
38+
HttpPost request = new HttpPost(url);
39+
request.setEntity(stringEntity);
40+
return request;
3541
}
3642

3743
private String createBuildRetentionLogMsg(BuildRetention buildRetention, boolean async) {

Diff for: build-info-extractor/src/test/java/org/jfrog/build/extractor/clientConfiguration/client/ArtifactoryManagerTest.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
public class ArtifactoryManagerTest extends IntegrationTestsBase {
3131
private static final String TEST_SPACE = "bi_client_test_space";
3232
private static final File tempWorkspace = new File(System.getProperty("java.io.tmpdir"), TEST_SPACE);
33+
private static final String BUILD_NAME = "ArtifactoryManagerTest";
34+
private static final String BUILD_NUMBER = "13";
3335

3436
@BeforeMethod
3537
@AfterMethod
@@ -42,18 +44,18 @@ protected void cleanup() throws IOException {
4244
* Send build info to artifactory, receive it and compare.
4345
*/
4446
@Test
45-
public void sendBuildInfoTest() throws IOException {
47+
public void sendBuildInfoAndBuildRetentioTest() throws IOException {
4648
doSendBuildInfoTest(null);
49+
sendBuildRetention("");
4750
}
4851

4952
@Test
5053
public void sendBuildInfoWithProjectTest() throws IOException {
5154
doSendBuildInfoTest("jit");
55+
sendBuildRetention("jit");
5256
}
5357

5458
private void doSendBuildInfoTest(String project) throws IOException {
55-
final String BUILD_NAME = "ArtifactoryManagerTest";
56-
final String BUILD_NUMBER = "13";
5759
final Date STARTED = new Date();
5860
final List<Vcs> VCS = Arrays.asList(new Vcs("foo", "1"),
5961
new Vcs("bar", "2"),
@@ -95,4 +97,11 @@ private void doSendBuildInfoTest(String project) throws IOException {
9597
// Compare
9698
Assert.assertEquals(toJsonString(buildInfoToSend), toJsonString(receivedBuildInfo));
9799
}
100+
101+
private void sendBuildRetention(String project) throws IOException {
102+
BuildRetention buildRetention = new BuildRetention();
103+
buildRetention.setCount(1);
104+
buildRetention.setDeleteBuildArtifacts(false);
105+
artifactoryManager.sendBuildRetention(buildRetention, BUILD_NAME, project, false);
106+
}
98107
}

0 commit comments

Comments
 (0)