diff --git a/opscodeplatform/src/main/java/org/jclouds/opscodeplatform/OpscodePlatformAsyncClient.java b/opscodeplatform/src/main/java/org/jclouds/opscodeplatform/OpscodePlatformAsyncClient.java index ca2a5bbd44..a67673989c 100644 --- a/opscodeplatform/src/main/java/org/jclouds/opscodeplatform/OpscodePlatformAsyncClient.java +++ b/opscodeplatform/src/main/java/org/jclouds/opscodeplatform/OpscodePlatformAsyncClient.java @@ -46,6 +46,7 @@ import org.jclouds.opscodeplatform.domain.User; import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.Headers; import org.jclouds.rest.annotations.ParamParser; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; @@ -66,6 +67,7 @@ import com.google.common.util.concurrent.ListenableFuture; */ @RequestFilters(SignedHeaderAuth.class) @Consumes(MediaType.APPLICATION_JSON) +@Headers(keys = "X-Chef-Version", values = ChefAsyncClient.VERSION) public interface OpscodePlatformAsyncClient { /** * @see ChefCookbooks#listCookbooksInOrganization diff --git a/opscodeplatform/src/main/java/org/jclouds/opscodeplatform/config/OrganizationName.java b/opscodeplatform/src/main/java/org/jclouds/opscodeplatform/config/OrganizationName.java index 4e0c1b7d0d..8eb005b61d 100644 --- a/opscodeplatform/src/main/java/org/jclouds/opscodeplatform/config/OrganizationName.java +++ b/opscodeplatform/src/main/java/org/jclouds/opscodeplatform/config/OrganizationName.java @@ -32,7 +32,7 @@ import com.google.common.base.Function; public class OrganizationName implements Function { public String apply(Object from) { - return ((Organization) from).getName(); + return ((Organization) from).getFullName(); } } \ No newline at end of file diff --git a/opscodeplatform/src/main/java/org/jclouds/opscodeplatform/domain/Organization.java b/opscodeplatform/src/main/java/org/jclouds/opscodeplatform/domain/Organization.java index 7fe6d15e71..64e8495f52 100644 --- a/opscodeplatform/src/main/java/org/jclouds/opscodeplatform/domain/Organization.java +++ b/opscodeplatform/src/main/java/org/jclouds/opscodeplatform/domain/Organization.java @@ -18,74 +18,56 @@ */ package org.jclouds.opscodeplatform.domain; +import static com.google.common.base.Preconditions.checkNotNull; + import java.security.PrivateKey; import com.google.gson.annotations.SerializedName; /** - * User object. + * Organization object. * * @author Adrian Cole */ -public class Organization implements Comparable { +public class Organization { + + public interface Type { + public static final String BUSINESS = "Business"; + public static final String NON_PROFIT = "Non-Profit"; + public static final String PERSONAL = "Personal"; + } + + private String guid; + @SerializedName("name") private String name; @SerializedName("full_name") private String fullName; + private String clientname; @SerializedName("org_type") private String orgType; - private String clientname; @SerializedName("private_key") private PrivateKey privateKey; - public Organization(String name) { - this(); - this.name = name; - } - - // hidden but needs to be here for json deserialization to work Organization() { - super(); + } - @Override - public int compareTo(Organization o) { - return name.compareTo(o.name); + public Organization(String name, String fullName, String clientname, String orgType) { + this(null, name, fullName, clientname, orgType, null); } - public String getName() { - return name; + public Organization(String name, String orgType) { + this(null, name, name, name + "-validator", orgType, null); } - public void setName(String name) { + public Organization(String guid, String name, String fullName, String clientname, String orgType, + PrivateKey privateKey) { + this.guid = guid; this.name = name; - } - - public String getFullName() { - return fullName; - } - - public void setFullName(String fullName) { this.fullName = fullName; - } - - public String getOrgType() { - return orgType; - } - - public void setOrgType(String orgType) { - this.orgType = orgType; - } - - public String getClientname() { - return clientname; - } - - public void setClientname(String clientname) { - this.clientname = clientname; - } - - public PrivateKey getPrivateKey() { - return privateKey; + this.clientname = checkNotNull(clientname, "clientname"); + this.orgType = checkNotNull(orgType, "orgType"); + this.privateKey = privateKey; } @Override @@ -94,8 +76,10 @@ public class Organization implements Comparable { int result = 1; result = prime * result + ((clientname == null) ? 0 : clientname.hashCode()); result = prime * result + ((fullName == null) ? 0 : fullName.hashCode()); + result = prime * result + ((guid == null) ? 0 : guid.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((orgType == null) ? 0 : orgType.hashCode()); + result = prime * result + ((privateKey == null) ? 0 : privateKey.hashCode()); return result; } @@ -118,6 +102,11 @@ public class Organization implements Comparable { return false; } else if (!fullName.equals(other.fullName)) return false; + if (guid == null) { + if (other.guid != null) + return false; + } else if (!guid.equals(other.guid)) + return false; if (name == null) { if (other.name != null) return false; @@ -128,13 +117,42 @@ public class Organization implements Comparable { return false; } else if (!orgType.equals(other.orgType)) return false; + if (privateKey == null) { + if (other.privateKey != null) + return false; + } else if (!privateKey.equals(other.privateKey)) + return false; return true; } + public String getGuid() { + return guid; + } + + public String getName() { + return name; + } + + public String getFullName() { + return fullName; + } + + public String getClientname() { + return clientname; + } + + public String getOrgType() { + return orgType; + } + + public PrivateKey getPrivateKey() { + return privateKey; + } + @Override public String toString() { - return "Organization [clientname=" + clientname + ", fullName=" + fullName + ", name=" + name + ", orgType=" - + orgType + "]"; + return "[name=" + name + ", clientname=" + clientname + ", fullName=" + fullName + ", guid=" + guid + + ", orgType=" + orgType + ", privateKey=" + (privateKey != null) + "]"; } } diff --git a/opscodeplatform/src/main/java/org/jclouds/opscodeplatform/domain/User.java b/opscodeplatform/src/main/java/org/jclouds/opscodeplatform/domain/User.java index ec35d0383a..28fc8135e5 100644 --- a/opscodeplatform/src/main/java/org/jclouds/opscodeplatform/domain/User.java +++ b/opscodeplatform/src/main/java/org/jclouds/opscodeplatform/domain/User.java @@ -19,6 +19,9 @@ package org.jclouds.opscodeplatform.domain; import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.cert.Certificate; +import java.security.cert.X509Certificate; import com.google.gson.annotations.SerializedName; @@ -27,7 +30,7 @@ import com.google.gson.annotations.SerializedName; * * @author Adrian Cole */ -public class User implements Comparable { +public class User { private String username; @SerializedName("first_name") private String firstName; @@ -38,94 +41,62 @@ public class User implements Comparable { @SerializedName("display_name") private String displayName; private String email; + @SerializedName("twitter_account") + private String twitterAccount; + private String city; + private String country; + @SerializedName("image_file_name") + private String imageFileName; private String password; + @SerializedName("public_key") + private PublicKey publicKey; @SerializedName("private_key") private PrivateKey privateKey; + private X509Certificate certificate; + private String salt; public User(String username) { this.username = username; } - // hidden but needs to be here for json deserialization to work - User() { - super(); - } - - @Override - public int compareTo(User o) { - return username.compareTo(o.username); - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { + public User(String username, String firstName, String middleName, String lastName, String displayName, String email, + String twitterAccount, String city, String country, String imageFileName, String password, + PublicKey publicKey, PrivateKey privateKey, X509Certificate certificate, String salt) { this.username = username; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { this.firstName = firstName; - } - - public String getMiddleName() { - return middleName; - } - - public void setMiddleName(String middleName) { this.middleName = middleName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { this.lastName = lastName; - } - - public String getDisplayName() { - return displayName; - } - - public void setDisplayName(String displayName) { this.displayName = displayName; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { this.email = email; - } - - public void setPassword(String password) { + this.twitterAccount = twitterAccount; + this.city = city; + this.country = country; + this.imageFileName = imageFileName; this.password = password; - } - - public String getPassword() { - return password; - } - - public PrivateKey getPrivateKey() { - return privateKey; + this.publicKey = publicKey; + this.privateKey = privateKey; + this.certificate = certificate; + this.salt = salt; } @Override public int hashCode() { final int prime = 31; int result = 1; + result = prime * result + ((certificate == null) ? 0 : certificate.hashCode()); + result = prime * result + ((city == null) ? 0 : city.hashCode()); + result = prime * result + ((country == null) ? 0 : country.hashCode()); result = prime * result + ((displayName == null) ? 0 : displayName.hashCode()); result = prime * result + ((email == null) ? 0 : email.hashCode()); result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); + result = prime * result + ((imageFileName == null) ? 0 : imageFileName.hashCode()); result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); result = prime * result + ((middleName == null) ? 0 : middleName.hashCode()); result = prime * result + ((password == null) ? 0 : password.hashCode()); + result = prime * result + ((privateKey == null) ? 0 : privateKey.hashCode()); + result = prime * result + ((publicKey == null) ? 0 : publicKey.hashCode()); + result = prime * result + ((salt == null) ? 0 : salt.hashCode()); + result = prime * result + ((twitterAccount == null) ? 0 : twitterAccount.hashCode()); result = prime * result + ((username == null) ? 0 : username.hashCode()); return result; } @@ -139,6 +110,21 @@ public class User implements Comparable { if (getClass() != obj.getClass()) return false; User other = (User) obj; + if (certificate == null) { + if (other.certificate != null) + return false; + } else if (!certificate.equals(other.certificate)) + return false; + if (city == null) { + if (other.city != null) + return false; + } else if (!city.equals(other.city)) + return false; + if (country == null) { + if (other.country != null) + return false; + } else if (!country.equals(other.country)) + return false; if (displayName == null) { if (other.displayName != null) return false; @@ -154,6 +140,11 @@ public class User implements Comparable { return false; } else if (!firstName.equals(other.firstName)) return false; + if (imageFileName == null) { + if (other.imageFileName != null) + return false; + } else if (!imageFileName.equals(other.imageFileName)) + return false; if (lastName == null) { if (other.lastName != null) return false; @@ -169,6 +160,26 @@ public class User implements Comparable { return false; } else if (!password.equals(other.password)) return false; + if (privateKey == null) { + if (other.privateKey != null) + return false; + } else if (!privateKey.equals(other.privateKey)) + return false; + if (publicKey == null) { + if (other.publicKey != null) + return false; + } else if (!publicKey.equals(other.publicKey)) + return false; + if (salt == null) { + if (other.salt != null) + return false; + } else if (!salt.equals(other.salt)) + return false; + if (twitterAccount == null) { + if (other.twitterAccount != null) + return false; + } else if (!twitterAccount.equals(other.twitterAccount)) + return false; if (username == null) { if (other.username != null) return false; @@ -177,10 +188,78 @@ public class User implements Comparable { return true; } + // only for deserialization + User() { + + } + + public String getUsername() { + return username; + } + + public String getFirstName() { + return firstName; + } + + public String getMiddleName() { + return middleName; + } + + public String getLastName() { + return lastName; + } + + public String getDisplayName() { + return displayName; + } + + public String getEmail() { + return email; + } + + public String getTwitterAccount() { + return twitterAccount; + } + + public String getCity() { + return city; + } + + public String getCountry() { + return country; + } + + public String getImageFileName() { + return imageFileName; + } + + public String getPassword() { + return password; + } + + public PublicKey getPublicKey() { + return publicKey; + } + @Override public String toString() { - return "User [displayName=" + displayName + ", email=" + email + ", firstName=" + firstName + ", lastName=" - + lastName + ", middleName=" + middleName + ", password=" + password + ", username=" + username + "]"; + return "[certificate=" + certificate + ", city=" + city + ", country=" + country + ", displayName=" + displayName + + ", email=" + email + ", firstName=" + firstName + ", imageFileName=" + imageFileName + ", lastName=" + + lastName + ", middleName=" + middleName + ", password=" + (password != null) + ", privateKey=" + + (privateKey != null) + ", publicKey=" + publicKey + ", salt=" + salt + ", twitterAccount=" + + twitterAccount + ", username=" + username + "]"; + } + + public PrivateKey getPrivateKey() { + return privateKey; + } + + public Certificate getCertificate() { + return certificate; + } + + public String getSalt() { + return salt; } } diff --git a/opscodeplatform/src/test/java/org/jclouds/opscodeplatform/OpscodePlatformAsyncClientTest.java b/opscodeplatform/src/test/java/org/jclouds/opscodeplatform/OpscodePlatformAsyncClientTest.java index 432f679df5..e753d6747e 100644 --- a/opscodeplatform/src/test/java/org/jclouds/opscodeplatform/OpscodePlatformAsyncClientTest.java +++ b/opscodeplatform/src/test/java/org/jclouds/opscodeplatform/OpscodePlatformAsyncClientTest.java @@ -104,7 +104,7 @@ public class OpscodePlatformAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method); assertRequestLineEquals(httpRequest, "GET https://api.opscode.com/users HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n"); assertPayloadEquals(httpRequest, null, null, false); assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class); @@ -119,7 +119,7 @@ public class OpscodePlatformAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, "user"); assertRequestLineEquals(httpRequest, "HEAD https://api.opscode.com/users/user HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n"); assertPayloadEquals(httpRequest, null, null, false); assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class); @@ -134,7 +134,7 @@ public class OpscodePlatformAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, "organization"); assertRequestLineEquals(httpRequest, "HEAD https://api.opscode.com/organizations/organization HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n"); assertPayloadEquals(httpRequest, null, null, false); assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class); @@ -145,13 +145,12 @@ public class OpscodePlatformAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method); assertRequestLineEquals(httpRequest, "GET https://api.opscode.com/organizations HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n"); assertPayloadEquals(httpRequest, null, null, false); assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class); @@ -168,7 +167,7 @@ public class OpscodePlatformAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, "myuser"); assertRequestLineEquals(httpRequest, "GET https://api.opscode.com/users/myuser HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n"); assertPayloadEquals(httpRequest, null, null, false); assertResponseParserClassEquals(method, httpRequest, ParseJson.class); @@ -234,7 +234,7 @@ public class OpscodePlatformAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, "myuser"); assertRequestLineEquals(httpRequest, "DELETE https://api.opscode.com/users/myuser HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n"); assertPayloadEquals(httpRequest, null, null, false); assertResponseParserClassEquals(method, httpRequest, ParseJson.class); @@ -248,11 +248,13 @@ public class OpscodePlatformAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, new Organization( - "myorganization")); + "myorganization", "myorganization", "myorganization-validator", Organization.Type.BUSINESS)); assertRequestLineEquals(httpRequest, "POST https://api.opscode.com/organizations HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, "{\"name\":\"myorganization\"}", "application/json", false); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n"); + assertPayloadEquals(httpRequest, + "{\"name\":\"myorganization\",\"full_name\":\"myorganization\",\"clientname\":\"myorganization-validator\",\"org_type\":\"Business\"}", + "application/json", false); assertResponseParserClassEquals(method, httpRequest, ParseJson.class); assertSaxResponseParserClassEquals(method, null); @@ -265,11 +267,13 @@ public class OpscodePlatformAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, new Organization( - "myorganization")); + "myorganization", "myorganization", "myorganization-validator", Organization.Type.BUSINESS)); assertRequestLineEquals(httpRequest, "PUT https://api.opscode.com/organizations/myorganization HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, "{\"name\":\"myorganization\"}", "application/json", false); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n"); + assertPayloadEquals(httpRequest, + "{\"name\":\"myorganization\",\"full_name\":\"myorganization\",\"clientname\":\"myorganization-validator\",\"org_type\":\"Business\"}", + "application/json", false); assertResponseParserClassEquals(method, httpRequest, ParseJson.class); assertSaxResponseParserClassEquals(method, null); @@ -284,7 +288,7 @@ public class OpscodePlatformAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, "myorganization"); assertRequestLineEquals(httpRequest, "GET https://api.opscode.com/organizations/myorganization HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n"); assertPayloadEquals(httpRequest, null, null, false); assertResponseParserClassEquals(method, httpRequest, ParseJson.class); @@ -300,7 +304,7 @@ public class OpscodePlatformAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, "myorganization"); assertRequestLineEquals(httpRequest, "DELETE https://api.opscode.com/organizations/myorganization HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n"); assertPayloadEquals(httpRequest, null, null, false); assertResponseParserClassEquals(method, httpRequest, ParseJson.class); diff --git a/opscodeplatform/src/test/java/org/jclouds/opscodeplatform/OpscodePlatformClientLiveTest.java b/opscodeplatform/src/test/java/org/jclouds/opscodeplatform/OpscodePlatformClientLiveTest.java index c682a2f523..d6bf496d50 100644 --- a/opscodeplatform/src/test/java/org/jclouds/opscodeplatform/OpscodePlatformClientLiveTest.java +++ b/opscodeplatform/src/test/java/org/jclouds/opscodeplatform/OpscodePlatformClientLiveTest.java @@ -26,6 +26,7 @@ package org.jclouds.opscodeplatform; import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; import java.io.File; import java.io.IOException; @@ -35,12 +36,13 @@ import java.util.Set; import org.jclouds.chef.BaseChefClientLiveTest; import org.jclouds.chef.ChefClient; import org.jclouds.chef.config.ChefParserModule; -import org.jclouds.http.HttpResponseException; +import org.jclouds.crypto.Pems; import org.jclouds.json.Json; import org.jclouds.json.config.GsonModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.opscodeplatform.domain.Organization; import org.jclouds.opscodeplatform.domain.User; +import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.HttpClient; import org.jclouds.rest.RestContextFactory; import org.testng.annotations.BeforeClass; @@ -124,8 +126,8 @@ public class OpscodePlatformClientLiveTest extends BaseChefClientLiveTest { protected void closeContexts() { if (orgUser != null) adminConnection.getApi().deleteUser(PREFIX); - if (org != null) - adminConnection.getApi().deleteOrganization(PREFIX); + if (createdOrgname != null) + adminConnection.getApi().deleteOrganization(createdOrgname); if (clientConnection != null) clientConnection.close(); if (validatorConnection != null) @@ -137,52 +139,60 @@ public class OpscodePlatformClientLiveTest extends BaseChefClientLiveTest { private String orgname; private Organization org; private User orgUser; + private String createdOrgname; - // http://tickets.corp.opscode.com/browse/PL-524 - @Test(expectedExceptions = HttpResponseException.class) + // @Test(expectedExceptions = AuthorizationException.class) public void testListOrganizations() throws Exception { Set orgs = adminConnection.getApi().listOrganizations(); assertNotNull(orgs); } - // http://tickets.corp.opscode.com/browse/PL-524 - @Test(expectedExceptions = HttpResponseException.class) + /** + * this test only works when you have a super user not yet supported in the + * official api + */ + @Test(enabled = false, expectedExceptions = AuthorizationException.class) public void testCreateOrganization() throws Exception { - adminConnection.getApi().deleteOrganization(PREFIX); - adminConnection.getApi().createOrganization(new Organization(PREFIX)); - org = adminConnection.getApi().getOrganization(PREFIX); + createdOrgname = orgname + 1; + adminConnection.getApi().deleteOrganization(createdOrgname); + org = adminConnection.getApi().createOrganization(new Organization(createdOrgname, Organization.Type.BUSINESS)); assertNotNull(org); - assertEquals(org.getName(), PREFIX); - assertEquals(org.getClientname(), PREFIX + "-validator"); + assertNull(org.getName()); + assertNull(org.getFullName()); + assertEquals(org.getClientname(), createdOrgname + "-validator"); + assertNull(org.getOrgType()); + assertNotNull(org.getPrivateKey()); + OpscodePlatformContext connection = null; + try { + connection = createConnection(org.getClientname(), Pems.pem(org.getPrivateKey())); + } finally { + if (connection != null) + connection.close(); + } } - // http://tickets.corp.opscode.com/browse/PL-524 - @Test(expectedExceptions = HttpResponseException.class) public void testOrganizationExists() throws Exception { assertNotNull(adminConnection.getApi().organizationExists(orgname)); } - @Test(enabled = false, dependsOnMethods = "testCreateOrganization") + @Test(enabled = false, dependsOnMethods = "testCreateOrganization", expectedExceptions = AuthorizationException.class) public void testUpdateOrganization() throws Exception { - Organization org = adminConnection.getApi().getOrganization(PREFIX); + Organization org = adminConnection.getApi().getOrganization(createdOrgname); adminConnection.getApi().updateOrganization(org); } - // http://tickets.corp.opscode.com/browse/PL-524 - @Test(expectedExceptions = HttpResponseException.class) public void testGetOrganization() throws Exception { adminConnection.getApi().getOrganization(orgname); } - // http://tickets.corp.opscode.com/browse/PL-524 - @Test(expectedExceptions = HttpResponseException.class) + @Test(expectedExceptions = AuthorizationException.class) public void testListUsers() throws Exception { Set orgs = adminConnection.getApi().listUsers(); assertNotNull(orgs); } - // http://tickets.corp.opscode.com/browse/PL-524 - @Test(expectedExceptions = HttpResponseException.class) + // @Test(expectedExceptions = HttpResponseException.class) + @Test(enabled = false, expectedExceptions = AuthorizationException.class) public void testCreateUser() throws Exception { adminConnection.getApi().deleteUser(PREFIX); adminConnection.getApi().createUser(new User(PREFIX)); @@ -192,30 +202,27 @@ public class OpscodePlatformClientLiveTest extends BaseChefClientLiveTest { assertNotNull(orgUser.getPrivateKey()); } - // http://tickets.corp.opscode.com/browse/PL-524 - @Test(expectedExceptions = HttpResponseException.class) public void testUserExists() throws Exception { assertNotNull(adminConnection.getApi().userExists(user)); } - // http://tickets.corp.opscode.com/browse/PL-524 - @Test(expectedExceptions = HttpResponseException.class) public void testGetUser() throws Exception { adminConnection.getApi().getUser(user); } - @Test(enabled = false, dependsOnMethods = "testCreateUser") + // disabled while create user fails + @Test(dependsOnMethods = "testCreateUser", enabled = false) public void testUpdateUser() throws Exception { User user = adminConnection.getApi().getUser(PREFIX); adminConnection.getApi().updateUser(user); } - @Test(expectedExceptions = HttpResponseException.class) + @Test(expectedExceptions = AuthorizationException.class) public void testGetOrganizationFailsForValidationKey() throws Exception { validatorConnection.getApi().getOrganization(orgname); } - @Test(dependsOnMethods = "testGenerateKeyForClient", expectedExceptions = HttpResponseException.class) + @Test(dependsOnMethods = "testGenerateKeyForClient", expectedExceptions = AuthorizationException.class) public void testGetOrganizationFailsForClient() throws Exception { clientConnection.getApi().getOrganization(orgname); } diff --git a/opscodeplatform/src/test/java/org/jclouds/opscodeplatform/functions/ParseOrganizationFromJsonTest.java b/opscodeplatform/src/test/java/org/jclouds/opscodeplatform/functions/ParseOrganizationFromJsonTest.java index dc600b0cef..5096ef9adb 100644 --- a/opscodeplatform/src/test/java/org/jclouds/opscodeplatform/functions/ParseOrganizationFromJsonTest.java +++ b/opscodeplatform/src/test/java/org/jclouds/opscodeplatform/functions/ParseOrganizationFromJsonTest.java @@ -55,13 +55,10 @@ public class ParseOrganizationFromJsonTest { public void test() { - Organization org = new Organization("opscode"); - org.setFullName("Opscode, Inc."); - org.setOrgType("Business"); - org.setClientname("opscode-validator"); - - String toParse = "{\"name\": \"opscode\",\"full_name\": \"Opscode, Inc.\", \"org_type\": \"Business\",\"clientname\": \"opscode-validator\" }"; + Organization org = new Organization("486ca3ac66264fea926aa0b4ff74341c", "jclouds", "jclouds", + "jclouds-validator", "Business", null); + String toParse = "{\"guid\":\"486ca3ac66264fea926aa0b4ff74341c\",\"name\":\"jclouds\",\"full_name\":\"jclouds\",\"clientname\":\"jclouds-validator\",\"org_type\":\"Business\",\"name\":\"jclouds\"}"; assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads.newStringPayload(toParse))), org); } } diff --git a/opscodeplatform/src/test/java/org/jclouds/opscodeplatform/functions/ParseUserFromJsonTest.java b/opscodeplatform/src/test/java/org/jclouds/opscodeplatform/functions/ParseUserFromJsonTest.java index 65eb09bee8..4d8eef3c51 100644 --- a/opscodeplatform/src/test/java/org/jclouds/opscodeplatform/functions/ParseUserFromJsonTest.java +++ b/opscodeplatform/src/test/java/org/jclouds/opscodeplatform/functions/ParseUserFromJsonTest.java @@ -3,14 +3,17 @@ package org.jclouds.opscodeplatform.functions; import static org.testng.Assert.assertEquals; import java.io.IOException; +import java.security.cert.CertificateException; +import java.security.spec.InvalidKeySpecException; import org.jclouds.chef.config.ChefParserModule; +import org.jclouds.crypto.Crypto; +import org.jclouds.crypto.Pems; import org.jclouds.http.HttpResponse; import org.jclouds.http.functions.ParseJson; import org.jclouds.io.Payloads; import org.jclouds.json.config.GsonModule; import org.jclouds.opscodeplatform.domain.User; -import org.jclouds.util.Utils; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -28,25 +31,40 @@ import com.google.inject.TypeLiteral; public class ParseUserFromJsonTest { private ParseJson handler; + private Crypto crypto; @BeforeTest protected void setUpInjector() throws IOException { Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule()); handler = injector.getInstance(Key.get(new TypeLiteral>() { })); + crypto = injector.getInstance(Crypto.class); } - public void test() { + public void test() throws InvalidKeySpecException, CertificateException, IOException { + User user = new User( + "dopey", + "Adrian", + "", + "Cole", + "Adrian Cole", + "adrian+dopey@opscode.com", + null, + null, + null, + null, + "abcdef", + crypto + .rsaKeyFactory() + .generatePublic( + Pems + .publicKeySpec("-----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEAvCKTqPdHv7GsHTjk02g91Aw3T6xQmdRaI70X6E6GGFxZtcH+tb1X\nqHxwhFydECVXhu0WVjTcWvxZ1aMFzn9BLHQYWzZxU/fIKVNR6ujyZ3jRxDXRFpX5\n/zvMdvNbdsJ+8foEbdoP1iujUMZuy6ZMvcbTDCgWjYVQ2omR9CkH/5Fwlbk3cSrF\n6qfGaM7340OGknKUfXdvhCq4vxydlOwfHJyNDWY0PW+8rDKHWxxNtYDDDeIMw2z/\nYC34f1bcAkR+/lyx5b25RwDomZNqXJqp1hjOVJVlo+UMvzWfXph5hgjcgtwzc5Iu\nmWWMUdxLcdw+/iQm6NW9cmU28bvHu0q7FwIDAQAB\n-----END RSA PUBLIC KEY-----\n")), + null, + Pems + .x509Certificate("-----BEGIN CERTIFICATE-----\nMIIClzCCAgCgAwIBAgIBATANBgkqhkiG9w0BAQUFADCBnjELMAkGA1UEBhMCVVMx\nEzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxFjAUBgNVBAoM\nDU9wc2NvZGUsIEluYy4xHDAaBgNVBAsME0NlcnRpZmljYXRlIFNlcnZpY2UxMjAw\nBgNVBAMMKW9wc2NvZGUuY29tL2VtYWlsQWRkcmVzcz1hdXRoQG9wc2NvZGUuY29t\nMB4XDTEwMDgwMzA0MDUzNVoXDTIwMDczMTA0MDUzNVowADCCASIwDQYJKoZIhvcN\nAQEBBQADggEPADCCAQoCggEBALwik6j3R7+xrB045NNoPdQMN0+sUJnUWiO9F+hO\nhhhcWbXB/rW9V6h8cIRcnRAlV4btFlY03Fr8WdWjBc5/QSx0GFs2cVP3yClTUero\n8md40cQ10RaV+f87zHbzW3bCfvH6BG3aD9Yro1DGbsumTL3G0wwoFo2FUNqJkfQp\nB/+RcJW5N3EqxeqnxmjO9+NDhpJylH13b4QquL8cnZTsHxycjQ1mND1vvKwyh1sc\nTbWAww3iDMNs/2At+H9W3AJEfv5cseW9uUcA6JmTalyaqdYYzlSVZaPlDL81n16Y\neYYI3ILcM3OSLplljFHcS3HcPv4kJujVvXJlNvG7x7tKuxcCAwEAATANBgkqhkiG\n9w0BAQUFAAOBgQBcoSP/2tFhP8yjF/dRDRdDed0/Cg0xnpp2wvM38gBRgvhpZbQ3\nI2rqpw5THNzrzBVnrYxd57uAa+y2MMG57XnvNWOmyL6WIYXLfN1QI3nHdpHS/QVF\nCRWpDWxLM1TkqAD9xQZOpUDdByF2exiCDNTzSYYg/ISLlIEzicNJeoPNbA==\n-----END CERTIFICATE-----\n"), + "xBOmipWikVEicS7tNOPdQzPsPmsROMgPme5O19ZHh6R7N9MQT7d5olDiGFpO"); - User user = new User("bobo"); - user.setFirstName("Bobo"); - user.setMiddleName("Tiberion"); - user.setLastName("Clown"); - user.setDisplayName("Bobo T. Clown"); - user.setEmail("bobo@clownco.com"); - - String toParse = "{\n\"username\": \"bobo\",\n\"first_name\": \"Bobo\",\n\"middle_name\": \"Tiberion\",\n\"last_name\": \"Clown\",\n\"display_name\": \"Bobo T. Clown\",\n\"email\": \"bobo@clownco.com\" \n}"; - - assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils.toInputStream(toParse)))), user); + assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(ParseUserFromJsonTest.class + .getResourceAsStream("/user.json")))), user); } } diff --git a/opscodeplatform/src/test/resources/user.json b/opscodeplatform/src/test/resources/user.json new file mode 100644 index 0000000000..25c2e3454c --- /dev/null +++ b/opscodeplatform/src/test/resources/user.json @@ -0,0 +1 @@ +{"public_key":"-----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEAvCKTqPdHv7GsHTjk02g91Aw3T6xQmdRaI70X6E6GGFxZtcH+tb1X\nqHxwhFydECVXhu0WVjTcWvxZ1aMFzn9BLHQYWzZxU/fIKVNR6ujyZ3jRxDXRFpX5\n/zvMdvNbdsJ+8foEbdoP1iujUMZuy6ZMvcbTDCgWjYVQ2omR9CkH/5Fwlbk3cSrF\n6qfGaM7340OGknKUfXdvhCq4vxydlOwfHJyNDWY0PW+8rDKHWxxNtYDDDeIMw2z/\nYC34f1bcAkR+/lyx5b25RwDomZNqXJqp1hjOVJVlo+UMvzWfXph5hgjcgtwzc5Iu\nmWWMUdxLcdw+/iQm6NW9cmU28bvHu0q7FwIDAQAB\n-----END RSA PUBLIC KEY-----\n","middle_name":"","certificate":"-----BEGIN CERTIFICATE-----\nMIIClzCCAgCgAwIBAgIBATANBgkqhkiG9w0BAQUFADCBnjELMAkGA1UEBhMCVVMx\nEzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxFjAUBgNVBAoM\nDU9wc2NvZGUsIEluYy4xHDAaBgNVBAsME0NlcnRpZmljYXRlIFNlcnZpY2UxMjAw\nBgNVBAMMKW9wc2NvZGUuY29tL2VtYWlsQWRkcmVzcz1hdXRoQG9wc2NvZGUuY29t\nMB4XDTEwMDgwMzA0MDUzNVoXDTIwMDczMTA0MDUzNVowADCCASIwDQYJKoZIhvcN\nAQEBBQADggEPADCCAQoCggEBALwik6j3R7+xrB045NNoPdQMN0+sUJnUWiO9F+hO\nhhhcWbXB/rW9V6h8cIRcnRAlV4btFlY03Fr8WdWjBc5/QSx0GFs2cVP3yClTUero\n8md40cQ10RaV+f87zHbzW3bCfvH6BG3aD9Yro1DGbsumTL3G0wwoFo2FUNqJkfQp\nB/+RcJW5N3EqxeqnxmjO9+NDhpJylH13b4QquL8cnZTsHxycjQ1mND1vvKwyh1sc\nTbWAww3iDMNs/2At+H9W3AJEfv5cseW9uUcA6JmTalyaqdYYzlSVZaPlDL81n16Y\neYYI3ILcM3OSLplljFHcS3HcPv4kJujVvXJlNvG7x7tKuxcCAwEAATANBgkqhkiG\n9w0BAQUFAAOBgQBcoSP/2tFhP8yjF/dRDRdDed0/Cg0xnpp2wvM38gBRgvhpZbQ3\nI2rqpw5THNzrzBVnrYxd57uAa+y2MMG57XnvNWOmyL6WIYXLfN1QI3nHdpHS/QVF\nCRWpDWxLM1TkqAD9xQZOpUDdByF2exiCDNTzSYYg/ISLlIEzicNJeoPNbA==\n-----END CERTIFICATE-----\n","city":null,"email":"adrian+dopey@opscode.com","country":null,"first_name":"Adrian","password":"abcdef","twitter_account":null,"salt":"xBOmipWikVEicS7tNOPdQzPsPmsROMgPme5O19ZHh6R7N9MQT7d5olDiGFpO","display_name":"Adrian Cole","last_name":"Cole","image_file_name":null,"username":"dopey"} \ No newline at end of file