9
9
import java .util .zip .ZipEntry ;
10
10
import java .util .zip .ZipOutputStream ;
11
11
12
- import com .amazonaws .services .lambda .runtime .events .SQSEvent ;
13
12
import lombok .val ;
14
13
import org .apache .commons .io .IOUtils ;
15
14
16
- import com .amazonaws .services .kinesis .model .Record ;
17
- import com .amazonaws .services .lambda .model .FunctionCode ;
18
- import software .amazon .awssdk .core .SdkBytes ;
19
-
20
15
/**
21
16
* Utility methods used for the LocalStack unit and integration tests.
22
17
*
23
18
* @author Waldemar Hummer
24
19
*/
25
20
public class LocalTestUtil {
26
21
27
- public static FunctionCode createFunctionCode (Class <?> clazz ) throws Exception {
28
- val code = new FunctionCode ();
29
- code .setZipFile (createFunctionByteBuffer (clazz ));
22
+ public static com . amazonaws . services . lambda . model . FunctionCode createFunctionCode (Class <?> clazz ) throws Exception {
23
+ val code = new com . amazonaws . services . lambda . model . FunctionCode ();
24
+ code .setZipFile (createFunctionByteBuffer (clazz , false ));
30
25
return code ;
31
26
}
32
27
33
28
public static software .amazon .awssdk .services .lambda .model .FunctionCode createFunctionCodeSDKV2 (Class <?> clazz ) throws Exception {
34
29
val codeBuilder = software .amazon .awssdk .services .lambda .model .FunctionCode .builder ();
35
- codeBuilder .zipFile (SdkBytes .fromByteBuffer (createFunctionByteBuffer (clazz )));
30
+ codeBuilder .zipFile (software . amazon . awssdk . core . SdkBytes .fromByteBuffer (createFunctionByteBuffer (clazz , true )));
36
31
return codeBuilder .build ();
37
32
}
38
33
39
- private static ByteBuffer createFunctionByteBuffer (Class <?> clazz ) throws Exception {
34
+ private static ByteBuffer createFunctionByteBuffer (Class <?> clazz , boolean sdkv2 ) throws Exception {
40
35
ByteArrayOutputStream zipOut = new ByteArrayOutputStream ();
41
36
ByteArrayOutputStream jarOut = new ByteArrayOutputStream ();
42
37
// create zip file
@@ -46,8 +41,10 @@ private static ByteBuffer createFunctionByteBuffer(Class<?> clazz) throws Except
46
41
47
42
// write class files into jar stream
48
43
addClassToJar (clazz , jarStream );
49
- addClassToJar (Record .class , jarStream );
50
- addClassToJar (SQSEvent .class , jarStream );
44
+ if (!sdkv2 ) {
45
+ addClassToJar (com .amazonaws .services .kinesis .model .Record .class , jarStream );
46
+ addClassToJar (com .amazonaws .services .lambda .runtime .events .SQSEvent .class , jarStream );
47
+ }
51
48
// write MANIFEST into jar stream
52
49
JarEntry mfEntry = new JarEntry ("META-INF/MANIFEST.MF" );
53
50
jarStream .putNextEntry (mfEntry );
0 commit comments