Merge pull request #240 from andreisavu/domain-user-account

Unit test for parsing registerUserKeys response
This commit is contained in:
Adrian Cole 2011-12-13 11:01:44 -08:00
commit 11d07772c2
8 changed files with 457 additions and 3 deletions

View File

@ -19,6 +19,7 @@
package org.jclouds.cloudstack.options; package org.jclouds.cloudstack.options;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.User;
/** /**
* Options used to control what user information is returned * Options used to control what user information is returned
@ -55,8 +56,8 @@ public class ListUsersOptions extends AccountInDomainOptions {
* list accounts by state. Valid states are enabled, disabled, and * list accounts by state. Valid states are enabled, disabled, and
* locked. * locked.
*/ */
public ListUsersOptions state(String state) { public ListUsersOptions state(User.State state) {
this.queryParameters.replaceValues("state", ImmutableSet.of(state)); this.queryParameters.replaceValues("state", ImmutableSet.of(state.toString()));
return this; return this;
} }
@ -117,7 +118,7 @@ public class ListUsersOptions extends AccountInDomainOptions {
/** /**
* @see ListUsersOptions#state * @see ListUsersOptions#state
*/ */
public static ListUsersOptions state(String state) { public static ListUsersOptions state(User.State state) {
ListUsersOptions options = new ListUsersOptions(); ListUsersOptions options = new ListUsersOptions();
return options.state(state); return options.state(state);
} }

View File

@ -0,0 +1,66 @@
/**
* 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.CreateAccountOptions.Builder.account;
import static org.jclouds.cloudstack.options.CreateAccountOptions.Builder.domainId;
import static org.jclouds.cloudstack.options.CreateAccountOptions.Builder.networkDomain;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code CreateAccountOptions}
*
* @author Andrei Savu
*/
@Test(groups = "unit")
public class CreateAccountOptionsTest {
public void testNetworkDomain() {
CreateAccountOptions options = new CreateAccountOptions().networkDomain("net");
assertEquals(ImmutableSet.of("net"), options.buildQueryParameters().get("networkdomain"));
}
public void testNetworkDomainStatic() {
CreateAccountOptions options = networkDomain("net");
assertEquals(ImmutableSet.of("net"), options.buildQueryParameters().get("networkdomain"));
}
public void testAccount() {
CreateAccountOptions options = new CreateAccountOptions().account("accountName");
assertEquals(ImmutableSet.of("accountName"), options.buildQueryParameters().get("account"));
}
public void testAccountStatic() {
CreateAccountOptions options = account("accountName");
assertEquals(ImmutableSet.of("accountName"), options.buildQueryParameters().get("account"));
}
public void testAccountDomain() {
CreateAccountOptions options = new CreateAccountOptions().domainId(6);
assertEquals(ImmutableSet.of("6"), options.buildQueryParameters().get("domainid"));
}
public void testDomainIdStatic() {
CreateAccountOptions options = domainId(6);
assertEquals(ImmutableSet.of("6"), options.buildQueryParameters().get("domainid"));
}
}

View File

@ -0,0 +1,55 @@
/**
* 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.CreateUserOptions.Builder.domainId;
import static org.jclouds.cloudstack.options.CreateUserOptions.Builder.timezone;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code CreateUserOptions}
*
* @author Andrei Savu
*/
@Test(groups = "unit")
public class CreateUserOptionsTest {
public void testDomainId() {
CreateUserOptions options = new CreateUserOptions().domainId(6);
assertEquals(ImmutableSet.of("6"), options.buildQueryParameters().get("domainid"));
}
public void testDomainIdStatic() {
CreateUserOptions options = domainId(6);
assertEquals(ImmutableSet.of("6"), options.buildQueryParameters().get("domainid"));
}
public void testTimezone() {
CreateUserOptions options = new CreateUserOptions().timezone("something");
assertEquals(ImmutableSet.of("something"), options.buildQueryParameters().get("timezone"));
}
public void testTimezoneStatic() {
CreateUserOptions options = timezone("something");
assertEquals(ImmutableSet.of("something"), options.buildQueryParameters().get("timezone"));
}
}

View File

@ -0,0 +1,132 @@
/**
* 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.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.User;
import org.testng.annotations.Test;
import static org.jclouds.cloudstack.options.ListUsersOptions.Builder.accountInDomain;
import static org.jclouds.cloudstack.options.ListUsersOptions.Builder.accountType;
import static org.jclouds.cloudstack.options.ListUsersOptions.Builder.domainId;
import static org.jclouds.cloudstack.options.ListUsersOptions.Builder.id;
import static org.jclouds.cloudstack.options.ListUsersOptions.Builder.keyword;
import static org.jclouds.cloudstack.options.ListUsersOptions.Builder.page;
import static org.jclouds.cloudstack.options.ListUsersOptions.Builder.pageSize;
import static org.jclouds.cloudstack.options.ListUsersOptions.Builder.state;
import static org.jclouds.cloudstack.options.ListUsersOptions.Builder.userName;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code ListUsersOptions}
*
* @author Andrei Savu
*/
@Test(groups = "unit")
public class ListUsersOptionsTest {
public void testId() {
ListUsersOptions options = new ListUsersOptions().id(6);
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("id"));
}
public void testIdStatic() {
ListUsersOptions options = id(6);
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("id"));
}
public void testUserName() {
ListUsersOptions options = new ListUsersOptions().userName("andrei");
assertEquals(ImmutableSet.of("andrei"), options.buildQueryParameters().get("name"));
}
public void testUserNameStatic() {
ListUsersOptions options = userName("andrei");
assertEquals(ImmutableSet.of("andrei"), options.buildQueryParameters().get("name"));
}
public void testState() {
ListUsersOptions options = new ListUsersOptions().state(User.State.ENABLED);
assertEquals(ImmutableList.of("enabled"), options.buildQueryParameters().get("state"));
}
public void testStateStatic() {
ListUsersOptions options = state(User.State.ENABLED);
assertEquals(ImmutableList.of("enabled"), options.buildQueryParameters().get("state"));
}
public void testAccountType() {
ListUsersOptions options = new ListUsersOptions().accountType("user");
assertEquals(ImmutableList.of("user"), options.buildQueryParameters().get("accounttype"));
}
public void testAccountTypeStatic() {
ListUsersOptions options = accountType("user");
assertEquals(ImmutableList.of("user"), options.buildQueryParameters().get("accounttype"));
}
public void testKeyword() {
ListUsersOptions options = new ListUsersOptions().keyword("key");
assertEquals(ImmutableList.of("key"), options.buildQueryParameters().get("keyword"));
}
public void testKeywordStatic() {
ListUsersOptions options = keyword("key");
assertEquals(ImmutableList.of("key"), options.buildQueryParameters().get("keyword"));
}
public void testPage() {
ListUsersOptions options = new ListUsersOptions().page(6);
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("page"));
}
public void testPageStatic() {
ListUsersOptions options = page(6);
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("page"));
}
public void testPageSize() {
ListUsersOptions options = new ListUsersOptions().pageSize(6);
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("pagesize"));
}
public void testPageSizeStatic() {
ListUsersOptions options = pageSize(6);
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("pagesize"));
}
public void testAccountInDomainId() {
ListUsersOptions options = new ListUsersOptions().accountInDomain("adrian", 6);
assertEquals(ImmutableList.of("adrian"), options.buildQueryParameters().get("account"));
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid"));
}
public void testAccountInDomainIdStatic() {
ListUsersOptions options = accountInDomain("adrian", 6);
assertEquals(ImmutableList.of("adrian"), options.buildQueryParameters().get("account"));
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid"));
}
public void testDomainIdStatic() {
ListUsersOptions options = domainId(6);
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid"));
}
}

View File

@ -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.UpdateAccountOptions.Builder.networkDomain;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code UpdateAccountOptions}
*
* @author Andrei Savu
*/
@Test(groups = "unit")
public class UpdateAccountOptionsTest {
public void testNetworkDomain() {
UpdateAccountOptions options = new UpdateAccountOptions().networkDomain("net");
assertEquals(ImmutableSet.of("net"), options.buildQueryParameters().get("networkdomain"));
}
public void testNameStatic() {
UpdateAccountOptions options = networkDomain("net");
assertEquals(ImmutableSet.of("net"), options.buildQueryParameters().get("networkdomain"));
}
}

View File

@ -0,0 +1,110 @@
/**
* 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.UpdateUserOptions.Builder.email;
import static org.jclouds.cloudstack.options.UpdateUserOptions.Builder.firstName;
import static org.jclouds.cloudstack.options.UpdateUserOptions.Builder.lastName;
import static org.jclouds.cloudstack.options.UpdateUserOptions.Builder.timezone;
import static org.jclouds.cloudstack.options.UpdateUserOptions.Builder.userApiKey;
import static org.jclouds.cloudstack.options.UpdateUserOptions.Builder.userName;
import static org.jclouds.cloudstack.options.UpdateUserOptions.Builder.userSecretKey;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code UpdateUserOptions}
*
* @author Andrei Savu
*/
@Test(groups = "unit")
public class UpdateUserOptionsTest {
public void testEmail() {
UpdateUserOptions options = new UpdateUserOptions().email("andrei@example.com");
assertEquals(ImmutableSet.of("andrei@example.com"), options.buildQueryParameters().get("email"));
}
public void testEmailStatic() {
UpdateUserOptions options = email("andrei@example.com");
assertEquals(ImmutableSet.of("andrei@example.com"), options.buildQueryParameters().get("email"));
}
public void testFirstName() {
UpdateUserOptions options = new UpdateUserOptions().firstName("First");
assertEquals(ImmutableSet.of("First"), options.buildQueryParameters().get("firstname"));
}
public void testFirstStatic() {
UpdateUserOptions options = firstName("First");
assertEquals(ImmutableSet.of("First"), options.buildQueryParameters().get("firstname"));
}
public void testLastName() {
UpdateUserOptions options = new UpdateUserOptions().lastName("Last");
assertEquals(ImmutableSet.of("Last"), options.buildQueryParameters().get("lastname"));
}
public void testLastNameStatic() {
UpdateUserOptions options = lastName("Last");
assertEquals(ImmutableSet.of("Last"), options.buildQueryParameters().get("lastname"));
}
public void testTimezone() {
UpdateUserOptions options = new UpdateUserOptions().timezone("timez");
assertEquals(ImmutableSet.of("timez"), options.buildQueryParameters().get("timezone"));
}
public void testTimezoneStatic() {
UpdateUserOptions options = timezone("timez");
assertEquals(ImmutableSet.of("timez"), options.buildQueryParameters().get("timezone"));
}
public void testUserApiKey() {
UpdateUserOptions options = new UpdateUserOptions().userApiKey("sdfoasdjfo");
assertEquals(ImmutableSet.of("sdfoasdjfo"), options.buildQueryParameters().get("userapikey"));
}
public void testUserApiKeyStatic() {
UpdateUserOptions options = userApiKey("sdfoasdjfo");
assertEquals(ImmutableSet.of("sdfoasdjfo"), options.buildQueryParameters().get("userapikey"));
}
public void testUserSecretKey() {
UpdateUserOptions options = new UpdateUserOptions().userSecretKey("sdfoasdjfo");
assertEquals(ImmutableSet.of("sdfoasdjfo"), options.buildQueryParameters().get("usersecretkey"));
}
public void testUserSecretKeyStatic() {
UpdateUserOptions options = userSecretKey("sdfoasdjfo");
assertEquals(ImmutableSet.of("sdfoasdjfo"), options.buildQueryParameters().get("usersecretkey"));
}
public void testUserName() {
UpdateUserOptions options = new UpdateUserOptions().userName("andrei");
assertEquals(ImmutableSet.of("andrei"), options.buildQueryParameters().get("username"));
}
public void testUserNameStatic() {
UpdateUserOptions options = userName("andrei");
assertEquals(ImmutableSet.of("andrei"), options.buildQueryParameters().get("username"));
}
}

View File

@ -0,0 +1,45 @@
/**
* 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.parse;
import org.jclouds.cloudstack.domain.ApiKeyPair;
import org.jclouds.json.BaseParserTest;
import org.jclouds.rest.annotations.SelectJson;
import org.testng.annotations.Test;
/**
* @author Andrei Savu
*/
@Test(groups = "unit")
public class RegisterUserKeysResponseTest extends BaseParserTest<ApiKeyPair, Object> {
@Override
public String resource() {
return "/registeruserkeysresponse.json";
}
@Override
@SelectJson("userkeys")
public ApiKeyPair expected() {
return ApiKeyPair.builder()
.apiKey("5nn6IAQ-0BYuAKTu45rf49VsyX0rg9t48TpY8NKsduE5t-_1_g_AU8ZjP3OJvVdlzWKL3Lgfa6_nkC9hU6NyQQ")
.secretKey("GSCDYzj65CiSkxzCJxlFvcF52qglM7HbuG6QL7zYVeWVhVO8GnW85wGTBBuZ3xpzEN_UfKnsORvrNszYQ1ofAw").build();
}
}

View File

@ -0,0 +1 @@
{ "registeruserkeysresponse" : { "userkeys" : {"apikey":"5nn6IAQ-0BYuAKTu45rf49VsyX0rg9t48TpY8NKsduE5t-_1_g_AU8ZjP3OJvVdlzWKL3Lgfa6_nkC9hU6NyQQ","secretkey":"GSCDYzj65CiSkxzCJxlFvcF52qglM7HbuG6QL7zYVeWVhVO8GnW85wGTBBuZ3xpzEN_UfKnsORvrNszYQ1ofAw"} } }