-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathGitLabSCMSourceDeserializationTest.java
More file actions
61 lines (51 loc) · 2.69 KB
/
GitLabSCMSourceDeserializationTest.java
File metadata and controls
61 lines (51 loc) · 2.69 KB
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
package io.jenkins.plugins.gitlabbranchsource;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.lang.reflect.Field;
import jenkins.branch.BranchSource;
import jenkins.scm.api.SCMSource;
import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject;
import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
@WithJenkins
class GitLabSCMSourceDeserializationTest {
private static final String PROJECT_NAME = "project";
private static final String SOURCE_ID = "id";
@Test
void afterRestartingJenkinsTransientFieldsAreNotNull(JenkinsRule j) throws Throwable {
GitLabSCMSourceBuilder sb =
new GitLabSCMSourceBuilder(SOURCE_ID, "server", "creds", "po", "group/project", "project");
WorkflowMultiBranchProject project = j.createProject(WorkflowMultiBranchProject.class, PROJECT_NAME);
project.getSourcesList().add(new BranchSource(sb.build()));
j.restart();
SCMSource source = j.getInstance().getAllItems(WorkflowMultiBranchProject.class).stream()
.filter(p -> PROJECT_NAME.equals(p.getName()))
.map(p -> p.getSCMSource(SOURCE_ID))
.findFirst()
.orElseThrow();
Class<? extends SCMSource> clazz = source.getClass();
Field mergeRequestContributorCache = clazz.getDeclaredField("mergeRequestContributorCache");
mergeRequestContributorCache.setAccessible(true);
Field mergeRequestMetadataCache = clazz.getDeclaredField("mergeRequestMetadataCache");
mergeRequestMetadataCache.setAccessible(true);
assertNotNull(mergeRequestMetadataCache.get(source));
assertNotNull(mergeRequestContributorCache.get(source));
}
@Test
void projectIdSurvivesConfigRoundtrip(JenkinsRule j) throws Exception {
GitLabSCMSourceBuilder sb =
new GitLabSCMSourceBuilder(SOURCE_ID, "server", "creds", "po", "group/project", "project");
WorkflowMultiBranchProject project = j.createProject(WorkflowMultiBranchProject.class, PROJECT_NAME);
GitLabSCMSource source = sb.build();
project.getSourcesList().add(new BranchSource(source));
long p = 42;
source.setProjectId(p);
j.configRoundtrip(project);
WorkflowMultiBranchProject item = j.jenkins.getItemByFullName(PROJECT_NAME, WorkflowMultiBranchProject.class);
assertNotNull(item);
GitLabSCMSource scmSource = (GitLabSCMSource) item.getSCMSource(SOURCE_ID);
assertNotNull(scmSource);
assertEquals(Long.valueOf(p), scmSource.getProjectId());
}
}