@Test public void testProcessErrorResponse() throws Exception { final HttpClientUtilResponse response = new HttpClientUtilResponse(); final String mockError = "<error>\n" + "<errorCode>905</errorCode>\n" + "<message>contactZipCode parameter should be 5 numeric characters</message>\n" + "</error>"; response.setResponseByteArray(mockError.getBytes("UTF-8")); final ServiceResponseException mockServiceResponseException = new ServiceResponseException(); mockServiceResponseException.setErrorCode("905"); mockServiceResponseException.setMessage( "contactZipCode parameter should be 5 numeric characters"); PowerMockito.when(marshaller.unmarshal(Mockito.any(Source.class))) .thenReturn(mockServiceResponseException); final FormHandlerResponseInterface result = customerCareService.processErrorResponse(null, response, true); assertNotNull(result); assertEquals(new Integer(905), ((Errors) result).getErrors().get(0).getCode()); assertEquals( "contactZipCode parameter should be 5 numeric characters", ((Errors) result).getErrors().get(0).getMessage()); }
@Test public void testProcessCustomerCareRequests() throws Exception { final HttpClientUtilResponse mockResponse = new HttpClientUtilResponse(); mockResponse.setStatus(403); PowerMockito.when( customerCaseDAO.saveWebCase( Mockito.eq("http://localhost:8080/dealer/CustomerCare.do"), Mockito.anyString())) .thenReturn(mockResponse); final HttpClientUtilResponse result = customerCareService.processCustomerCareRequests( createExtendedParams(), new StreamResult(new StringWriter()), "http://localhost:8080/dealer/CustomerCare.do"); assertNotNull(result); assertEquals(403, result.getStatus()); }
@Test public void testProcessCustomerCareServiceResponse() throws Exception { final HttpClientUtilResponse mockResponse = new HttpClientUtilResponse(); final String sample = "<customer-care-case>\n" + "<vin>WAURFAFR7AA078877</vin>\n" + "<case-number>71300077</case-number>\n" + "</customer-care-case>\n"; mockResponse.setResponseByteArray(sample.getBytes("UTF-8")); final CustomerCareServiceResponseVO mockMarshallResponse = new CustomerCareServiceResponseVO(); mockMarshallResponse.setVin("WAURFAFR7AA078877"); mockMarshallResponse.setCaseNumber("71300077"); PowerMockito.when(marshaller.unmarshal(Mockito.any(Source.class))) .thenReturn(mockMarshallResponse); final FormHandlerResponseInterface result = customerCareService.processCustomerCareServiceResponse(null, mockResponse); assertNotNull(result); assertEquals("WAURFAFR7AA078877", ((Formhandler) result).getVin()); assertEquals("71300077", ((Formhandler) result).getCaseNumber()); }