Skip to content

Commit

Permalink
Add WADL tests for users.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Morgan committed Jun 24, 2009
1 parent 9e3b0a8 commit c693558
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/org/hyperic/hq/hqapi1/test/WADLUser_test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package org.hyperic.hq.hqapi1.test;

import org.hyperic.hq.hqapi1.wadl.*;

public class WADLUser_test extends WADL_test {

public void testUserList() throws Exception {

Endpoint.UserListHqu userList = new Endpoint.UserListHqu();

UsersResponse users = userList.getAsUsersResponse();
hqAssertSuccess(users);
}

public void testUserGet() throws Exception {

Endpoint.UserGetHqu userGet = new Endpoint.UserGetHqu();

UserResponse user = userGet.getAsUserResponse("guest");
hqAssertSuccess(user);
}

public void testUserCreateDeleteSyncChangePassword() throws Exception {

Endpoint.UserCreateHqu userCreate = new Endpoint.UserCreateHqu();
Endpoint.UserDeleteHqu userDelete = new Endpoint.UserDeleteHqu();
Endpoint.UserChangePasswordHqu userChangePassword =
new Endpoint.UserChangePasswordHqu();
Endpoint.UserSyncHqu userSync = new Endpoint.UserSyncHqu();

// Test User Sync - Required Atts
UserResponse responseReq = userCreate.getAsUserResponse("testWadl",
"testWadl",
"Test",
"WADL",
"testwadl@springsource.com");
hqAssertSuccess(responseReq);

// Test User Change password
StatusResponse changeResponse =
userChangePassword.getAsStatusResponse(responseReq.getUser().getName(),
"newPassword");
hqAssertSuccess(changeResponse);

// Test User Delete
StatusResponse deleteReq = userDelete.getAsStatusResponse(responseReq.getUser().getName());
hqAssertSuccess(deleteReq);

// Test User Create Required + Optional attributes
UserResponse responseOpt = userCreate.getAsUserResponse("testWadl",
"testWadl",
"Test",
"WADL",
"testwadl@springsource.com",
true,
true,
"WADL Dept",
"415-555-5555",
"testwadl@springsource.com");
hqAssertSuccess(responseOpt);

// Test User Sync
User u = responseOpt.getUser();
u.setFirstName("New First Name");
UsersRequest r = new UsersRequest();
r.getUser().add(u);
StatusResponse syncResponse = userSync.postAsStatusResponse(r);
hqAssertSuccess(syncResponse);

StatusResponse deleteOpt = userDelete.getAsStatusResponse(responseOpt.getUser().getName());
hqAssertSuccess(deleteOpt);
}
}
30 changes: 30 additions & 0 deletions src/org/hyperic/hq/hqapi1/test/WADL_test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.hyperic.hq.hqapi1.test;

import junit.framework.TestCase;

import org.hyperic.hq.hqapi1.wadl.*;

import java.net.Authenticator;
import java.net.PasswordAuthentication;

public class WADL_test extends TestCase {

public void setUp() throws Exception {
final String username ="hqadmin";
final String password ="hqadmin";

Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication (username, password.toCharArray());
}
});
}

// Assert SUCCESS

void hqAssertSuccess(Response response) {
String error = (response.getError() != null) ?
response.getError().getReasonText() : "";
assertEquals(error, ResponseStatus.SUCCESS, response.getStatus());
}
}

0 comments on commit c693558

Please sign in to comment.