Repository: ambari Updated Branches: refs/heads/trunk 389b2505d -> 62e2f9f8e
AMBARI-6834. Provide undefined prarameters for view instance. Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/62e2f9f8 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/62e2f9f8 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/62e2f9f8 Branch: refs/heads/trunk Commit: 62e2f9f8efd2d5d934e9c87f0d36568124660248 Parents: 389b250 Author: Mahadev Konar <maha...@apache.org> Authored: Tue Aug 12 12:09:09 2014 -0700 Committer: Mahadev Konar <maha...@apache.org> Committed: Tue Aug 12 12:09:13 2014 -0700 ---------------------------------------------------------------------- .../internal/ViewInstanceResourceProvider.java | 8 +- .../ViewInstanceResourceProviderTest.java | 82 ++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/62e2f9f8/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java index 2ebd9f4..c1a3d79 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java @@ -33,6 +33,7 @@ import org.apache.ambari.server.orm.entities.ViewEntity; import org.apache.ambari.server.orm.entities.ViewInstanceDataEntity; import org.apache.ambari.server.orm.entities.ViewInstanceEntity; import org.apache.ambari.server.orm.entities.ViewInstancePropertyEntity; +import org.apache.ambari.server.orm.entities.ViewParameterEntity; import org.apache.ambari.server.view.ViewRegistry; import java.util.Collection; @@ -199,7 +200,7 @@ public class ViewInstanceResourceProvider extends AbstractResourceProvider { // ----- helper methods ---------------------------------------------------- // Convert an instance entity to a resource - private Resource toResource(ViewInstanceEntity viewInstanceEntity, Set<String> requestedIds) { + protected Resource toResource(ViewInstanceEntity viewInstanceEntity, Set<String> requestedIds) { Resource resource = new ResourceImpl(Resource.Type.ViewInstance); ViewEntity viewEntity = viewInstanceEntity.getViewEntity(); @@ -218,6 +219,11 @@ public class ViewInstanceResourceProvider extends AbstractResourceProvider { for (ViewInstancePropertyEntity viewInstancePropertyEntity : viewInstanceEntity.getProperties()) { properties.put(viewInstancePropertyEntity.getName(), viewInstancePropertyEntity.getValue()); } + for (ViewParameterEntity viewParameterEntity : viewEntity.getParameters()) { + if (!properties.containsKey(viewParameterEntity.getName())) { + properties.put(viewParameterEntity.getName(), null); + } + } setResourceProperty(resource, PROPERTIES_PROPERTY_ID, properties, requestedIds); Map<String, String> applicationData = new HashMap<String, String>(); http://git-wip-us.apache.org/repos/asf/ambari/blob/62e2f9f8/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProviderTest.java new file mode 100644 index 0000000..52f0231 --- /dev/null +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProviderTest.java @@ -0,0 +1,82 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.server.controller.internal; + +import org.apache.ambari.server.controller.spi.Predicate; +import org.apache.ambari.server.controller.spi.Request; +import org.apache.ambari.server.controller.spi.Resource; +import org.apache.ambari.server.orm.entities.ViewEntity; +import org.apache.ambari.server.orm.entities.ViewInstanceDataEntity; +import org.apache.ambari.server.orm.entities.ViewInstanceEntity; +import org.apache.ambari.server.orm.entities.ViewInstancePropertyEntity; +import org.apache.ambari.server.orm.entities.ViewParameterEntity; +import org.easymock.EasyMock; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import static org.junit.Assert.*; +import static org.easymock.EasyMock.*; + +public class ViewInstanceResourceProviderTest { + + @Test + public void testToResource() throws Exception { + ViewInstanceResourceProvider provider = new ViewInstanceResourceProvider(); + Set<String> propertyIds = new HashSet<String>(); + propertyIds.add(ViewInstanceResourceProvider.PROPERTIES_PROPERTY_ID); + ViewInstanceEntity viewInstanceEntity = createNiceMock(ViewInstanceEntity.class); + ViewEntity viewEntity = createNiceMock(ViewEntity.class); + expect(viewInstanceEntity.getViewEntity()).andReturn(viewEntity); + + ViewInstancePropertyEntity propertyEntity1 = createNiceMock(ViewInstancePropertyEntity.class); + expect(propertyEntity1.getName()).andReturn("par1").anyTimes(); + expect(propertyEntity1.getValue()).andReturn("val1").anyTimes(); + ViewInstancePropertyEntity propertyEntity3 = createNiceMock(ViewInstancePropertyEntity.class); + expect(propertyEntity3.getName()).andReturn("par3").anyTimes(); + expect(propertyEntity3.getValue()).andReturn("val3").anyTimes(); + expect(viewInstanceEntity.getProperties()).andReturn(Arrays.asList(propertyEntity1, propertyEntity3)); + + ViewParameterEntity parameter1 = createNiceMock(ViewParameterEntity.class); + expect(parameter1.getName()).andReturn("par1").anyTimes(); + ViewParameterEntity parameter2 = createNiceMock(ViewParameterEntity.class); + expect(parameter2.getName()).andReturn("par2").anyTimes(); + expect(viewEntity.getParameters()).andReturn(Arrays.asList(parameter1, parameter2)); + + expect(viewInstanceEntity.getData()).andReturn(Collections.<ViewInstanceDataEntity>emptyList()); + + replay(viewEntity, viewInstanceEntity, parameter1, parameter2, propertyEntity1, propertyEntity3); + + Resource resource = provider.toResource(viewInstanceEntity, propertyIds); + Map<String, Map<String, Object>> properties = resource.getPropertiesMap(); + assertEquals(1, properties.size()); + Map<String, Object> props = properties.get("ViewInstanceInfo/properties"); + assertNotNull(props); + assertEquals(3, props.size()); + assertEquals("val1", props.get("par1")); + assertEquals("val3", props.get("par3")); + assertNull(props.get("par2")); + } +} \ No newline at end of file