* [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.
44 lines
1.1 KiB
Java
44 lines
1.1 KiB
Java
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");
|
|
}
|
|
}
|
|
|
|
} |