ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbeerbo...@apache.org
Subject git commit: AMBARI-4541 - NPE for View instance with no properties.
Date Thu, 06 Feb 2014 16:39:48 GMT
Updated Branches:
  refs/heads/trunk 1617c7357 -> eec3548f1


AMBARI-4541 - NPE for View instance with no properties.


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/eec3548f
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/eec3548f
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/eec3548f

Branch: refs/heads/trunk
Commit: eec3548f10e8bceea9127f8cd641e4d77ed2474a
Parents: 1617c73
Author: tbeerbower <tbeerbower@hortonworks.com>
Authored: Wed Feb 5 16:40:55 2014 -0800
Committer: tbeerbower <tbeerbower@hortonworks.com>
Committed: Thu Feb 6 08:39:32 2014 -0800

----------------------------------------------------------------------
 .../view/configuration/InstanceConfig.java      |  3 +-
 .../view/configuration/InstanceConfigTest.java  | 32 ++++++++++++++++++++
 .../view/configuration/ViewConfigTest.java      |  6 +++-
 3 files changed, 39 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/eec3548f/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/InstanceConfig.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/InstanceConfig.java
b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/InstanceConfig.java
index fd80922..4b0c085 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/InstanceConfig.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/InstanceConfig.java
@@ -21,6 +21,7 @@ package org.apache.ambari.server.view.configuration;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -54,6 +55,6 @@ public class InstanceConfig {
    * @return the instance properties
    */
   public List<PropertyConfig> getProperties() {
-    return properties;
+    return properties == null ? Collections.<PropertyConfig>emptyList() : properties;
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/eec3548f/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/InstanceConfigTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/InstanceConfigTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/InstanceConfigTest.java
index 28fe7f3..4f49425 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/InstanceConfigTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/InstanceConfigTest.java
@@ -28,6 +28,25 @@ import java.util.List;
  * InstanceConfig tests.
  */
 public class InstanceConfigTest {
+
+  private static String xml_no_properties = "<view>\n" +
+      "    <name>MY_VIEW</name>\n" +
+      "    <label>My View!</label>\n" +
+      "    <version>1.0.0</version>\n" +
+      "    <resource>\n" +
+      "        <name>resource</name>\n" +
+      "        <plural-name>resources</plural-name>\n" +
+      "        <id-property>id</id-property>\n" +
+      "        <resource-class>org.apache.ambari.server.view.configuration.ViewConfigTest$MyResource</resource-class>\n"
+
+      "        <provider-class>org.apache.ambari.server.view.configuration.ViewConfigTest$MyResourceProvider</provider-class>\n"
+
+      "        <service-class>org.apache.ambari.server.view.configuration.ViewConfigTest$MyResourceService</service-class>\n"
+
+      "        <sub-resource-name>subresource</sub-resource-name>\n" +
+      "    </resource>\n" +
+      "    <instance>\n" +
+      "        <name>INSTANCE1</name>\n" +
+      "    </instance>\n" +
+      "</view>";
+
   @Test
   public void testGetName() throws Exception {
     List<InstanceConfig> instances = getInstanceConfigs();
@@ -47,10 +66,23 @@ public class InstanceConfigTest {
 
     properties = instances.get(1).getProperties();
     Assert.assertEquals(1, properties.size());
+
+    // check the case where no properties are specified for the instance...
+    instances = getInstanceConfigs(xml_no_properties);
+
+    Assert.assertEquals(1, instances.size());
+    properties = instances.get(0).getProperties();
+    Assert.assertNotNull(properties);
+    Assert.assertEquals(0, properties.size());
   }
 
   public static List<InstanceConfig> getInstanceConfigs() throws JAXBException {
     ViewConfig config = ViewConfigTest.getConfig();
     return config.getInstances();
   }
+
+  public static List<InstanceConfig> getInstanceConfigs(String xml) throws JAXBException
{
+    ViewConfig config = ViewConfigTest.getConfig(xml);
+    return config.getInstances();
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/eec3548f/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ViewConfigTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ViewConfigTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ViewConfigTest.java
index 0ca6764..04e71a8 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ViewConfigTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ViewConfigTest.java
@@ -184,7 +184,11 @@ public class ViewConfigTest {
   }
 
   public static  ViewConfig getConfig() throws JAXBException {
-    InputStream configStream =  new ByteArrayInputStream(xml.getBytes());
+      return getConfig(xml);
+  }
+
+  public static  ViewConfig getConfig(String xml) throws JAXBException {
+      InputStream configStream =  new ByteArrayInputStream(xml.getBytes());
     JAXBContext jaxbContext = JAXBContext.newInstance(ViewConfig.class);
     Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
     return (ViewConfig) unmarshaller.unmarshal(configStream);


Mime
View raw message