Skip to content

Commit e4967c4

Browse files
committed
Setup test resources
1 parent 5adf635 commit e4967c4

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.amazonaws.serverless.proxy.spring.echoapp.profile;
2+
3+
import com.amazonaws.serverless.proxy.spring.echoapp.model.MapResponseModel;
4+
import org.springframework.beans.factory.annotation.Value;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RequestMethod;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
@RestController
10+
@RequestMapping("/profile")
11+
public class DefaultProfileResource {
12+
@Value("${spring-proxy.profile-test}")
13+
private String profileTest;
14+
15+
@Value("${spring-proxy.not-overridden-test}")
16+
private String noOverride;
17+
18+
@RequestMapping(path = "/spring-properties", method = RequestMethod.GET)
19+
public MapResponseModel loadProperties() {
20+
MapResponseModel model = new MapResponseModel();
21+
22+
model.addValue("profileTest", profileTest);
23+
model.addValue("noOverride", noOverride);
24+
return model;
25+
}
26+
}
27+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

Comments
 (0)