Search in sources :

Example 11 with DescribableList

use of hudson.util.DescribableList in project blueocean-plugin by jenkinsci.

the class GithubIssueTest method changeSetEntry.

@Test
public void changeSetEntry() throws Exception {
    MultiBranchProject project = mock(MultiBranchProject.class);
    Job job = mock(MockJob.class);
    Run run = mock(Run.class);
    ChangeLogSet logSet = mock(ChangeLogSet.class);
    ChangeLogSet.Entry entry = mock(ChangeLogSet.Entry.class);
    when(project.getProperties()).thenReturn(new DescribableList(project));
    when(entry.getParent()).thenReturn(logSet);
    when(logSet.getRun()).thenReturn(run);
    when(run.getParent()).thenReturn(job);
    when(job.getParent()).thenReturn(project);
    GitHubSCMSource source = new GitHubSCMSource("foo", null, null, null, "example", "repo");
    when(project.getSCMSources()).thenReturn(Collections.singletonList(source));
    when(entry.getMsg()).thenReturn("Closed #123 #124");
    Collection<BlueIssue> resolved = BlueIssueFactory.resolve(entry);
    Assert.assertEquals(2, resolved.size());
    Map<String, BlueIssue> issueMap = resolved.stream().collect(Collectors.toMap(BlueIssue::getId, blueIssue -> blueIssue));
    BlueIssue issue123 = issueMap.get("#123");
    Assert.assertEquals("https://github.com/example/repo/issues/123", issue123.getURL());
    BlueIssue issue124 = issueMap.get("#124");
    Assert.assertEquals("https://github.com/example/repo/issues/124", issue124.getURL());
}
Also used : GitHubSCMSource(org.jenkinsci.plugins.github_branch_source.GitHubSCMSource) Arrays(java.util.Arrays) MultiBranchProject(jenkins.branch.MultiBranchProject) ChangeLogSet(hudson.scm.ChangeLogSet) BlueIssueFactory(io.jenkins.blueocean.rest.factory.BlueIssueFactory) RunWith(org.junit.runner.RunWith) ArrayList(java.util.ArrayList) Map(java.util.Map) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) PowerMockIgnore(org.powermock.core.classloader.annotations.PowerMockIgnore) Nonnull(javax.annotation.Nonnull) DescribableList(hudson.util.DescribableList) Collection(java.util.Collection) AbstractFolder(com.cloudbees.hudson.plugins.folder.AbstractFolder) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) ItemGroup(hudson.model.ItemGroup) Run(hudson.model.Run) Rule(org.junit.Rule) BlueIssue(io.jenkins.blueocean.rest.model.BlueIssue) Job(hudson.model.Job) Assert(org.junit.Assert) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) Collections(java.util.Collections) GitSCMSource(jenkins.plugins.git.GitSCMSource) Mockito.mock(org.mockito.Mockito.mock) ChangeLogSet(hudson.scm.ChangeLogSet) DescribableList(hudson.util.DescribableList) MultiBranchProject(jenkins.branch.MultiBranchProject) Run(hudson.model.Run) GitHubSCMSource(org.jenkinsci.plugins.github_branch_source.GitHubSCMSource) Job(hudson.model.Job) BlueIssue(io.jenkins.blueocean.rest.model.BlueIssue) Test(org.junit.Test)

Example 12 with DescribableList

use of hudson.util.DescribableList in project hudson-2.x by hudson.

the class DescribableListProjectPropertyTest method testReturnOriginalValue.

/**
 * Verify {@link CopyOnWriteListProjectProperty#returnOriginalValue()} method.
 */
@Test
public void testReturnOriginalValue() {
    // Return cascading is property is not overridden and is empty.
    assertFalse(property.returnOriginalValue());
    // Return properties' originalValue if it was overridden
    property.setOverridden(true);
    assertTrue(property.returnOriginalValue());
    // If property has not empty value - return it (basically for non-cascadable projects)
    property.setOriginalValue(new DescribableList(project, Arrays.asList(new Object())), false);
    assertTrue(property.returnOriginalValue());
    // If property has not empty value and was overridden - return it
    property.setOriginalValue(new DescribableList(project, Arrays.asList(new Object())), true);
    assertTrue(property.returnOriginalValue());
}
Also used : DescribableList(hudson.util.DescribableList) Test(org.junit.Test)

Example 13 with DescribableList

use of hudson.util.DescribableList in project hudson-2.x by hudson.

the class DescribableListProjectPropertyTest method testGetDefaultValue.

/**
 * Verify {@link DescribableListProjectProperty#getDefaultValue()} method.
 */
@Test
public void testGetDefaultValue() {
    DescribableList defaultValue = property.getDefaultValue();
    assertNotNull(defaultValue);
    // Default value should be initialized and stored as original value
    assertTrue(property.getOriginalValue() == defaultValue);
    assertFalse(property.isOverridden());
}
Also used : DescribableList(hudson.util.DescribableList) Test(org.junit.Test)

Example 14 with DescribableList

use of hudson.util.DescribableList in project hudson-2.x by hudson.

the class DescribableListProjectProperty method getDefaultValue.

@Override
public DescribableList getDefaultValue() {
    DescribableList result = new DescribableList(getJob());
    setOriginalValue(result, false);
    return result;
}
Also used : DescribableList(hudson.util.DescribableList)

Example 15 with DescribableList

use of hudson.util.DescribableList in project configuration-as-code-plugin by jenkinsci.

the class JenkinsConfiguratorTest method shouldExportLabelAtoms.

@Test
@ConfiguredWithCode("ConfigureLabels.yml")
public void shouldExportLabelAtoms() throws Exception {
    DescribableList properties = Jenkins.get().getLabelAtom("label1").getProperties();
    properties.add(new TestProperty(1));
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    ConfigurationAsCode.get().export(out);
    final String exported = out.toString();
    String content = FileUtils.readFileToString(new File(getClass().getResource("ExpectedLabelsConfiguration.yml").toURI()), "UTF-8");
    assertThat(exported, containsString(content));
}
Also used : DescribableList(hudson.util.DescribableList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Aggregations

DescribableList (hudson.util.DescribableList)15 Test (org.junit.Test)8 MultiBranchProject (jenkins.branch.MultiBranchProject)5 AbstractFolderProperty (com.cloudbees.hudson.plugins.folder.AbstractFolderProperty)3 AbstractFolderPropertyDescriptor (com.cloudbees.hudson.plugins.folder.AbstractFolderPropertyDescriptor)3 Domain (com.cloudbees.plugins.credentials.domains.Domain)3 Job (hudson.model.Job)3 Run (hudson.model.Run)3 ChangeLogSet (hudson.scm.ChangeLogSet)3 BlueOceanCredentialsProvider (io.jenkins.blueocean.rest.impl.pipeline.credential.BlueOceanCredentialsProvider)3 BlueIssue (io.jenkins.blueocean.rest.model.BlueIssue)3 AbstractFolder (com.cloudbees.hudson.plugins.folder.AbstractFolder)2 BitbucketSCMSource (com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource)2 Descriptor (hudson.model.Descriptor)2 IOException (java.io.IOException)2 GitSCMSource (jenkins.plugins.git.GitSCMSource)2 JSONObject (net.sf.json.JSONObject)2 GitHubSCMSource (org.jenkinsci.plugins.github_branch_source.GitHubSCMSource)2 ObjectComponent (com.cloudbees.jenkins.support.api.ObjectComponent)1 ObjectComponentDescriptor (com.cloudbees.jenkins.support.api.ObjectComponentDescriptor)1