|
| 1 | +package com.amazonaws.serverless.proxy.spring.profile; |
| 2 | + |
| 3 | +import com.amazonaws.serverless.proxy.internal.model.AwsProxyRequest; |
| 4 | +import com.amazonaws.serverless.proxy.internal.model.AwsProxyResponse; |
| 5 | +import com.amazonaws.serverless.proxy.internal.testutils.AwsProxyRequestBuilder; |
| 6 | +import com.amazonaws.serverless.proxy.internal.testutils.MockLambdaContext; |
| 7 | +import com.amazonaws.serverless.proxy.spring.SpringLambdaContainerHandler; |
| 8 | +import com.amazonaws.serverless.proxy.spring.echoapp.EchoSpringAppConfig; |
| 9 | +import com.amazonaws.serverless.proxy.spring.echoapp.model.MapResponseModel; |
| 10 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 11 | +import org.junit.Test; |
| 12 | +import org.junit.runner.RunWith; |
| 13 | +import org.springframework.beans.factory.annotation.Autowired; |
| 14 | +import org.springframework.test.context.ContextConfiguration; |
| 15 | +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
| 16 | +import org.springframework.test.context.web.WebAppConfiguration; |
| 17 | + |
| 18 | +import java.io.IOException; |
| 19 | + |
| 20 | +import static org.junit.Assert.assertEquals; |
| 21 | + |
| 22 | + |
| 23 | +@RunWith(SpringJUnit4ClassRunner.class) |
| 24 | +@ContextConfiguration(classes = {EchoSpringAppConfig.class}) |
| 25 | +@WebAppConfiguration |
| 26 | +public class SpringProfileTest { |
| 27 | + @Autowired |
| 28 | + private ObjectMapper objectMapper; |
| 29 | + |
| 30 | + @Autowired |
| 31 | + private MockLambdaContext lambdaContext; |
| 32 | + |
| 33 | + @Autowired |
| 34 | + private SpringLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler; |
| 35 | + |
| 36 | + @Test |
| 37 | + public void profile_defaultProfile() throws IOException { |
| 38 | + AwsProxyRequest request = new AwsProxyRequestBuilder("/profile/spring-properties", "GET") |
| 39 | + .build(); |
| 40 | + |
| 41 | + AwsProxyResponse output = handler.proxy(request, lambdaContext); |
| 42 | + assertEquals(200, output.getStatusCode()); |
| 43 | + |
| 44 | + MapResponseModel response = objectMapper.readValue(output.getBody(), MapResponseModel.class); |
| 45 | + assertEquals("default-profile", response.getValues().get("profileTest")); |
| 46 | + assertEquals("not-overridden", response.getValues().get("noOverride")); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void profile_overrideProfile() throws IOException { |
| 51 | + AwsProxyRequest request = new AwsProxyRequestBuilder("/profile/spring-properties", "GET") |
| 52 | + .stage("override") |
| 53 | + .build(); |
| 54 | + |
| 55 | + AwsProxyResponse output = handler.proxy(request, lambdaContext); |
| 56 | + assertEquals(200, output.getStatusCode()); |
| 57 | + |
| 58 | + MapResponseModel response = objectMapper.readValue(output.getBody(), MapResponseModel.class); |
| 59 | + assertEquals("override-profile", response.getValues().get("profileTest")); |
| 60 | + assertEquals("not-overridden", response.getValues().get("noOverride")); |
| 61 | + } |
| 62 | +} |
0 commit comments