@Override protected void setHeaders() throws ServiceException, AuthenticationException { getSoapClientHandler().clearHeaders(getSoapClient()); headerHandler.setHeaders(getSoapClient(), adsSession, adsServiceDescriptor); } }
/** @see SoapServiceClient#handleException */ @Override protected Throwable handleException(Throwable e) { return super.handleException(e); } }
/** * Creates the proxy for the {@link AdsServiceClient}. * * @param <T> the service type * @param adsServiceClient the client to proxy * @return the proxy */ <T> T createProxy(Class<T> interfaceClass, C adsServiceClient) { Set<Class<?>> interfaces = Sets.newHashSet(adsServiceClient.getClass().getInterfaces()); interfaces.add(interfaceClass); Object proxy = Proxy.newProxyInstance( adsServiceClient.getSoapClient().getClass().getClassLoader(), interfaces.toArray(new Class[] {}), adsServiceClient); return interfaceClass.cast(proxy); } }
/** * Creates an {@link AdsServiceClient} given an {@link AdsServiceDescriptor} * descriptor and an {@link AdsSession}. * * @param adsServiceDescriptor descriptor with information on ads service * @param adsSession the session associated with the desired * client * @return the created {@link AdsServiceClient} * @throws ServiceException if the ads service client could not be created */ @Override public C createAdsServiceClient(D adsServiceDescriptor, S adsSession) throws ServiceException { Object soapClient = createSoapClient(adsServiceDescriptor); C adsServiceClient = createServiceClient(soapClient, adsServiceDescriptor, adsSession); try { adsServiceClient.setEndpointAddress(adsServiceDescriptor.getEndpointAddress(adsSession .getEndpoint())); } catch (MalformedURLException e) { throw new ServiceException("Unexpected exception", e); } return adsServiceClient; }
@Test public void testLogSoapCall() { RemoteCallReturn remoteCallReturn = Mockito.mock(RemoteCallReturn.class); adsServiceClient.logSoapCall(remoteCallReturn); verify(adsServiceLoggers).logRequest(remoteCallReturn); }
@Test public void testSetHeaders() throws Exception { adsServiceClient.setHeaders(); verify(soapClientHandler).clearHeaders(soapClient); verify(headerHandler).setHeaders(soapClient, adsSession, adsServiceDescriptor); } }
/** * Creates the proxy for the {@link AdsServiceClient}. * * @param <T> the service type * @param adsServiceClient the client to proxy * @return the proxy */ <T> T createProxy(Class<T> interfaceClass, C adsServiceClient) { Set<Class<?>> interfaces = Sets.newHashSet(adsServiceClient.getClass().getInterfaces()); interfaces.add(interfaceClass); Object proxy = Proxy.newProxyInstance( adsServiceClient.getSoapClient().getClass().getClassLoader(), interfaces.toArray(new Class[] {}), adsServiceClient); return interfaceClass.cast(proxy); } }
/** * Creates an {@link AdsServiceClient} given an {@link AdsServiceDescriptor} * descriptor and an {@link AdsSession}. * * @param adsServiceDescriptor descriptor with information on ads service * @param adsSession the session associated with the desired * client * @return the created {@link AdsServiceClient} * @throws ServiceException if the ads service client could not be created */ @Override public C createAdsServiceClient(D adsServiceDescriptor, S adsSession) throws ServiceException { Object soapClient = createSoapClient(adsServiceDescriptor); C adsServiceClient = createServiceClient(soapClient, adsServiceDescriptor, adsSession); try { adsServiceClient.setEndpointAddress(adsServiceDescriptor.getEndpointAddress(adsSession .getEndpoint())); } catch (MalformedURLException e) { throw new ServiceException("Unexpected exception", e); } return adsServiceClient; }
@Override protected void setHeaders() throws ServiceException, AuthenticationException { getSoapClientHandler().clearHeaders(getSoapClient()); headerHandler.setHeaders(getSoapClient(), adsSession, adsServiceDescriptor); } }
/** * Test that verifies that an object implementing the requested interface is returned from a * valid call to getServiceClient. */ @Test public void testGetServiceClient() { String version = "v1.1"; when(adsServiceClientFactoryHelper.determineVersion(MockSoapClientInterface.class)) .thenReturn(version); when( adsServiceClientFactoryHelper.createServiceDescriptor( MockSoapClientInterface.class, version)).thenReturn(adsServiceDescriptor); when(adsServiceClientFactoryHelper.createAdsServiceClient(adsServiceDescriptor, adsSession)) .thenReturn(adsServiceClient); Mockito.<Class<?>>when(adsServiceDescriptor.getInterfaceClass()) .thenReturn(MockSoapClientInterface.class); when(adsServiceClient.getSoapClient()).thenReturn(soapServiceClient); MockSoapClientInterface mockSoapClientInterface = adsServiceClientFactory.getServiceClient(adsSession, MockSoapClientInterface.class); assertNotNull("Null mock interface returned from getServiceClient", mockSoapClientInterface); }
/** @see SoapServiceClient#handleException */ @Override protected Throwable handleException(Throwable e) { return super.handleException(e); } }
/** * Test to verify that a ServiceException is thrown if the preconditions check by the underlying * AdsServiceClientFactoryHelper fails. */ @Test public void testGetServiceClient_failPreconditions() { String version = "v1.1"; ServiceException serviceException = new ServiceException("A service exception"); doThrow(serviceException) .when(adsServiceClientFactoryHelper) .checkServiceClientPreconditions(adsSession, MockSoapClientInterface.class); when(adsServiceClientFactoryHelper.determineVersion(MockSoapClientInterface.class)) .thenReturn(version); when( adsServiceClientFactoryHelper.createServiceDescriptor( MockSoapClientInterface.class, version)).thenReturn(adsServiceDescriptor); when(adsServiceClientFactoryHelper.createAdsServiceClient(adsServiceDescriptor, adsSession)) .thenReturn(adsServiceClient); Mockito.<Class<?>>when(adsServiceDescriptor.getInterfaceClass()) .thenReturn(MockSoapClientInterface.class); when(adsServiceClient.getSoapClient()).thenReturn(soapServiceClient); thrown.expect(Matchers.<Exception>is(serviceException)); adsServiceClientFactory.getServiceClient(adsSession, MockSoapClientInterface.class); } }