forked from jfrog/build-info
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArtifactoryManagerTest.java
145 lines (128 loc) · 5.35 KB
/
ArtifactoryManagerTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package org.jfrog.build.extractor.clientConfiguration.client;
import org.apache.commons.io.FileUtils;
import org.jfrog.build.IntegrationTestsBase;
import org.jfrog.build.api.builder.PromotionBuilder;
import org.jfrog.build.api.release.Promotion;
import org.jfrog.build.api.release.PromotionStatus;
import org.jfrog.build.extractor.builder.BuildInfoBuilder;
import org.jfrog.build.extractor.ci.*;
import org.jfrog.build.extractor.ci.Module;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import static org.jfrog.build.extractor.clientConfiguration.util.JsonUtils.toJsonString;
/**
* Integration tests for the ArtifactoryBuildInfoClient.
* Performs tests using the infrastructure resources provided by IntegrationTestsBase (such as Artifactory, localRepo, and credentials).
*
* @author Yahav Itzhak
*/
@Test
public class ArtifactoryManagerTest extends IntegrationTestsBase {
private static final String TEST_SPACE = "bi_client_test_space";
private static final File tempWorkspace = new File(System.getProperty("java.io.tmpdir"), TEST_SPACE);
private static final String BUILD_NAME = "ArtifactoryManagerTest";
private static final String BUILD_NUMBER = String.valueOf(System.currentTimeMillis());
@BeforeMethod
@AfterMethod
protected void cleanup() throws IOException {
FileUtils.deleteDirectory(tempWorkspace);
deleteContentFromRepo(localRepo1);
}
/**
* Send build info to artifactory, receive it and compare.
*/
@Test
public void sendBuildInfoAndBuildRetentionTest() throws IOException {
try {
publishAndCheckBuildInfo(null);
sendBuildRetention(null);
} finally {
cleanTestBuilds(BUILD_NAME, BUILD_NUMBER, null);
}
}
@Test
public void sendBuildInfoWithProjectTest() throws IOException {
String projectKey = "btests";
try {
publishAndCheckBuildInfo(projectKey);
sendBuildRetention(projectKey);
} finally {
cleanTestBuilds(BUILD_NAME, BUILD_NUMBER, projectKey);
}
}
@Test
public void buildStagingTest() throws IOException {
try {
publishAndCheckBuildInfo(null);
stageBuild(null);
} finally {
cleanTestBuilds(BUILD_NAME, BUILD_NUMBER, null);
}
}
@Test
public void buildStagingWithProjectTest() throws IOException {
String projectKey = "btests";
try {
publishAndCheckBuildInfo(projectKey);
stageBuild(projectKey);
} finally {
cleanTestBuilds(BUILD_NAME, BUILD_NUMBER, projectKey);
}
}
private void publishAndCheckBuildInfo(String project) throws IOException {
final Date STARTED = new Date();
final List<Vcs> VCS = Arrays.asList(new Vcs("foo", "1"),
new Vcs("bar", "2"),
new Vcs("baz", "3"));
final List<MatrixParameter> RUN_PARAMETERS = Arrays.asList(new MatrixParameter("a", "b"), new MatrixParameter("c", "d"));
final Module module = new Module();
module.setId("foo");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(BuildInfo.STARTED_FORMAT);
final List<PromotionStatus> STATUSES = Collections.singletonList(new PromotionStatus("a", "b", "c", simpleDateFormat.format(STARTED), "e", "f"));
BuildInfoBuilder buildInfoBuilder = new BuildInfoBuilder(BUILD_NAME)
.number(BUILD_NUMBER)
.setProject(project)
.buildAgent(new BuildAgent("agent11", "11"))
.agent(new Agent("agent22", "22"))
.startedDate(STARTED)
.durationMillis(100)
.principal("foo")
.artifactoryPrincipal(getUsername())
.artifactoryPluginVersion("2.3.1")
.url(getArtifactoryUrl())
.parentName("baz")
.parentNumber("10")
.vcs(VCS)
.buildRetention(new BuildRetention(true))
.buildRunParameters(RUN_PARAMETERS)
.modules(Collections.singletonList(module))
.statuses(STATUSES)
.issues(new Issues());
BuildInfo buildInfoToSend = buildInfoBuilder.build();
// Publish build info
artifactoryManager.publishBuildInfo(buildInfoToSend, project);
// Get build info
BuildInfo receivedBuildInfo = artifactoryManager.getBuildInfo(BUILD_NAME, BUILD_NUMBER, project);
// Compare
Assert.assertEquals(toJsonString(buildInfoToSend), toJsonString(receivedBuildInfo));
}
private void sendBuildRetention(String project) throws IOException {
BuildRetention buildRetention = new BuildRetention();
buildRetention.setCount(1);
buildRetention.setDeleteBuildArtifacts(false);
artifactoryManager.sendBuildRetention(buildRetention, BUILD_NAME, project, false);
}
private void stageBuild(String project) throws IOException {
Promotion promotion = new PromotionBuilder().build();
artifactoryManager.stageBuild(BUILD_NAME, BUILD_NUMBER, project, promotion);
}
}