MinimalRenderer extends BaseRenderer implements Renderer { @Override public TreeNode<Set<String>> finalizeProperties( TreeNode<QueryInfo> queryTree, boolean isCollection) { QueryInfo queryInfo = queryTree.getObject(); TreeNode<Set<String>> resultTree = new TreeNodeImpl<Set<String>>( null, queryInfo.getProperties(), queryTree.getName()); copyPropertiesToResult(queryTree, resultTree); m_rootType = queryTree.getObject().getResource().getType(); m_isCollection = isCollection; boolean addKeysToEmptyResource = true; if (! isCollection && isRequestWithNoProperties(queryTree)) { addSubResources(queryTree, resultTree); addKeysToEmptyResource = false; } processRequestedProperties(queryTree); ensureRequiredProperties(resultTree, addKeysToEmptyResource); return resultTree; }  @Override TreeNode<Set<String>> finalizeProperties(
      TreeNode<QueryInfo> queryTree, boolean isCollection); @Override Result finalizeResult(Result queryResult); @Override ResultPostProcessor getResultPostProcessor(Request request);  }
@Test public void testFinalizeProperties__instance_noProperties() { SchemaFactory schemaFactory = createNiceMock(SchemaFactory.class); Schema schema = createNiceMock(Schema.class); expect(schemaFactory.getSchema(Resource.Type.Component)).andReturn(schema).anyTimes(); expect(schemaFactory.getSchema(Resource.Type.Alert)).andReturn(schema).anyTimes(); expect(schemaFactory.getSchema(Resource.Type.Artifact)).andReturn(schema).anyTimes(); expect(schema.getKeyPropertyId(Resource.Type.Component)).andReturn("ServiceComponentInfo/component_name").anyTimes(); replay(schemaFactory, schema); QueryInfo rootQuery = new QueryInfo(new ServiceResourceDefinition(), new HashSet<String>()); TreeNode<QueryInfo> queryTree = new TreeNodeImpl<QueryInfo>(null, rootQuery, "Service"); MinimalRenderer renderer = new MinimalRenderer(); renderer.init(schemaFactory); TreeNode<Set<String>> propertyTree = renderer.finalizeProperties(queryTree, false); assertTrue(propertyTree.getObject().isEmpty()); assertEquals(3, propertyTree.getChildren().size()); TreeNode<Set<String>> componentNode = propertyTree.getChild("Component"); assertEquals(1, componentNode.getObject().size()); assertTrue(componentNode.getObject().contains("ServiceComponentInfo/component_name")); verify(schemaFactory, schema); }
@Test public void testFinalizeProperties__instance_properties() { SchemaFactory schemaFactory = createNiceMock(SchemaFactory.class); Schema schema = createNiceMock(Schema.class); expect(schemaFactory.getSchema(Resource.Type.Service)).andReturn(schema).anyTimes(); expect(schema.getKeyPropertyId(Resource.Type.Service)).andReturn("ServiceInfo/service_name").anyTimes(); replay(schemaFactory, schema); HashSet<String> serviceProperties = new HashSet<String>(); serviceProperties.add("foo/bar"); QueryInfo rootQuery = new QueryInfo(new ServiceResourceDefinition(), serviceProperties); TreeNode<QueryInfo> queryTree = new TreeNodeImpl<QueryInfo>(null, rootQuery, "Service"); MinimalRenderer renderer = new MinimalRenderer(); renderer.init(schemaFactory); TreeNode<Set<String>> propertyTree = renderer.finalizeProperties(queryTree, false); assertEquals(2, propertyTree.getObject().size()); assertTrue(propertyTree.getObject().contains("ServiceInfo/service_name")); assertTrue(propertyTree.getObject().contains("foo/bar")); assertEquals(0, propertyTree.getChildren().size()); verify(schemaFactory, schema); }
@Test public void testFinalizeProperties__collection_noProperties() { SchemaFactory schemaFactory = createNiceMock(SchemaFactory.class); Schema schema = createNiceMock(Schema.class); expect(schemaFactory.getSchema(Resource.Type.Service)).andReturn(schema).anyTimes(); expect(schema.getKeyPropertyId(Resource.Type.Service)).andReturn("ServiceInfo/service_name").anyTimes(); replay(schemaFactory, schema); HashSet<String> serviceProperties = new HashSet<String>(); QueryInfo rootQuery = new QueryInfo(new ServiceResourceDefinition(), serviceProperties); TreeNode<QueryInfo> queryTree = new TreeNodeImpl<QueryInfo>(null, rootQuery, "Service"); MinimalRenderer renderer = new MinimalRenderer(); renderer.init(schemaFactory); TreeNode<Set<String>> propertyTree = renderer.finalizeProperties(queryTree, true); assertEquals(1, propertyTree.getObject().size()); assertTrue(propertyTree.getObject().contains("ServiceInfo/service_name")); assertEquals(0, propertyTree.getChildren().size()); verify(schemaFactory, schema); }
@Test public void testFinalizeProperties__collection_properties() { SchemaFactory schemaFactory = createNiceMock(SchemaFactory.class); Schema schema = createNiceMock(Schema.class); expect(schemaFactory.getSchema(Resource.Type.Service)).andReturn(schema).anyTimes(); expect(schema.getKeyPropertyId(Resource.Type.Service)).andReturn("ServiceInfo/service_name").anyTimes(); replay(schemaFactory, schema); HashSet<String> serviceProperties = new HashSet<String>(); serviceProperties.add("foo/bar"); QueryInfo rootQuery = new QueryInfo(new ServiceResourceDefinition(), serviceProperties); TreeNode<QueryInfo> queryTree = new TreeNodeImpl<QueryInfo>(null, rootQuery, "Service"); MinimalRenderer renderer = new MinimalRenderer(); renderer.init(schemaFactory); TreeNode<Set<String>> propertyTree = renderer.finalizeProperties(queryTree, true); assertEquals(2, propertyTree.getObject().size()); assertTrue(propertyTree.getObject().contains("ServiceInfo/service_name")); assertTrue(propertyTree.getObject().contains("foo/bar")); assertEquals(0, propertyTree.getChildren().size()); verify(schemaFactory, schema); }
@Test public void testFinalizeProperties__instance_subResource_noProperties() { SchemaFactory schemaFactory = createNiceMock(SchemaFactory.class); Schema serviceSchema = createNiceMock(Schema.class); Schema componentSchema = createNiceMock(Schema.class); expect(schemaFactory.getSchema(Resource.Type.Service)).andReturn(serviceSchema).anyTimes(); expect(serviceSchema.getKeyPropertyId(Resource.Type.Service)).andReturn("ServiceInfo/service_name").anyTimes(); expect(schemaFactory.getSchema(Resource.Type.Component)).andReturn(componentSchema).anyTimes(); expect(componentSchema.getKeyPropertyId(Resource.Type.Component)).andReturn("ServiceComponentInfo/component_name").anyTimes(); replay(schemaFactory, serviceSchema, componentSchema); HashSet<String> serviceProperties = new HashSet<String>(); QueryInfo rootQuery = new QueryInfo(new ServiceResourceDefinition(), serviceProperties); TreeNode<QueryInfo> queryTree = new TreeNodeImpl<QueryInfo>(null, rootQuery, "Service"); queryTree.addChild(new QueryInfo(new ComponentResourceDefinition(), new HashSet<String>()), "Component"); MinimalRenderer renderer = new MinimalRenderer(); renderer.init(schemaFactory); TreeNode<Set<String>> propertyTree = renderer.finalizeProperties(queryTree, false); assertEquals(1, propertyTree.getChildren().size()); assertEquals(1, propertyTree.getObject().size()); assertTrue(propertyTree.getObject().contains("ServiceInfo/service_name")); TreeNode<Set<String>> componentNode = propertyTree.getChild("Component"); assertEquals(0, componentNode.getChildren().size()); assertEquals(1, componentNode.getObject().size()); assertTrue(componentNode.getObject().contains("ServiceComponentInfo/component_name")); verify(schemaFactory, serviceSchema, componentSchema); }
@Test public void testFinalizeProperties__instance_subResource_properties() { SchemaFactory schemaFactory = createNiceMock(SchemaFactory.class); Schema serviceSchema = createNiceMock(Schema.class); Schema componentSchema = createNiceMock(Schema.class); expect(schemaFactory.getSchema(Resource.Type.Service)).andReturn(serviceSchema).anyTimes(); expect(serviceSchema.getKeyPropertyId(Resource.Type.Service)).andReturn("ServiceInfo/service_name").anyTimes(); expect(schemaFactory.getSchema(Resource.Type.Component)).andReturn(componentSchema).anyTimes(); expect(componentSchema.getKeyPropertyId(Resource.Type.Component)).andReturn("ServiceComponentInfo/component_name").anyTimes(); replay(schemaFactory, serviceSchema, componentSchema); HashSet<String> serviceProperties = new HashSet<String>(); serviceProperties.add("foo/bar"); QueryInfo rootQuery = new QueryInfo(new ServiceResourceDefinition(), serviceProperties); TreeNode<QueryInfo> queryTree = new TreeNodeImpl<QueryInfo>(null, rootQuery, "Service"); HashSet<String> componentProperties = new HashSet<String>(); componentProperties.add("goo/car"); queryTree.addChild(new QueryInfo(new ComponentResourceDefinition(), componentProperties), "Component"); MinimalRenderer renderer = new MinimalRenderer(); renderer.init(schemaFactory); TreeNode<Set<String>> propertyTree = renderer.finalizeProperties(queryTree, false); assertEquals(1, propertyTree.getChildren().size()); assertEquals(2, propertyTree.getObject().size()); assertTrue(propertyTree.getObject().contains("ServiceInfo/service_name")); assertTrue(propertyTree.getObject().contains("foo/bar")); TreeNode<Set<String>> componentNode = propertyTree.getChild("Component"); assertEquals(0, componentNode.getChildren().size()); assertEquals(2, componentNode.getObject().size()); assertTrue(componentNode.getObject().contains("ServiceComponentInfo/component_name")); assertTrue(componentNode.getObject().contains("goo/car")); verify(schemaFactory, serviceSchema, componentSchema); }
@Test public void testFinalizeProperties__collection_subResource_noProperties() { SchemaFactory schemaFactory = createNiceMock(SchemaFactory.class); Schema serviceSchema = createNiceMock(Schema.class); Schema componentSchema = createNiceMock(Schema.class); expect(schemaFactory.getSchema(Resource.Type.Service)).andReturn(serviceSchema).anyTimes(); expect(serviceSchema.getKeyPropertyId(Resource.Type.Service)).andReturn("ServiceInfo/service_name").anyTimes(); expect(schemaFactory.getSchema(Resource.Type.Component)).andReturn(componentSchema).anyTimes(); expect(componentSchema.getKeyPropertyId(Resource.Type.Component)).andReturn("ServiceComponentInfo/component_name").anyTimes(); replay(schemaFactory, serviceSchema, componentSchema); HashSet<String> serviceProperties = new HashSet<String>(); QueryInfo rootQuery = new QueryInfo(new ServiceResourceDefinition(), serviceProperties); TreeNode<QueryInfo> queryTree = new TreeNodeImpl<QueryInfo>(null, rootQuery, "Service"); queryTree.addChild(new QueryInfo(new ComponentResourceDefinition(), new HashSet<String>()), "Component"); MinimalRenderer renderer = new MinimalRenderer(); renderer.init(schemaFactory); TreeNode<Set<String>> propertyTree = renderer.finalizeProperties(queryTree, true); assertEquals(1, propertyTree.getChildren().size()); assertEquals(1, propertyTree.getObject().size()); assertTrue(propertyTree.getObject().contains("ServiceInfo/service_name")); TreeNode<Set<String>> componentNode = propertyTree.getChild("Component"); assertEquals(0, componentNode.getChildren().size()); assertEquals(1, componentNode.getObject().size()); assertTrue(componentNode.getObject().contains("ServiceComponentInfo/component_name")); verify(schemaFactory, serviceSchema, componentSchema); }
@Test public void testFinalizeProperties__collection_subResource_propertiesTopLevelOnly() { SchemaFactory schemaFactory = createNiceMock(SchemaFactory.class); Schema serviceSchema = createNiceMock(Schema.class); Schema componentSchema = createNiceMock(Schema.class); expect(schemaFactory.getSchema(Resource.Type.Service)).andReturn(serviceSchema).anyTimes(); expect(serviceSchema.getKeyPropertyId(Resource.Type.Service)).andReturn("ServiceInfo/service_name").anyTimes(); expect(schemaFactory.getSchema(Resource.Type.Component)).andReturn(componentSchema).anyTimes(); expect(componentSchema.getKeyPropertyId(Resource.Type.Component)).andReturn("ServiceComponentInfo/component_name").anyTimes(); replay(schemaFactory, serviceSchema, componentSchema); HashSet<String> serviceProperties = new HashSet<String>(); serviceProperties.add("foo/bar"); QueryInfo rootQuery = new QueryInfo(new ServiceResourceDefinition(), serviceProperties); TreeNode<QueryInfo> queryTree = new TreeNodeImpl<QueryInfo>(null, rootQuery, "Service"); queryTree.addChild(new QueryInfo(new ComponentResourceDefinition(), new HashSet<String>()), "Component"); MinimalRenderer renderer = new MinimalRenderer(); renderer.init(schemaFactory); TreeNode<Set<String>> propertyTree = renderer.finalizeProperties(queryTree, true); assertEquals(1, propertyTree.getChildren().size()); assertEquals(2, propertyTree.getObject().size()); assertTrue(propertyTree.getObject().contains("ServiceInfo/service_name")); assertTrue(propertyTree.getObject().contains("foo/bar")); TreeNode<Set<String>> componentNode = propertyTree.getChild("Component"); assertEquals(0, componentNode.getChildren().size()); assertEquals(1, componentNode.getObject().size()); assertTrue(componentNode.getObject().contains("ServiceComponentInfo/component_name")); verify(schemaFactory, serviceSchema, componentSchema); }