Skip to content

Commit

Permalink
Merge branch 'HHQ-3076' into hqapi-1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Morgan committed Sep 25, 2009
2 parents 1a5c59e + 6622a54 commit 1127b3f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
19 changes: 18 additions & 1 deletion hqu/hqapi1/app/ApplicationController.groovy
Expand Up @@ -9,6 +9,7 @@ import org.hyperic.hq.appdef.shared.ApplicationValue
import org.hyperic.hq.appdef.shared.ServiceValue
import org.hyperic.dao.DAOFactory
import org.hyperic.hq.appdef.server.session.AppServiceDAO
import org.hyperic.hq.appdef.shared.AppdefDuplicateNameException;

class ApplicationController extends ApiController {

Expand Down Expand Up @@ -105,7 +106,14 @@ class ApplicationController extends ApiController {
applicationValue.applicationType = appMan.findApplicationType(1)
newApp = appMan.createApplication( user, applicationValue, new ArrayList())
// Initialize appServices to avoid NPE
newApp.appServices = new ArrayList()
newApp.appServices = new ArrayList()
} catch (AppdefDuplicateNameException e) {
renderXml() {
ApplicationResponse() {
out << getFailureXML(ErrorCode.OBJECT_EXISTS)
}
}
return
} catch (Exception e) {
renderXml() {
log.error("Error creating application", e)
Expand Down Expand Up @@ -197,6 +205,15 @@ class ApplicationController extends ApiController {

try {
appMan.updateApplication(user, applicationValue)
} catch (AppdefDuplicateNameException e) {
renderXml() {
ApplicationResponse() {
out << getFailureXML(ErrorCode.INVALID_PARAMETERS,
"There is already an application named " +
appName)
}
}
return
} catch (Exception e) {
renderXml() {
log.error("Error updating application", e)
Expand Down
19 changes: 19 additions & 0 deletions src/org/hyperic/hq/hqapi1/test/ApplicationCreate_test.java
Expand Up @@ -75,4 +75,23 @@ public void testApplicationCreateWithPlatforms() throws Exception {
ApplicationResponse response = appApi.createApplication(a);
hqAssertFailureInvalidParameters(response); // Invalid - cannot have servers
}

public void testApplicationCreateDuplicateName() throws Exception {

HQApi api = getApi();
ApplicationApi appApi = api.getApplicationApi();

Application a = generateTestApplication();

ApplicationResponse createResponse = appApi.createApplication(a);
hqAssertSuccess(createResponse);

// Attempt to create it again
ApplicationResponse dupResponse = appApi.createApplication(a);
hqAssertFailureObjectExists(dupResponse);

StatusResponse deleteResponse =
appApi.deleteApplication(createResponse.getApplication().getId());
hqAssertSuccess(deleteResponse);
}
}
19 changes: 19 additions & 0 deletions src/org/hyperic/hq/hqapi1/test/ApplicationUpdate_test.java
Expand Up @@ -165,4 +165,23 @@ public void testUpdateNonPersistedApplication() throws Exception {
ApplicationResponse response = appApi.updateApplication(a);
hqAssertFailureInvalidParameters(response);
}

public void testUpdateExistingApplicationName() throws Exception {
ApplicationApi appApi = getApi().getApplicationApi();

Application app1 = createTestApplication(null);
Application app2 = createTestApplication(null);

// Try to rename app2 to app1
app2.setName(app1.getName());

ApplicationResponse response = appApi.updateApplication(app2);
hqAssertFailureInvalidParameters(response);

StatusResponse deleteResponse = appApi.deleteApplication(app1.getId());
hqAssertSuccess(deleteResponse);

deleteResponse = appApi.deleteApplication(app2.getId());
hqAssertSuccess(deleteResponse);
}
}

0 comments on commit 1127b3f

Please sign in to comment.