Skip to content

Commit

Permalink
chore(citrus-rmi): review and code cleanup
Browse files Browse the repository at this point in the history
pr: #1224

`citrus-rmi` module.
  • Loading branch information
bbortt committed Nov 24, 2024
1 parent 30a7fbb commit f797dee
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@

package org.citrusframework.rmi.client;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.Registry;
import java.util.Arrays;

import org.citrusframework.context.TestContext;
import org.citrusframework.endpoint.AbstractEndpoint;
import org.citrusframework.exceptions.CitrusRuntimeException;
Expand All @@ -46,6 +38,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.Registry;
import java.util.Arrays;

/**
* @since 2.5
*/
Expand Down Expand Up @@ -112,8 +112,8 @@ public void send(final Message message, TestContext context) {
}

if (logger.isDebugEnabled()) {
logger.debug("Sending message to RMI server: '" + binding + "'");
logger.debug("Message to send:\n" + message.getPayload(String.class));
logger.debug("Sending message to RMI server: '{}'", binding);
logger.debug("Message to send:\n{}", message.getPayload(String.class));
}
context.onOutboundMessage(message);

Expand All @@ -132,7 +132,7 @@ public void send(final Message message, TestContext context) {
Message response = new DefaultMessage(payload.toString());
correlationManager.store(correlationKey, response);

logger.info("Message was sent to RMI server: '" + binding + "'");
logger.info("Message was sent to RMI server: '{}'", binding);
if (result != null) {
context.onInboundMessage(response);
}
Expand All @@ -146,7 +146,7 @@ public void send(final Message message, TestContext context) {
throw new CitrusRuntimeException("Failed to invoke method on remote target, because remote method not accessible", e);
}

logger.info("Message was sent to RMI server: '" + binding + "'");
logger.info("Message was sent to RMI server: '{}'", binding);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@

package org.citrusframework.rmi.server;

import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.Message;
import org.citrusframework.rmi.endpoint.RmiEndpointConfiguration;
import org.citrusframework.rmi.model.RmiServiceInvocation;
import org.citrusframework.rmi.model.RmiServiceResult;
import org.citrusframework.server.AbstractServer;
import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.transform.Source;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
Expand All @@ -26,17 +37,6 @@
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.List;
import javax.xml.transform.Source;

import org.citrusframework.exceptions.CitrusRuntimeException;
import org.citrusframework.message.Message;
import org.citrusframework.rmi.endpoint.RmiEndpointConfiguration;
import org.citrusframework.rmi.model.RmiServiceInvocation;
import org.citrusframework.rmi.model.RmiServiceResult;
import org.citrusframework.server.AbstractServer;
import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @since 2.5
Expand Down Expand Up @@ -78,7 +78,7 @@ public RmiServer(RmiEndpointConfiguration endpointConfiguration) {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (logger.isDebugEnabled()) {
logger.debug("Received message on RMI server: '" + endpointConfiguration.getBinding() + "'");
logger.debug("Received message on RMI server: '{}'", endpointConfiguration.getBinding());
}

Message response = getEndpointAdapter().handleMessage(endpointConfiguration.getMessageConverter()
Expand Down Expand Up @@ -153,15 +153,15 @@ protected void shutdown() {
try {
registry.unbind(endpointConfiguration.getBinding());
} catch (Exception e) {
logger.warn("Failed to unbind from registry:" + e.getMessage());
logger.warn("Failed to unbind from registry:{}", e.getMessage());
}
}

if (proxy != null) {
try {
UnicastRemoteObject.unexportObject(proxy, true);
} catch (Exception e) {
logger.warn("Failed to unexport from remote object:" + e.getMessage());
logger.warn("Failed to unexport from remote object:{}", e.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
import org.citrusframework.annotations.CitrusTestSource;
import org.citrusframework.common.TestLoader;
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
import org.testng.annotations.Ignore;
import org.testng.annotations.Test;

/**
* @since 2.0
*/
public class RmiDynamicEndpointIT extends TestNGCitrusSpringSupport {

@Test
@CitrusTestSource(type = TestLoader.SPRING, name = "RmiDynamicEndpointIT")
public void testDynamicEndpoint() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.citrusframework.annotations.CitrusTestSource;
import org.citrusframework.common.TestLoader;
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
import org.testng.annotations.Ignore;
import org.testng.annotations.Test;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.testng.annotations.Ignore;
import org.testng.annotations.Test;

import static org.citrusframework.actions.ReceiveMessageAction.Builder.receive;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@

package org.citrusframework.rmi.server;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.reset;

import java.io.IOException;
import java.rmi.Remote;
import java.rmi.registry.Registry;
import java.util.List;
import org.citrusframework.endpoint.EndpointAdapter;
import org.citrusframework.message.DefaultMessage;
import org.citrusframework.message.Message;
Expand All @@ -38,22 +29,41 @@
import org.mockito.MockitoAnnotations;
import org.mockito.stubbing.Answer;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.io.IOException;
import java.rmi.Remote;
import java.rmi.registry.Registry;
import java.util.List;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.reset;

/**
* @since 2.5
*/
public class RmiServerTest extends AbstractTestNGUnitTest {

@Mock
private Registry registry;

@Mock
private EndpointAdapter endpointAdapter;

@BeforeClass
private AutoCloseable mockitoContext;

@BeforeMethod
public void setup() {
MockitoAnnotations.openMocks(this);
mockitoContext = MockitoAnnotations.openMocks(this);
}

@AfterMethod
public void teardown() throws Exception {
mockitoContext.close();
}

@Test
Expand Down Expand Up @@ -82,8 +92,8 @@ public void testServiceInvocationWithArgument() throws Exception {

try {
Assert.assertEquals(
message.getPayload(String.class).replaceAll("\\s", ""),
FileUtils.readToString(Resources.create("service-invocation.xml", RmiServer.class)).replaceAll("\\s", "")
message.getPayload(String.class).replaceAll("\\s", ""),
FileUtils.readToString(Resources.create("service-invocation.xml", RmiServer.class)).replaceAll("\\s", "")
);
} catch (IOException e) {
Assert.fail(e.getMessage());
Expand All @@ -95,7 +105,7 @@ public void testServiceInvocationWithArgument() throws Exception {
rmiServer.startup();

try {
((HelloService)remote[0]).sayHello("Hello RMI this is cool!");
((HelloService) remote[0]).sayHello("Hello RMI this is cool!");
} catch (Throwable throwable) {
Assert.fail("Failed to invoke remote service", throwable);
}
Expand Down Expand Up @@ -127,8 +137,8 @@ public void testServiceInvocationWithResult() throws Exception {

try {
Assert.assertEquals(
message.getPayload(String.class).replaceAll("\\s", ""),
FileUtils.readToString(Resources.create("service-invocation-2.xml", RmiServer.class)).replaceAll("\\s", "")
message.getPayload(String.class).replaceAll("\\s", ""),
FileUtils.readToString(Resources.create("service-invocation-2.xml", RmiServer.class)).replaceAll("\\s", "")
);
} catch (IOException e) {
Assert.fail(e.getMessage());
Expand All @@ -140,7 +150,7 @@ public void testServiceInvocationWithResult() throws Exception {
rmiServer.startup();

try {
Assert.assertEquals(((HelloService)remote[0]).getHelloCount(), 10);
Assert.assertEquals(((HelloService) remote[0]).getHelloCount(), 10);
} catch (Throwable throwable) {
Assert.fail("Failed to invoke remote service", throwable);
}
Expand Down

0 comments on commit f797dee

Please sign in to comment.