// Copyright 2011 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.v201008;
import junit.framework.TestCase;
import com.google.api.adwords.lib.AdWordsService;
import com.google.api.adwords.lib.AdWordsUser;
import com.google.api.adwords.v201008.cm.DateRange;
import com.google.api.adwords.v201008.cm.Operator;
import com.google.api.adwords.v201008.info.ApiUsageInfo;
import com.google.api.adwords.v201008.info.ApiUsageType;
import com.google.api.adwords.v201008.info.InfoSelector;
import com.google.api.adwords.v201008.info.InfoServiceInterface;
/**
* Functional tests for InfoService.
*
* @author api.naoki.ishihara@gmail.com (Naoki Ishihara)
*/
public class InfoServiceTest extends TestCase {
private AdWordsUser user = null;
private String clientId;
private InfoServiceInterface service = null;
/**
* Set up the test fixtures.
*/
@Override
protected void setUp() throws Exception {
super.setUp();
user = new AdWordsUser("test_data/test.properties");
clientId = user.getClientEmail();
service = user.getService(AdWordsService.V201008.INFO_SERVICE);
}
/**
* Test getting API usage.
*/
public void testGetApiUsage() throws Exception {
// Create selector.
InfoSelector selector = new InfoSelector();
selector.setServiceName("CampaignService");
selector.setMethodName("mutate");
selector.setOperator(Operator.ADD);
selector.setDateRange(new DateRange(TestUtils.firstDayOfMonth(), TestUtils.today()));
selector.setApiUsageType(ApiUsageType.UNIT_COUNT);
ApiUsageInfo apiUsageInfo = service.get(selector);
assertNull(apiUsageInfo.getApiUsageRecords());
assertNotNull(apiUsageInfo.getCost());
}
/**
* Test getting monthly API usage limits.
*/
public void testGetMonthlyLimits() throws Exception {
// Create selector.
InfoSelector selector = new InfoSelector();
selector.setApiUsageType(ApiUsageType.UNIT_COUNT);
ApiUsageInfo apiUsageInfo = service.get(selector);
assertNull(apiUsageInfo.getApiUsageRecords());
assertNotNull(apiUsageInfo.getCost());
}
/**
* Test getting a unit count for clients.
*/
public void testGetntCountForClients() throws Exception {
// Create selector.
DateRange range = new DateRange(TestUtils.firstDayOfMonth(), TestUtils.today());
InfoSelector selector = new InfoSelector("CampaignService", "mutate", Operator.ADD, range,
new String[] {clientId}, ApiUsageType.UNIT_COUNT_FOR_CLIENTS);
ApiUsageInfo apiUsageInfo = service.get(selector);
assertNotNull(apiUsageInfo.getApiUsageRecords());
assertEquals(clientId, apiUsageInfo.getApiUsageRecords()[0].getClientEmail());
assertNotNull(apiUsageInfo.getApiUsageRecords()[0].getCost());
}
/**
* Test getting the cost of a method.
*/
public void testGetMethodCost() throws Exception {
// Create selector.
DateRange range = new DateRange(TestUtils.firstDayOfMonth(), TestUtils.today());
InfoSelector selector = new InfoSelector("CampaignService", "mutate", Operator.ADD, range,
null, ApiUsageType.METHOD_COST);
ApiUsageInfo apiUsageInfo = service.get(selector);
assertNull(apiUsageInfo.getApiUsageRecords());
assertNotNull(apiUsageInfo.getCost());
}
}