aws / aws/aws-lambda-java-libs

Creation of events failing when running tests through another handler

Abierto
#329 2 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Java
Estrellas
548
Forks
241
Merge medio
2 d 5 min
PR fusionados (30 d)
11

Descripción

I am trying to use `aws-lambda-java-tests`, but I am unable to deserialize objects to pass to the test cases. I receive ` java.lang.ClassNotFoundException: com.amazonaws.services.s3.event.S3EventNotification$S3EventNotificationRecord`.

This might be related to issue ##262

I am having a simple lambda with two entry points, where one is just an entry to run test cases on the other one. However, I am encountering the above issue when I am trying to create an `s3Event ` from `EventLoader.loadS3Event`

Please let me know if there is a way in which I can fix this problem, or if there exist any workarounds to it. Thanks

I am using
`aws lambda invoke --function-name aws-helloworld-junt5-test --payload file://AWSTestingHelloWorld/src/test/resources/events/put.json response2.txt
`
Here is my Lambda code

```

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.S3Event;

import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
import org.junit.platform.launcher.Launcher;
import org.junit.platform.launcher.LauncherDiscoveryRequest;
import org.junit.platform.launcher.core.LauncherFactory;

import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;

import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
import org.junit.platform.launcher.listeners.TestExecutionSummary;

import java.util.List;

public class AwsHelloWorldJunit5 implements RequestHandler {

public String handleRequest(S3Event s3Event, Context context) {

System.out.println("executing the lambda");
return null;
}

@Override
public String handleRequest(Object s3Event, Context context) {
//invoke the Junit Test.
final LauncherDiscoveryRequest request =
LauncherDiscoveryRequestBuilder.request()
.selectors(selectClass(AwsHelloWorldJunit5Test.class))
.build();

final Launcher launcher = LauncherFactory.create();
final SummaryGeneratingListener listener = new SummaryGeneratingListener();

launcher.registerTestExecutionListeners(listener);
launcher.execute(request);

TestExecutionSummary summary = listener.getSummary();
long testFoundCount = summary.getTestsFoundCount();
List failures = summary.getFailures();
System.out.println("getTestsSucceededCount() : " + summary.getTestsSucceededCount());
failures.forEach(failure -> System.out.println("failure - " + failure.getException()));
return "testFoundCount = " + testFoundCount + " failures = " + failures.size();
}
}
```

And here is my lambda test code
```
import com.amazonaws.services.lambda.runtime.events.S3Event;
import com.amazonaws.services.lambda.runtime.tests.EventLoader;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class AwsHelloWorldJunit5Test {

@Test
public void testInjectSQSEvent4() throws IOException {
System.out.println("before running TC4");
S3Event s3Event = EventLoader.loadS3Event("events/put.json");
String output = (new AwsHelloWorldJunit5()).handleRequest(s3Event, null);
System.out.println("TC4: printing the output = " + output);
assertEquals("Hello World1", output);
}
}

```

```

4.0.0

serverless.fuzzing
ls-unittest-helloworld
1.0-SNAPSHOT
jar


8
1.8
1.8
UTF-8
5.7.0
0.8.7



com.amazonaws
aws-java-sdk
1.12.201
provided



com.amazonaws
aws-java-sdk-s3
1.12.201


com.amazonaws
aws-lambda-java-core
1.2.1


org.junit.jupiter
junit-jupiter
${junit.version}
test


org.junit.platform
junit-platform-console-standalone
1.8.2
compile


com.amazonaws
aws-lambda-java-serialization
1.0.0


com.amazonaws
aws-lambda-java-tests
1.1.1





org.apache.maven.plugins
maven-shade-plugin
3.2.2

false



package

shade




org.apache.maven.plugins
maven-surefire-plugin
2.22.2




src/test/resources/events
./events


```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.