modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/AlertHandlerBean.java | 4 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/IntegerValue.java | 55 +++++++++ modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/StringValue.java | 6 - modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/AlertTest.java | 25 ++++ modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/OperationsTest.java | 24 ++++ modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ReportsTest.java | 56 ++++++++++ 6 files changed, 164 insertions(+), 6 deletions(-)
New commits: commit 564ac02d1aa2c0f5c9dab04c873f3150b789d703 Author: Heiko W. Rupp hwr@redhat.com Date: Mon Feb 4 09:49:19 2013 +0100
BZ 905210 retrieval of alertCount failed for requested xml content type
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/AlertHandlerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/AlertHandlerBean.java index e77e8b5..b497954 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/AlertHandlerBean.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/AlertHandlerBean.java @@ -135,7 +135,7 @@ public class AlertHandlerBean extends AbstractRestBean { @GET @Path("count") @ApiOperation("Return a count of alerts in the system depending on criteria") - public int countAlerts(@ApiParam(value = "If non-null only send alerts that have fired after this time, time is millisecond since epoch") + public IntegerValue countAlerts(@ApiParam(value = "If non-null only send alerts that have fired after this time, time is millisecond since epoch") @QueryParam("since") Long since) {
AlertCriteria criteria = new AlertCriteria(); @@ -151,7 +151,7 @@ public class AlertHandlerBean extends AbstractRestBean { PageList<Alert> alerts = alertManager.findAlertsByCriteria(caller,criteria); int count = alerts.getTotalSize();
- return count; + return new IntegerValue(count); }
@GET diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/IntegerValue.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/IntegerValue.java new file mode 100644 index 0000000..11d8c13 --- /dev/null +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/IntegerValue.java @@ -0,0 +1,55 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2013 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +package org.rhq.enterprise.server.rest.domain; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; + +import com.wordnik.swagger.annotations.ApiClass; +import com.wordnik.swagger.annotations.ApiProperty; + +/** + * Encapsulate a simple integer value + * @author Heiko W. Rupp + */ +@ApiClass("Encapsulates a simple integer value. In XML this is represented as <value value="..."/>") +@XmlRootElement(name = "value") +public class IntegerValue { + + Integer value; + + @SuppressWarnings("unused") + public IntegerValue() { + } + + public IntegerValue(Integer value) { + this.value = value; + } + + @XmlAttribute + @ApiProperty("The actual value") + public Integer getValue() { + return value; + } + + public void setValue(Integer value) { + this.value = value; + } +} diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/StringValue.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/StringValue.java index dde8648..67a7932 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/StringValue.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/StringValue.java @@ -1,5 +1,6 @@ package org.rhq.enterprise.server.rest.domain;
+import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlRootElement;
import com.wordnik.swagger.annotations.ApiClass; @@ -9,8 +10,8 @@ import com.wordnik.swagger.annotations.ApiProperty; * Encapsulate a simple string value * @author Heiko W. Rupp */ -@ApiClass("Encapsulates a simple string value") -@XmlRootElement +@ApiClass("Encapsulates a simple string value. In XML this is represented as <value value="..."/>") +@XmlRootElement(name = "value") public class StringValue {
String value; @@ -22,6 +23,7 @@ public class StringValue { this.value = value; }
+ @XmlAttribute @ApiProperty("The actual value") public String getValue() { return value; diff --git a/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/AlertTest.java b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/AlertTest.java index aa25197..3ccb73e 100644 --- a/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/AlertTest.java +++ b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/AlertTest.java @@ -20,6 +20,7 @@ package org.rhq.modules.integrationTests.restApi;
import com.jayway.restassured.http.ContentType; +import com.jayway.restassured.path.xml.XmlPath;
import org.junit.Test;
@@ -31,6 +32,7 @@ import org.rhq.modules.integrationTests.restApi.d.Group; import static com.jayway.restassured.RestAssured.delete; import static com.jayway.restassured.RestAssured.expect; import static com.jayway.restassured.RestAssured.given; +import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.iterableWithSize;
@@ -51,13 +53,32 @@ public class AlertTest extends AbstractBase { }
@Test - public void testGetAlertCount() throws Exception { + public void testGetAlertCountJson() throws Exception {
- expect() + given() + .header(acceptJson) + .expect() .statusCode(200) + .log().ifError() + .body("value", instanceOf(Number.class)) .when() .get("/alert/count"); + } + + @Test + public void testGetAlertCountXml() throws Exception { + + XmlPath xmlPath = + given() + .header(acceptXml) + .expect() + .statusCode(200) + .log().everything() + .when() + .get("/alert/count") + .xmlPath();
+ int count = xmlPath.getInt("value.@value"); }
@Test diff --git a/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/OperationsTest.java b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/OperationsTest.java index 72d40c9..9472059 100644 --- a/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/OperationsTest.java +++ b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/OperationsTest.java @@ -232,6 +232,30 @@ public class OperationsTest extends AbstractBase {
} finally {
+ // Wait until the operation has finished and then delete + boolean done = false; + int count = 0; + while (!done) { + String status = + given() + .pathParam("hid",historyId) + .expect() + .statusCode(200) + .log().everything() + .when() + .get("/operation/history/{hid}") + .jsonPath().getString("status"); + + if (status.equals("Success") || status.equals("Failed")) { + done = true; + } else { + Thread.sleep(2000); + } + assert count < 10 :"Waited for 20sec -- something is wrong"; + } + + + // Delete the history item given() .pathParam("hid",historyId) diff --git a/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ReportsTest.java b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ReportsTest.java new file mode 100644 index 0000000..f0eb501 --- /dev/null +++ b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ReportsTest.java @@ -0,0 +1,56 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2013 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +package org.rhq.modules.integrationTests.restApi; + +import com.jayway.restassured.RestAssured; + +import org.junit.Before; +import org.junit.Test; + +import static com.jayway.restassured.RestAssured.given; + +/** + * Tests for the reports that also run via the Rest-api (but different base url) + * @author Heiko W. Rupp + */ +public class ReportsTest extends AbstractBase { + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + + RestAssured.basePath = "/coregui/reports"; + } + +// @Test + public void testGetAlertDefinitions() throws Exception { + + given() + .header(acceptCsv) + .expect() + .statusCode(200) + .log().ifError() + .when() + .get("/alertDefinitions"); + + + } +}
rhq-commits@lists.fedorahosted.org