Package com.google.api.adwords.lib

Source Code of com.google.api.adwords.lib.AdWordsServiceFactoryTest

// Copyright 2010 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.api.adwords.lib;

import junit.framework.TestCase;

import org.apache.axis.client.Stub;
import org.apache.axis.message.SOAPHeaderElement;

import javax.xml.rpc.ServiceException;

/**
* Tests the {@link AdWordsServiceFactory} to ensure that all services
* can be instantiated correctly. The credentials are taken from
* "test_data/test.properties".
*
* @author api.arogal@gmail.com (Adam Rogal)
*/
public class AdWordsServiceFactoryTest extends TestCase {
  private AdWordsUser testUser;

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    testUser = new AdWordsUser("test_data/test.properties");
  }

  /**
   * Tests that all service can be generated for v13.
   */
  public void testGenerateServiceStub_allV13() throws ServiceException {
    AdWordsServiceFactory.generateServiceStub(AdWordsService.V13.ACCOUNT_SERVICE, testUser);
    AdWordsServiceFactory.generateServiceStub(AdWordsService.V13.REPORT_SERVICE, testUser);
  }

  /**
   * Tests that the headers are set correctly.
   */
  public void testGenerateServiceStub_v13Headers() throws ServiceException {
    Stub stub = (Stub) testUser.getService(AdWordsService.V13.ACCOUNT_SERVICE);
    for (SOAPHeaderElement soapHeaderElement : stub.getHeaders()) {
      if (soapHeaderElement.getLocalName().equals("email")) {
        assertEquals("email", testUser.getEmail(), soapHeaderElement.getValue());
      } else if (soapHeaderElement.getLocalName().equals("password")) {
        assertEquals("password", testUser.getPassword(), soapHeaderElement.getValue());
      } else if (soapHeaderElement.getLocalName().equals("developerToken")) {
        assertEquals("developerToken", testUser.getDeveloperToken(), soapHeaderElement.getValue());
      } else if (soapHeaderElement.getLocalName().equals("applicationToken")) {
        assertEquals("applicationToken", testUser.getApplicationToken(),
            soapHeaderElement.getValue());
      } else if (soapHeaderElement.getLocalName().equals("useragent")) {
        assertEquals("userAgent", testUser.getClientLibraryIdentifier(),
            soapHeaderElement.getValue());
      } else if (soapHeaderElement.getLocalName().equals("clientEmail")) {
        assertEquals("clientEmail", testUser.getClientEmail(), soapHeaderElement.getValue());
      } else if (soapHeaderElement.getLocalName().equals("clientCustomerId")) {
        assertEquals("clientCustomerId", testUser.getClientCustomerId(),
            soapHeaderElement.getValue());
      } else {
        fail("Unknown header found: " + soapHeaderElement.getLocalName());
      }
    }
  }

  /**
   * Tests that all service can be generated for v200909.
   */
  public void testGenerateServiceStub_allV200909() throws ServiceException {
      testUser.setAuthToken("testAuthToken");
      AdWordsServiceFactory.generateServiceStub(
          AdWordsService.V200909.AD_EXTENSION_OVERRIDE_SERVICE, testUser);
      AdWordsServiceFactory.generateServiceStub(AdWordsService.V200909.ADGROUP_AD_SERVICE,
          testUser);
      AdWordsServiceFactory.generateServiceStub(AdWordsService.V200909.ADGROUP_CRITERION_SERVICE,
          testUser);
      AdWordsServiceFactory.generateServiceStub(AdWordsService.V200909.ADGROUP_SERVICE,
          testUser);
      AdWordsServiceFactory.generateServiceStub(AdWordsService.V200909.BULK_MUTATE_JOB_SERVICE,
          testUser);
      AdWordsServiceFactory.generateServiceStub(
          AdWordsService.V200909.CAMPAIGN_AD_EXTENSION_SERVICE, testUser);
      AdWordsServiceFactory.generateServiceStub(AdWordsService.V200909.CAMPAIGN_CRITERION_SERVICE,
          testUser);
      AdWordsServiceFactory.generateServiceStub(AdWordsService.V200909.CAMPAIGN_SERVICE,
          testUser);
      AdWordsServiceFactory.generateServiceStub(AdWordsService.V200909.CAMPAIGN_TARGET_SERVICE,
          testUser);
      AdWordsServiceFactory.generateServiceStub(AdWordsService.V200909.GEO_LOCATION_SERVICE,
          testUser);
      AdWordsServiceFactory.generateServiceStub(AdWordsService.V200909.INFO_SERVICE,
          testUser);
      AdWordsServiceFactory.generateServiceStub(AdWordsService.V200909.TARGETING_IDEA_SERVICE,
          testUser);
  }

  /**
   * Tests that the headers are set correctly.
   */
  public void testGenerateServiceStub_v200909Headers() throws ServiceException {
    testUser.setAuthToken("testAuthToken");
    Stub stub = AdWordsServiceFactory.generateServiceStub(
        AdWordsService.V200909.ADGROUP_AD_SERVICE, testUser);

    for (SOAPHeaderElement soapHeaderElement : stub.getHeaders()) {
      com.google.api.adwords.v200909.cm.SoapHeader header =
          (com.google.api.adwords.v200909.cm.SoapHeader) soapHeaderElement.getObjectValue();

      assertEquals("authToken", "testAuthToken", header.getAuthToken());
      assertEquals("clientEmail", testUser.getClientEmail(), header.getClientEmail());
      assertEquals("clientCustomerId", testUser.getClientCustomerId(),
          header.getClientCustomerId());
      assertEquals("applicationToken", testUser.getApplicationToken(),
          header.getApplicationToken());
      assertEquals("developerToken", testUser.getDeveloperToken(), header.getDeveloperToken());
      assertEquals("userAgent", testUser.getClientLibraryIdentifier(),
          header.getUserAgent());
    }
  }
}
TOP

Related Classes of com.google.api.adwords.lib.AdWordsServiceFactoryTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.