Search in sources :

Example 21 with TaskListener

use of hudson.model.TaskListener in project pipeline-aws-plugin by jenkinsci.

the class CloudformationStackTests method doNotExecuteChangeSetIfNoChanges.

@Test
public void doNotExecuteChangeSetIfNoChanges() throws ExecutionException {
    TaskListener taskListener = Mockito.mock(TaskListener.class);
    Mockito.when(taskListener.getLogger()).thenReturn(System.out);
    AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class);
    CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener);
    Mockito.when(client.describeChangeSet(new DescribeChangeSetRequest().withStackName("foo").withChangeSetName("bar"))).thenReturn(new DescribeChangeSetResult().withStatus(ChangeSetStatus.FAILED).withStatusReason("the submitted information didn't contain changes"));
    Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))).thenReturn(new DescribeStacksResult().withStacks(new Stack().withOutputs(new Output().withOutputKey("bar").withOutputValue("baz"))));
    Map<String, String> outputs = stack.executeChangeSet("bar", PollConfiguration.DEFAULT);
    Mockito.verify(client, Mockito.never()).executeChangeSet(Mockito.any(ExecuteChangeSetRequest.class));
    Assertions.assertThat(outputs).containsEntry("bar", "baz").containsEntry("jenkinsStackUpdateStatus", "false");
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) ExecuteChangeSetRequest(com.amazonaws.services.cloudformation.model.ExecuteChangeSetRequest) DescribeChangeSetRequest(com.amazonaws.services.cloudformation.model.DescribeChangeSetRequest) Output(com.amazonaws.services.cloudformation.model.Output) TaskListener(hudson.model.TaskListener) DescribeChangeSetResult(com.amazonaws.services.cloudformation.model.DescribeChangeSetResult) DescribeStacksResult(com.amazonaws.services.cloudformation.model.DescribeStacksResult) Stack(com.amazonaws.services.cloudformation.model.Stack) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 22 with TaskListener

use of hudson.model.TaskListener in project pipeline-aws-plugin by jenkinsci.

the class CloudformationStackTests method executeChangeSetWithChanges.

@Test
public void executeChangeSetWithChanges() throws ExecutionException {
    TaskListener taskListener = Mockito.mock(TaskListener.class);
    Mockito.when(taskListener.getLogger()).thenReturn(System.out);
    Mockito.when(taskListener.getLogger()).thenReturn(System.out);
    AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class);
    Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client));
    CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener);
    Mockito.when(client.describeChangeSet(new DescribeChangeSetRequest().withStackName("foo").withChangeSetName("bar"))).thenReturn(new DescribeChangeSetResult().withChanges(new Change()));
    Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))).thenReturn(new DescribeStacksResult().withStacks(new Stack().withStackStatus("CREATE_COMPLETE").withOutputs(new Output().withOutputKey("bar").withOutputValue("baz"))));
    Map<String, String> outputs = stack.executeChangeSet("bar", PollConfiguration.DEFAULT);
    Mockito.verify(client).executeChangeSet(Mockito.any(ExecuteChangeSetRequest.class));
    Mockito.verify(this.eventPrinter).waitAndPrintStackEvents(Mockito.eq("foo"), Mockito.any(Waiter.class), Mockito.eq(PollConfiguration.DEFAULT));
    Assertions.assertThat(outputs).containsEntry("bar", "baz").containsEntry("jenkinsStackUpdateStatus", "true");
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) ExecuteChangeSetRequest(com.amazonaws.services.cloudformation.model.ExecuteChangeSetRequest) DescribeChangeSetResult(com.amazonaws.services.cloudformation.model.DescribeChangeSetResult) Change(com.amazonaws.services.cloudformation.model.Change) DescribeStacksResult(com.amazonaws.services.cloudformation.model.DescribeStacksResult) Stack(com.amazonaws.services.cloudformation.model.Stack) DescribeChangeSetRequest(com.amazonaws.services.cloudformation.model.DescribeChangeSetRequest) Output(com.amazonaws.services.cloudformation.model.Output) TaskListener(hudson.model.TaskListener) AmazonCloudFormationWaiters(com.amazonaws.services.cloudformation.waiters.AmazonCloudFormationWaiters) Waiter(com.amazonaws.waiters.Waiter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 23 with TaskListener

use of hudson.model.TaskListener in project pipeline-aws-plugin by jenkinsci.

the class CloudformationStackTests method updateStackWithPreviousTemplate.

@Test
public void updateStackWithPreviousTemplate() throws ExecutionException {
    TaskListener taskListener = Mockito.mock(TaskListener.class);
    Mockito.when(taskListener.getLogger()).thenReturn(System.out);
    AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class);
    Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client));
    Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))).thenReturn(new DescribeStacksResult().withStacks(new Stack().withOutputs(new Output().withOutputKey("bar").withOutputValue("baz"))));
    CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener);
    RollbackConfiguration rollbackConfig = new RollbackConfiguration().withMonitoringTimeInMinutes(10);
    Map<String, String> outputs = stack.update(null, null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), PollConfiguration.DEFAULT, "myarn", rollbackConfig);
    ArgumentCaptor<UpdateStackRequest> captor = ArgumentCaptor.forClass(UpdateStackRequest.class);
    Mockito.verify(client).updateStack(captor.capture());
    Assertions.assertThat(captor.getValue()).isEqualTo(new UpdateStackRequest().withStackName("foo").withUsePreviousTemplate(true).withCapabilities(Capability.values()).withParameters(Collections.emptyList()).withRoleARN("myarn").withRollbackConfiguration(rollbackConfig));
    Mockito.verify(this.eventPrinter).waitAndPrintStackEvents(Mockito.eq("foo"), Mockito.any(Waiter.class), Mockito.eq(PollConfiguration.DEFAULT));
    Assertions.assertThat(outputs).containsEntry("bar", "baz").containsEntry("jenkinsStackUpdateStatus", "true");
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) UpdateStackRequest(com.amazonaws.services.cloudformation.model.UpdateStackRequest) DescribeStacksResult(com.amazonaws.services.cloudformation.model.DescribeStacksResult) Stack(com.amazonaws.services.cloudformation.model.Stack) RollbackConfiguration(com.amazonaws.services.cloudformation.model.RollbackConfiguration) Output(com.amazonaws.services.cloudformation.model.Output) TaskListener(hudson.model.TaskListener) AmazonCloudFormationWaiters(com.amazonaws.services.cloudformation.waiters.AmazonCloudFormationWaiters) Waiter(com.amazonaws.waiters.Waiter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 24 with TaskListener

use of hudson.model.TaskListener in project pipeline-aws-plugin by jenkinsci.

the class CloudformationStackTests method describeStack.

@Test
public void describeStack() {
    TaskListener taskListener = Mockito.mock(TaskListener.class);
    Mockito.when(taskListener.getLogger()).thenReturn(System.out);
    AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class);
    CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener);
    Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))).thenReturn(new DescribeStacksResult().withStacks(new Stack().withOutputs(new Output().withOutputKey("bar").withOutputValue("baz"))));
    Assertions.assertThat(stack.describeOutputs()).isEqualTo(Collections.singletonMap("bar", "baz"));
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) Output(com.amazonaws.services.cloudformation.model.Output) TaskListener(hudson.model.TaskListener) DescribeStacksResult(com.amazonaws.services.cloudformation.model.DescribeStacksResult) Stack(com.amazonaws.services.cloudformation.model.Stack) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 25 with TaskListener

use of hudson.model.TaskListener in project nodejs-plugin by jenkinsci.

the class NodeJSCommandInterpreterTest method test_inject_path_variable.

@Issue("JENKINS-41947")
@Test
public void test_inject_path_variable() throws Exception {
    NodeJSInstallation installation = mockInstaller();
    NodeJSCommandInterpreter builder = CIBuilderHelper.createMock("test_executable_value", installation, null, new CIBuilderHelper.Verifier() {

        @Override
        public void verify(AbstractBuild<?, ?> build, Launcher launcher, TaskListener listener) throws Exception {
            assertFalse("No Environments", build.getEnvironments().isEmpty());
            EnvVars env = build.getEnvironment(listener);
            assertThat(env.keySet(), CoreMatchers.hasItems(NodeJSConstants.ENVVAR_NODEJS_PATH, NodeJSConstants.ENVVAR_NODEJS_HOME));
            assertEquals(getTestHome(), env.get(NodeJSConstants.ENVVAR_NODEJS_HOME));
            assertEquals(getTestBin(), env.get(NodeJSConstants.ENVVAR_NODEJS_PATH));
        }
    });
    FreeStyleProject job = j.createFreeStyleProject();
    job.getBuildersList().add(builder);
    j.assertBuildStatusSuccess(job.scheduleBuild2(0));
}
Also used : NodeJSInstallation(jenkins.plugins.nodejs.tools.NodeJSInstallation) Verifier(jenkins.plugins.nodejs.CIBuilderHelper.Verifier) EnvVars(hudson.EnvVars) CIBuilderHelper(jenkins.plugins.nodejs.CIBuilderHelper) TaskListener(hudson.model.TaskListener) Launcher(hudson.Launcher) FreeStyleProject(hudson.model.FreeStyleProject) IOException(java.io.IOException) DetectionFailedException(jenkins.plugins.nodejs.tools.DetectionFailedException) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Aggregations

TaskListener (hudson.model.TaskListener)42 Test (org.junit.Test)28 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)25 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)24 DescribeStacksResult (com.amazonaws.services.cloudformation.model.DescribeStacksResult)16 AmazonCloudFormationWaiters (com.amazonaws.services.cloudformation.waiters.AmazonCloudFormationWaiters)16 Waiter (com.amazonaws.waiters.Waiter)15 DescribeStacksRequest (com.amazonaws.services.cloudformation.model.DescribeStacksRequest)14 Stack (com.amazonaws.services.cloudformation.model.Stack)12 EnvVars (hudson.EnvVars)10 Output (com.amazonaws.services.cloudformation.model.Output)9 DescribeChangeSetResult (com.amazonaws.services.cloudformation.model.DescribeChangeSetResult)8 IOException (java.io.IOException)8 DescribeChangeSetRequest (com.amazonaws.services.cloudformation.model.DescribeChangeSetRequest)6 LogTaskListener (hudson.util.LogTaskListener)4 PrintStream (java.io.PrintStream)4 ArrayList (java.util.ArrayList)4 Change (com.amazonaws.services.cloudformation.model.Change)3 CreateChangeSetRequest (com.amazonaws.services.cloudformation.model.CreateChangeSetRequest)3 ExecuteChangeSetRequest (com.amazonaws.services.cloudformation.model.ExecuteChangeSetRequest)3