@Override protected void setHeaders() throws ServiceException, AuthenticationException { getSoapClientHandler().clearHeaders(getSoapClient()); headerHandler.setHeaders(getSoapClient(), 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); } }
@Override protected void setHeaders() throws ServiceException, AuthenticationException { getSoapClientHandler().clearHeaders(getSoapClient()); headerHandler.setHeaders(getSoapClient(), 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); } }
/** * 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); }
/** * 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); } }