Service Virtualization

How to implement Java Exception to VSI

  • 1.  How to implement Java Exception to VSI

    Posted Dec 06, 2014 01:33 AM

    Hello,

     

    In virtualization of Java, I would like to reproduce the exception.
    In [Response]-[Body] of VSI, How do I describe exception?

     

    When i record the operation of the exception, the [Response]-[Body] of VSI stored the following values.

    <lisa.vse.java.response>
    <lisa.vse.java.response.args>
    </lisa.vse.java.response.args>
    </lisa.vse.java.response>


    The following source code is an excerpt.

    public class JavaVirtualize {
        public void run() {
            try {
                DataAccessBean da = new DataAccessBeanImpl();
                Request req = new Request();
                req.setId("");
                req.setName("");
                Response res = da.getData(req);    <--- da.getData() is subject of virtualization.
            } catch(DataNotFoundException ex) {
                System.out.println(ex.getMessage());
            }
        }
    }
    

     

    public class DataAccessBeanImpl implements DataAccessBean {
        @Override
        public Response getData(Request request) throws DataNotFoundException {
            System.out.println("# implemented logic is called!!");
            if ("02".equals(request.getId())) {
                DataNotFoundException dnfe = new DataNotFoundException();
                dnfe.setId(request.getId());
                dnfe.setName(request.getName());            
                throw dnfe;
            } else {
                return new Response();
            }
        }
    }
    

     

    public class DataNotFoundException extends DataAccessException {
        private String id;
        private String name;
        public DataNotFoundException() {
            super("Data is not found!!");
        }
        ( ...getter / setter is omitted ...)
    }
    

     

    Thanks,

    Masateru