Updated Branches:
  refs/heads/master 21fcbcd30 -> 04c2e1c35

JCLOUDS-38: Removed servlet project and unused constants


Project: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/commit/04c2e1c3
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/tree/04c2e1c3
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/diff/04c2e1c3

Branch: refs/heads/master
Commit: 04c2e1c356d05625f8f9b2e09ee122f8fef0ddef
Parents: 21fcbcd
Author: Ignasi Barrera <[email protected]>
Authored: Tue Jun 4 09:47:25 2013 +0200
Committer: Ignasi Barrera <[email protected]>
Committed: Tue Jun 4 17:47:41 2013 +0200

----------------------------------------------------------------------
 .../org/jclouds/chef/config/ChefProperties.java    |    5 -
 pom.xml                                            |    1 -
 servlet/pom.xml                                    |   64 ------
 .../chef/servlet/ChefRegistrationListener.java     |  144 -------------
 .../servlet/functions/InitParamsToProperties.java  |   48 -----
 .../ohai/servlet/config/ServletOhaiModule.java     |   41 ----
 .../suppliers/ServletContextInfoSupplier.java      |   49 -----
 .../servlet/suppliers/ServletContextSupplier.java  |   50 -----
 .../suppliers/ServletContextInfoSupplierTest.java  |  160 ---------------
 9 files changed, 0 insertions(+), 562 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/04c2e1c3/core/src/main/java/org/jclouds/chef/config/ChefProperties.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/jclouds/chef/config/ChefProperties.java 
b/core/src/main/java/org/jclouds/chef/config/ChefProperties.java
index 3618ef6..75b3aa8 100644
--- a/core/src/main/java/org/jclouds/chef/config/ChefProperties.java
+++ b/core/src/main/java/org/jclouds/chef/config/ChefProperties.java
@@ -30,11 +30,6 @@ public interface ChefProperties {
     */
    public static final String CHEF_LOGGER = "jclouds.chef";
 
-   public static final String CHEF_SERVICE_CLIENT = "chef.service-api";
-   public static final String CHEF_NODE = "chef.node";
-   public static final String CHEF_NODE_PATTERN = "chef.node-pattern";
-   public static final String CHEF_RUN_LIST = "chef.run-list";
-
    /**
     * Ddatabag that holds chef bootstrap hints, should be a json ball in the
     * following format:

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/04c2e1c3/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index cf030f0..4c91831 100644
--- a/pom.xml
+++ b/pom.xml
@@ -33,7 +33,6 @@
   <modules>
     <module>project</module>
     <module>core</module>
-    <module>servlet</module>
     <module>compute</module>
     <module>labs</module>
   </modules>

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/04c2e1c3/servlet/pom.xml
----------------------------------------------------------------------
diff --git a/servlet/pom.xml b/servlet/pom.xml
deleted file mode 100644
index f03659f..0000000
--- a/servlet/pom.xml
+++ /dev/null
@@ -1,64 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
-    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.
-
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
-  <modelVersion>4.0.0</modelVersion>
-  <parent>
-    <groupId>org.apache.jclouds.chef</groupId>
-    <artifactId>chef-parent</artifactId>
-    <version>1.7.0-SNAPSHOT</version>
-    <relativePath>../project/pom.xml</relativePath>
-  </parent>
-  <artifactId>chef-servlet</artifactId>
-  <name>JClouds Chef :: Servlet</name>
-  <description>jclouds components to access chef from a servlet 
container</description>
-
-  <properties>
-    <jclouds.osgi.import>
-      org.jclouds;version=${jclouds.version},
-      org.jclouds*;version=${jclouds.version},
-      *
-    </jclouds.osgi.import>
-    <jclouds.osgi.export>
-      org.jclouds.chef.servlet*;version=${project.version};-noimport:=true,
-      org.jclouds.ohai.servlet*;version=${project.version};-noimport:=true,
-    </jclouds.osgi.export>
-  </properties>
-
-  <dependencies>
-    <dependency>
-      <groupId>org.apache.jclouds.api</groupId>
-      <artifactId>chef</artifactId>
-      <version>${project.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.jclouds</groupId>
-      <artifactId>jclouds-core</artifactId>
-      <version>${jclouds.version}</version>
-      <type>test-jar</type>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.geronimo.specs</groupId>
-      <artifactId>geronimo-servlet_2.5_spec</artifactId>
-      <version>1.2</version>
-      <scope>provided</scope>
-    </dependency>
-  </dependencies>
-</project>

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/04c2e1c3/servlet/src/main/java/org/jclouds/chef/servlet/ChefRegistrationListener.java
----------------------------------------------------------------------
diff --git 
a/servlet/src/main/java/org/jclouds/chef/servlet/ChefRegistrationListener.java 
b/servlet/src/main/java/org/jclouds/chef/servlet/ChefRegistrationListener.java
deleted file mode 100644
index 67b614b..0000000
--- 
a/servlet/src/main/java/org/jclouds/chef/servlet/ChefRegistrationListener.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * 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.jclouds.chef.servlet;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.collect.Sets.newHashSet;
-import static java.util.Collections.singleton;
-import static org.jclouds.chef.config.ChefProperties.CHEF_NODE;
-import static org.jclouds.chef.config.ChefProperties.CHEF_NODE_PATTERN;
-import static org.jclouds.chef.config.ChefProperties.CHEF_RUN_LIST;
-import static org.jclouds.chef.config.ChefProperties.CHEF_SERVICE_CLIENT;
-
-import java.util.Properties;
-import java.util.Set;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-
-import org.jclouds.ContextBuilder;
-import org.jclouds.chef.ChefApi;
-import org.jclouds.chef.ChefApiMetadata;
-import org.jclouds.chef.ChefContext;
-import org.jclouds.chef.ChefService;
-import org.jclouds.chef.domain.Node;
-import org.jclouds.chef.servlet.functions.InitParamsToProperties;
-import org.jclouds.logging.Logger;
-import org.jclouds.logging.jdk.JDKLogger;
-
-import com.google.common.base.Splitter;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.io.Closeables;
-import com.google.inject.AbstractModule;
-
-/**
- * Registers a new node in Chef and binds its name to
- * {@link ChefConstants.CHEF_NODE}, its role to {@link ChefConstants.CHEF_ROLE}
- * and the {@link ChefService} for the client to
- * {@link ChefConstants.CHEF_SERVICE_CLIENT} upon initialized. Deletes the node
- * and client when the context is destroyed.
- * 
- * @author Adrian Cole
- */
-public class ChefRegistrationListener implements ServletContextListener {
-
-   private Logger logger = new 
JDKLogger.JDKLoggerFactory().getLogger(ChefRegistrationListener.class.getName());
-
-   @Override
-   public void contextInitialized(ServletContextEvent servletContextEvent) {
-      try {
-         logger.debug("starting initialization");
-         Properties overrides = 
InitParamsToProperties.INSTANCE.apply(servletContextEvent.getServletContext());
-
-         logger.trace("creating client connection");
-
-         ChefService client = createService(overrides, servletContextEvent);
-         logger.debug("created client connection");
-
-         Node node;
-         String nodeName;
-         while (true) {
-            nodeName = findNextNodeName(client, 
getInitParam(servletContextEvent, CHEF_NODE_PATTERN));
-            try {
-               node = client.createNodeAndPopulateAutomaticAttributes(nodeName,
-                     Splitter.on(',').split(getInitParam(servletContextEvent, 
CHEF_RUN_LIST)));
-               break;
-            } catch (IllegalStateException ex) {
-               logger.debug("client already exists %s: %s", nodeName, 
ex.getMessage());
-            }
-         }
-
-         servletContextEvent.getServletContext().setAttribute(CHEF_NODE, node);
-         
servletContextEvent.getServletContext().setAttribute(CHEF_SERVICE_CLIENT, 
client);
-         logger.debug("initialized");
-      } catch (RuntimeException e) {
-         logger.error(e, "error registering");
-         throw e;
-      }
-   }
-
-   private String findNextNodeName(ChefService client, String pattern) {
-      ChefApi api = client.getContext().unwrapApi(ChefApi.class);
-      Set<String> nodes = api.listNodes();
-      String nodeName;
-      Set<String> names = newHashSet(nodes);
-      int index = 0;
-      while (true) {
-         nodeName = String.format(pattern, index++);
-         if (!names.contains(nodeName)) {
-            break;
-         }
-      }
-      return nodeName;
-   }
-
-   private ChefService createService(Properties props, final 
ServletContextEvent servletContextEvent) {
-      return ContextBuilder.newBuilder(new 
ChefApiMetadata()).modules(ImmutableSet.of(new AbstractModule() {
-
-         @Override
-         protected void configure() {
-            
bind(ServletContext.class).toInstance(servletContextEvent.getServletContext());
-         }
-
-      })).overrides(props).buildView(ChefContext.class).getChefService();
-   }
-
-   private static String getInitParam(ServletContextEvent servletContextEvent, 
String name) {
-      return 
checkNotNull(servletContextEvent.getServletContext().getInitParameter(name));
-   }
-
-   @SuppressWarnings("unchecked")
-   private static <T> T getContextAttributeOrNull(ServletContextEvent 
servletContextEvent, String name) {
-      return (T) servletContextEvent.getServletContext().getAttribute(name);
-   }
-
-   /**
-    * removes the node and client if found, and closes the client context.
-    */
-   @Override
-   public void contextDestroyed(ServletContextEvent servletContextEvent) {
-      ChefService client = getContextAttributeOrNull(servletContextEvent, 
CHEF_SERVICE_CLIENT);
-      Node node = getContextAttributeOrNull(servletContextEvent, CHEF_NODE);
-      if (node != null && client != null) {
-         client.deleteAllNodesInList(singleton(node.getName()));
-      }
-      if (client != null) {
-         Closeables.closeQuietly(client.getContext());
-      }
-   }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/04c2e1c3/servlet/src/main/java/org/jclouds/chef/servlet/functions/InitParamsToProperties.java
----------------------------------------------------------------------
diff --git 
a/servlet/src/main/java/org/jclouds/chef/servlet/functions/InitParamsToProperties.java
 
b/servlet/src/main/java/org/jclouds/chef/servlet/functions/InitParamsToProperties.java
deleted file mode 100644
index fe9f938..0000000
--- 
a/servlet/src/main/java/org/jclouds/chef/servlet/functions/InitParamsToProperties.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.jclouds.chef.servlet.functions;
-
-import java.util.Enumeration;
-import java.util.Properties;
-
-import javax.inject.Singleton;
-import javax.servlet.ServletContext;
-
-import com.google.common.base.Function;
-
-/**
- * 
- * @author Adrian Cole
- */
-@Singleton
-public class InitParamsToProperties
-               implements
-                       Function<ServletContext, Properties> {
-
-       public static final InitParamsToProperties INSTANCE = new 
InitParamsToProperties();
-
-       public Properties apply(ServletContext servletContext) {
-               Properties overrides = new Properties();
-               Enumeration<?> e = servletContext.getInitParameterNames();
-               while (e.hasMoreElements()) {
-                       String propertyName = e.nextElement().toString();
-                       overrides.setProperty(propertyName,
-                                       
servletContext.getInitParameter(propertyName));
-               }
-               return overrides;
-       }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/04c2e1c3/servlet/src/main/java/org/jclouds/ohai/servlet/config/ServletOhaiModule.java
----------------------------------------------------------------------
diff --git 
a/servlet/src/main/java/org/jclouds/ohai/servlet/config/ServletOhaiModule.java 
b/servlet/src/main/java/org/jclouds/ohai/servlet/config/ServletOhaiModule.java
deleted file mode 100644
index f115572..0000000
--- 
a/servlet/src/main/java/org/jclouds/ohai/servlet/config/ServletOhaiModule.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.jclouds.ohai.servlet.config;
-
-import static org.jclouds.chef.util.ChefUtils.ohaiAutomaticAttributeBinder;
-
-import org.jclouds.domain.JsonBall;
-import org.jclouds.ohai.config.multibindings.MapBinder;
-import org.jclouds.ohai.servlet.suppliers.ServletContextInfoSupplier;
-
-import com.google.common.base.Supplier;
-import com.google.inject.AbstractModule;
-
-/**
- * Wires the components needed to parse ohai data
- * 
- * @author Adrian Cole
- */
-public class ServletOhaiModule extends AbstractModule {
-
-       @Override
-       protected void configure() {
-               MapBinder<String, Supplier<JsonBall>> mapbinder = 
ohaiAutomaticAttributeBinder(binder());
-               
mapbinder.addBinding("webapp").to(ServletContextInfoSupplier.class);
-       }
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/04c2e1c3/servlet/src/main/java/org/jclouds/ohai/servlet/suppliers/ServletContextInfoSupplier.java
----------------------------------------------------------------------
diff --git 
a/servlet/src/main/java/org/jclouds/ohai/servlet/suppliers/ServletContextInfoSupplier.java
 
b/servlet/src/main/java/org/jclouds/ohai/servlet/suppliers/ServletContextInfoSupplier.java
deleted file mode 100644
index a7f6339..0000000
--- 
a/servlet/src/main/java/org/jclouds/ohai/servlet/suppliers/ServletContextInfoSupplier.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.jclouds.ohai.servlet.suppliers;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.ServletContext;
-
-import org.jclouds.chef.servlet.functions.InitParamsToProperties;
-import org.jclouds.json.Json;
-
-/**
- * 
- * @author Adrian Cole
- */
-@Singleton
-public class ServletContextInfoSupplier extends ServletContextSupplier {
-       private final InitParamsToProperties converter;
-       private final Json json;
-
-       @Inject
-       public ServletContextInfoSupplier(ServletContext servletContext,
-                       InitParamsToProperties converter, Json json) {
-               super(servletContext);
-               this.converter = converter;
-               this.json = json;
-       }
-
-       @Override
-       protected String provideJson(ServletContext servletContext) {
-               return 
String.format("{\"server_info\":\"%s\",\"init_params\":%s}",
-                               servletContext.getServerInfo(),
-                               json.toJson(converter.apply(servletContext)));
-       }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/04c2e1c3/servlet/src/main/java/org/jclouds/ohai/servlet/suppliers/ServletContextSupplier.java
----------------------------------------------------------------------
diff --git 
a/servlet/src/main/java/org/jclouds/ohai/servlet/suppliers/ServletContextSupplier.java
 
b/servlet/src/main/java/org/jclouds/ohai/servlet/suppliers/ServletContextSupplier.java
deleted file mode 100644
index 6b2504c..0000000
--- 
a/servlet/src/main/java/org/jclouds/ohai/servlet/suppliers/ServletContextSupplier.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.jclouds.ohai.servlet.suppliers;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.ServletContext;
-
-import org.jclouds.domain.JsonBall;
-
-import com.google.common.base.Supplier;
-
-/**
- * 
- * @author Adrian Cole
- */
-@Singleton
-public abstract class ServletContextSupplier implements Supplier<JsonBall> {
-       private final ServletContext servletContext;
-
-       @Inject
-       public ServletContextSupplier(ServletContext servletContext) {
-               this.servletContext = servletContext;
-       }
-
-       @Override
-       public JsonBall get() {
-               String path = servletContext.getContextPath();
-               if (path == null || path.equals(""))
-                       path = "/";
-               return new JsonBall(String.format("{\"%s\":%s}", path,
-                               provideJson(servletContext)));
-       }
-
-       protected abstract String provideJson(ServletContext servletContext);
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/04c2e1c3/servlet/src/test/java/org/jclouds/chef/servlet/suppliers/ServletContextInfoSupplierTest.java
----------------------------------------------------------------------
diff --git 
a/servlet/src/test/java/org/jclouds/chef/servlet/suppliers/ServletContextInfoSupplierTest.java
 
b/servlet/src/test/java/org/jclouds/chef/servlet/suppliers/ServletContextInfoSupplierTest.java
deleted file mode 100644
index 1d74512..0000000
--- 
a/servlet/src/test/java/org/jclouds/chef/servlet/suppliers/ServletContextInfoSupplierTest.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * 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.jclouds.chef.servlet.suppliers;
-
-import static org.easymock.EasyMock.expect;
-import static org.easymock.classextension.EasyMock.createMock;
-import static org.easymock.classextension.EasyMock.replay;
-import static org.testng.Assert.assertEquals;
-
-import java.util.Properties;
-
-import javax.servlet.ServletContext;
-
-import org.jclouds.chef.servlet.functions.InitParamsToProperties;
-import org.jclouds.json.Json;
-import org.jclouds.json.config.GsonModule;
-import org.jclouds.ohai.servlet.config.ServletOhaiModule;
-import org.jclouds.ohai.servlet.suppliers.ServletContextInfoSupplier;
-import org.testng.annotations.Test;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.Provides;
-
-/**
- * 
- * @author Adrian Cole
- */
-
-@Test(groups = {"unit"})
-public class ServletContextInfoSupplierTest {
-
-       @Test
-       public void testApply() {
-
-               final ServletContext servletContext = 
createMock(ServletContext.class);
-               final InitParamsToProperties converter = 
createMock(InitParamsToProperties.class);
-               Properties props = new Properties();
-               props.setProperty("foo", "bar");
-
-               expect(servletContext.getContextPath()).andReturn("path");
-               expect(servletContext.getServerInfo()).andReturn("serverinfo");
-               expect(converter.apply(servletContext)).andReturn(props);
-
-               replay(servletContext);
-               replay(converter);
-
-               Injector injector = Guice.createInjector(new GsonModule(),
-                               new ServletOhaiModule() {
-                                       @SuppressWarnings("unused")
-                                       @Provides
-                                       protected ServletContext 
provideServletContext() {
-                                               return servletContext;
-                                       }
-
-                                       @SuppressWarnings("unused")
-                                       @Provides
-                                       protected InitParamsToProperties 
provideInitParamsToProperties() {
-                                               return converter;
-                                       }
-                               });
-
-               Json json = injector.getInstance(Json.class);
-               ServletContextInfoSupplier ohai = injector
-                               .getInstance(ServletContextInfoSupplier.class);
-               assertEquals(json.toJson(ohai.get()),
-                               
"{\"path\":{\"server_info\":\"serverinfo\",\"init_params\":{\"foo\":\"bar\"}}}");
-
-       }
-
-       @Test
-       public void testApplyNullPath() {
-
-               final ServletContext servletContext = 
createMock(ServletContext.class);
-               final InitParamsToProperties converter = 
createMock(InitParamsToProperties.class);
-               Properties props = new Properties();
-               props.setProperty("foo", "bar");
-
-               expect(servletContext.getContextPath()).andReturn(null);
-               expect(servletContext.getServerInfo()).andReturn("serverinfo");
-               expect(converter.apply(servletContext)).andReturn(props);
-
-               replay(servletContext);
-               replay(converter);
-
-               Injector injector = Guice.createInjector(new GsonModule(),
-                               new ServletOhaiModule() {
-                                       @SuppressWarnings("unused")
-                                       @Provides
-                                       protected ServletContext 
provideServletContext() {
-                                               return servletContext;
-                                       }
-
-                                       @SuppressWarnings("unused")
-                                       @Provides
-                                       protected InitParamsToProperties 
provideInitParamsToProperties() {
-                                               return converter;
-                                       }
-                               });
-
-               Json json = injector.getInstance(Json.class);
-               ServletContextInfoSupplier ohai = injector
-                               .getInstance(ServletContextInfoSupplier.class);
-               assertEquals(json.toJson(ohai.get()),
-                               
"{\"/\":{\"server_info\":\"serverinfo\",\"init_params\":{\"foo\":\"bar\"}}}");
-
-       }
-
-       @Test
-       public void testApplyEmptyPath() {
-
-               final ServletContext servletContext = 
createMock(ServletContext.class);
-               final InitParamsToProperties converter = 
createMock(InitParamsToProperties.class);
-               Properties props = new Properties();
-               props.setProperty("foo", "bar");
-
-               expect(servletContext.getContextPath()).andReturn("");
-               expect(servletContext.getServerInfo()).andReturn("serverinfo");
-               expect(converter.apply(servletContext)).andReturn(props);
-
-               replay(servletContext);
-               replay(converter);
-
-               Injector injector = Guice.createInjector(new GsonModule(),
-                               new ServletOhaiModule() {
-                                       @SuppressWarnings("unused")
-                                       @Provides
-                                       protected ServletContext 
provideServletContext() {
-                                               return servletContext;
-                                       }
-
-                                       @SuppressWarnings("unused")
-                                       @Provides
-                                       protected InitParamsToProperties 
provideInitParamsToProperties() {
-                                               return converter;
-                                       }
-                               });
-
-               Json json = injector.getInstance(Json.class);
-               ServletContextInfoSupplier ohai = injector
-                               .getInstance(ServletContextInfoSupplier.class);
-               assertEquals(json.toJson(ohai.get()),
-                               
"{\"/\":{\"server_info\":\"serverinfo\",\"init_params\":{\"foo\":\"bar\"}}}");
-
-       }
-}

Reply via email to