-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from mattcorey/profile-support
Profile support
- Loading branch information
Showing
12 changed files
with
168 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...ng/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/ProfileOverrideConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.amazonaws.serverless.proxy.spring.echoapp; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.context.annotation.PropertySource; | ||
|
||
/** | ||
* Created by matthewcorey on 2/20/17. | ||
*/ | ||
@Configuration | ||
@Profile("override") | ||
@PropertySource("classpath:/application-override.properties") | ||
public class ProfileOverrideConfig { | ||
} |
12 changes: 12 additions & 0 deletions
12
...va/com/amazonaws/serverless/proxy/spring/echoapp/profile/DefaultProfileConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.amazonaws.serverless.proxy.spring.echoapp.profile; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class DefaultProfileConfiguration { | ||
@Bean | ||
public String beanInjectedValue() { | ||
return "default-profile-from-bean"; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...st/java/com/amazonaws/serverless/proxy/spring/echoapp/profile/DefaultProfileResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.amazonaws.serverless.proxy.spring.echoapp.profile; | ||
|
||
import com.amazonaws.serverless.proxy.spring.echoapp.model.MapResponseModel; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/profile") | ||
public class DefaultProfileResource { | ||
@Value("${spring-proxy.profile-test}") | ||
private String profileTest; | ||
|
||
@Value("${spring-proxy.not-overridden-test}") | ||
private String noOverride; | ||
|
||
@Autowired | ||
private String beanInjectedValue; | ||
|
||
@RequestMapping(path = "/spring-properties", method = RequestMethod.GET) | ||
public MapResponseModel loadProperties() { | ||
MapResponseModel model = new MapResponseModel(); | ||
|
||
model.addValue("profileTest", profileTest); | ||
model.addValue("noOverride", noOverride); | ||
model.addValue("beanInjectedValue", beanInjectedValue); | ||
return model; | ||
} | ||
} | ||
|
14 changes: 14 additions & 0 deletions
14
...a/com/amazonaws/serverless/proxy/spring/echoapp/profile/OverrideProfileConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.amazonaws.serverless.proxy.spring.echoapp.profile; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
|
||
@Configuration | ||
@Profile("override") | ||
public class OverrideProfileConfiguration { | ||
@Bean | ||
public String beanInjectedValue() { | ||
return "override-profile-from-bean"; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...spring/src/test/java/com/amazonaws/serverless/proxy/spring/profile/SpringProfileTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.amazonaws.serverless.proxy.spring.profile; | ||
|
||
import com.amazonaws.serverless.proxy.internal.model.AwsProxyRequest; | ||
import com.amazonaws.serverless.proxy.internal.model.AwsProxyResponse; | ||
import com.amazonaws.serverless.proxy.internal.servlet.AwsProxyServletContext; | ||
import com.amazonaws.serverless.proxy.internal.testutils.AwsProxyRequestBuilder; | ||
import com.amazonaws.serverless.proxy.internal.testutils.MockLambdaContext; | ||
import com.amazonaws.serverless.proxy.spring.SpringLambdaContainerHandler; | ||
import com.amazonaws.serverless.proxy.spring.echoapp.EchoSpringAppConfig; | ||
import com.amazonaws.serverless.proxy.spring.echoapp.model.MapResponseModel; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.TestExecutionListeners; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; | ||
import org.springframework.test.context.web.WebAppConfiguration; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration(classes = EchoSpringAppConfig.class) | ||
@WebAppConfiguration | ||
@TestExecutionListeners(inheritListeners = false, listeners = {DependencyInjectionTestExecutionListener.class}) | ||
public class SpringProfileTest { | ||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
@Autowired | ||
private MockLambdaContext lambdaContext; | ||
|
||
@Before | ||
public void clearServletContextCache() { | ||
AwsProxyServletContext.clearServletContextCache(); | ||
} | ||
|
||
@Test | ||
public void profile_defaultProfile() throws Exception { | ||
AwsProxyRequest request = new AwsProxyRequestBuilder("/profile/spring-properties", "GET") | ||
.build(); | ||
|
||
SpringLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler = SpringLambdaContainerHandler.getAwsProxyHandler(EchoSpringAppConfig.class); | ||
AwsProxyResponse output = handler.proxy(request, lambdaContext); | ||
assertEquals(200, output.getStatusCode()); | ||
|
||
MapResponseModel response = objectMapper.readValue(output.getBody(), MapResponseModel.class); | ||
assertEquals(3, response.getValues().size()); | ||
assertEquals("default-profile", response.getValues().get("profileTest")); | ||
assertEquals("not-overridden", response.getValues().get("noOverride")); | ||
assertEquals("default-profile-from-bean", response.getValues().get("beanInjectedValue")); | ||
} | ||
|
||
@Test | ||
public void profile_overrideProfile() throws Exception { | ||
AwsProxyRequest request = new AwsProxyRequestBuilder("/profile/spring-properties", "GET") | ||
.stage("override") | ||
.build(); | ||
|
||
SpringLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler = SpringLambdaContainerHandler.getAwsProxyHandler(EchoSpringAppConfig.class); | ||
AwsProxyResponse output = handler.proxy(request, lambdaContext); | ||
assertEquals(200, output.getStatusCode()); | ||
|
||
MapResponseModel response = objectMapper.readValue(output.getBody(), MapResponseModel.class); | ||
assertEquals(3, response.getValues().size()); | ||
assertEquals("override-profile", response.getValues().get("profileTest")); | ||
assertEquals("not-overridden", response.getValues().get("noOverride")); | ||
assertEquals("override-profile-from-bean", response.getValues().get("beanInjectedValue")); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
aws-serverless-java-container-spring/src/test/resources/application-override.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
spring-proxy.profile-test=override-profile |
2 changes: 2 additions & 0 deletions
2
aws-serverless-java-container-spring/src/test/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
spring-proxy.profile-test=default-profile | ||
spring-proxy.not-overridden-test=not-overridden |