Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
Got generics working, but before is still broken. Starting refactor o…
Browse files Browse the repository at this point in the history
…f rest test framework.
  • Loading branch information
GERey committed Mar 18, 2015
1 parent eb0c689 commit ee21606
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 108 deletions.
Expand Up @@ -584,7 +584,7 @@ public void clientCredentialsFlowWithHeaderAuthorization() throws Exception {
String clientId = orgCredentials.getClientId();
String clientSecret = orgCredentials.getClientSecret();

Token token = clientSetup.getRestClient().management().token().post(new Token("client_credentials", clientId, clientSecret));
Token token = clientSetup.getRestClient().management().token().post(Token.class,new Token("client_credentials", clientId, clientSecret));

//GET the token endpoint, adding authorization header
Token apiResponse = this.app().token().getResource(false)
Expand Down
Expand Up @@ -881,7 +881,7 @@ public void revokeToken() throws Exception {
assertNotNull(entity1);

assertNotNull(entity2);
Token adminToken = this.clientSetup.getRestClient().management().token().post(new Token(clientSetup.getUsername(), clientSetup.getUsername()));
Token adminToken = this.clientSetup.getRestClient().management().token().post(Token.class,new Token(clientSetup.getUsername(), clientSetup.getUsername()));
// now revoke the tokens
this.app().token().setToken(adminToken);

Expand Down Expand Up @@ -929,7 +929,7 @@ public void revokeToken() throws Exception {
assertNotNull(entity2);

// now revoke the token3
adminToken = this.clientSetup.getRestClient().management().token().post(new Token(clientSetup.getUsername(), clientSetup.getUsername()));
adminToken = this.clientSetup.getRestClient().management().token().post(Token.class,new Token(clientSetup.getUsername(), clientSetup.getUsername()));
// now revoke the tokens
this.app().token().setToken(adminToken);
usersResource.entity("edanuff").connection("revoketokens").post();
Expand Down
Expand Up @@ -93,16 +93,16 @@ public void setSelfAdminPasswordAsAdmin() throws IOException {
passwordPayload.put( "oldpassword", password );

// change the password as admin. The old password isn't required
management.users().user( username ).password().post(passwordPayload);
management.users().user( username ).password().post(Entity.class,passwordPayload);

this.refreshIndex();

//Get the token using the new password
management.token().post( new Token( username, "testPassword" ) );
management.token().post( Token.class, new Token( username, "testPassword" ) );

//Check that we cannot get the token using the old password
try {
management.token().post( new Token( username, password ) );
management.token().post( Token.class, new Token( username, password ));
fail( "We shouldn't be able to get a token using the old password" );
}catch(UniformInterfaceException uie) {
errorParse( 400,"invalid_grant",uie );
Expand All @@ -125,18 +125,19 @@ public void passwordMismatchErrorAdmin() {
passwordPayload.put( "oldpassword", password );

// change the password as admin. The old password isn't required
management.users().user( username ).password().post( passwordPayload );
management.users().user( username ).password().post(Entity.class, passwordPayload );

this.refreshIndex();


//Get the token using the new password
management.token().post( new Token( username, "testPassword" ) );
management.token().post( Token.class, new Token( username, "testPassword" ) );



// Check that we can't change the password using the old password.
try {
management.users().user( username ).password().post( passwordPayload );
management.users().user( username ).password().post( Entity.class ,passwordPayload );
fail("We shouldn't be able to change the password with the same payload");
}
catch ( UniformInterfaceException uie ) {
Expand Down Expand Up @@ -164,11 +165,12 @@ public void setAdminPasswordAsSysAdmin() throws IOException {

this.refreshIndex();

assertNotNull( management.token().post( new Token( username, "testPassword" ) ) );
assertNotNull(management.token().post( Token.class, new Token( username, "testPassword" ) ));


//Check that we cannot get the token using the old password
try {
management.token().post( new Token( username, password ) );
management.token().post( Token.class, new Token( username, password) );
fail( "We shouldn't be able to get a token using the old password" );
}catch(UniformInterfaceException uie) {
errorParse( 400,"invalid_grant",uie );
Expand Down Expand Up @@ -306,8 +308,9 @@ public void testSystemAdminNeedsNoConfirmation() throws Exception{
clientSetup.getRestClient().testPropertiesResource().post( testPropertiesPayload );
refreshIndex();

Token superuserToken = management().token().post(
new Token( clientSetup.getSuperuserName(), clientSetup.getSuperuserPassword() ) );
Token superuserToken = management.token().post( Token.class,
new Token( clientSetup.getSuperuserName(), clientSetup.getSuperuserPassword() ) );




Expand Down Expand Up @@ -343,7 +346,7 @@ public void testTestUserNeedsNoConfirmation() throws Exception{
clientSetup.getRestClient().testPropertiesResource().post( testPropertiesPayload );
refreshIndex();

Token testToken = management().token().post(
Token testToken = management().token().post(Token.class,
new Token( originalTestProperties.getAsString( PROPERTIES_TEST_ACCOUNT_ADMIN_USER_EMAIL ),
originalTestProperties.getAsString( PROPERTIES_TEST_ACCOUNT_ADMIN_USER_PASSWORD ) ));

Expand Down Expand Up @@ -414,7 +417,7 @@ public void reactivateTest() throws Exception {
public void checkFormPasswordReset() throws Exception {


management().users().user( clientSetup.getUsername() ).resetpw().post(null);
management().users().user( clientSetup.getUsername() ).resetpw().post(new Form());

//Create mocked inbox
List<Message> inbox = Mailbox.get( clientSetup.getEmail() );
Expand Down Expand Up @@ -501,7 +504,7 @@ public void checkPasswordHistoryConflict() throws Exception {

//Makes sure we can't replace a password with itself ( as it is the only one in the history )
try {
management().users().user( clientSetup.getUsername() ).password().post( payload );
management().users().user( clientSetup.getUsername() ).password().post(Entity.class ,payload );

fail( "should fail with conflict" );
}
Expand All @@ -511,7 +514,7 @@ public void checkPasswordHistoryConflict() throws Exception {

//Change the password
payload.put( "newpassword", passwords[1] );
management().users().user( clientSetup.getUsername() ).password().post( payload );
management().users().user( clientSetup.getUsername() ).password().post( Entity.class,payload );

refreshIndex();

Expand All @@ -520,7 +523,7 @@ public void checkPasswordHistoryConflict() throws Exception {

//Make sure that we can't change the password with itself using a different entry in the history.
try {
management().users().user( clientSetup.getUsername() ).password().post( payload );
management().users().user( clientSetup.getUsername() ).password().post( Entity.class,payload );

fail( "should fail with conflict" );
}
Expand Down Expand Up @@ -603,12 +606,12 @@ public void listOrgUsersByName() {
adminUserPayload.put( "password", username );

//post new admin user besides the default
management().orgs().organization( clientSetup.getOrganizationName() ).users().post( adminUserPayload );
management().orgs().organization( clientSetup.getOrganizationName() ).users().post(ApiResponse.class ,adminUserPayload );

refreshIndex();

//Retrieves the admin users
Entity adminUsers = management().orgs().organization( clientSetup.getOrganizationName() ).users().get();
Entity adminUsers = management().orgs().organization( clientSetup.getOrganizationName() ).users().get(Entity.class);

assertEquals("There need to be 2 admin users",2,( ( ArrayList ) adminUsers.getResponse().getData() ).size());

Expand All @@ -623,7 +626,8 @@ public void listOrgUsersByName() {
@Test
public void createOrgFromUserConnectionFail() throws Exception {

Token token = management().token().post( new Token( clientSetup.getUsername(),clientSetup.getPassword() ) );
Token token = management().token().post(Token.class ,new Token( clientSetup.getUsername(),clientSetup.getPassword() ) );

// try to create the same org again off the connection
try {
management().users().user( clientSetup.getUsername() ).organizations().post( clientSetup.getOrganization(),token );
Expand Down
Expand Up @@ -139,7 +139,7 @@ public void importGetCollectionJobStatTest() throws Exception {
.app()
.addToPath(app)
.addToPath("imports")
.post(payload);
.post(Entity.class,payload);

assertNotNull(entity);

Expand Down Expand Up @@ -177,7 +177,7 @@ public void importTokenAuthorizationTest() throws Exception {
.app()
.addToPath(app)
.addToPath("imports")
.post(payload);
.post(Entity.class,payload);


assertNotNull(entity);
Expand All @@ -200,7 +200,7 @@ public void importTokenAuthorizationTest() throws Exception {

//log into the new org/app and get a token
Token tokenPayload = new Token("password", newOrgUsername, newOrgPassword);
Token newOrgToken = clientSetup.getRestClient().management().token().post(tokenPayload);
Token newOrgToken = clientSetup.getRestClient().management().token().post(Token.class,tokenPayload);

//save the old token and set the newly issued token as current
context().setToken(newOrgToken);
Expand All @@ -227,7 +227,7 @@ public void importPostApplicationNullPointerProperties() throws Exception {
Entity payload = new Entity();

try {
this.management().orgs().organization(org).app().addToPath(app).addToPath("imports").post(payload);
this.management().orgs().organization(org).app().addToPath(app).addToPath("imports").post(Entity.class,payload);
} catch (UniformInterfaceException uie) {
responseStatus = uie.getResponse().getClientResponseStatus();
}
Expand All @@ -246,7 +246,7 @@ public void importPostApplicationNullPointerStorageInfo() throws Exception {
properties.remove("storage_info");

try {
this.management().orgs().organization(org).app().addToPath(app).addToPath("imports").post(payload);
this.management().orgs().organization(org).app().addToPath(app).addToPath("imports").post(Entity.class,payload);
} catch (UniformInterfaceException uie) {
responseStatus = uie.getResponse().getClientResponseStatus();
}
Expand All @@ -267,7 +267,7 @@ public void importPostApplicationNullPointerStorageProvider() throws Exception {


try {
this.management().orgs().organization(org).app().addToPath(app).addToPath("imports").post(payload);
this.management().orgs().organization(org).app().addToPath(app).addToPath("imports").post(Entity.class,payload);
} catch (UniformInterfaceException uie) {
responseStatus = uie.getResponse().getClientResponseStatus();
}
Expand All @@ -289,7 +289,7 @@ public void importPostApplicationNullPointerStorageVerification() throws Excepti
storage_info.remove("s3_key");

try {
this.management().orgs().organization(org).app().addToPath(app).addToPath("imports").post(payload);
this.management().orgs().organization(org).app().addToPath(app).addToPath("imports").post(Entity.class,payload);
} catch (UniformInterfaceException uie) {
responseStatus = uie.getResponse().getClientResponseStatus();
}
Expand All @@ -302,7 +302,7 @@ public void importPostApplicationNullPointerStorageVerification() throws Excepti
storage_info.remove("s3_access_id");

try {
this.management().orgs().organization(org).app().addToPath(app).addToPath("imports").post(payload);
this.management().orgs().organization(org).app().addToPath(app).addToPath("imports").post(Entity.class,payload);
} catch (UniformInterfaceException uie) {
responseStatus = uie.getResponse().getClientResponseStatus();
}
Expand All @@ -315,7 +315,7 @@ public void importPostApplicationNullPointerStorageVerification() throws Excepti
storage_info.remove("bucket_location");

try {
this.management().orgs().organization(org).app().addToPath(app).addToPath("imports").post(payload);
this.management().orgs().organization(org).app().addToPath(app).addToPath("imports").post(Entity.class,payload);
} catch (UniformInterfaceException uie) {
responseStatus = uie.getResponse().getClientResponseStatus();
}
Expand Down Expand Up @@ -626,7 +626,7 @@ private Entity importCollection() throws Exception {
}});

Entity importEntity = this.management().orgs().organization(org).app().addToPath(app).addToPath("imports")
.post(importPayload);
.post(Entity.class,importPayload);

int maxRetries = 120;
int retries = 0;
Expand Down
Expand Up @@ -73,7 +73,7 @@ public void createOrgAndOwner() throws Exception {

//Creates token
Token token =
clientSetup.getRestClient().management().token().post( new Token( "password",
clientSetup.getRestClient().management().token().post(Token.class, new Token( "password",
organization.getUsername(), organization.getPassword() ) );

assertNotNull( token );
Expand Down Expand Up @@ -109,7 +109,7 @@ public void testCreateDuplicateOrgName() throws Exception {

//Ensure that the token from the newly created organization works.
Token tokenPayload = new Token( "password", organization.getUsername(), organization.getPassword() );
Token tokenReturned = clientSetup.getRestClient().management().token().post( tokenPayload );
Token tokenReturned = clientSetup.getRestClient().management().token().post(Token.class, tokenPayload );

assertNotNull( tokenReturned );

Expand All @@ -131,7 +131,7 @@ public void testCreateDuplicateOrgName() throws Exception {
tokenPayload = new Token( "password", organization.getName() + "test", organization.getPassword() );
Token tokenError = null;
try {
tokenError = clientSetup.getRestClient().management().token().post( tokenPayload );
tokenError = clientSetup.getRestClient().management().token().post(Token.class, tokenPayload );
fail( "Should not have created user" );
}
catch ( UniformInterfaceException ex ) {
Expand Down Expand Up @@ -163,7 +163,7 @@ public void testCreateDuplicateOrgEmail() throws Exception {

//get token from organization that was created to verify it exists.
Token tokenPayload = new Token( "password", organization.getUsername(), organization.getPassword() );
Token tokenReturned = clientSetup.getRestClient().management().token().post( tokenPayload );
Token tokenReturned = clientSetup.getRestClient().management().token().post(Token.class, tokenPayload );

assertNotNull( tokenReturned );

Expand All @@ -186,7 +186,7 @@ public void testCreateDuplicateOrgEmail() throws Exception {
tokenPayload = new Token( "password", organization.getUsername()+"test", organization.getPassword()+"test" );
Token tokenError = null;
try {
tokenError = clientSetup.getRestClient().management().token().post( tokenPayload );
tokenError = clientSetup.getRestClient().management().token().post(Token.class, tokenPayload );
fail( "Should not have created organization" );
}
catch ( UniformInterfaceException ex ) {
Expand Down Expand Up @@ -225,7 +225,7 @@ public void testOrgPOSTParams() throws IOException {

//get token from organization that was created to verify it exists. also sets the current context.
Token tokenPayload = new Token( "password", organization.getName(), organization.getPassword() );
Token tokenReturned = clientSetup.getRestClient().management().token().post( tokenPayload );
Token tokenReturned = clientSetup.getRestClient().management().token().post(Token.class, tokenPayload );

assertNotNull( tokenReturned );

Expand Down Expand Up @@ -263,7 +263,7 @@ public void testOrgPOSTForm() throws IOException {

//get token from organization that was created to verify it exists. also sets the current context.
Token tokenPayload = new Token( "password", organization.getName(), organization.getPassword() );
Token tokenReturned = clientSetup.getRestClient().management().token().post( tokenPayload );
Token tokenReturned = clientSetup.getRestClient().management().token().post(Token.class, tokenPayload );

assertNotNull( tokenReturned );

Expand Down Expand Up @@ -310,7 +310,7 @@ public void testCreateOrgUserAndReturnCorrectUsername() throws Exception {
adminUserPayload.put( "password", username );

//create adminUser
Entity adminUserResponse = restClient.management().orgs().organization( clientSetup.getOrganizationName() ).users().post( adminUserPayload );
Entity adminUserResponse = restClient.management().orgs().organization( clientSetup.getOrganizationName() ).users().post(Entity.class, adminUserPayload );

//verify that the response contains the correct data
assertNotNull( adminUserResponse );
Expand Down
Expand Up @@ -116,7 +116,8 @@ private void doTest(String symbol) throws UniformInterfaceException {
assertNotNull(organization);

//Retrieve an authorization token using the credentials created above
Token tokenReturned = clientSetup.getRestClient().management().token().post(new Token("password", username, password));
Token tokenReturned = clientSetup.getRestClient().management().token()
.post(Token.class,new Token("password", username, password));
assertNotNull(tokenReturned);

//Instruct the test framework to use the new token
Expand Down
Expand Up @@ -166,13 +166,13 @@ public void errorParse(int expectedStatus, String expectedErrorMessage, UniformI


protected Token getAdminToken(String username, String password){
return this.clientSetup.getRestClient().management().token().post(
return this.clientSetup.getRestClient().management().token().post(Token.class,
new Token(username, password)
);
}

protected Token getAdminToken(){
return this.clientSetup.getRestClient().management().token().post(
return this.clientSetup.getRestClient().management().token().post(Token.class,
new Token(this.clientSetup.getUsername(),this.clientSetup.getUsername())
);
}
Expand Down

0 comments on commit ee21606

Please sign in to comment.