Package com.google.api.adwords.lib

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

// 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 com.google.api.adwords.v13.AccountInfo;
import com.google.api.adwords.v13.AccountInterface;
import com.google.api.adwords.v13.ApiException;
import com.google.api.adwords.v13.DefinedReportJob;
import com.google.api.adwords.v13.ReportInterface;

import junit.framework.TestCase;

import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

/**
* Smoke tests the v13 version of AdWords API. The credentials are taken
* from "test_data/test.properties".
*
* @author api.arogal@gmail.com (Adam Rogal)
*/
public class AdWordsV13SmokeTest extends TestCase {
  private AdWordsUser testUser;

  private AccountInterface accountService;
  private ReportInterface reportService;

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

    accountService = testUser.getService(AdWordsService.V13.ACCOUNT_SERVICE);
    reportService = testUser.getService(AdWordsService.V13.REPORT_SERVICE);
  }

  /**
   * Tests logging in with incorrect credentials.
   */
  public void testBadLogin() throws RemoteException, ServiceException {
    AdWordsUser user = new AdWordsUser("test@gmail.com", "test",
        "client_1+test@gmail.com", "user-agent",
        "incorrect developer token", "any app token", true);

    try {
      ((AccountInterface) user.getService(AdWordsService.V13.ACCOUNT_SERVICE)).getAccountInfo();
    } catch (ApiException e) {
      assertEquals(42, e.getCode());
    }


    AccountInfo info = accountService.getAccountInfo();
  }

  /**
   * A smoke test for the ReportService.
   */
  public void testReportService() throws ApiException, RemoteException {
    DefinedReportJob job = new DefinedReportJob();
    job.setSelectedReportType("Structure");
    job.setAggregationTypes(new String[] {"Keyword"});
    job.setStartDay(new ReportDate(2009, 0, 1).toDate());
    job.setEndDay(new ReportDate(2009, 0, 31).toDate());
    job.setName("Demo Structure Keyword Report");
    job.setSelectedColumns(new String[] {
        "Campaign", "CampaignId", "AdGroup", "AdGroupId", "Keyword",
        "KeywordId", "MaximumCPC"});

    reportService.validateReportJob(job);
  }
}
TOP

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

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.