com.amazonaws.services.cloudformation.model.ValidateTemplateRequest Java Examples

The following examples show how to use com.amazonaws.services.cloudformation.model.ValidateTemplateRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CFNValidateStepTests.java    From pipeline-aws-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void validateWithUrlFailure() throws Exception {
	WorkflowJob job = this.jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
	AmazonCloudFormationException ex = new AmazonCloudFormationException("invalid template");
	Mockito.when(this.cloudFormation.validateTemplate(Mockito.any(ValidateTemplateRequest.class)))
			.thenThrow(ex);
	job.setDefinition(new CpsFlowDefinition(""
			+ "node {\n"
			+ "  cfnValidate(url: 'foo')"
			+ "}\n", true)
	);

	this.jenkinsRule.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0));

	ArgumentCaptor<ValidateTemplateRequest> captor = ArgumentCaptor.forClass(ValidateTemplateRequest.class);
	Mockito.verify(this.cloudFormation).validateTemplate(captor.capture());
	Assertions.assertThat(captor.getValue()).isEqualTo(new ValidateTemplateRequest()
			.withTemplateURL("foo")
	);
}
 
Example #2
Source File: CloudformationTest.java    From lambadaframework with MIT License 5 votes vote down vote up
@Test
@Ignore
public void testCloudFormationTemplateValidate() {
    try {
        Cloudformation cf = new Cloudformation(getMockDeployment());
        cf.getCloudFormationClient().validateTemplate(new ValidateTemplateRequest().withTemplateBody(cf.getCloudformationTemplate()));
    } catch (AmazonServiceException amazonServiceException) {
        //DO nothing, AWS credentials do not exist in CI environment.
    }
}
 
Example #3
Source File: CFNValidateStep.java    From pipeline-aws-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean start() throws Exception {
	final String file = this.step.getFile();
	final String url = this.step.getUrl();

	if ((file == null || file.isEmpty()) && (url == null || url.isEmpty())) {
		throw new IllegalArgumentException("Either a file or url for the template must be specified");
	}

	this.getContext().get(TaskListener.class).getLogger().format("Validating CloudFormation template %s %n", file);

	final String template = this.readTemplate(file);

	new Thread("cfnValidate-" + file) {
		@Override
		public void run() {
			AmazonCloudFormation client = AWSClientFactory.create(AmazonCloudFormationClientBuilder.standard(), Execution.this.getContext());
			try {
				ValidateTemplateRequest request = new ValidateTemplateRequest();
				if (template != null) {
					request.withTemplateBody(template);
				} else {
					request.withTemplateURL(url);
				}
				ValidateTemplateResult result = client.validateTemplate(request);
				Execution.this.getContext().onSuccess(AwsSdkResponseToJson.convertToMap(result));
			} catch (AmazonCloudFormationException | IOException e) {
				Execution.this.getContext().onFailure(e);
			}
		}
	}.start();
	return false;
}
 
Example #4
Source File: CFNValidateStepTests.java    From pipeline-aws-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void validateWithUrlSuccess() throws Exception {
	WorkflowJob job = this.jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
	job.setDefinition(new CpsFlowDefinition(""
			+ "node {\n"
			+ "  def response = cfnValidate(url: 'foo')\n"
			+ "  echo \"description=${response.description}\"\n"
			+ "  echo \"parameters=${response.parameters.toString()}\"\n"
			+ "}\n", true)
	);
	Mockito.when(this.cloudFormation.validateTemplate(Mockito.any())).thenReturn(new ValidateTemplateResult()
			.withDescription("myDescription")
			.withParameters(new TemplateParameter()
					.withDefaultValue("hello")
					.withDescription("myParamDescription")
					.withParameterKey("myParam")
			)
	);

	WorkflowRun run = this.jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));

	jenkinsRule.assertLogContains("description=myDescription", run);
	jenkinsRule.assertLogContains("parameters=[[parameterKey:myParam, defaultValue:hello, noEcho:null, description:myParamDescription]]", run);
	ArgumentCaptor<ValidateTemplateRequest> captor = ArgumentCaptor.forClass(ValidateTemplateRequest.class);
	Mockito.verify(this.cloudFormation).validateTemplate(captor.capture());
	Assertions.assertThat(captor.getValue()).isEqualTo(new ValidateTemplateRequest()
			.withTemplateURL("foo")
	);
}