Java Code Examples for com.amazonaws.services.secretsmanager.model.GetSecretValueResult#setSecretString()

The following examples show how to use com.amazonaws.services.secretsmanager.model.GetSecretValueResult#setSecretString() . 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: AwsSecretsManagerPropertySourceLocatorTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
public void contextExpectedToHave2Elements() {
	AwsSecretsManagerProperties properties = new AwsSecretsManagerPropertiesBuilder()
			.withDefaultContext("application").withName("application").build();

	GetSecretValueResult secretValueResult = new GetSecretValueResult();
	secretValueResult.setSecretString("{\"key1\": \"value1\", \"key2\": \"value2\"}");
	when(smClient.getSecretValue(any(GetSecretValueRequest.class)))
			.thenReturn(secretValueResult);

	AwsSecretsManagerPropertySourceLocator locator = new AwsSecretsManagerPropertySourceLocator(
			smClient, properties);
	env.setActiveProfiles("test");
	locator.locate(env);

	assertThat(locator.getContexts()).hasSize(2);
}
 
Example 2
Source File: AwsSecretsManagerPropertySourceLocatorTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
public void contextExpectedToHave4Elements() {
	AwsSecretsManagerProperties properties = new AwsSecretsManagerPropertiesBuilder()
			.withDefaultContext("application").withName("messaging-service").build();

	GetSecretValueResult secretValueResult = new GetSecretValueResult();
	secretValueResult.setSecretString("{\"key1\": \"value1\", \"key2\": \"value2\"}");
	when(smClient.getSecretValue(any(GetSecretValueRequest.class)))
			.thenReturn(secretValueResult);

	AwsSecretsManagerPropertySourceLocator locator = new AwsSecretsManagerPropertySourceLocator(
			smClient, properties);
	env.setActiveProfiles("test");
	locator.locate(env);

	assertThat(locator.getContexts()).hasSize(4);
}
 
Example 3
Source File: AwsSecretsManagerPropertySourceLocatorTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
public void contextSpecificOrderExpected() {
	AwsSecretsManagerProperties properties = new AwsSecretsManagerPropertiesBuilder()
			.withDefaultContext("application").withName("messaging-service").build();

	GetSecretValueResult secretValueResult = new GetSecretValueResult();
	secretValueResult.setSecretString("{\"key1\": \"value1\", \"key2\": \"value2\"}");
	when(smClient.getSecretValue(any(GetSecretValueRequest.class)))
			.thenReturn(secretValueResult);

	AwsSecretsManagerPropertySourceLocator locator = new AwsSecretsManagerPropertySourceLocator(
			smClient, properties);
	env.setActiveProfiles("test");
	locator.locate(env);

	List<String> contextToBeTested = new ArrayList<>(locator.getContexts());

	assertThat(contextToBeTested.get(0)).isEqualTo("/secret/messaging-service_test");
	assertThat(contextToBeTested.get(1)).isEqualTo("/secret/messaging-service");
	assertThat(contextToBeTested.get(2)).isEqualTo("/secret/application_test");
	assertThat(contextToBeTested.get(3)).isEqualTo("/secret/application");

}
 
Example 4
Source File: AwsSecretsManagerPropertySourceTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void shouldParseSecretValue() {
	GetSecretValueResult secretValueResult = new GetSecretValueResult();
	secretValueResult.setSecretString("{\"key1\": \"value1\", \"key2\": \"value2\"}");

	when(smClient.getSecretValue(any(GetSecretValueRequest.class)))
			.thenReturn(secretValueResult);

	propertySource.init();

	assertThat(propertySource.getPropertyNames()).containsExactly("key1", "key2");
	assertThat(propertySource.getProperty("key1")).isEqualTo("value1");
	assertThat(propertySource.getProperty("key2")).isEqualTo("value2");
}
 
Example 5
Source File: AwsSecretsManagerPropertySourceLocatorTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void locate_nameSpecifiedInConstructor_returnsPropertySourceWithSpecifiedName() {
	GetSecretValueResult secretValueResult = new GetSecretValueResult();
	secretValueResult.setSecretString("{\"key1\": \"value1\", \"key2\": \"value2\"}");
	when(smClient.getSecretValue(any(GetSecretValueRequest.class)))
			.thenReturn(secretValueResult);

	AwsSecretsManagerProperties properties = new AwsSecretsManagerProperties();
	AwsSecretsManagerPropertySourceLocator locator = new AwsSecretsManagerPropertySourceLocator(
			"my-name", smClient, properties);

	PropertySource propertySource = locator.locate(env);

	assertThat(propertySource.getName()).isEqualTo("my-name");
}
 
Example 6
Source File: AwsSecretsManagerPropertySourceLocatorTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void locate_nameNotSpecifiedInConstructor_returnsPropertySourceWithDefaultName() {
	GetSecretValueResult secretValueResult = new GetSecretValueResult();
	secretValueResult.setSecretString("{\"key1\": \"value1\", \"key2\": \"value2\"}");
	when(smClient.getSecretValue(any(GetSecretValueRequest.class)))
			.thenReturn(secretValueResult);

	AwsSecretsManagerProperties properties = new AwsSecretsManagerProperties();
	AwsSecretsManagerPropertySourceLocator locator = new AwsSecretsManagerPropertySourceLocator(
			smClient, properties);
	PropertySource propertySource = locator.locate(env);

	assertThat(propertySource.getName()).isEqualTo("aws-secrets-manager");
}