Search in sources :

Example 16 with TaskListener

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

the class CloudformationStackTests method changeSetDoesNotExists.

@Test
public void changeSetDoesNotExists() {
    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);
    AmazonCloudFormationException ex = new AmazonCloudFormationException("foo");
    ex.setErrorCode("ValidationError");
    ex.setErrorMessage("change set bar does not exist");
    Mockito.when(client.describeChangeSet(new DescribeChangeSetRequest().withStackName("foo").withChangeSetName("bar"))).thenThrow(ex);
    Assertions.assertThat(stack.changeSetExists("bar")).isFalse();
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) DescribeChangeSetRequest(com.amazonaws.services.cloudformation.model.DescribeChangeSetRequest) TaskListener(hudson.model.TaskListener) AmazonCloudFormationException(com.amazonaws.services.cloudformation.model.AmazonCloudFormationException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 17 with TaskListener

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

the class CloudformationStackTests method createStack.

@Test
public void createStack() 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);
    Map<String, String> outputs = stack.create("templateBody", null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), PollConfiguration.DEFAULT, "myarn", OnFailure.DO_NOTHING.toString(), null);
    ArgumentCaptor<CreateStackRequest> captor = ArgumentCaptor.forClass(CreateStackRequest.class);
    Mockito.verify(client).createStack(captor.capture());
    Assertions.assertThat(captor.getValue()).isEqualTo(new CreateStackRequest().withStackName("foo").withTemplateBody("templateBody").withCapabilities(Capability.values()).withParameters(Collections.emptyList()).withTimeoutInMinutes((int) PollConfiguration.DEFAULT.getTimeout().toMinutes()).withOnFailure(OnFailure.DO_NOTHING).withRoleARN("myarn"));
    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) DescribeStacksResult(com.amazonaws.services.cloudformation.model.DescribeStacksResult) Stack(com.amazonaws.services.cloudformation.model.Stack) Output(com.amazonaws.services.cloudformation.model.Output) TaskListener(hudson.model.TaskListener) AmazonCloudFormationWaiters(com.amazonaws.services.cloudformation.waiters.AmazonCloudFormationWaiters) Waiter(com.amazonaws.waiters.Waiter) CreateStackRequest(com.amazonaws.services.cloudformation.model.CreateStackRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 18 with TaskListener

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

the class CloudformationStackTests method describeChangeSet.

@Test
public void describeChangeSet() {
    TaskListener taskListener = Mockito.mock(TaskListener.class);
    Mockito.when(taskListener.getLogger()).thenReturn(System.out);
    AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class);
    DescribeChangeSetResult expected = new DescribeChangeSetResult().withChanges(new Change());
    Mockito.when(client.describeChangeSet(Mockito.any(DescribeChangeSetRequest.class))).thenReturn(expected);
    CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener);
    DescribeChangeSetResult result = stack.describeChangeSet("bar");
    Assertions.assertThat(result).isSameAs(expected);
    ArgumentCaptor<DescribeChangeSetRequest> captor = ArgumentCaptor.forClass(DescribeChangeSetRequest.class);
    Mockito.verify(client).describeChangeSet(captor.capture());
    Assertions.assertThat(captor.getValue()).isEqualTo(new DescribeChangeSetRequest().withStackName("foo").withChangeSetName("bar"));
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) DescribeChangeSetRequest(com.amazonaws.services.cloudformation.model.DescribeChangeSetRequest) TaskListener(hudson.model.TaskListener) DescribeChangeSetResult(com.amazonaws.services.cloudformation.model.DescribeChangeSetResult) Change(com.amazonaws.services.cloudformation.model.Change) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 19 with TaskListener

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

the class CloudformationStackTests method stackDoesNotExists.

@Test
public void stackDoesNotExists() {
    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);
    AmazonCloudFormationException ex = new AmazonCloudFormationException("foo");
    ex.setErrorCode("ValidationError");
    ex.setErrorMessage("stack foo does not exist");
    Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))).thenThrow(ex);
    Assertions.assertThat(stack.exists()).isFalse();
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) TaskListener(hudson.model.TaskListener) AmazonCloudFormationException(com.amazonaws.services.cloudformation.model.AmazonCloudFormationException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with TaskListener

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

the class CloudformationStackTests method updateStack.

@Test
public void updateStack() 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("templateBody", 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").withTemplateBody("templateBody").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)

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