ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbeerbo...@apache.org
Subject git commit: AMBARI-4679 - NPE for View with no instances / resources / parameters.
Date Fri, 14 Feb 2014 18:17:33 GMT
Updated Branches:
  refs/heads/trunk ba50ff704 -> af54f0ff9


AMBARI-4679 - NPE for View with no instances / resources / parameters.


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

Branch: refs/heads/trunk
Commit: af54f0ff9aac7d054ef7de1514b780a164e178f5
Parents: ba50ff7
Author: tbeerbower <tbeerbower@hortonworks.com>
Authored: Fri Feb 14 11:19:54 2014 -0500
Committer: tbeerbower <tbeerbower@hortonworks.com>
Committed: Fri Feb 14 13:16:55 2014 -0500

----------------------------------------------------------------------
 .../server/view/configuration/ViewConfig.java   |  7 ++--
 .../view/configuration/ViewConfigTest.java      | 37 ++++++++++++++------
 2 files changed, 31 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/af54f0ff/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ViewConfig.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ViewConfig.java
b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ViewConfig.java
index fa1bed1..829e08a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ViewConfig.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ViewConfig.java
@@ -23,6 +23,7 @@ import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -104,7 +105,7 @@ public class ViewConfig {
    * @return the list of parameters
    */
   public List<ParameterConfig> getParameters() {
-    return parameters;
+    return parameters == null ? Collections.<ParameterConfig>emptyList() : parameters;
   }
 
   /**
@@ -113,7 +114,7 @@ public class ViewConfig {
    * @return return the list of resources
    */
   public List<ResourceConfig> getResources() {
-    return resources;
+    return resources == null ? Collections.<ResourceConfig>emptyList() : resources;
   }
 
   /**
@@ -122,6 +123,6 @@ public class ViewConfig {
    * @return the list of view instances
    */
   public List<InstanceConfig> getInstances() {
-    return instances;
+    return instances == null ? Collections.<InstanceConfig>emptyList() : instances;
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/af54f0ff/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 27a7644..42dd7be 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
@@ -73,14 +73,6 @@ public class ViewConfigTest {
       "        <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"
+
       "    </resource>\n" +
-      "    <servlet>\n" +
-      "        <servlet-name>MyViewServlet</servlet-name>\n" +
-      "        <servlet-path>org.apache.ambari.server.view.configuration.ViewConfigTest$MyViewServlet</servlet-path>\n"
+
-      "    </servlet>\n" +
-      "    <servlet-mapping>\n" +
-      "        <servlet-name>MyViewServlet</servlet-name>\n" +
-      "        <url-pattern>/ui</url-pattern>\n" +
-      "    </servlet-mapping>\n" +
       "    <instance>\n" +
       "        <name>INSTANCE1</name>\n" +
       "        <property>\n" +
@@ -102,6 +94,13 @@ public class ViewConfigTest {
       "</view>";
 
 
+  private static String minimal_xml = "<view>\n" +
+      "    <name>MY_VIEW</name>\n" +
+      "    <label>My View!</label>\n" +
+      "    <version>1.0.0</version>\n" +
+      "</view>";
+
+
   @Test
   public void testGetName() throws Exception {
     ViewConfig config = getConfig();
@@ -127,6 +126,12 @@ public class ViewConfigTest {
     Assert.assertEquals(2, parameters.size());
     Assert.assertEquals("p1", parameters.get(0).getName());
     Assert.assertEquals("p2", parameters.get(1).getName());
+
+    // check the case where no parameters are specified for the view...
+    config = getConfig(minimal_xml);
+    parameters = config.getParameters();
+    Assert.assertNotNull(parameters);
+    Assert.assertEquals(0, parameters.size());
   }
 
   @Test
@@ -136,15 +141,27 @@ public class ViewConfigTest {
     Assert.assertEquals(2, resources.size());
     Assert.assertEquals("resource", resources.get(0).getName());
     Assert.assertEquals("subresource", resources.get(1).getName());
+
+    // check the case where no resources are specified for the view...
+    config = getConfig(minimal_xml);
+    resources = config.getResources();
+    Assert.assertNotNull(resources);
+    Assert.assertEquals(0, resources.size());
   }
 
   @Test
   public void testGetInstances() throws Exception {
-    ViewConfig config = getConfig();
+    ViewConfig config = getConfig(xml);
     List<InstanceConfig> instances = config.getInstances();
     Assert.assertEquals(2, instances.size());
     Assert.assertEquals("INSTANCE1", instances.get(0).getName());
     Assert.assertEquals("INSTANCE2", instances.get(1).getName());
+
+    // check the case where no instances are specified for the view...
+    config = getConfig(minimal_xml);
+    instances = config.getInstances();
+    Assert.assertNotNull(instances);
+    Assert.assertEquals(0, instances.size());
   }
 
   public static  ViewConfig getConfig() throws JAXBException {
@@ -152,7 +169,7 @@ public class ViewConfigTest {
   }
 
   public static  ViewConfig getConfig(String xml) throws JAXBException {
-      InputStream configStream =  new ByteArrayInputStream(xml.getBytes());
+    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