ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbeerbo...@apache.org
Subject [1/2] git commit: AMBARI-4428 - Add Ambari View configuration code.
Date Tue, 28 Jan 2014 10:12:05 GMT
Updated Branches:
  refs/heads/trunk 682ef9984 -> 3d7270b38


AMBARI-4428 - Add Ambari View configuration code.


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

Branch: refs/heads/trunk
Commit: 3d7270b38d20346228b7e6e793a538a2deda6b4f
Parents: 89af4f1
Author: tbeerbower <tbeerbower@hortonworks.com>
Authored: Mon Jan 27 12:21:42 2014 -0500
Committer: tbeerbower <tbeerbower@hortonworks.com>
Committed: Tue Jan 28 05:06:59 2014 -0500

----------------------------------------------------------------------
 .../view/configuration/InstanceConfig.java      |  59 +++++
 .../view/configuration/ParameterConfig.java     |  70 ++++++
 .../view/configuration/PropertyConfig.java      |  56 +++++
 .../view/configuration/ResourceConfig.java      | 174 +++++++++++++
 .../view/configuration/ServletConfig.java       |  72 ++++++
 .../configuration/ServletMappingConfig.java     |  60 +++++
 .../server/view/configuration/ViewConfig.java   | 197 +++++++++++++++
 .../view/configuration/InstanceConfigTest.java  |  56 +++++
 .../view/configuration/ParameterConfigTest.java |  62 +++++
 .../view/configuration/PropertyConfigTest.java  |  60 +++++
 .../view/configuration/ResourceConfigTest.java  |  99 ++++++++
 .../view/configuration/ServletConfigTest.java   |  51 ++++
 .../configuration/ServletMappingConfigTest.java |  51 ++++
 .../view/configuration/ViewConfigTest.java      | 244 +++++++++++++++++++
 14 files changed, 1311 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/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
new file mode 100644
index 0000000..fd80922
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/InstanceConfig.java
@@ -0,0 +1,59 @@
+/**
+ * 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.view.configuration;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import java.util.List;
+
+/**
+ * View instance configuration.
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+public class InstanceConfig {
+  /**
+   * The instance name.
+   */
+  private String name;
+
+  /**
+   * The instance properties.
+   */
+  @XmlElement(name="property")
+  private List<PropertyConfig> properties;
+
+  /**
+   * Get the instance name.
+   *
+   * @return the name
+   */
+  public String getName() {
+    return name;
+  }
+
+  /**
+   * Get the instance properties.
+   *
+   * @return the instance properties
+   */
+  public List<PropertyConfig> getProperties() {
+    return properties;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ParameterConfig.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ParameterConfig.java b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ParameterConfig.java
new file mode 100644
index 0000000..97c9e22
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ParameterConfig.java
@@ -0,0 +1,70 @@
+/**
+ * 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.view.configuration;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+
+/**
+ * View parameter configuration.
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ParameterConfig {
+  /**
+   * The parameter name.
+   */
+  private String name;
+
+  /**
+   * The parameter description.
+   */
+  private String description;
+
+  /**
+   * Indicates whether or not the parameter is required.
+   */
+  private boolean required;
+
+  /**
+   * Get the parameter name.
+   *
+   * @return the name
+   */
+  public String getName() {
+    return name;
+  }
+
+  /**
+   * Get the parameter description.
+   *
+   * @return the description
+   */
+  public String getDescription() {
+    return description;
+  }
+
+  /**
+   * Indicates whether or not the parameter is required.
+   *
+   * @return true if the parameter is required; false otherwise
+   */
+  public boolean isRequired() {
+    return required;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/PropertyConfig.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/PropertyConfig.java b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/PropertyConfig.java
new file mode 100644
index 0000000..e420c40
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/PropertyConfig.java
@@ -0,0 +1,56 @@
+/**
+ * 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.view.configuration;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+
+/**
+ * View instance property configuration.
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+public class PropertyConfig {
+  /**
+   * The property key.
+   */
+  private String key;
+
+  /**
+   * The property value.
+   */
+  private String value;
+
+  /**
+   * Get the property key.
+   *
+   * @return the property key
+   */
+  public String getKey() {
+    return key;
+  }
+
+  /**
+   * Get the property value.
+   *
+   * @return the property value
+   */
+  public String getValue() {
+    return value;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ResourceConfig.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ResourceConfig.java b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ResourceConfig.java
new file mode 100644
index 0000000..8bc3de1
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ResourceConfig.java
@@ -0,0 +1,174 @@
+/**
+ * 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.view.configuration;
+
+
+import org.apache.ambari.view.ResourceProvider;
+
+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;
+
+/**
+ * View resource configuration.
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ResourceConfig {
+  /**
+   * The resource name.
+   */
+  private String name;
+
+  /**
+   * The plural name of the resource.
+   */
+  @XmlElement(name="plural-name")
+  private String pluralName;
+
+  /**
+   * The id property of the resource.
+   */
+  @XmlElement(name="id-property")
+  private String idProperty;
+
+  /**
+   * The list of sub resource names.
+   */
+  @XmlElement(name="sub-resource-name")
+  private List<String> subResourceNames;
+
+  /**
+   * The resource provider class name.
+   */
+  @XmlElement(name="provider-class")
+  private String provider;
+
+  /**
+   * The resource provider class.
+   */
+  private Class<? extends ResourceProvider> providerClass = null;
+
+  /**
+   * The resource service class name.
+   */
+  @XmlElement(name="service-class")
+  private String service;
+
+  /**
+   * The resource service class.
+   */
+  private Class<?> serviceClass = null;
+
+  /**
+   * The resource service class name.
+   */
+  @XmlElement(name="resource-class")
+  private String resource;
+
+  /**
+   * The resource service class.
+   */
+  private Class<?> resourceClass = null;
+
+  /**
+   * Get the resource name.
+   *
+   * @return the resource name
+   */
+  public String getName() {
+    return name;
+  }
+
+  /**
+   * Get the resource plural name.
+   *
+   * @return the plural name
+   */
+  public String getPluralName() {
+    return pluralName;
+  }
+
+  /**
+   * Get the id property of the resource.
+   *
+   * @return the id property
+   */
+  public String getIdProperty() {
+    return idProperty;
+  }
+
+  /**
+   * Get the list of sub-resource names.
+   *
+   * @return the sub-resource names
+   */
+  public List<String> getSubResourceNames() {
+    return subResourceNames == null ? Collections.<String>emptyList() : subResourceNames;
+  }
+
+  /**
+   * Get the resource provider class.
+   *
+   * @param cl  the class loader
+   *
+   * @return the resource provider class
+   *
+   * @throws ClassNotFoundException if the class can not be loaded
+   */
+  public Class<? extends ResourceProvider> getProviderClass(ClassLoader cl) throws ClassNotFoundException {
+    if (providerClass == null) {
+      providerClass = cl.loadClass(provider).asSubclass(ResourceProvider.class);
+    }
+    return providerClass;
+  }
+
+  /**
+   * Get the resource service class.
+   *
+   * @param cl  the class loader
+   *
+   * @return the resource service class
+   *
+   * @throws ClassNotFoundException if the class can not be loaded
+   */
+  public Class<?> getServiceClass(ClassLoader cl) throws ClassNotFoundException {
+    if (serviceClass == null) {
+      serviceClass = cl.loadClass(service);
+    }
+    return serviceClass;
+  }
+
+  /**
+   * Get the resource class.
+   *
+   * @param cl  the class loader
+   *
+   * @return the resource class
+   *
+   * @throws ClassNotFoundException if the class can not be loaded
+   */
+  public Class<?> getResourceClass(ClassLoader cl) throws ClassNotFoundException {
+    if (resourceClass == null) {
+      resourceClass = cl.loadClass(resource);
+    }
+    return resourceClass;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ServletConfig.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ServletConfig.java b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ServletConfig.java
new file mode 100644
index 0000000..a62d0f3
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ServletConfig.java
@@ -0,0 +1,72 @@
+/**
+ * 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.view.configuration;
+
+import javax.servlet.http.HttpServlet;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+
+/**
+ *  View servlet mapping.
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ServletConfig {
+  /**
+   * The servlet name.
+   */
+  @XmlElement(name="servlet-name")
+  private String name;
+
+  /**
+   * The servlet class name.
+   */
+  @XmlElement(name="servlet-path")
+  private String path;
+
+  /**
+   * The servlet class.
+   */
+  private Class<? extends HttpServlet> servletClass = null;
+
+  /**
+   * The servlet name.
+   *
+   * @return the servlet name
+   */
+  public String getName() {
+    return name;
+  }
+
+  /**
+   * Get the servlet class.
+   *
+   * @param cl  the class loader
+   *
+   * @return the servlet class
+   *
+   * @throws ClassNotFoundException if the class can not be loaded
+   */
+  public Class<? extends HttpServlet> getServletClass(ClassLoader cl) throws ClassNotFoundException {
+    if (servletClass == null) {
+      servletClass = cl.loadClass(path).asSubclass(HttpServlet.class);
+    }
+    return servletClass;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ServletMappingConfig.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ServletMappingConfig.java b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ServletMappingConfig.java
new file mode 100644
index 0000000..cc11e07
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ServletMappingConfig.java
@@ -0,0 +1,60 @@
+/**
+ * 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.view.configuration;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+
+/**
+ * View servlet mapping configuration.
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ServletMappingConfig {
+
+  /**
+   * The servlet name.
+   */
+  @XmlElement(name="servlet-name")
+  private String name;
+
+  /**
+   * The URL pattern.
+   */
+  @XmlElement(name="url-pattern")
+  private String urlPattern;
+
+  /**
+   * Get the servlet name.
+   *
+   * @return the servlet name
+   */
+  public String getName() {
+    return name;
+  }
+
+  /**
+   * Get the URL pattern.
+   *
+   * @return the URL pattern
+   */
+  public String getUrlPattern() {
+    return urlPattern;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/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
new file mode 100644
index 0000000..daac81f
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ViewConfig.java
@@ -0,0 +1,197 @@
+/**
+ * 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.view.configuration;
+
+import javax.servlet.http.HttpServlet;
+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.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * View configuration.
+ */
+@XmlRootElement(name="view")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ViewConfig {
+  /**
+   * The unique view name.
+   */
+  private String name;
+
+  /**
+   * The public view name.
+   */
+  private String label;
+
+  /**
+   * The view version.
+   */
+  private String version;
+
+  /**
+   * The list of view parameters.
+   */
+  @XmlElement(name="parameter")
+  private List<ParameterConfig> parameters;
+
+  /**
+   * The list of view resources.
+   */
+  @XmlElement(name="resource")
+  private List<ResourceConfig> resources;
+
+  /**
+   * The list of view instances.
+   */
+  @XmlElement(name="instance")
+  private List<InstanceConfig> instances;
+
+  /**
+   * The list of servlets.
+   */
+  @XmlElement(name="servlet")
+  private List<ServletConfig> servlets;
+
+  /**
+   * The mapping of servlet names to servlet classes.
+   */
+  public Map<String, Class<? extends HttpServlet>> servletPathMap = null;
+
+  /**
+   * The list of servlet mappings.
+   */
+  @XmlElement(name="servlet-mapping")
+  private List<ServletMappingConfig> mappings;
+
+  /**
+   * The mapping of servlet names to URL patterns.
+   */
+  public Map<String, String> servletURLPatternMap = null;
+
+  /**
+   * Get the unique name.
+   *
+   * @return the view name
+   */
+  public String getName() {
+    return name;
+  }
+
+  /**
+   * Get the public view name.
+   *
+   * @return the view label
+   */
+  public String getLabel() {
+    return label;
+  }
+
+  /**
+   * Get the view version.
+   *
+   * @return the version
+   */
+  public String getVersion() {
+    return version;
+  }
+
+  /**
+   * Get the list of view parameters.
+   *
+   * @return the list of parameters
+   */
+  public List<ParameterConfig> getParameters() {
+    return parameters;
+  }
+
+  /**
+   * Get the list of view resources.
+   *
+   * @return return the list of resources
+   */
+  public List<ResourceConfig> getResources() {
+    return resources;
+  }
+
+  /**
+   * Get the list of view instances.
+   *
+   * @return the list of view instances
+   */
+  public List<InstanceConfig> getInstances() {
+    return instances;
+  }
+
+  /**
+   * Get the list of servlets.
+   *
+   * @return the list of view servlets
+   */
+  public List<ServletConfig> getServlets() {
+    return servlets;
+  }
+
+  /**
+   * Get the list of servlet mappings.
+   *
+   * @return the list of view servlet mappings.
+   */
+  public List<ServletMappingConfig> getMappings() {
+    return mappings;
+  }
+
+  /**
+   * Get the mapping of servlet names to servlet classes.
+   *
+   * @param cl  the class loader
+   *
+   * @return the mapping of servlet names to servlet classes
+   *
+   * @throws ClassNotFoundException if a servlet class can not be loaded
+   */
+  public synchronized Map<String, Class<? extends HttpServlet>> getServletPathMap(ClassLoader cl)
+      throws ClassNotFoundException{
+    if (servletPathMap == null) {
+      servletPathMap = new HashMap<String, Class<? extends HttpServlet>>();
+      for (ServletConfig servletConfig : servlets) {
+        servletPathMap.put(servletConfig.getName(), servletConfig.getServletClass(cl));
+      }
+    }
+    return servletPathMap;
+  }
+
+  /**
+   * Get the mapping of servlet names to URL patterns.
+   *
+   * @return the mapping of servlet names to URL patterns
+   */
+  public synchronized Map<String, String> getServletURLPatternMap() {
+    if (servletURLPatternMap == null) {
+      servletURLPatternMap = new HashMap<String, String>();
+      for (ServletMappingConfig servletMappingConfig : mappings) {
+        servletURLPatternMap.put(servletMappingConfig.getName(), servletMappingConfig.getUrlPattern());
+      }
+    }
+    return servletURLPatternMap;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/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
new file mode 100644
index 0000000..28fe7f3
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/InstanceConfigTest.java
@@ -0,0 +1,56 @@
+/**
+ * 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.view.configuration;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.xml.bind.JAXBException;
+import java.util.List;
+
+/**
+ * InstanceConfig tests.
+ */
+public class InstanceConfigTest {
+  @Test
+  public void testGetName() throws Exception {
+    List<InstanceConfig> instances = getInstanceConfigs();
+
+    Assert.assertEquals(2, instances.size());
+    Assert.assertEquals("INSTANCE1", instances.get(0).getName());
+    Assert.assertEquals("INSTANCE2", instances.get(1).getName());
+  }
+
+  @Test
+  public void testGetProperties() throws Exception {
+    List<InstanceConfig> instances = getInstanceConfigs();
+
+    Assert.assertEquals(2, instances.size());
+    List<PropertyConfig> properties = instances.get(0).getProperties();
+    Assert.assertEquals(2, properties.size());
+
+    properties = instances.get(1).getProperties();
+    Assert.assertEquals(1, properties.size());
+  }
+
+  public static List<InstanceConfig> getInstanceConfigs() throws JAXBException {
+    ViewConfig config = ViewConfigTest.getConfig();
+    return config.getInstances();
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ParameterConfigTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ParameterConfigTest.java b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ParameterConfigTest.java
new file mode 100644
index 0000000..7069d37
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ParameterConfigTest.java
@@ -0,0 +1,62 @@
+/**
+ * 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.view.configuration;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.xml.bind.JAXBException;
+import java.util.List;
+
+/**
+ * ParameterConfig tests.
+ */
+public class ParameterConfigTest {
+  @Test
+  public void testGetName() throws Exception {
+    List<ParameterConfig> parameters = getParameterConfigs();
+
+    Assert.assertEquals(2, parameters.size());
+    Assert.assertEquals("p1", parameters.get(0).getName());
+    Assert.assertEquals("p2", parameters.get(1).getName());
+  }
+
+  @Test
+  public void testGetDescription() throws Exception {
+    List<ParameterConfig> parameters = getParameterConfigs();
+
+    Assert.assertEquals(2, parameters.size());
+    Assert.assertEquals("Parameter 1.", parameters.get(0).getDescription());
+    Assert.assertEquals("Parameter 2.", parameters.get(1).getDescription());
+  }
+
+  @Test
+  public void testIsRequired() throws Exception {
+    List<ParameterConfig> parameters = getParameterConfigs();
+
+    Assert.assertEquals(2, parameters.size());
+    Assert.assertEquals(true, parameters.get(0).isRequired());
+    Assert.assertEquals(false, parameters.get(1).isRequired());
+  }
+
+  public static List<ParameterConfig> getParameterConfigs() throws JAXBException {
+    ViewConfig viewConfig = ViewConfigTest.getConfig();
+    return viewConfig.getParameters ();
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/PropertyConfigTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/PropertyConfigTest.java b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/PropertyConfigTest.java
new file mode 100644
index 0000000..ce8b390
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/PropertyConfigTest.java
@@ -0,0 +1,60 @@
+/**
+ * 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.view.configuration;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.List;
+
+/**
+ * PropertyConfig tests.
+ */
+public class PropertyConfigTest {
+  @Test
+  public void testGetKey() throws Exception {
+
+    List<InstanceConfig> instanceConfigs = InstanceConfigTest.getInstanceConfigs();
+    for (InstanceConfig instanceConfig : instanceConfigs) {
+      List<PropertyConfig> propertyConfigs = instanceConfig.getProperties();
+
+      Assert.assertTrue(propertyConfigs.size() <= 2);
+      Assert.assertEquals("p1", propertyConfigs.get(0).getKey());
+
+      if (propertyConfigs.size() == 2) {
+        Assert.assertEquals("p2", propertyConfigs.get(1).getKey());
+      }
+    }
+  }
+
+  @Test
+  public void testGetValue() throws Exception {
+    List<InstanceConfig> instanceConfigs = InstanceConfigTest.getInstanceConfigs();
+    for (InstanceConfig instanceConfig : instanceConfigs) {
+      List<PropertyConfig> propertyConfigs = instanceConfig.getProperties();
+
+      Assert.assertTrue(propertyConfigs.size() <= 2);
+      Assert.assertTrue(propertyConfigs.get(0).getValue().startsWith("v1-"));
+
+      if (propertyConfigs.size() == 2) {
+        Assert.assertTrue(propertyConfigs.get(1).getValue().startsWith("v2-"));
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ResourceConfigTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ResourceConfigTest.java b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ResourceConfigTest.java
new file mode 100644
index 0000000..c9cc5dd
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ResourceConfigTest.java
@@ -0,0 +1,99 @@
+/**
+ * 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.view.configuration;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.xml.bind.JAXBException;
+import java.util.List;
+
+/**
+ * ResourceConfig tests.
+ */
+public class ResourceConfigTest {
+  @Test
+  public void testGetName() throws Exception {
+    List<ResourceConfig> resourceConfigs = getResourceConfigs();
+
+    Assert.assertEquals(2, resourceConfigs.size());
+    Assert.assertEquals("resource", resourceConfigs.get(0).getName());
+    Assert.assertEquals("subresource", resourceConfigs.get(1).getName());
+  }
+
+  @Test
+  public void testGetPluralName() throws Exception {
+    List<ResourceConfig> resourceConfigs = getResourceConfigs();
+
+    Assert.assertEquals(2, resourceConfigs.size());
+    Assert.assertEquals("resources", resourceConfigs.get(0).getPluralName());
+    Assert.assertEquals("subresources", resourceConfigs.get(1).getPluralName());
+  }
+
+  @Test
+  public void testGetIdProperty() throws Exception {
+    List<ResourceConfig> resourceConfigs = getResourceConfigs();
+
+    Assert.assertEquals(2, resourceConfigs.size());
+    Assert.assertEquals("id", resourceConfigs.get(0).getIdProperty());
+    Assert.assertEquals("id", resourceConfigs.get(1).getIdProperty());
+  }
+
+  @Test
+  public void testGetSubResourceNames() throws Exception {
+    List<ResourceConfig> resourceConfigs = getResourceConfigs();
+
+    Assert.assertEquals(2, resourceConfigs.size());
+    Assert.assertEquals(1, resourceConfigs.get(0).getSubResourceNames().size());
+    Assert.assertEquals("subresource", resourceConfigs.get(0).getSubResourceNames().get(0));
+    Assert.assertEquals(0, resourceConfigs.get(1).getSubResourceNames().size());
+  }
+
+  @Test
+  public void testGetProviderClass() throws Exception {
+    List<ResourceConfig> resourceConfigs = getResourceConfigs();
+
+    Assert.assertEquals(2, resourceConfigs.size());
+    Assert.assertTrue(resourceConfigs.get(0).getProviderClass(getClass().getClassLoader()).equals(ViewConfigTest.MyResourceProvider.class));
+    Assert.assertTrue(resourceConfigs.get(1).getProviderClass(getClass().getClassLoader()).equals(ViewConfigTest.MyResourceProvider.class));
+  }
+
+  @Test
+  public void testGetServiceClass() throws Exception {
+    List<ResourceConfig> resourceConfigs = getResourceConfigs();
+
+    Assert.assertEquals(2, resourceConfigs.size());
+    Assert.assertTrue(resourceConfigs.get(0).getResourceClass(getClass().getClassLoader()).equals(ViewConfigTest.MyResource.class));
+    Assert.assertTrue(resourceConfigs.get(1).getResourceClass(getClass().getClassLoader()).equals(ViewConfigTest.MyResource.class));
+  }
+
+  @Test
+  public void testGetResourceClass() throws Exception {
+    List<ResourceConfig> resourceConfigs = getResourceConfigs();
+
+    Assert.assertEquals(2, resourceConfigs.size());
+    Assert.assertTrue(resourceConfigs.get(0).getServiceClass(getClass().getClassLoader()).equals(ViewConfigTest.MyResourceService.class));
+    Assert.assertTrue(resourceConfigs.get(1).getServiceClass(getClass().getClassLoader()).equals(ViewConfigTest.MyResourceService.class));
+  }
+
+  public static List<ResourceConfig> getResourceConfigs() throws JAXBException {
+    ViewConfig viewConfig = ViewConfigTest.getConfig();
+    return viewConfig.getResources ();
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ServletConfigTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ServletConfigTest.java b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ServletConfigTest.java
new file mode 100644
index 0000000..8cf0ff7
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ServletConfigTest.java
@@ -0,0 +1,51 @@
+/**
+ * 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.view.configuration;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.xml.bind.JAXBException;
+import java.util.List;
+
+/**
+ * ServletConfig tests.
+ */
+public class ServletConfigTest {
+  @Test
+  public void testGetName() throws Exception {
+    List<ServletConfig> servletConfigs = getServletConfigs();
+
+    Assert.assertEquals(1, servletConfigs.size());
+    Assert.assertEquals("MyViewServlet", servletConfigs.get(0).getName());
+  }
+
+  @Test
+  public void testGetServletClass() throws Exception {
+    List<ServletConfig> servletConfigs = getServletConfigs();
+
+    Assert.assertEquals(1, servletConfigs.size());
+    Assert.assertTrue(servletConfigs.get(0).getServletClass(getClass().getClassLoader()).equals(ViewConfigTest.MyViewServlet.class));
+  }
+
+  public static List<ServletConfig> getServletConfigs() throws JAXBException {
+    ViewConfig viewConfig = ViewConfigTest.getConfig();
+    return viewConfig.getServlets();
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ServletMappingConfigTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ServletMappingConfigTest.java b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ServletMappingConfigTest.java
new file mode 100644
index 0000000..c0447bb
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ServletMappingConfigTest.java
@@ -0,0 +1,51 @@
+/**
+ * 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.view.configuration;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.xml.bind.JAXBException;
+import java.util.List;
+
+/**
+ * ServletMappingConfig tests.
+ */
+public class ServletMappingConfigTest {
+  @Test
+  public void testGetName() throws Exception {
+    List<ServletMappingConfig> mappingConfigs = getServletMappingConfigs();
+
+    Assert.assertEquals(1, mappingConfigs.size());
+    Assert.assertEquals("MyViewServlet", mappingConfigs.get(0).getName());
+  }
+
+  @Test
+  public void testGetUrlPattern() throws Exception {
+    List<ServletMappingConfig> mappingConfigs = getServletMappingConfigs();
+
+    Assert.assertEquals(1, mappingConfigs.size());
+    Assert.assertEquals("/ui", mappingConfigs.get(0).getUrlPattern());
+  }
+
+  public static List<ServletMappingConfig> getServletMappingConfigs() throws JAXBException {
+    ViewConfig viewConfig = ViewConfigTest.getConfig();
+    return viewConfig.getMappings();
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/3d7270b3/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
new file mode 100644
index 0000000..0ca6764
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ViewConfigTest.java
@@ -0,0 +1,244 @@
+/**
+ * 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.view.configuration;
+
+import org.apache.ambari.view.NoSuchResourceException;
+import org.apache.ambari.view.ReadRequest;
+import org.apache.ambari.view.ResourceAlreadyExistsException;
+import org.apache.ambari.view.ResourceProvider;
+import org.apache.ambari.view.SystemException;
+import org.apache.ambari.view.UnsupportedPropertyException;
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.servlet.http.HttpServlet;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * ViewConfig tests.
+ */
+public class ViewConfigTest {
+
+  private static String xml = "<view>\n" +
+      "    <name>MY_VIEW</name>\n" +
+      "    <label>My View!</label>\n" +
+      "    <version>1.0.0</version>\n" +
+      "    <parameter>\n" +
+      "        <name>p1</name>\n" +
+      "        <description>Parameter 1.</description>\n" +
+      "        <required>true</required>\n" +
+      "    </parameter>\n" +
+      "    <parameter>\n" +
+      "        <name>p2</name>\n" +
+      "        <description>Parameter 2.</description>\n" +
+      "        <required>false</required>\n" +
+      "    </parameter>\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" +
+      "    <resource>\n" +
+      "        <name>subresource</name>\n" +
+      "        <plural-name>subresources</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" +
+      "    </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" +
+      "            <key>p1</key>\n" +
+      "            <value>v1-1</value>\n" +
+      "        </property>\n" +
+      "        <property>\n" +
+      "            <key>p2</key>\n" +
+      "            <value>v2-1</value>\n" +
+      "        </property>\n" +
+      "    </instance>\n" +
+      "    <instance>\n" +
+      "        <name>INSTANCE2</name>\n" +
+      "        <property>\n" +
+      "            <key>p1</key>\n" +
+      "            <value>v1-2</value>\n" +
+      "        </property>\n" +
+      "    </instance>\n" +
+      "</view>";
+
+
+  @Test
+  public void testGetName() throws Exception {
+    ViewConfig config = getConfig();
+    Assert.assertEquals("MY_VIEW", config.getName());
+  }
+
+  @Test
+  public void testGetLabel() throws Exception {
+    ViewConfig config = getConfig();
+    Assert.assertEquals("My View!", config.getLabel());
+  }
+
+  @Test
+  public void testGetVersion() throws Exception {
+    ViewConfig config = getConfig();
+    Assert.assertEquals("1.0.0", config.getVersion());
+  }
+
+  @Test
+  public void testGetParameters() throws Exception {
+    ViewConfig config = getConfig();
+    List<ParameterConfig> parameters = config.getParameters();
+    Assert.assertEquals(2, parameters.size());
+    Assert.assertEquals("p1", parameters.get(0).getName());
+    Assert.assertEquals("p2", parameters.get(1).getName());
+  }
+
+  @Test
+  public void testGetResources() throws Exception {
+    ViewConfig config = getConfig();
+    List<ResourceConfig> resources = config.getResources();
+    Assert.assertEquals(2, resources.size());
+    Assert.assertEquals("resource", resources.get(0).getName());
+    Assert.assertEquals("subresource", resources.get(1).getName());
+  }
+
+  @Test
+  public void testGetInstances() throws Exception {
+    ViewConfig config = getConfig();
+    List<InstanceConfig> instances = config.getInstances();
+    Assert.assertEquals(2, instances.size());
+    Assert.assertEquals("INSTANCE1", instances.get(0).getName());
+    Assert.assertEquals("INSTANCE2", instances.get(1).getName());
+  }
+
+  @Test
+  public void testGetServlets() throws Exception {
+    ViewConfig config = getConfig();
+    List<ServletConfig> servlets = config.getServlets();
+    Assert.assertEquals(1, servlets.size());
+    Assert.assertEquals("MyViewServlet", servlets.get(0).getName());
+  }
+
+  @Test
+  public void testGetMappings() throws Exception {
+    ViewConfig config = getConfig();
+    List<ServletMappingConfig> mappings = config.getMappings();
+    Assert.assertEquals(1, mappings.size());
+    Assert.assertEquals("MyViewServlet", mappings.get(0).getName());
+  }
+
+  @Test
+  public void testGetServletPathMap() throws Exception {
+    ViewConfig config = getConfig();
+    Map<String, Class<? extends HttpServlet>> servletPathMap = config.getServletPathMap(getClass().getClassLoader());
+
+    Assert.assertEquals(1, servletPathMap.size());
+    Assert.assertEquals("MyViewServlet", servletPathMap.keySet().iterator().next());
+    Assert.assertTrue(servletPathMap.values().iterator().next().equals(MyViewServlet.class));
+  }
+
+  @Test
+  public void testGetServletURLPatternMap() throws Exception {
+    ViewConfig config = getConfig();
+    Map<String, String> servletURLPatternMap = config.getServletURLPatternMap();
+
+    Assert.assertEquals(1, servletURLPatternMap.size());
+    Assert.assertEquals("MyViewServlet", servletURLPatternMap.keySet().iterator().next());
+    Assert.assertEquals("/ui", servletURLPatternMap.values().iterator().next());
+  }
+
+  public static  ViewConfig getConfig() throws JAXBException {
+    InputStream configStream =  new ByteArrayInputStream(xml.getBytes());
+    JAXBContext jaxbContext = JAXBContext.newInstance(ViewConfig.class);
+    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+    return (ViewConfig) unmarshaller.unmarshal(configStream);
+  }
+
+  public static class MyViewServlet extends HttpServlet {
+    // nothing
+  }
+
+  public static class MyResource {
+    private String id;
+
+    public String getId() {
+      return id;
+    }
+
+    public void setId(String id) {
+      this.id = id;
+    }
+  }
+
+  public static class MyResourceProvider implements ResourceProvider<MyResource> {
+
+    @Override
+    public MyResource getResource(String resourceId, Set<String> properties)
+        throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
+      return null;
+    }
+
+    @Override
+    public Set<MyResource> getResources(ReadRequest request)
+        throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
+      return null;
+    }
+
+    @Override
+    public void createResource(String resourceId, Map<String, Object> properties)
+        throws SystemException, ResourceAlreadyExistsException, NoSuchResourceException, UnsupportedPropertyException {
+    }
+
+    @Override
+    public boolean updateResource(String resourceId, Map<String, Object> properties)
+        throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
+      return false;
+    }
+
+    @Override
+    public boolean deleteResource(String resourceId)
+        throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
+      return false;
+    }
+  }
+
+  public static class MyResourceService {
+    // nothing
+  }
+}


Mime
View raw message