[BAEL 1209] - Java RMI Files. (#3374)

* [BAEL 1209] - Java RMI Files.

* Added parent tag and deleted dependency tag for junit.

* Added java-rmi module.

* Removed duplicate java-lite module entry.

* Deleting this file as it is covered in test class.

* Spell check.
This commit is contained in:
gautamshetty
2018-01-25 04:16:39 -06:00
committed by Grzegorz Piwowarek
parent 70e4a55256
commit 19e8849361
6 changed files with 151 additions and 2 deletions

View File

@@ -0,0 +1,44 @@
package com.baeldung.rmi;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import org.junit.BeforeClass;
import org.junit.Test;
public class JavaRMIIntegrationTest {
@BeforeClass
public static void whenRunServer_thenServerStarts() {
try {
MessengerServiceImpl server = new MessengerServiceImpl();
server.createStubAndBind();
} catch (RemoteException e) {
fail("Exception Occurred");
}
}
@Test
public void whenClientSendsMessageToServer_thenServerSendsResponseMessage() {
try {
Registry registry = LocateRegistry.getRegistry();
MessengerService server = (MessengerService) registry.lookup("MessengerService");
String responseMessage = server.sendMessage("Client Message");
String expectedMessage = "Server Message";
assertEquals(responseMessage, expectedMessage);
} catch (RemoteException e) {
fail("Exception Occurred");
} catch (NotBoundException nb) {
fail("Exception Occurred");
}
}
}