How to use getExceptionMessage method of org.evomaster.client.java.controller.problem.rpc.RPCExceptionHandler class

Best EvoMaster code snippet using org.evomaster.client.java.controller.problem.rpc.RPCExceptionHandler.getExceptionMessage

Source:RPCExceptionHandler.java Github

copy

Full Screen

...67 private static RPCExceptionInfoDto handleExceptionNameAndMessage(Object e){68 RPCExceptionInfoDto dto = new RPCExceptionInfoDto();69 if (Exception.class.isAssignableFrom(e.getClass())){70 dto.exceptionName = e.getClass().getName();71 dto.exceptionMessage = getExceptionMessage(e);72 }else73 SimpleLogger.error("ERROR: the exception is not java.lang.Exception "+e.getClass().getName());74 return dto;75 }76 /**77 * handle exceptions from thrift78 * https://javadoc.io/doc/org.apache.thrift/libthrift/latest/org/apache/thrift/TException.html79 * @param e is an exception thrown from the rpc call execution80 * @param endpointSchema is the schema of this endpoint81 * @return extracted exception dto82 */83 private static boolean handleThrift(Object e, EndpointSchema endpointSchema, RPCExceptionInfoDto dto) {84 boolean handled = false;85 try {86 if (!isRootThriftException(e)){87 //SimpleLogger.info("Exception e is not an instance of TException of Thrift, and it is "+ e.getClass().getName());88 return false;89 }90 handled = handleTException(e, dto);91 if (!handled){92 SimpleLogger.error("Fail to extract exception type info for an exception "+ e.getClass().getName());93 }94 } catch (ClassNotFoundException ex) {95 SimpleLogger.error("ERROR: in handling Thrift exception with error msg:"+ex.getMessage());96 //throw new IllegalStateException("ERROR: in handling Thrift exception with error msg:"+ex.getMessage());97 }98 return handled;99 }100 private static boolean handleDefinedException(Object e, EndpointSchema endpointSchema, RPCType rpcType, RPCExceptionInfoDto dto) throws ClassNotFoundException {101 if (endpointSchema.getExceptions() == null) return false;102 for (NamedTypedValue p : endpointSchema.getExceptions()){103 String type = p.getType().getFullTypeNameWithGenericType();104 // skip to handle root TException here105 if (rpcType == RPCType.THRIFT && type.equals(THRIFT_EXCEPTION_ROOT))106 continue;107 if (isInstanceOf(e, type)){108 p.setValueBasedOnInstance(e);109 dto.exceptionDto = p.getDto();110 dto.type = RPCExceptionType.CUSTOMIZED_EXCEPTION;111 return true;112 }113 }114 return false;115 }116 private static boolean handleTException(Object e, RPCExceptionInfoDto dto) {117 Method getType = null;118 try {119 getType = e.getClass().getDeclaredMethod("getType");120 getType.setAccessible(true);121 int type = (int) getType.invoke(e);122 dto.type = getExceptionType(extract(e), type);123 return true;124 } catch (NoSuchMethodException | ClassNotFoundException | InvocationTargetException | IllegalAccessException ex) {125 SimpleLogger.error("Fail to get type of TException with getType() "+ex.getMessage());126 }127 return false;128 }129 private static String getExceptionMessage(Object e) {130 Method getMessage = null;131 try {132 getMessage = e.getClass().getMethod("getMessage");133 getMessage.setAccessible(true);134 return (String) getMessage.invoke(e);135 } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {136 SimpleLogger.error("Error: fail to get message of the exception with "+ex.getMessage());137 return null;138 }139 }140 private static Object getExceptionCause(Object e) {141 Method getCause = null;142 try {143 getCause = e.getClass().getMethod("getCause");...

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 EvoMaster 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