How to use exception method of com.consol.citrus.rmi.message.RmiMessage class

Best Citrus code snippet using com.consol.citrus.rmi.message.RmiMessage.exception

Source:RmiClientTest.java Github

copy

Full Screen

1/*2 * Copyright 2006-2016 the original author or authors.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.consol.citrus.rmi.client;17import com.consol.citrus.message.Message;18import com.consol.citrus.message.MessageCorrelator;19import com.consol.citrus.rmi.endpoint.RmiEndpointConfiguration;20import com.consol.citrus.rmi.message.RmiMessage;21import com.consol.citrus.rmi.remote.HelloService;22import com.consol.citrus.testng.AbstractTestNGUnitTest;23import org.mockito.Mockito;24import org.springframework.core.io.ClassPathResource;25import org.springframework.util.FileCopyUtils;26import org.springframework.util.StringUtils;27import org.testng.Assert;28import org.testng.annotations.Test;29import java.io.InputStreamReader;30import java.rmi.registry.Registry;31import static org.mockito.Mockito.*;32/**33 * @author Christoph Deppisch34 * @since 2.535 */36public class RmiClientTest extends AbstractTestNGUnitTest {37 private HelloService remoteInterface = Mockito.mock(HelloService.class);38 private Registry registry = Mockito.mock(Registry.class);39 @Test40 public void testRmiClient() throws Exception {41 RmiEndpointConfiguration endpointConfiguration = new RmiEndpointConfiguration();42 RmiClient rmiClient = new RmiClient(endpointConfiguration);43 String binding = "helloService";44 final String responseBody = FileCopyUtils.copyToString(new InputStreamReader(new ClassPathResource("service-result.xml",45 RmiClient.class).getInputStream()));46 endpointConfiguration.setBinding(binding);47 Message requestMessage = RmiMessage.invocation("getHelloCount");48 endpointConfiguration.setRegistry(registry);49 reset(registry, remoteInterface);50 when(registry.lookup(binding)).thenReturn(remoteInterface);51 when(remoteInterface.getHelloCount()).thenReturn(100);52 rmiClient.send(requestMessage, context);53 Message responseMessage = rmiClient.receive(context, endpointConfiguration.getTimeout());54 Assert.assertEquals(StringUtils.trimAllWhitespace(responseMessage.getPayload(String.class)),55 StringUtils.trimAllWhitespace(responseBody));56 }57 @Test58 public void testRmiClientWithArgument() throws Exception {59 RmiEndpointConfiguration endpointConfiguration = new RmiEndpointConfiguration();60 RmiClient rmiClient = new RmiClient(endpointConfiguration);61 String binding = "helloService";62 final String responseBody = FileCopyUtils.copyToString(new InputStreamReader(new ClassPathResource("service-result-2.xml",63 RmiClient.class).getInputStream()));64 endpointConfiguration.setBinding(binding);65 Message requestMessage = RmiMessage.invocation("sayHello").argument("Christoph");66 endpointConfiguration.setRegistry(registry);67 reset(registry, remoteInterface);68 when(registry.lookup(binding)).thenReturn(remoteInterface);69 rmiClient.send(requestMessage, context);70 Message responseMessage = rmiClient.receive(context, endpointConfiguration.getTimeout());71 Assert.assertEquals(StringUtils.trimAllWhitespace(responseMessage.getPayload(String.class)),72 StringUtils.trimAllWhitespace(responseBody));73 verify(remoteInterface).sayHello(eq("Christoph"));74 }75 @Test76 public void testReplyMessageCorrelator() throws Exception {77 RmiEndpointConfiguration endpointConfiguration = new RmiEndpointConfiguration();78 RmiClient rmiClient = new RmiClient(endpointConfiguration);79 String binding = "helloService";80 String responseBody = FileCopyUtils.copyToString(new InputStreamReader(new ClassPathResource("service-result-3.xml",81 RmiClient.class).getInputStream()));82 endpointConfiguration.setBinding(binding);83 MessageCorrelator correlator = Mockito.mock(MessageCorrelator.class);84 endpointConfiguration.setCorrelator(correlator);85 Message requestMessage = RmiMessage.invocation("getHelloCount");86 endpointConfiguration.setRegistry(registry);87 reset(registry, remoteInterface, correlator);88 when(registry.lookup(binding)).thenReturn(remoteInterface);89 when(remoteInterface.getHelloCount())90 .thenReturn(99);91 when(correlator.getCorrelationKey(requestMessage)).thenReturn("correlationKey");92 when(correlator.getCorrelationKeyName(any(String.class))).thenReturn("correlationKeyName");93 rmiClient.send(requestMessage, context);94 Message responseMessage = rmiClient.receive("correlationKey", context, endpointConfiguration.getTimeout());95 Assert.assertEquals(StringUtils.trimAllWhitespace(responseMessage.getPayload(String.class)),96 StringUtils.trimAllWhitespace(responseBody));97 }98}...

Full Screen

Full Screen

Source:RmiMessage.java Github

copy

Full Screen

...13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.consol.citrus.rmi.message;17import com.consol.citrus.exceptions.CitrusRuntimeException;18import com.consol.citrus.message.DefaultMessage;19import com.consol.citrus.rmi.model.*;20import org.springframework.xml.transform.StringResult;21import java.rmi.Remote;22/**23 * @author Christoph Deppisch24 * @since 2.525 */26public class RmiMessage extends DefaultMessage {27 /** Model objects */28 private RmiServiceInvocation serviceInvocation;29 private RmiServiceResult serviceResult;30 private RmiMarshaller marshaller = new RmiMarshaller();31 /**32 * Prevent traditional instantiation.33 */34 private RmiMessage() { super(); }35 /**36 * Constructor initializes new service invocation message.37 * @param serviceInvocation38 */39 private RmiMessage(RmiServiceInvocation serviceInvocation) {40 super(serviceInvocation);41 this.serviceInvocation = serviceInvocation;42 }43 /**44 * Constructor initializes new service result message.45 * @param serviceResult46 */47 private RmiMessage(RmiServiceResult serviceResult) {48 super(serviceResult);49 this.serviceResult = serviceResult;50 }51 public static RmiMessage invocation(String method) {52 RmiServiceInvocation invocation = new RmiServiceInvocation();53 invocation.setMethod(method);54 return new RmiMessage(invocation);55 }56 public static RmiMessage invocation(Class<? extends Remote> remoteTarget, String method) {57 RmiServiceInvocation invocation = new RmiServiceInvocation();58 invocation.setRemote(remoteTarget.getName());59 invocation.setMethod(method);60 return new RmiMessage(invocation);61 }62 public static RmiMessage result(Object resultObject) {63 RmiServiceResult serviceResult = new RmiServiceResult();64 RmiServiceResult.Object serviceResultObject = new RmiServiceResult.Object();65 serviceResultObject.setValueObject(resultObject);66 serviceResult.setObject(serviceResultObject);67 return new RmiMessage(serviceResult);68 }69 public static RmiMessage result() {70 return new RmiMessage(new RmiServiceResult());71 }72 public RmiMessage argument(Object arg) {73 return argument(arg, arg.getClass());74 }75 public RmiMessage argument(Object arg, Class<?> argType) {76 if (serviceInvocation == null) {77 throw new CitrusRuntimeException("Invalid access to method argument for RMI message");78 }79 if (serviceInvocation.getArgs() == null) {80 serviceInvocation.setArgs(new RmiServiceInvocation.Args());81 }82 MethodArg methodArg = new MethodArg();83 methodArg.setValueObject(arg);84 methodArg.setType(argType.getName());85 serviceInvocation.getArgs().getArgs().add(methodArg);86 return this;87 }88 public RmiMessage exception(String message) {89 if (serviceResult == null) {90 throw new CitrusRuntimeException("Invalid access to result exception for RMI message");91 }92 serviceResult.setException(message);93 return this;94 }95 @Override96 public <T> T getPayload(Class<T> type) {97 if (RmiServiceInvocation.class.equals(type) && serviceInvocation != null) {98 return (T) serviceInvocation;99 } else if (RmiServiceResult.class.equals(type) && serviceResult != null) {100 return (T) serviceResult;101 } else if (String.class.equals(type)) {102 return (T) getPayload();103 } else {104 return super.getPayload(type);...

Full Screen

Full Screen

exception

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.rmi;2import org.springframework.context.support.ClassPathXmlApplicationContext;3import com.consol.citrus.rmi.message.RmiMessage;4public class RmiExceptionTest {5 public static void main(String[] args) {6 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("rmi-exception-test.xml");7 RmiMessage rmiMessage = new RmiMessage();8 rmiMessage.setServiceInterface("com.consol.citrus.rmi.Hello");9 rmiMessage.setOperation("sayHello");10 rmiMessage.setException("java.rmi.RemoteException");11 rmiMessage.setExceptionMessage("Hello World");12 rmiMessage.setPayload("Hello World");13 context.getBean("rmiClient", RmiClient.class).send(rmiMessage);14 }15}16package com.consol.citrus.rmi;17import org.springframework.context.support.ClassPathXmlApplicationContext;18import com.consol.citrus.rmi.message.RmiMessage;19public class RmiExceptionTest {20 public static void main(String[] args) {21 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("rmi-exception-test.xml");

Full Screen

Full Screen

exception

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.rmi;2import com.consol.citrus.rmi.message.RmiMessage;3import org.springframework.context.support.ClassPathXmlApplicationContext;4public class RmiClient {5 public static void main(String[] args) {6 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("context.xml");7 RmiMessage message = new RmiMessage();8 message.setServiceInterface("com.consol.citrus.rmi.service.HelloWorldService");9 message.setOperation("sayHello");10 message.setException(new RuntimeException("test exception"));11 message.setPayload("Hello");12 context.getBean("rmiClient", RmiClient.class).sayHello(message);13 }14 public String sayHello(RmiMessage message) {15 return message.getPayload(String.class);16 }17}18package com.consol.citrus.rmi;19import com.consol.citrus.rmi.message.RmiMessage;20import org.springframework.context.support.ClassPathXmlApplicationContext;21public class RmiClient {22 public static void main(String[] args) {23 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("context.xml");24 RmiMessage message = new RmiMessage();25 message.setServiceInterface("com.consol.citrus.rmi.service.HelloWorldService");26 message.setOperation("sayHello");27 message.setException(new RuntimeException("test exception"));28 message.setPayload("Hello");29 context.getBean("rmiClient", RmiClient.class).sayHello(message);30 }31 public String sayHello(RmiMessage message) {32 return message.getPayload(String.class);33 }34}35package com.consol.citrus.rmi;36import com.consol.citrus.rmi.message.RmiMessage;37import org.springframework.context.support.ClassPathXmlApplicationContext;38public class RmiClient {39 public static void main(String[] args) {40 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("context.xml");41 RmiMessage message = new RmiMessage();42 message.setServiceInterface("com.consol.citrus.rmi.service.HelloWorldService");

Full Screen

Full Screen

exception

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.rmi.client;2import org.springframework.context.support.ClassPathXmlApplicationContext;3import com.consol.citrus.rmi.message.RmiMessage;4public class RmiClient {5 public static void main(String[] args) {6 ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:com/consol/citrus/rmi/client/rmiClient-context.xml");7 RmiMessage message = new RmiMessage();8 message.setServiceInterface("com.consol.citrus.rmi.service.HelloService");9 message.setServiceName("HelloService");10 message.setServiceOperation("sayHello");11 message.setException("java.lang.RuntimeException");12 message.setExceptionMessage("Error in the remote method");13 message.setExceptionStackTrace("java.lang.RuntimeException: Error in the remote method14at com.consol.citrus.rmi.service.HelloService.sayHello(HelloService.java:12)");15 ctx.getBean("rmiClient", RmiClient.class).send(message);16 }17 public void send(RmiMessage message) {18 System.out.println("Client sending message: " + message);19 }20}21package com.consol.citrus.rmi.server;22import java.rmi.RemoteException;23import org.springframework.context.support.ClassPathXmlApplicationContext;24import com.consol.citrus.rmi.service.HelloService;25import com.consol.citrus.rmi.service.HelloServiceImpl;26public class RmiServer {27 public static void main(String[] args) {28 new RmiServer().start();29 }30 public void start() {31 ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:com/consol/citrus/rmi/server/rmiServer-context.xml");32 ctx.getBean("rmiServer", RmiServer.class).startServer();33 }34 public void startServer() {35 try {36 HelloService helloService = new HelloServiceImpl();37 java.rmi.Naming.rebind("HelloService", helloService);38 System.out.println("Server started");39 } catch (RemoteException e) {40 e.printStackTrace();41 } catch (java.net.MalformedURLException e) {42 e.printStackTrace();43 }44 }45}

Full Screen

Full Screen

exception

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.rmi.sample;2import org.apache.camel.builder.RouteBuilder;3import org.apache.camel.model.dataformat.JaxbDataFormat;4import org.apache.camel.model.dataformat.RmiDataFormat;5import org.apache.camel.spi.DataFormat;6import com.consol.citrus.rmi.sample.model.Book;7import com.consol.citrus.rmi.sample.model.BookList;8public class CamelRouteBuilder extends RouteBuilder {9 public void configure() throws Exception {10 DataFormat rmiDataFormat = new RmiDataFormat();11 DataFormat jaxbDataFormat = new JaxbDataFormat("com.consol.citrus.rmi.sample.model");12 .unmarshal(rmiDataFormat)13 .bean(new BookStoreService(), "handleException")14 .marshal(jaxbDataFormat)15 .to("file:target/camel");16 }17}18package com.consol.citrus.rmi.sample;19import java.util.ArrayList;20import java.util.List;21import org.apache.camel.Exchange;22import org.apache.camel.Processor;23import com.consol.citrus.rmi.message.RmiMessage;24public class BookStoreService implements Processor {25 public void process(Exchange exchange) throws Exception {26 exchange.getIn().setBody(new RmiMessage(new Exception("Exception occured in Camel route")));27 }28 public List<Book> handleException(Exception ex) {29 System.out.println("Exception occured in Camel route");30 List<Book> books = new ArrayList<Book>();31 books.add(new Book("Book1", "Author1"));32 books.add(new Book("Book2", "Author2"));33 return books;34 }35}36package com.consol.citrus.rmi.sample;37import java.util.List;38public class BookStoreServiceBean {39 public List<Book> findAllBooks() {40 System.out.println("findAllBooks called");41 List<Book> books = new ArrayList<Book>();42 books.add(new Book("Book1", "Author1"));43 books.add(new Book("Book2", "Author2"));44 return books;45 }46}47package com.consol.citrus.rmi.sample;48public class Book {49 private String name;50 private String author;51 public Book() {52 }

Full Screen

Full Screen

exception

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples.rmi;2import java.util.HashMap;3import java.util.Map;4import com.consol.citrus.annotations.CitrusTest;5import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;6import com.consol.citrus.rmi.message.RmiMessage;7import com.consol.citrus.rmi.server.RmiServer;8import com.consol.citrus.rmi.server.RmiServerConfig;9import com.consol.citrus.rmi.server.RmiServerConfigBuilder;10import com.consol.citrus.rmi.server.RmiServerConfigurator;11import com.consol.citrus.rmi.server.RmiServiceExporter;12import org.springframework.context.annotation.Bean;13import org.springframework.context.annotation.Configuration;14import org.springframework.context.annotation.Import;15import org.springframework.remoting.rmi.RmiServiceExporter;16import org.testng.annotations.Test;17public class RmiSampleIT extends TestNGCitrusTestDesigner {18 public void rmiSampleIT() {19 variable("rmiPort", "1099");20 rmi(action -> action.server(rmiServer())21 .client(rmiClient())22 .send()23 .message(RmiMessage.with()24 .object("Hello")25 .build())26 .receive()27 .message(RmiMessage.with()28 .object("Hello World!")29 .build()));30 }31 public RmiServer rmiServer() {32 RmiServerConfigBuilder configBuilder = new RmiServerConfigBuilder();33 configBuilder.port(1099);34 RmiServerConfigurator rmiServerConfigurator = new RmiServerConfigurator();35 rmiServerConfigurator.setServiceInterface(RmiServiceExporter.class);36 rmiServerConfigurator.setService(new RmiServiceExporter());37 rmiServerConfigurator.setServiceName("rmiService");38 return new RmiServer(configBuilder.build(), rmiServerConfigurator);39 }40}41package com.consol.citrus.samples.rmi;42import java.util.HashMap;43import java.util.Map;44import com.consol.citrus.annotations.CitrusTest;45import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;46import com.consol.citrus

Full Screen

Full Screen

exception

Using AI Code Generation

copy

Full Screen

1public class 3 extends TestCase {2 public void rmiClient() {3 rmi(action -> action.client(rmiClient)4 .send()5 .message(new RmiMessage()6 .exception(new Exception("RMI exception"))));7 }8 public void rmiServer() {9 rmi(action -> action.server(rmiServer)10 .receive()11 .message(new RmiMessage()12 .exception(new Exception("RMI exception"))));13 }14}15public class 4 extends TestCase {16 public void rmiClient() {17 rmi(action -> action.client(rmiClient)18 .send()19 .message(new RmiMessage()20 .exception(new Exception("RMI exception"))));21 }22 public void rmiServer() {23 rmi(action -> action.server(rmiServer)24 .receive()25 .message(new RmiMessage()26 .exception(new Exception("RMI exception"))));27 }28}29public class 5 extends TestCase {30 public void rmiClient() {31 rmi(action -> action.client(rmiClient)32 .send()33 .message(new RmiMessage()34 .exception(new Exception("RMI exception"))));35 }36 public void rmiServer() {37 rmi(action -> action.server(rmiServer)38 .receive()39 .message(new RmiMessage()40 .exception(new Exception("RMI exception"))));41 }42}43public class 6 extends TestCase {44 public void rmiClient() {45 rmi(action -> action.client(rmiClient)46 .send()47 .message(new RmiMessage()48 .exception(new Exception("RMI exception"))));49 }

Full Screen

Full Screen

exception

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.junit.JUnit4CitrusTestDesigner;4import com.consol.citrus.rmi.endpoint.RmiEndpoint;5import com.consol.citrus.rmi.message.RmiMessage;6import org.junit.Test;7import org.springframework.beans.factory.annotation.Autowired;8import org.springframework.core.io.ClassPathResource;9import org.springframework.util.StringUtils;10import java.rmi.RemoteException;11import java.rmi.server.RemoteServer;12public class RmiExceptionIT extends JUnit4CitrusTestDesigner {13 private RmiEndpoint rmiEndpoint;14 public void rmiException() {15 variable("exceptionMessage", "test exception message");16 variable("exceptionCause", "test exception cause");17 variable("exceptionStackTrace", "test exception stacktrace");18 send(rmiEndpoint)19 .payload(new RmiMessage() {20 public Object getMessage() throws RemoteException {21 throw new RemoteException("test exception message", new RuntimeException("test exception cause"));22 }23 });24 receive(rmiEndpoint)25 .payload(new RmiMessage() {26 public Object getMessage() throws RemoteException {27 throw new RemoteException("test exception message", new RuntimeException("test exception cause"));28 }29 })30 .exception(RemoteException.class)31 .message(RemoteException.class)32 .message(StringUtils.trimAllWhitespace("test exception message"))33 .message(new RuntimeException("test exception cause"))34 .message(StringUtils.trimAllWhitespace("test exception stacktrace"));35 }36 public void rmiExceptionWithScript() {37 variable("exceptionMessage", "test exception message");38 variable("exceptionCause", "test exception cause");39 variable("exceptionStackTrace", "test exception stacktrace");40 send(rmiEndpoint)41 .payload(new RmiMessage() {42 public Object getMessage() throws RemoteException {43 throw new RemoteException("test exception message", new RuntimeException("test exception cause"));44 }45 });46 receive(rmiEndpoint)47 .payload(new RmiMessage() {

Full Screen

Full Screen

exception

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.rmi;2import org.springframework.context.support.ClassPathXmlApplicationContext;3import com.consol.citrus.rmi.message.RmiMessage;4import com.consol.citrus.rmi.server.RmiServer;5public class RmiServerTest {6 public static void main(String[] args) {7 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("server.xml");8 RmiServer server = context.getBean("rmiServer", RmiServer.class);9 RmiMessage message = (RmiMessage) server.receive();10 System.out.println(message.getException());11 context.close();12 }13}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Citrus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful