/** * Gets a client given a session and the class of the desired stub interface. * * @param <T> the service type * @param adsSession the session associated with the desired * client * @param interfaceClass the class type of the desired client * @return a client for the specified ads service * @throws ServiceException if the service client could not be created */ public synchronized <T> T getServiceClient(S adsSession, Class<T> interfaceClass) throws ServiceException { adsServiceFactoryHelper.checkServiceClientPreconditions(adsSession, interfaceClass); String version = adsServiceFactoryHelper.determineVersion(interfaceClass); D adsServiceDescriptor = adsServiceFactoryHelper.createServiceDescriptor(interfaceClass, version); C adsServiceClient = adsServiceFactoryHelper.createAdsServiceClient(adsServiceDescriptor, adsSession); return createProxy(interfaceClass, adsServiceClient); }
/** * 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 testCreateSoapClient() { when(soapClientHandler.createSoapClient(adsServiceDescriptor)) .thenReturn(soapClient); Object testSoapClient = abstractAdsServiceClientFactoryHelper.createSoapClient(adsServiceDescriptor); assertSame(soapClient, testSoapClient); }
/** * 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 public void testCreateServiceClient() { when(adsServiceClientFactory.create( soapClient, adsServiceDescriptor, adsSession)).thenReturn( adsServiceClient); AdsServiceClient<AdsSession, AdsServiceDescriptor> testAdsServiceClient = abstractAdsServiceClientFactoryHelper.createServiceClient(soapClient, adsServiceDescriptor, adsSession); assertSame(adsServiceClient, testAdsServiceClient); }
@Test public void testCreateServiceDescriptor() { Class<MockSoapClientInterface> interfaceClass = MockSoapClientInterface.class; when(adsServiceDescriptorFactory.create(interfaceClass, VERSION)) .thenReturn(adsServiceDescriptor); AdsServiceDescriptor testAdsServiceDescriptor = abstractAdsServiceClientFactoryHelper.createServiceDescriptor(interfaceClass, VERSION); assertSame(adsServiceDescriptor, testAdsServiceDescriptor); } }
@Test public void testCreateAdsServiceClient() { when(soapClientHandler.createSoapClient(adsServiceDescriptor)).thenReturn(soapClient); when(adsServiceClientFactory.create(soapClient, adsServiceDescriptor, adsSession)) .thenReturn(adsServiceClient); AdsServiceClient<AdsSession, AdsServiceDescriptor> testAdsServiceClient = abstractAdsServiceClientFactoryHelper.createAdsServiceClient(adsServiceDescriptor, adsSession); assertSame(adsServiceClient, testAdsServiceClient); }
/** * Gets a client given a session and the class of the desired stub interface. * * @param <T> the service type * @param adsSession the session associated with the desired * client * @param interfaceClass the class type of the desired client * @return a client for the specified ads service * @throws ServiceException if the service client could not be created */ public synchronized <T> T getServiceClient(S adsSession, Class<T> interfaceClass) throws ServiceException { adsServiceFactoryHelper.checkServiceClientPreconditions(adsSession, interfaceClass); String version = adsServiceFactoryHelper.determineVersion(interfaceClass); D adsServiceDescriptor = adsServiceFactoryHelper.createServiceDescriptor(interfaceClass, version); C adsServiceClient = adsServiceFactoryHelper.createAdsServiceClient(adsServiceDescriptor, adsSession); return createProxy(interfaceClass, adsServiceClient); }
/** * 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 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); } }