diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/GenerateUsageRecordsOptions.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/GenerateUsageRecordsOptions.java new file mode 100644 index 0000000000..58e01e434e --- /dev/null +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/GenerateUsageRecordsOptions.java @@ -0,0 +1,44 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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 org.jclouds.cloudstack.options; + +import com.google.common.collect.ImmutableSet; +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * Options to the GlobalUsageClient.generateUsageOptions() API call + * + * @author Richard Downer + */ +public class GenerateUsageRecordsOptions extends BaseHttpRequestOptions { + + public static final GenerateUsageRecordsOptions NONE = new GenerateUsageRecordsOptions(); + + public static class Builder { + public static GenerateUsageRecordsOptions domainId(long domainId) { + GenerateUsageRecordsOptions options = new GenerateUsageRecordsOptions(); + return options.domainId(domainId); + } + } + + public GenerateUsageRecordsOptions domainId(long domainId) { + this.queryParameters.replaceValues("domainid", ImmutableSet.of(domainId + "")); + return this; + } +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/GenerateUsageRecordsOptionsTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/GenerateUsageRecordsOptionsTest.java new file mode 100644 index 0000000000..d06407afae --- /dev/null +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/GenerateUsageRecordsOptionsTest.java @@ -0,0 +1,44 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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 org.jclouds.cloudstack.options; + +import com.google.common.collect.ImmutableSet; +import org.testng.annotations.Test; + +import static org.jclouds.cloudstack.options.GenerateUsageRecordsOptions.Builder.domainId; +import static org.testng.Assert.assertEquals; + +/** + * Tests behavior of {@code GenerateUsageRecordsOptions} + * + * @author Richard Downer + */ +@Test(groups = "unit") +public class GenerateUsageRecordsOptionsTest { + + public void testDomainId() { + GenerateUsageRecordsOptions options = new GenerateUsageRecordsOptions().domainId(42); + assertEquals(ImmutableSet.of("42"), options.buildQueryParameters().get("domainid")); + } + + public void testDomainIdStatic() { + GenerateUsageRecordsOptions options = domainId(42); + assertEquals(ImmutableSet.of("42"), options.buildQueryParameters().get("domainid")); + } +}