30
30
import software .amazon .awssdk .services .s3 .model .GetObjectRequest ;
31
31
import software .amazon .awssdk .services .s3 .model .NoSuchKeyException ;
32
32
33
-
34
33
@ TestMethodOrder (MethodOrderer .OrderAnnotation .class )
35
34
public class LambdaIntegrationTest extends LocalStackSetupConfigurations {
36
35
@@ -86,13 +85,13 @@ public String getFilename() {
86
85
var headers = new HttpHeaders ();
87
86
headers .setContentType (MediaType .MULTIPART_FORM_DATA );
88
87
// request body with the file resource and headers
89
- MultiValueMap < String , Object > requestBody = new LinkedMultiValueMap <> ();
88
+ MultiValueMap < String , Object > requestBody = new LinkedMultiValueMap < > ();
90
89
requestBody .add ("file" , resource );
91
- HttpEntity < MultiValueMap < String , Object >> requestEntity = new HttpEntity <> (requestBody ,
92
- headers );
90
+ HttpEntity < MultiValueMap < String , Object >> requestEntity = new HttpEntity < > (requestBody ,
91
+ headers );
93
92
94
- ResponseEntity < String > postResponse = restTemplate .exchange (BASE_URL + postUrl ,
95
- HttpMethod .POST , requestEntity , String .class );
93
+ ResponseEntity < String > postResponse = restTemplate .exchange (BASE_URL + postUrl ,
94
+ HttpMethod .POST , requestEntity , String .class );
96
95
97
96
assertEquals (HttpStatus .OK , postResponse .getStatusCode ());
98
97
@@ -104,8 +103,8 @@ public String getFilename() {
104
103
e .printStackTrace ();
105
104
}
106
105
107
- ResponseEntity < byte []> responseEntity = restTemplate .exchange (BASE_URL + getUrl ,
108
- HttpMethod .GET , null , byte [].class );
106
+ ResponseEntity < byte [] > responseEntity = restTemplate .exchange (BASE_URL + getUrl ,
107
+ HttpMethod .GET , null , byte [].class );
109
108
110
109
assertEquals (HttpStatus .OK , responseEntity .getStatusCode ());
111
110
@@ -119,30 +118,29 @@ public String getFilename() {
119
118
@ Order (2 )
120
119
void testFileProcessedInLambdaHasMetadata () {
121
120
var getItemRequest = GetItemRequest .builder ()
122
- .tableName ("shipment" )
123
- .key (Map .of (
124
- "shipmentId" ,
125
- AttributeValue .builder ().s ("3317ac4f-1f9b-4bab-a974-4aa9876d5547" ).build ())).build ();
121
+ .tableName ("shipment" )
122
+ .key (Map .of (
123
+ "shipmentId" ,
124
+ AttributeValue .builder ().s ("3317ac4f-1f9b-4bab-a974-4aa9876d5547" ).build ())).build ();
126
125
127
126
var getItemResponse = dynamoDbClient .getItem (getItemRequest );
128
127
129
128
dynamoDbClient .getItem (getItemRequest );
130
129
GetObjectRequest getObjectRequest = GetObjectRequest .builder ()
131
- .bucket (BUCKET_NAME )
132
- .key (getItemResponse .item ().get ("imageLink" ).s ())
133
- .build ();
130
+ .bucket (BUCKET_NAME )
131
+ .key (getItemResponse .item ().get ("imageLink" ).s ())
132
+ .build ();
134
133
try {
135
134
// already processed objects have a metadata field added, not be processed again
136
135
var s3ObjectResponse = s3Client .getObject (getObjectRequest );
137
136
assertTrue (s3ObjectResponse .response ().metadata ().entrySet ().stream ().anyMatch (
138
- entry -> entry .getKey ().equals ("exclude-lambda" ) && entry .getValue ().equals ("true" )));
137
+ entry -> entry .getKey ().equals ("exclude-lambda" ) && entry .getValue ().equals ("true" )));
139
138
} catch (NoSuchKeyException noSuchKeyException ) {
140
139
noSuchKeyException .printStackTrace ();
141
140
}
142
141
dynamoDbClient .close ();
143
142
s3Client .close ();
144
143
145
-
146
144
}
147
145
148
146
private String applyHash (byte [] data ) {
@@ -155,7 +153,7 @@ private String applyHash(byte[] data) {
155
153
156
154
// convert the hash bytes to a hexadecimal representation
157
155
var hexString = new StringBuilder ();
158
- for (byte b : hash ) {
156
+ for (byte b : hash ) {
159
157
var hex = Integer .toHexString (0xff & b );
160
158
if (hex .length () == 1 ) {
161
159
hexString .append ('0' );
0 commit comments