You need to add an appropriate test for this behavior in JsonRpcHandler and
Renderer as well.

On Fri, Sep 26, 2008 at 8:29 PM, <[EMAIL PROTECTED]> wrote:

> Author: johnh
> Date: Fri Sep 26 17:29:37 2008
> New Revision: 699536
>
> URL: http://svn.apache.org/viewvc?rev=699536&view=rev
> Log:
> Inability to find a currentView no longer an Exception-causing event in
> Processor.process()
>
> In other words, a Gadget with null currentView is a valid return value. The
> receiver of the Gadget object determines whether a currentView
> is a requirement for its purposes or not. This enables JsonRpcHandler to
> return metadata about a gadget without the caller knowing in
> advance a valid view (particularly important for Gadgets without a default
> view). There is more to be done for /gadgets/metadata, but this
> reenables that functionality at least.
>
> Meanwhile, Renderer updated to check that getCurrentView() is non-null. If
> it is, an error is thrown (the same as if a ProcessingException
> were caught). HtmlRenderer doesn't perform this check since Renderer gets
> to it first.
>
>
> Modified:
>
>  
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/process/Processor.java
>
>  
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/render/Renderer.java
>
>  
> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/process/ProcessorTest.java
>
> Modified:
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/process/Processor.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/process/Processor.java?rev=699536&r1=699535&r2=699536&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/process/Processor.java
> (original)
> +++
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/process/Processor.java
> Fri Sep 26 17:29:37 2008
> @@ -83,17 +83,10 @@
>       GadgetSpec spec = gadgetSpecFactory.getGadgetSpec(context);
>       spec = substituter.substitute(context, spec);
>
> -      View view = getView(context, spec);
> -
> -      if (view == null) {
> -        throw new ProcessingException("Unable to locate an appropriate
> view in this gadget. " +
> -            "Requested: '" + context.getView() + "' Available: " +
> spec.getViews().keySet());
> -      }
> -
>       return new Gadget()
>           .setContext(context)
>           .setSpec(spec)
> -          .setCurrentView(view);
> +          .setCurrentView(getView(context, spec));
>     } catch (GadgetException e) {
>       throw new ProcessingException(e);
>     }
>
> Modified:
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/render/Renderer.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/render/Renderer.java?rev=699536&r1=699535&r2=699536&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/render/Renderer.java
> (original)
> +++
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/render/Renderer.java
> Fri Sep 26 17:29:37 2008
> @@ -72,6 +72,12 @@
>
>     try {
>       Gadget gadget = processor.process(context);
> +
> +      if (gadget.getCurrentView() == null) {
> +        return RenderingResults.error("Unable to locate an appropriate
> view in this gadget. " +
> +            "Requested: '" + gadget.getContext().getView() +
> +            "' Available: " + gadget.getSpec().getViews().keySet());
> +      }
>
>       if (gadget.getCurrentView().getType() == View.ContentType.URL) {
>         return RenderingResults.mustRedirect(getRedirect(gadget));
>
> Modified:
> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/process/ProcessorTest.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/process/ProcessorTest.java?rev=699536&r1=699535&r2=699536&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/process/ProcessorTest.java
> (original)
> +++
> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/process/ProcessorTest.java
> Fri Sep 26 17:29:37 2008
> @@ -18,6 +18,7 @@
>  package org.apache.shindig.gadgets.process;
>
>  import static org.junit.Assert.assertEquals;
> +import static org.junit.Assert.assertNull;
>  import static org.junit.Assert.assertTrue;
>
>  import org.apache.shindig.common.ContainerConfig;
> @@ -105,9 +106,10 @@
>     assertEquals(BASIC_HTML_CONTENT, gadget.getCurrentView().getContent());
>   }
>
> -  @Test(expected = ProcessingException.class)
> -  public void noSupportedViewThrows() throws Exception {
> -    processor.process(makeContext("not-real-view"));
> +  @Test
> +  public void noSupportedViewHasNoCurrentView() throws Exception {
> +    Gadget gadget = processor.process(makeContext("not-real-view"));
> +    assertNull(gadget.getCurrentView());
>   }
>
>   @Test
>
>
>

Reply via email to