Repository: iluwatar/java-design-patterns
Issue: Ambassador Pattern
Labels: info: help wanted

https://docs.microsoft.com/en-us/azure/architecture/patterns/ambassador

Issue comments:
@npathai According to me this pattern is just extended use of proxy pattern. Here at edge service, we are putting our logic for the proxy which hides actual Application and also provides us extendibility to put our circuit breaking and other logic in that.
Eg. Hibernate Transaction management uses proxy pattern in which it provide extendibility to provide support for commits/roll-back 
Let me know if it makes any sense 
@harshitrathod despite this seeming like an extension of proxy as you stated, is it still viable to create an example? If so I would be interested in doing so.
Yes, go ahead @okinskas 
@harshitrathod Yeah it does make sense. It is almost (if not exactly) same as Remote Proxy pattern.

Pull request review comments:
Isn't networking just one example of Ambassador usages? Could the description be more general?
This can be written on one line `private RemoteService() {}`. Please check whitespace usage elsewhere too.
Use logger for output. Check this elsewhere too.
Could be `private final ServiceAmbassador serviceAmbassador = new ServiceAmbassador();`
Use logger
Could be written on one line `RemoteService.getRemoteService().doRemoteFunction(value)`
Not sure where this assertion comes from
Not sure where this assertion comes from
Could be written on one line
Thank you for the review. I will implement the changes.

This assertion is because ServiceAmbassador will either return input * 10 (100) using the remote service or -1 if the connection fails after 3 attempts so either of those assertions is valid. 

Would you suggest a better way of testing this?

Patch that resolved the issue:
diff --git a/ambassador/README.md b/ambassador/README.md
new file mode 100644
index 000000000000..f23d1e13cedb
--- /dev/null
+++ b/ambassador/README.md
@@ -0,0 +1,178 @@
+---
+layout: pattern
+title: Ambassador
+folder: ambassador
+permalink: /patterns/ambassador/
+categories: Structural
+tags:
+ - Java
+ - Difficulty-Intermediate
+---
+
+## Intent
+Provide a helper service instance on a client and offload common functionality away from a shared resource.
+
+## Explanation
+Real world example
+
+> A remote service has many clients accessing a function it provides. The service is a legacy application and is impossible to update. Large numbers of requests from users are causing connectivity issues. New rules for request frequency should be implemented along with latency checks and client-side logging.
+
+In plain words
+
+> Using the ambassador pattern, we can implement less-frequent polling from clients along with latency checks and logging.
+
+Microsoft documentation states
+
+> An ambassador service can be thought of as an out-of-process proxy that is co-located with the client.
+  This pattern can be useful for offloading common client connectivity tasks such as monitoring, logging, routing, security (such as TLS), and resiliency patterns in a language agnostic way. It is often used with legacy applications, or other applications that are difficult to modify, in order to extend their networking capabilities. It can also enable a specialized team to implement those features.
+
+**Programmatic Example**
+
+With the above example in mind we will imitate the functionality in a simple manner. We have an interface implemented by the remote service as well as the ambassador service:
+
+```java
+interface RemoteServiceInterface {
+
+    long doRemoteFunction(int value) throws Exception;
+}
+```
+
+A remote services represented as a singleton.
+
+```java
+public class RemoteService implements RemoteServiceInterface {
+
+		private static final Logger LOGGER = LoggerFactory.getLogger(RemoteService.class);
+    private static RemoteService service = null;2
+
+    static synchronized RemoteService getRemoteService() {
+        if (service == null) {
+            service = new RemoteService();
+        }
+        return service;
+    }
+
+    private RemoteService() {}
+
+    @Override
+    public long doRemoteFunction(int value) {
+
+        long waitTime = (long) Math.floor(Math.random() * 1000);
+
+        try {
+            sleep(waitTime);
+        } catch (InterruptedException e) {
+            LOGGER.error("Thread sleep interrupted", e)
+        }
+        return waitTime >= 200 ? value * 10 : -1;
+    }
+}
+```
+
+A service ambassador adding additional features such as logging, latency checks
+
+```java
+public class ServiceAmbassador implements RemoteServiceInterface {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(ServiceAmbassador.class);
+    private static final int RETRIES = 3;
+    private static final int DELAY_MS = 3000;
+
+    ServiceAmbassador() {}
+
+    @Override
+    public long doRemoteFunction(int value) {
+
+        return safeCall(value);
+    }
+
+    private long checkLatency(int value) {
+        RemoteService service = RemoteService.getRemoteService();
+        long startTime = System.currentTimeMillis();
+        long result = service.doRemoteFunction(value);
+        long timeTaken = System.currentTimeMillis() - startTime;
+
+        LOGGER.info("Time taken (ms): " + timeTaken);
+        return result;
+    }
+
+    private long safeCall(int value) {
+
+        int retries = 0;
+        long result = -1;
+
+        for (int i = 0; i < RETRIES; i++) {
+
+            if (retries >= RETRIES) {
+                return -1;
+            }
+
+            if ((result = checkLatency(value)) == -1) {
+                LOGGER.info("Failed to reach remote: (" + (i + 1) + ")");
+                retries++;
+                try {
+                    sleep(DELAY_MS);
+                } catch (InterruptedException e) {
+                    LOGGER.error("Thread sleep state interrupted", e);
+                }
+            } else {
+                break;
+            }
+        }
+        return result;
+    }
+}
+```
+
+A client has a local service ambassador used to interact with the remote service:
+
+```java
+public class Client {
+
+    private ServiceAmbassador serviceAmbassador;
+
+    Client() {
+        serviceAmbassador = new ServiceAmbassador();
+    }
+
+    long useService(int value) {
+        long result = serviceAmbassador.doRemoteFunction(value);
+        LOGGER.info("Service result: " + result)
+        return result;
+    }
+}
+```
+
+And here are two clients using the service.
+
+```java
+Client host1 = new Client();
+Client host2 = new Client();
+host1.useService(12);
+host2.useService(73);
+```
+
+## Applicability
+Ambassador is applicable when working with a legacy remote service that cannot
+be modified or would be extremely difficult to modify. Connectivity features can
+be implemented on the client avoiding the need for changes on the remote service.
+
+* Ambassador provides a local interface for a remote service.
+* Ambassador provides logging, circuit breaking, retries and security on the client.
+
+## Typical Use Case
+
+* Control access to another object
+* Implement logging
+* Implement circuit breaking
+* Offload remote service tasks
+* Facilitate network connection
+
+## Real world examples
+
+* [Kubernetes-native API gateway for microservices](https://github.com/datawire/ambassador)
+
+## Credits
+
+* [Ambassador pattern](https://docs.microsoft.com/en-us/azure/architecture/patterns/ambassador)
+* [Designing Distributed Systems: Patterns and Paradigms for Scalable, Reliable Services](https://books.google.co.uk/books?id=6BJNDwAAQBAJ&pg=PT35&lpg=PT35&dq=ambassador+pattern+in+real+world&source=bl&ots=d2e7GhYdHi&sig=Lfl_MDnCgn6lUcjzOg4GXrN13bQ&hl=en&sa=X&ved=0ahUKEwjk9L_18rrbAhVpKcAKHX_KA7EQ6AEIWTAI#v=onepage&q=ambassador%20pattern%20in%20real%20world&f=false)
diff --git a/ambassador/pom.xml b/ambassador/pom.xml
new file mode 100644
index 000000000000..f47b76f9a643
--- /dev/null
+++ b/ambassador/pom.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    The MIT License
+    Copyright (c) 2014-2016 Ilkka Seppälä
+
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <parent>
+    <artifactId>java-design-patterns</artifactId>
+    <groupId>com.iluwatar</groupId>
+    <version>1.20.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>ambassador</artifactId>
+  <dependencies>
+    <dependency>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter-api</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter-engine</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file
diff --git a/ambassador/src/main/java/com/iluwatar/ambassador/App.java b/ambassador/src/main/java/com/iluwatar/ambassador/App.java
new file mode 100644
index 000000000000..e4b4d392ab3c
--- /dev/null
+++ b/ambassador/src/main/java/com/iluwatar/ambassador/App.java
@@ -0,0 +1,53 @@
+/**
+ * The MIT License
+ * Copyright (c) 2014-2016 Ilkka Seppälä
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package com.iluwatar.ambassador;
+
+/**
+ *
+ * The ambassador pattern creates a helper service that sends network requests on behalf of a
+ * client. It is often used in cloud-based applications to offload features of a remote service.
+ *
+ * An ambassador service can be thought of as an out-of-process proxy that is co-located with
+ * the client. Similar to the proxy design pattern, the ambassador service provides an interface
+ * for another remote service. In addition to the interface, the ambassador provides extra
+ * functionality and features, specifically offloaded common connectivity tasks. This usually
+ * consists of monitoring, logging, routing, security etc. This is extremely useful in
+ * legacy applications where the codebase is difficult to modify and allows for improvements
+ * in the application's networking capabilities.
+ *
+ * In this example, we will the ({@link ServiceAmbassador}) class represents the ambassador while the
+ * ({@link RemoteService}) class represents a remote application.
+ *
+ */
+public class App {
+
+  /**
+  * Entry point
+  */
+  public static void main(String[] args) {
+    Client host1 = new Client();
+    Client host2 = new Client();
+    host1.useService(12);
+    host2.useService(73);
+  }
+}
diff --git a/ambassador/src/main/java/com/iluwatar/ambassador/Client.java b/ambassador/src/main/java/com/iluwatar/ambassador/Client.java
new file mode 100644
index 000000000000..9832265303ec
--- /dev/null
+++ b/ambassador/src/main/java/com/iluwatar/ambassador/Client.java
@@ -0,0 +1,42 @@
+/**
+ * The MIT License
+ * Copyright (c) 2014-2016 Ilkka Seppälä
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package com.iluwatar.ambassador;
+
+import org.slf4j.LoggerFactory;
+
+import org.slf4j.Logger;
+
+/**
+ * A simple Client
+ */
+public class Client {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(Client.class);
+  private final ServiceAmbassador serviceAmbassador = new ServiceAmbassador();
+
+  long useService(int value) {
+    long result = serviceAmbassador.doRemoteFunction(value);
+    LOGGER.info("Service result: " + result);
+    return result;
+  }
+}
diff --git a/ambassador/src/main/java/com/iluwatar/ambassador/RemoteService.java b/ambassador/src/main/java/com/iluwatar/ambassador/RemoteService.java
new file mode 100644
index 000000000000..225e033d8e78
--- /dev/null
+++ b/ambassador/src/main/java/com/iluwatar/ambassador/RemoteService.java
@@ -0,0 +1,65 @@
+/**
+ * The MIT License
+ * Copyright (c) 2014-2016 Ilkka Seppälä
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package com.iluwatar.ambassador;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static java.lang.Thread.sleep;
+
+/**
+ * A remote legacy application represented by a Singleton implementation.
+ */
+public class RemoteService implements RemoteServiceInterface {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(RemoteService.class);
+  private static RemoteService service = null;
+
+  static synchronized RemoteService getRemoteService() {
+    if (service == null) {
+      service = new RemoteService();
+    }
+    return service;
+  }
+
+  private RemoteService() {}
+
+  /**
+   * Remote function takes a value and multiplies it by 10 taking a random amount of time.
+   * Will sometimes return -1. This imitates connectivity issues a client might have to account for.
+   * @param value integer value to be multiplied.
+   * @return if waitTime is more than 200ms, it returns value * 10, otherwise -1.
+   */
+  @Override
+  public long doRemoteFunction(int value) {
+
+    long waitTime = (long) Math.floor(Math.random() * 1000);
+
+    try {
+      sleep(waitTime);
+    } catch (InterruptedException e) {
+      LOGGER.error("Thread sleep state interrupted", e);
+    }
+    return waitTime >= 200 ? value * 10 : -1;
+  }
+}
diff --git a/ambassador/src/main/java/com/iluwatar/ambassador/RemoteServiceInterface.java b/ambassador/src/main/java/com/iluwatar/ambassador/RemoteServiceInterface.java
new file mode 100644
index 000000000000..940313de36a0
--- /dev/null
+++ b/ambassador/src/main/java/com/iluwatar/ambassador/RemoteServiceInterface.java
@@ -0,0 +1,31 @@
+/**
+ * The MIT License
+ * Copyright (c) 2014-2016 Ilkka Seppälä
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package com.iluwatar.ambassador;
+
+/**
+ * Interface shared by ({@link RemoteService}) and ({@link ServiceAmbassador}).
+ */
+interface RemoteServiceInterface {
+    
+  long doRemoteFunction(int value) throws Exception;
+}
diff --git a/ambassador/src/main/java/com/iluwatar/ambassador/ServiceAmbassador.java b/ambassador/src/main/java/com/iluwatar/ambassador/ServiceAmbassador.java
new file mode 100644
index 000000000000..4be1dfcbf2db
--- /dev/null
+++ b/ambassador/src/main/java/com/iluwatar/ambassador/ServiceAmbassador.java
@@ -0,0 +1,84 @@
+/**
+ * The MIT License
+ * Copyright (c) 2014-2016 Ilkka Seppälä
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package com.iluwatar.ambassador;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static java.lang.Thread.sleep;
+
+/**
+ *
+ * ServiceAmbassador provides an interface for a ({@link Client}) to access ({@link RemoteService}).
+ * The interface adds logging, latency testing and usage of the service in a safe way that will not
+ * add stress to the remote service when connectivity issues occur.
+ *
+ */
+public class ServiceAmbassador implements RemoteServiceInterface {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(ServiceAmbassador.class);
+  private static final int RETRIES = 3;
+  private static final int DELAY_MS = 3000;
+
+  ServiceAmbassador() {}
+
+  @Override
+  public long doRemoteFunction(int value) {
+    return safeCall(value);
+  }
+
+  private long checkLatency(int value) {
+    long startTime = System.currentTimeMillis();
+    long result = RemoteService.getRemoteService().doRemoteFunction(value);
+    long timeTaken = System.currentTimeMillis() - startTime;
+
+    LOGGER.info("Time taken (ms): " + timeTaken);
+    return result;
+  }
+
+  private long safeCall(int value) {
+
+    int retries = 0;
+    long result = -1;
+
+    for (int i = 0; i < RETRIES; i++) {
+
+      if (retries >= RETRIES) {
+        return -1;
+      }
+
+      if ((result = checkLatency(value)) == -1) {
+        LOGGER.info("Failed to reach remote: (" + (i + 1) + ")");
+        retries++;
+        try {
+          sleep(DELAY_MS);
+        } catch (InterruptedException e) {
+          LOGGER.error("Thread sleep state interrupted", e);
+        }
+      } else {
+        break;
+      }
+    }
+    return result;
+  }
+}
diff --git a/pom.xml b/pom.xml
index 00b0de4f1fe2..81763b6c1100 100644
--- a/pom.xml
+++ b/pom.xml
@@ -161,7 +161,8 @@
         <module>dirty-flag</module>
         <module>trampoline</module>
         <module>serverless</module>
-		<module>acyclic-visitor</module>
+        <module>ambassador</module>
+		    <module>acyclic-visitor</module>
     </modules>
 
     <repositories>


Test patch:
diff --git a/ambassador/src/test/java/com/iluwatar/ambassador/AppTest.java b/ambassador/src/test/java/com/iluwatar/ambassador/AppTest.java
new file mode 100644
index 000000000000..cb072c1eb406
--- /dev/null
+++ b/ambassador/src/test/java/com/iluwatar/ambassador/AppTest.java
@@ -0,0 +1,36 @@
+/**
+ * The MIT License
+ * Copyright (c) 2014-2016 Ilkka Seppälä
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package com.iluwatar.ambassador;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Application test
+ */
+public class AppTest {
+
+  @Test
+  public void test() {
+    App.main(new String[]{});
+  }
+}
diff --git a/ambassador/src/test/java/com/iluwatar/ambassador/ClientTest.java b/ambassador/src/test/java/com/iluwatar/ambassador/ClientTest.java
new file mode 100644
index 000000000000..9354c4f868d4
--- /dev/null
+++ b/ambassador/src/test/java/com/iluwatar/ambassador/ClientTest.java
@@ -0,0 +1,40 @@
+/**
+ * The MIT License
+ * Copyright (c) 2014-2016 Ilkka Seppälä
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package com.iluwatar.ambassador;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test for {@link Client}
+ */
+public class ClientTest {
+
+  @Test
+  public void test() {
+
+    Client client = new Client();
+    long result = client.useService(10);
+
+    assert result == 100 || result == -1;
+  }
+}
diff --git a/ambassador/src/test/java/com/iluwatar/ambassador/RemoteServiceTest.java b/ambassador/src/test/java/com/iluwatar/ambassador/RemoteServiceTest.java
new file mode 100644
index 000000000000..e0b297af4841
--- /dev/null
+++ b/ambassador/src/test/java/com/iluwatar/ambassador/RemoteServiceTest.java
@@ -0,0 +1,37 @@
+/**
+ * The MIT License
+ * Copyright (c) 2014-2016 Ilkka Seppälä
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package com.iluwatar.ambassador;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test for {@link RemoteService}
+ */
+public class RemoteServiceTest {
+
+  @Test
+  public void test() {
+    long result = RemoteService.getRemoteService().doRemoteFunction(10);
+    assert result == 100 || result == -1;
+  }
+}
diff --git a/ambassador/src/test/java/com/iluwatar/ambassador/ServiceAmbassadorTest.java b/ambassador/src/test/java/com/iluwatar/ambassador/ServiceAmbassadorTest.java
new file mode 100644
index 000000000000..432df9fd13e4
--- /dev/null
+++ b/ambassador/src/test/java/com/iluwatar/ambassador/ServiceAmbassadorTest.java
@@ -0,0 +1,37 @@
+/**
+ * The MIT License
+ * Copyright (c) 2014-2016 Ilkka Seppälä
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package com.iluwatar.ambassador;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test for {@link ServiceAmbassador}
+ */
+public class ServiceAmbassadorTest {
+
+  @Test
+  public void test() {
+    long result = new ServiceAmbassador().doRemoteFunction(10);
+    assert result == 100 || result == -1;
+  }
+}