From: <rm...@hy...> - 2008-11-17 15:56:56
|
Author: rmorgan Date: 2008-11-17 07:56:49 -0800 (Mon, 17 Nov 2008) New Revision: 286 URL: http://svn.hyperic.org/?view=rev&root=HQApi&revision=286 Modified: trunk/hqu/hqapi1/app/GroupController.groovy trunk/src/org/hyperic/hq/hqapi1/GroupApi.java trunk/src/org/hyperic/hq/hqapi1/test/Group_test.java trunk/xsd/Group.xsd Log: Start GroupApi. Modified: trunk/hqu/hqapi1/app/GroupController.groovy =================================================================== --- trunk/hqu/hqapi1/app/GroupController.groovy 2008-11-17 15:56:31 UTC (rev 285) +++ trunk/hqu/hqapi1/app/GroupController.groovy 2008-11-17 15:56:49 UTC (rev 286) @@ -2,6 +2,17 @@ class GroupController extends ApiController { + private Closure getGroupXML(g) { + { doc -> + Group(id : g.id, + name : g.name, + description : g.description, + location : g.location) { + // TODO: Roles, Criteria, Prototype + } + } + } + def create(params) { renderXml() { CreateGroupResponse() { @@ -27,17 +38,46 @@ } def list(params) { - renderXml() { - GetGroupsResponse() { - out << getFailureXML(ErrorCode.NOT_IMPLEMENTED) + def groups = resourceHelper.findViewableGroups() + + renderXml() { + out << GetGroupsResponse() { + out << getSuccessXML() + for (g in groups.sort {a, b -> a.name <=> b.name}) { + out << getGroupXML(g) + } } } } def listResources(params) { + def id = params.getOne("groupId")?.toInteger() + + if (!id) { + renderXml() { + FindResourcesResponse() { + out << getFailureXML(ErrorCode.INVALID_PARAMETERS) + } + } + return + } + + def group = resourceHelper.findGroup(id) + if (!group) { + renderXml() { + FindResourcesResponse() { + out << getFailureXML(ErrorCode.OBJECT_NOT_FOUND); + } + } + } + + def resources = group.resources renderXml() { FindResourcesResponse() { - out << getFailureXML(ErrorCode.NOT_IMPLEMENTED) + out << getSuccessXML() + for (r in resources.sort {a, b -> a.name <=> b.name}) { + out << getResourceXML(r) + } } } } Modified: trunk/src/org/hyperic/hq/hqapi1/GroupApi.java =================================================================== --- trunk/src/org/hyperic/hq/hqapi1/GroupApi.java 2008-11-17 15:56:31 UTC (rev 285) +++ trunk/src/org/hyperic/hq/hqapi1/GroupApi.java 2008-11-17 15:56:49 UTC (rev 286) @@ -59,7 +59,7 @@ * * @throws IOException If a network error occurs while making the request. */ - public DeleteGroupResponse deleteGroup(Integer id) + public DeleteGroupResponse deleteGroup(int id) throws IOException { Map<String,String> params = new HashMap<String,String>(); @@ -91,8 +91,7 @@ } /** - * List all the Groups in HQ visible by the login.<br><b>This API is - * not yet availabile. It will return an not implemented error.</b> + * List all {@link org.hyperic.hq.hqapi1.types.Group}s. * * @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS} if * all the groups were successfully retrieved from the server. @@ -107,8 +106,7 @@ } /** - * List all the Resources associated with a {@link Group}.<br><b>This API is - * not yet availabile. It will return an not implemented error.</b> + * List all the Resources associated with a {@link Group}. * * @param groupId The {@link org.hyperic.hq.hqapi1.types.Group} id to query. * Modified: trunk/src/org/hyperic/hq/hqapi1/test/Group_test.java =================================================================== --- trunk/src/org/hyperic/hq/hqapi1/test/Group_test.java 2008-11-17 15:56:31 UTC (rev 285) +++ trunk/src/org/hyperic/hq/hqapi1/test/Group_test.java 2008-11-17 15:56:49 UTC (rev 286) @@ -8,13 +8,22 @@ import org.hyperic.hq.hqapi1.types.GetGroupsResponse; import org.hyperic.hq.hqapi1.types.FindResourcesResponse; import org.hyperic.hq.hqapi1.types.AddResourceToGroupResponse; +import org.hyperic.hq.hqapi1.types.Resource; +import java.util.List; + public class Group_test extends HQApiTestBase { public Group_test(String name) { super(name); } + private void validateGroup(Group g) { + assertTrue("Invalid id for Group.", g.getId() > 0); + assertTrue("Found invalid name for Group with id=" + g.getId(), + g.getName().length() > 0); + } + public void testCreate() throws Exception { GroupApi api = getApi().getGroupApi(); @@ -41,15 +50,53 @@ GroupApi api = getApi().getGroupApi(); GetGroupsResponse resp = api.listGroups(); - hqAssertFailureNotImplemented(resp); + hqAssertSuccess(resp); + + List<Group> groups = resp.getGroup(); + if (groups.size() == 0) { + getLog().warn("No groups found, skipping test"); + return; + } + + for (Group g : groups) { + validateGroup(g); + } } public void testGetResourcesInGroup() throws Exception { + GroupApi api = getApi().getGroupApi(); + GetGroupsResponse resp = api.listGroups(); + hqAssertSuccess(resp); + + List<Group> groups = resp.getGroup(); + if (groups.size() == 0) { + getLog().warn("No groups found, skipping test"); + return; + } + + for (Group g : resp.getGroup()) { + validateGroup(g); + FindResourcesResponse resourceResponse = api.listResources(g.getId()); + hqAssertSuccess(resourceResponse); + if (resourceResponse.getResource().size() == 0) { + getLog().warn("Zero group members found for " + g.getId()); + } + + for (Resource r : resourceResponse.getResource()) { + assertNotNull(r); + assertTrue(r.getId() > 0); + assertTrue(r.getName().length() > 0); + } + } + } + + public void testGetResourcesInInvalidGroup() throws Exception { + GroupApi api = getApi().getGroupApi(); - FindResourcesResponse resp = api.listResources(1); - hqAssertFailureNotImplemented(resp); + FindResourcesResponse resp = api.listResources(Integer.MAX_VALUE); + hqAssertFailureObjectNotFound(resp); } public void testAddResource() throws Exception { Modified: trunk/xsd/Group.xsd =================================================================== --- trunk/xsd/Group.xsd 2008-11-17 15:56:31 UTC (rev 285) +++ trunk/xsd/Group.xsd 2008-11-17 15:56:49 UTC (rev 286) @@ -16,17 +16,14 @@ <xs:complexType name="Group"> <xs:sequence> - <xs:element name="role" type="Role" minOccurs="1" maxOccurs="unbounded"/> - <xs:element name="resource" type="Resource" minOccurs="1" maxOccurs="unbounded"/> - <xs:element name="criteria" type="Criteria" minOccurs="0"/> + <!-- xs:element name="role" type="Role" minOccurs="0" maxOccurs="unbounded"/ --> + <!-- xs:element name="criteria" type="Criteria" minOccurs="0"/ --> <xs:element name="prototype" type="ResourcePrototype" maxOccurs="1"/> - <xs:element name="description" type="xs:string"/> </xs:sequence> - <xs:attribute name="id" type="xs:int"/> - <xs:attribute name="name" type="xs:string"/> - <xs:attribute name="location" type="xs:string"/> - <xs:attribute name="groupType" type="xs:int"/> - <xs:attribute name="clusterId" type="xs:int"/> + <xs:attribute name="id" type="xs:int" use="required"/> + <xs:attribute name="name" type="xs:string" use="required"/> + <xs:attribute name="description" type="xs:string"/> + <xs:attribute name="location" type="xs:string"/> </xs:complexType> <!-- Group Responses --> @@ -76,7 +73,7 @@ <xs:complexContent> <xs:extension base="Response"> <xs:sequence> - <xs:element name="Group" type="Group"/> + <xs:element name="Group" type="Group" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:extension> </xs:complexContent> |