diff --git a/pom.xml b/pom.xml
index c81e50598b..24a4907f86 100644
--- a/pom.xml
+++ b/pom.xml
@@ -24,7 +24,7 @@
8
true
true
- true
+
@@ -112,15 +112,15 @@
org.codehaus.mojo
failsafe-maven-plugin
2.4.3-alpha-1
-
- ${skipITs}
-
integration-test
verify
+
+ ${skipITs}
+
diff --git a/sdk/pom.xml b/sdk/pom.xml
index e209c6cc4c..a2d816c770 100644
--- a/sdk/pom.xml
+++ b/sdk/pom.xml
@@ -92,6 +92,18 @@
5.5.2
test
+
+ org.springframework.boot
+ spring-boot-starter-web
+ 2.2.2.RELEASE
+ test
+
+
+ org.springframework.boot
+ spring-boot-autoconfigure
+ 2.2.2.RELEASE
+ test
+
diff --git a/sdk/src/test/java/io/dapr/it/DaprIntegrationTestingRunner.java b/sdk/src/test/java/io/dapr/it/DaprIntegrationTestingRunner.java
index 59a4fd0ff8..5abb5dbcb1 100644
--- a/sdk/src/test/java/io/dapr/it/DaprIntegrationTestingRunner.java
+++ b/sdk/src/test/java/io/dapr/it/DaprIntegrationTestingRunner.java
@@ -83,7 +83,7 @@ public DaprFreePorts initializeDapr() throws Exception {
private static final String DAPR_COMMAND = " -- mvn exec:java -Dexec.mainClass=%s -Dexec.classpathScope=test -Dexec.args=\"%d\"";
private String buildDaprCommand(){
- StringBuilder stringBuilder= new StringBuilder(String.format(DAPR_RUN, this.appName))
+ StringBuilder stringBuilder= new StringBuilder(String.format(DAPR_RUN, this.getAppName()))
.append(this.useAppPort ? "--app-port " + this.DAPR_FREEPORTS.appPort : "")
.append(" --grpc-port ")
.append(this.DAPR_FREEPORTS.grpcPort)
@@ -110,12 +110,22 @@ private static Integer findRandomOpenPortOnAllLocalInterfaces() throws Exception
public void destroyDapr() {
Optional.ofNullable(rt).ifPresent( runtime -> {
try {
- runtime.exec("dapr stop --app-id " + this.appName);
+ System.out.println("Start dapr Stop");
+ runtime.exec("dapr stop --app-id " + this.getAppName());
+ System.out.println("End Dapr Stop");
} catch (IOException e) {
throw new RuntimeException(e);
}
});
- Optional.ofNullable(proc).ifPresent(process -> process.destroy());
+ Optional.ofNullable(proc).ifPresent(process -> {
+ System.out.println("Start process Stop");
+ process.destroyForcibly();
+ System.out.println("End process Stop");
+ });
+ }
+
+ public String getAppName() {
+ return appName;
}
public static class DaprFreePorts
diff --git a/sdk/src/test/java/io/dapr/it/binding/http/OutputBindingExample.java b/sdk/src/test/java/io/dapr/it/binding/http/OutputBindingExample.java
new file mode 100644
index 0000000000..19d53d376c
--- /dev/null
+++ b/sdk/src/test/java/io/dapr/it/binding/http/OutputBindingExample.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) Microsoft Corporation.
+ * Licensed under the MIT License.
+ */
+
+package io.dapr.it.binding.http;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.dapr.client.DaprClient;
+import io.dapr.client.DaprClientBuilder;
+import io.dapr.client.domain.Verb;
+import io.dapr.it.BaseIT;
+import io.dapr.it.services.InputBindingExample;
+import io.dapr.serializer.DefaultObjectSerializer;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.Base64;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * Service for output binding example.
+ */
+public class OutputBindingExample extends BaseIT {
+
+ private static DaprClient client;
+
+ @BeforeClass
+ public static void init() throws Exception {
+ daprIntegrationTestingRunner =
+ createDaprIntegrationTestingRunner(
+ "dapr initialized. Status: Running. Init Elapsed",
+ InputBindingExample.class,
+ true,
+ 19000
+ );
+ daprIntegrationTestingRunner.initializeDapr();
+ client = new DaprClientBuilder(new DefaultObjectSerializer(), new DefaultObjectSerializer()).build();
+ }
+
+ public static class MyClass {
+ public MyClass(){}
+ public String message;
+ }
+
+ @Test
+ public void BindingTest() {
+
+
+ final String BINDING_NAME = "sample123";
+
+ // This is an example of sending data in a user-defined object. The input binding will receive:
+ // {"message":"hello"}
+ MyClass myClass = new MyClass();
+ myClass.message = "hello";
+
+ System.out.println("sending first message");
+ client.invokeBinding(BINDING_NAME, myClass).block();
+
+ // This is an example of sending a plain string. The input binding will receive
+ // cat
+ final String m = "cat";
+ System.out.println("sending " + m);
+ client.invokeBinding(BINDING_NAME, m).block();
+
+ try {
+ Thread.sleep(8000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ Thread.currentThread().interrupt();
+ return;
+ }
+
+ final List messages = client.invokeService(Verb.GET, daprIntegrationTestingRunner.getAppName(), "messages", null, List.class).block();
+ assertEquals(2,messages.size());
+ MyClass resultClass = null;
+ try {
+ resultClass = new ObjectMapper().readValue(new String(Base64.getDecoder().decode(messages.get(0))), MyClass.class);
+ }catch (Exception ex)
+ {
+ ex.printStackTrace();
+ fail("Error on decode message 1");
+ }
+
+ try {
+ assertEquals("cat", new ObjectMapper().readValue(new String(Base64.getDecoder().decode(messages.get(1))), String.class));
+ }catch (Exception ex){
+ ex.printStackTrace();
+ fail("Error on decode message 2");
+ }
+ assertEquals("hello",resultClass.message);
+ }
+}
diff --git a/sdk/src/test/java/io/dapr/it/services/InputBindingController.java b/sdk/src/test/java/io/dapr/it/services/InputBindingController.java
new file mode 100644
index 0000000000..8036674854
--- /dev/null
+++ b/sdk/src/test/java/io/dapr/it/services/InputBindingController.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) Microsoft Corporation.
+ * Licensed under the MIT License.
+ */
+
+package io.dapr.it.services;
+
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+import reactor.core.publisher.Mono;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * SpringBoot Controller to handle input binding.
+ */
+@RestController
+public class InputBindingController {
+
+ private static final List messagesReceived = new ArrayList();
+
+ @PostMapping(path = "/sample123")
+ public Mono handleInputBinding(@RequestBody(required = false) byte[] body) {
+
+ return Mono.fromRunnable(() -> {
+ messagesReceived.add(body);
+ System.out.println("Received message through binding: " + (body == null ? "" : new String(body)));
+ });
+ }
+
+ @GetMapping(path = "/messages")
+ public Mono> getMessages(){
+ return Mono.just( messagesReceived);
+ }
+
+
+
+}
diff --git a/sdk/src/test/java/io/dapr/it/services/InputBindingExample.java b/sdk/src/test/java/io/dapr/it/services/InputBindingExample.java
new file mode 100644
index 0000000000..8a84e34fc3
--- /dev/null
+++ b/sdk/src/test/java/io/dapr/it/services/InputBindingExample.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) Microsoft Corporation.
+ * Licensed under the MIT License.
+ */
+
+package io.dapr.it.services;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication(scanBasePackages = {"io.dapr.it.services"})
+public class InputBindingExample {
+
+ public static void main(String[] args) throws Exception {
+ // If port string is not valid, it will throw an exception.
+ int port = Integer.parseInt(args[0]);
+ // Start Dapr's callback endpoint.
+ InputBindingExample.start(port);
+ }
+
+ /**
+ * Starts Dapr's callback in a given port.
+ * @param port Port to listen to.
+ */
+ public static void start(int port) {
+ SpringApplication app = new SpringApplication(InputBindingExample.class);
+ app.run(String.format("--server.port=%d", port));
+ }
+
+}