QueryImpl implements Query, ResourceInstance { @Override public Result execute() throws UnsupportedPropertyException, SystemException, NoSuchResourceException, NoSuchParentResourceException { queryForResources(); return getResult(null); } QueryImpl(Map<Resource.Type, String> keyValueMap,
                   ResourceDefinition resourceDefinition,
                   ClusterController clusterController); @Override void addProperty(String propertyId, TemporalInfo temporalInfo); @Override void addLocalProperty(String property); @Override Result execute(); @Override Predicate getPredicate(); @Override Set<String> getProperties(); @Override void setUserPredicate(Predicate predicate); @Override void setPageRequest(PageRequest pageRequest); @Override void setSortRequest(SortRequest sortRequest); @Override void setRenderer(Renderer renderer); @Override void setRequestInfoProps(Map<String, String> requestInfoProperties); @Override Map<String, String> getRequestInfoProps(); @Override void setKeyValueMap(Map<Resource.Type, String> keyValueMap); @Override Map<Resource.Type, String> getKeyValueMap(); @Override Query getQuery(); @Override ResourceDefinition getResourceDefinition(); @Override boolean isCollectionResource(); @Override Map<String, ResourceInstance> getSubResources(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void testExecute__Cluster_instance_noSpecifiedProps() throws Exception { ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class); Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>(); mapIds.put(Resource.Type.Cluster, "cluster"); expect(resourceDefinition.getType()).andReturn(Resource.Type.Cluster).anyTimes(); Set<SubResourceDefinition> setChildren = new HashSet<SubResourceDefinition>(); setChildren.add(new SubResourceDefinition(Resource.Type.Host)); expect(resourceDefinition.getSubResourceDefinitions()).andReturn(setChildren).anyTimes(); replay(resourceDefinition); QueryImpl instance = new TestQuery(mapIds, resourceDefinition); Result result = instance.execute(); verify(resourceDefinition); TreeNode<Resource> tree = result.getResultTree(); Assert.assertEquals(1, tree.getChildren().size()); TreeNode<Resource> clusterNode = tree.getChild("Cluster:1"); Assert.assertEquals("Cluster:1", clusterNode.getName()); Assert.assertEquals(Resource.Type.Cluster, clusterNode.getObject().getType()); Assert.assertEquals(1, clusterNode.getChildren().size()); TreeNode<Resource> hostNode = clusterNode.getChild("hosts"); Assert.assertEquals(4, hostNode.getChildren().size()); }
@Test public void testExecute__Stack_instance_noSpecifiedProps() throws Exception { ResourceDefinition resourceDefinition = new StackResourceDefinition(); Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>(); mapIds.put(Resource.Type.Stack, "HDP"); QueryImpl instance = new TestQuery(mapIds, resourceDefinition); Result result = instance.execute(); TreeNode<Resource> tree = result.getResultTree(); Assert.assertEquals(1, tree.getChildren().size()); TreeNode<Resource> stackNode = tree.getChild("Stack:1"); Assert.assertEquals("Stack:1", stackNode.getName()); Assert.assertEquals(Resource.Type.Stack, stackNode.getObject().getType()); Assert.assertEquals(1, stackNode.getChildren().size()); TreeNode<Resource> versionsNode = stackNode.getChild("versions"); Assert.assertEquals(3, versionsNode.getChildren().size()); }
@Test public void testExecute__Host_collection_noSpecifiedProps() throws Exception { ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class); Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>(); expect(resourceDefinition.getType()).andReturn(Resource.Type.Host).anyTimes(); Set<SubResourceDefinition> setChildren = new HashSet<SubResourceDefinition>(); expect(resourceDefinition.getSubResourceDefinitions()).andReturn(setChildren).anyTimes(); replay(resourceDefinition); QueryImpl instance = new TestQuery(mapIds, resourceDefinition); Result result = instance.execute(); verify(resourceDefinition); TreeNode<Resource> tree = result.getResultTree(); Assert.assertEquals(4, tree.getChildren().size()); TreeNode<Resource> hostNode = tree.getChild("Host:1"); Assert.assertEquals("Host:1", hostNode.getName()); Assert.assertEquals(Resource.Type.Host, hostNode.getObject().getType()); hostNode = tree.getChild("Host:2"); Assert.assertEquals("Host:2", hostNode.getName()); Assert.assertEquals(Resource.Type.Host, hostNode.getObject().getType()); hostNode = tree.getChild("Host:3"); Assert.assertEquals("Host:3", hostNode.getName()); Assert.assertEquals(Resource.Type.Host, hostNode.getObject().getType()); hostNode = tree.getChild("Host:4"); Assert.assertEquals("Host:4", hostNode.getName()); Assert.assertEquals(Resource.Type.Host, hostNode.getObject().getType()); }
@Test public void testExecute__collection_nullInternalPredicate_nullUserPredicate() throws Exception { ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class); Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>(); expect(resourceDefinition.getType()).andReturn(Resource.Type.Cluster).anyTimes(); Set<SubResourceDefinition> setChildren = new HashSet<SubResourceDefinition>(); setChildren.add(new SubResourceDefinition(Resource.Type.Host)); expect(resourceDefinition.getSubResourceDefinitions()).andReturn(setChildren).anyTimes(); replay(resourceDefinition); QueryImpl instance = new TestQuery(mapIds, resourceDefinition); Result result = instance.execute(); verify(resourceDefinition); TreeNode<Resource> tree = result.getResultTree(); Assert.assertEquals(1, tree.getChildren().size()); TreeNode<Resource> clusterNode = tree.getChild("Cluster:1"); Assert.assertEquals("Cluster:1", clusterNode.getName()); Assert.assertEquals(Resource.Type.Cluster, clusterNode.getObject().getType()); Assert.assertEquals(0, clusterNode.getChildren().size()); }