@Test public void testEsquemaFamiliarCasoError() throws IOException { // Creo los mocks testKit.replaceService( "TipoGrupoFamiliar", new ExchangeHandler() { @Override public void handleMessage(Exchange exchange) throws HandlerException { throw new RuntimeException("Error en el provider!"); } @Override public void handleFault(Exchange exchange) { throw new RuntimeException("Sucedio error inesperado"); } }); try { // Ejecuto el servicio getEsquemaFamiliar.sendInOut( CotizadorPlanesUnitTest.loadFile( "unitTest/serviceRequest/getEsquemaFamiliarServiceRequest.xml")); } catch (InvocationFaultException e) { // Verifico que el servicio haya lanzado una excepción assertTrue(e.getFaultMessage().toString().contains("Error en el provider!")); } }
@Test public void testProcess() throws Exception { String message = "Hello ABC!"; String result = service.operation("process").sendInOut(message).getContent(String.class); // validate the results Assert.assertEquals("Service 3 Service 2 Service 1 Hello ABC!", result); }
@Test public void testItemLookupExists() throws Exception { final String ITEM_ID = "BUTTER"; Item item = lookupItem.sendInOut(ITEM_ID).getContent(Item.class); Assert.assertNotNull(item); Assert.assertEquals(ITEM_ID, item.getItemId()); }
@Test public void sendMessage() { Order order = new Order(); order.setOrderId("SHIPIT"); OrderAck ack = service.sendInOut(order).getContent(OrderAck.class); Assert.assertFalse(ack.isAccepted()); Assert.assertEquals(BackOrderBean.HOLD_STATUS, ack.getStatus()); }
@Test public void testItemLookupNonexistent() throws Exception { final String ITEM_ID = "GUNS"; try { // This should generate a fault because the ITEM_ID is not found lookupItem.sendInOut(ITEM_ID).getContent(Item.class); // Looks like we didn't fault, so fail Assert.fail("Invalid itemId accepted: " + ITEM_ID); } catch (InvocationFaultException ifEx) { Assert.assertTrue(ifEx.isType(ItemNotFoundException.class)); } }
@Test public void sanityCheck() throws Exception { // Mock providers for services called from IntakeService MockHandler lookUpService = testKit.registerInOutService("CustomerLookup").replyWithOut(null); MockHandler preQualService = testKit.replaceService("PreQualificationService").forwardInToOut(); service.operation("intake").sendInOnly(createApplication()); // validate that our downstream service references were called Assert.assertEquals(1, lookUpService.getMessages().size()); Assert.assertEquals(1, preQualService.getMessages().size()); }
@Test public void childrenHaveHorribleCredit() throws Exception { // Build the request message Applicant applicant = new Applicant(); applicant.setName("Peter Gibbons"); applicant.setAge(8); // Invoke the service service.operation("process").sendInOut(applicant); // validate the results Assert.assertEquals(160, applicant.getCreditScore()); }
@Test public void goodCredit() throws Exception { // Build the request message Applicant applicant = new Applicant(); applicant.setName("Bill Lumbergh"); applicant.setCreditScore(700); // Invoke the service service.operation("process").sendInOut(applicant); // validate the results Assert.assertTrue(applicant.isApproved()); }
@Test public void lowCredit() throws Exception { // Build the request message Applicant applicant = new Applicant(); applicant.setName("Peter Gibbons"); applicant.setCreditScore(400); // Invoke the service Applicant reply = service.operation("process").sendInOut(applicant).getContent(Applicant.class); // validate the results Assert.assertTrue(!reply.isApproved()); }
@Test public void adultsAreResponsible() throws Exception { // Build the request message Applicant request = new Applicant(); request.setName("Bill Lumbergh"); request.setAge(39); // Invoke the service Applicant reply = service.operation("process").sendInOut(request).getContent(Applicant.class); // validate the results Assert.assertNotSame(780, reply.getCreditScore()); }
@Test public void testEsquemaFamiliarCasoOk() throws IOException, SAXException { // Creo los mocks testKit.replaceService( "TipoGrupoFamiliar", new ExchangeHandler() { @Override public void handleMessage(Exchange exchange) throws HandlerException { String request = exchange.getMessage().getContent(String.class); LOG.info("getEsquemaFamiliar provider:" + request); try { // Verifico que el request que entra al mock sea el esperado XMLAssert.assertXMLEqual( CotizadorPlanesUnitTest.loadFile( "unitTest/providerMockExpectedRequest/getExquemaFamiliarProviderExpectedRequest.xml"), request); // Genero la respuesta mockeada String mockResponse = CotizadorPlanesUnitTest.loadFile( "unitTest/providerMockResponse/getExquemaFamiliarProviderResponse.xml"); LOG.info("mockResponse:" + mockResponse); // Envio la respuesta mockeada exchange.send(exchange.createMessage().setContent(mockResponse)); } catch (AssertionError a) { LOG.error("El request al provider no valida con el esperado", a); throw new HandlerException(a); } catch (Exception e) { LOG.error("Sucedió un error al obtener el archivo", e); throw new HandlerException(e); } } @Override public void handleFault(Exchange exchange) { throw new RuntimeException("Sucedio error inesperado"); } }); // Ejecuto el servicio Message response = getEsquemaFamiliar.sendInOut( CotizadorPlanesUnitTest.loadFile( "unitTest/serviceRequest/getEsquemaFamiliarServiceRequest.xml")); // Verifico los resultados XMLAssert.assertXMLEqual( CotizadorPlanesUnitTest.loadFile( "unitTest/serviceExpectedResponse/getExquemaFamiliarServiceExpectedResponse.xml"), response.getContent(String.class)); }
@Test public void testPlanesCasoError() throws IOException { // Creo los mocks testKit.replaceService( "PlanesComercialesSocio", new ExchangeHandler() { @Override public void handleMessage(Exchange exchange) throws HandlerException { throw new RuntimeException("Error en el provider!"); } @Override public void handleFault(Exchange exchange) { throw new RuntimeException("Sucedio error inesperado"); } }); try { // Ejecuto el servicio getPlanes.sendInOut( CotizadorPlanesUnitTest.loadFile("unitTest/serviceRequest/getPlanesServiceRequest.xml")); } catch (InvocationFaultException e) { assertTrue(e.getFaultMessage().toString().contains("Error en el provider!")); } }
@Test public void httpGatewayReferenceTest() throws Exception { Message responseMsg = _consumerService.operation("sayHello").sendInOut("magesh"); Assert.assertEquals("magesh", responseMsg.getContent(String.class)); }