Migrate to JUnit 5
spring-cloud-function-context spring-cloud-function-context: fix spring-cloud-function-web spring-cloud-function-adapters spring-cloud-function-samples spring-cloud-function-deployer; spring-cloud-function-kotlin Resolves #535
This commit is contained in:
committed by
Oleg Zhurakousky
parent
6ea91a77a8
commit
dfa02750c1
@@ -26,8 +26,8 @@ import java.util.function.Supplier;
|
||||
|
||||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
|
||||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||
import org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration;
|
||||
@@ -47,7 +47,7 @@ public class SpringBootApiGatewayRequestHandlerTests {
|
||||
|
||||
private SpringBootApiGatewayRequestHandler handler;
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void after() {
|
||||
System.clearProperty("function.name");
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import com.amazonaws.kinesis.agg.RecordAggregator;
|
||||
import com.amazonaws.services.lambda.runtime.events.KinesisEvent;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||
import org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration;
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.springframework.cloud.function.adapter.aws;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||
import org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration;
|
||||
@@ -37,7 +37,7 @@ public class SpringBootRequestHandlerTests {
|
||||
|
||||
private SpringBootRequestHandler<Foo, Bar> handler;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void after() {
|
||||
System.clearProperty("spring.cloud.function.definition");
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -45,7 +45,7 @@ public class SpringBootStreamHandlerTests {
|
||||
|
||||
private SpringBootStreamHandler handler;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
System.clearProperty("function.name");
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ import com.microsoft.azure.functions.HttpResponseMessage;
|
||||
import com.microsoft.azure.functions.HttpResponseMessage.Builder;
|
||||
import com.microsoft.azure.functions.HttpStatus;
|
||||
import com.microsoft.azure.functions.HttpStatusType;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -108,7 +108,7 @@ public class AzureSpringBootHttpRequestHandlerTests {
|
||||
assertThat(body).isNull();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void close() throws IOException {
|
||||
if (this.handler != null) {
|
||||
this.handler.close();
|
||||
|
||||
@@ -25,8 +25,8 @@ import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.microsoft.azure.functions.ExecutionContext;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -142,7 +142,7 @@ public class AzureSpringBootRequestHandlerTests {
|
||||
assertThat(consumerResult).isEqualTo("foo1");
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void close() throws IOException {
|
||||
if (this.handler != null) {
|
||||
this.handler.close();
|
||||
|
||||
@@ -63,11 +63,11 @@
|
||||
<version>${google.cloud.functions.invoker.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- replace com.github.stefanbirkner:system-rules:1.19.0. Used in FunctionInvokerBackgroundTests -->
|
||||
<dependency>
|
||||
<groupId>com.github.stefanbirkner</groupId>
|
||||
<artifactId>system-rules</artifactId>
|
||||
<version>1.19.0</version>
|
||||
<scope>test</scope>
|
||||
<groupId>com.github.blindpirate</groupId>
|
||||
<artifactId>junit5-capture-system-output-extension</artifactId>
|
||||
<version>0.1.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -20,10 +20,10 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.github.blindpirate.extensions.CaptureSystemOutput;
|
||||
import com.google.gson.Gson;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.contrib.java.lang.system.SystemOutRule;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration;
|
||||
import org.springframework.cloud.function.json.JsonMapper;
|
||||
@@ -35,85 +35,77 @@ import org.springframework.messaging.converter.AbstractMessageConverter;
|
||||
import org.springframework.messaging.converter.MessageConverter;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Unit tests for the background functions adapter for Google Cloud Functions.
|
||||
*
|
||||
* @author Dmitry Solomakha
|
||||
* @author Mike Eltsufin
|
||||
*/
|
||||
@CaptureSystemOutput
|
||||
public class FunctionInvokerBackgroundTests {
|
||||
|
||||
private static final Gson gson = new Gson();
|
||||
|
||||
/**
|
||||
* The rule for log.
|
||||
*/
|
||||
@Rule
|
||||
public final SystemOutRule systemOutRule = new SystemOutRule().enableLog();
|
||||
|
||||
private static final String DROPPED_LOG_PREFIX = "Dropping background function result: ";
|
||||
|
||||
@Test
|
||||
public void testHelloWorldSupplier_Background() throws Exception {
|
||||
testBackgroundFunction(HelloWorldSupplier.class, null, "Hello World!", null, null);
|
||||
public void testHelloWorldSupplier_Background(CaptureSystemOutput.OutputCapture outputCapture) {
|
||||
testBackgroundFunction(outputCapture, HelloWorldSupplier.class, null, "Hello World!", null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonInputFunction_Background() throws Exception {
|
||||
testBackgroundFunction(JsonInputFunction.class, new IncomingRequest("hello"),
|
||||
public void testJsonInputFunction_Background(CaptureSystemOutput.OutputCapture outputCapture) {
|
||||
testBackgroundFunction(outputCapture, JsonInputFunction.class, new IncomingRequest("hello"),
|
||||
"Thank you for sending the message: hello", null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonInputOutputFunction_Background() throws Exception {
|
||||
testBackgroundFunction(JsonInputOutputFunction.class, new IncomingRequest("hello"),
|
||||
public void testJsonInputOutputFunction_Background(CaptureSystemOutput.OutputCapture outputCapture) {
|
||||
testBackgroundFunction(outputCapture, JsonInputOutputFunction.class, new IncomingRequest("hello"),
|
||||
new OutgoingResponse("Thank you for sending the message: hello"), null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonInputConsumer() throws Exception {
|
||||
testBackgroundFunction(JsonInputConsumer.class, new IncomingRequest("hello"), null,
|
||||
public void testJsonInputConsumer(CaptureSystemOutput.OutputCapture outputCapture) {
|
||||
testBackgroundFunction(outputCapture, JsonInputConsumer.class, new IncomingRequest("hello"), null,
|
||||
"Thank you for sending the message: hello", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPubSubBackgroundFunction_PubSub() throws Exception {
|
||||
public void testPubSubBackgroundFunction_PubSub(CaptureSystemOutput.OutputCapture outputCapture) {
|
||||
PubSubMessage pubSubMessage = new PubSubMessage();
|
||||
pubSubMessage.setData("hello");
|
||||
testBackgroundFunction(PubsubBackgroundFunction.class, pubSubMessage, null,
|
||||
testBackgroundFunction(outputCapture, PubsubBackgroundFunction.class, pubSubMessage, null,
|
||||
"Thank you for sending the message: hello", "google.pubsub.topic.publish");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPubSubBackgroundFunction_PubSubPayload() throws Exception {
|
||||
public void testPubSubBackgroundFunction_PubSubPayload(CaptureSystemOutput.OutputCapture outputCapture) {
|
||||
PubSubMessage pubSubMessage = new PubSubMessage();
|
||||
IncomingRequest message = new IncomingRequest("Hello");
|
||||
pubSubMessage.setData(gson.toJson(message));
|
||||
testBackgroundFunction(PubsubBackgroundFunctionPayload.class, pubSubMessage, null,
|
||||
testBackgroundFunction(outputCapture, PubsubBackgroundFunctionPayload.class, pubSubMessage, null,
|
||||
"Thank you for sending the message: Hello", "google.pubsub.topic.publish");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPubSubBackgroundFunction_StringMessage() throws Exception {
|
||||
public void testPubSubBackgroundFunction_StringMessage(CaptureSystemOutput.OutputCapture outputCapture) {
|
||||
PubSubMessage pubSubMessage = new PubSubMessage();
|
||||
pubSubMessage.setMessageId("1234");
|
||||
pubSubMessage.setData("Hello");
|
||||
testBackgroundFunction(PubsubBackgroundFunctionStringMessage.class, pubSubMessage, null,
|
||||
testBackgroundFunction(outputCapture, PubsubBackgroundFunctionStringMessage.class, pubSubMessage, null,
|
||||
"Message: Hello; Type: google.pubsub.topic.publish; Message ID: 1234", "google.pubsub.topic.publish");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPubSubBackgroundFunction_PubSubMessage() throws Exception {
|
||||
public void testPubSubBackgroundFunction_PubSubMessage(CaptureSystemOutput.OutputCapture outputCapture) {
|
||||
PubSubMessage pubSubMessage = new PubSubMessage();
|
||||
pubSubMessage.setMessageId("1234");
|
||||
pubSubMessage.setData("Hello");
|
||||
testBackgroundFunction(PubsubBackgroundFunctionPubSubMessage.class, pubSubMessage, null,
|
||||
testBackgroundFunction(outputCapture, PubsubBackgroundFunctionPubSubMessage.class, pubSubMessage, null,
|
||||
"Message: Hello; Type: google.pubsub.topic.publish; Message ID: 1234", "google.pubsub.topic.publish");
|
||||
}
|
||||
|
||||
private <I, O> void testBackgroundFunction(Class<?> configurationClass, I input, O expectedResult,
|
||||
private <I, O> void testBackgroundFunction(CaptureSystemOutput.OutputCapture outputCapture, Class<?> configurationClass, I input, O expectedResult,
|
||||
String expectedSysOut, String eventType) {
|
||||
|
||||
FunctionInvoker handler = new FunctionInvoker(configurationClass);
|
||||
@@ -122,15 +114,15 @@ public class FunctionInvokerBackgroundTests {
|
||||
|
||||
// verify function sysout statements
|
||||
if (expectedSysOut != null) {
|
||||
assertThat(systemOutRule.getLog()).contains(expectedSysOut);
|
||||
outputCapture.expect(Matchers.containsString(expectedSysOut));
|
||||
}
|
||||
|
||||
// verify that if function had a return type, it was logged as being dropped
|
||||
if (expectedResult != null) {
|
||||
assertThat(systemOutRule.getLog()).contains(DROPPED_LOG_PREFIX + gson.toJson(expectedResult));
|
||||
outputCapture.expect(Matchers.containsString(DROPPED_LOG_PREFIX + gson.toJson(expectedResult)));
|
||||
}
|
||||
else {
|
||||
assertThat(systemOutRule.getLog()).doesNotContain(DROPPED_LOG_PREFIX);
|
||||
outputCapture.expect(Matchers.not(Matchers.containsString(DROPPED_LOG_PREFIX)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -163,11 +155,9 @@ public class FunctionInvokerBackgroundTests {
|
||||
|
||||
@Bean
|
||||
public Function<IncomingRequest, Message<OutgoingResponse>> function() {
|
||||
return (in) -> {
|
||||
return MessageBuilder
|
||||
.withPayload(new OutgoingResponse("Thank you for sending the message: " + in.message))
|
||||
.setHeader("foo", "bar").build();
|
||||
};
|
||||
return (in) -> MessageBuilder
|
||||
.withPayload(new OutgoingResponse("Thank you for sending the message: " + in.message))
|
||||
.setHeader("foo", "bar").build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -200,9 +190,7 @@ public class FunctionInvokerBackgroundTests {
|
||||
|
||||
@Bean
|
||||
public Consumer<IncomingRequest> consumerPayload() {
|
||||
return (in) -> {
|
||||
System.out.println("Thank you for sending the message: " + in.message);
|
||||
};
|
||||
return (in) -> System.out.println("Thank you for sending the message: " + in.message);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.util.function.Supplier;
|
||||
import com.google.cloud.functions.HttpRequest;
|
||||
import com.google.cloud.functions.HttpResponse;
|
||||
import com.google.gson.Gson;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration;
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.cloud.function.adapter.gcp.integration;
|
||||
import java.io.IOException;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@@ -21,8 +21,7 @@ import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -34,14 +33,12 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Kamesh Sampath
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@EnableAutoConfiguration
|
||||
@TestPropertySource(locations = "classpath:/application-test.properties")
|
||||
|
||||
Reference in New Issue
Block a user