Review Board 1.7.22


Closure compile all feature JavaScript as part of JUnit execution to ensure no JavaScript errors at build time

Review Request #5107 - Created May 14, 2012 and submitted

Stanton Sievers
SHINDIG-1771
Reviewers
shindig
shindig
See the JIRA for the high-level description.

My approach to doing this was to introduce a new test case in the end-to-end tests.  This way I can test with a real FeatureRegistry against the real web app.  I make a request to the JsServlet for all of the features, which will run through the compiler processors.  Because of the changes that went in for https://issues.apache.org/jira/browse/SHINDIG-1770, we will return the compile error and this will get printed as part of the JUnit assert failure, pin-pointing the exact compile problem.

Note that this does increase the time it takes to execute the EndToEndTest on the scale of tens of seconds.
Introduced some JS errors and verified that the unit test failed.  Additionally verified the reason for the failure was readily available.
http://svn.apache.org/repos/asf/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/AllJsFilter.java
New File

    
   
1
/*

    
   
2
 * Licensed to the Apache Software Foundation (ASF) under one

    
   
3
 * or more contributor license agreements.  See the NOTICE file

    
   
4
 * distributed with this work for additional information

    
   
5
 * regarding copyright ownership.  The ASF licenses this file

    
   
6
 * to you under the Apache License, Version 2.0 (the

    
   
7
 * "License"); you may not use this file except in compliance

    
   
8
 * with the License.  You may obtain a copy of the License at

    
   
9
 *

    
   
10
 *   http://www.apache.org/licenses/LICENSE-2.0

    
   
11
 *

    
   
12
 * Unless required by applicable law or agreed to in writing,

    
   
13
 * software distributed under the License is distributed on an

    
   
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

    
   
15
 * KIND, either express or implied.  See the License for the

    
   
16
 * specific language governing permissions and limitations

    
   
17
 * under the License.

    
   
18
 */

    
   
19
package org.apache.shindig.server.endtoend;

    
   
20

   

    
   
21
import java.io.IOException;

    
   
22
import java.util.Set;

    
   
23

   

    
   
24
import javax.servlet.FilterChain;

    
   
25
import javax.servlet.ServletException;

    
   
26
import javax.servlet.ServletRequest;

    
   
27
import javax.servlet.ServletResponse;

    
   
28
import javax.servlet.http.HttpServletRequest;

    
   
29
import javax.servlet.http.HttpServletResponse;

    
   
30

   

    
   
31
import org.apache.shindig.common.servlet.InjectedFilter;

    
   
32
import org.apache.shindig.gadgets.GadgetException;

    
   
33
import org.apache.shindig.gadgets.features.FeatureRegistry;

    
   
34
import org.apache.shindig.gadgets.features.FeatureRegistryProvider;

    
   
35

   

    
   
36
import com.google.common.base.Joiner;

    
   
37
import com.google.inject.Inject;

    
   
38

   

    
   
39
public class AllJsFilter extends InjectedFilter {

    
   
40

   

    
   
41
  private String allFeatures;

    
   
42

   

    
   
43
  @Inject

    
   
44
  public void setFeatureRegistryProvider(FeatureRegistryProvider provider) {

    
   
45
    try {

    
   
46
      FeatureRegistry registry = provider.get(null);

    
   
47
      Set<String> allFeatureNames = registry.getAllFeatureNames();

    
   
48
      allFeatures = Joiner.on(':').join(allFeatureNames);

    
   
49
    } catch (GadgetException e) {

    
   
50
      e.printStackTrace();

    
   
51
    }

    
   
52
  }

    
   
53

   

    
   
54
  @Override

    
   
55
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)

    
   
56
          throws IOException, ServletException {

    
   
57
    if (!(request instanceof HttpServletRequest && response instanceof HttpServletResponse)) {

    
   
58
      throw new ServletException("Only HTTP!");

    
   
59
    }

    
   
60

   

    
   
61
    HttpServletRequest req = (HttpServletRequest) request;

    
   
62
    HttpServletResponse resp = (HttpServletResponse) response;

    
   
63

   

    
   
64
    String requestURI = req.getRequestURI();

    
   
65
    if (!requestURI.contains("all-features-please.js")) {

    
   
66
      chain.doFilter(request, response);

    
   
67
    } else {

    
   
68
      String newURI = requestURI.replace("all-features-please.js", allFeatures + ".js") + "?" + req.getQueryString();

    
   
69
      resp.sendRedirect(newURI);

    
   
70
    }

    
   
71
  }

    
   
72

   

    
   
73
  public void destroy() {

    
   
74
  }

    
   
75
}

    
   
76

   
http://svn.apache.org/repos/asf/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndServer.java
Revision 1337280 New Change
 
http://svn.apache.org/repos/asf/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java
Revision 1337280 New Change
 
  1. http://svn.apache.org/repos/asf/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/AllJsFilter.java: Loading...
  2. http://svn.apache.org/repos/asf/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndServer.java: Loading...
  3. http://svn.apache.org/repos/asf/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java: Loading...