Package org.apache.shindig.gadgets

Examples of org.apache.shindig.gadgets.GadgetContext


  private void expectFeatureCalls(Gadget gadget,
                                  List<FeatureResource> gadgetResources,
                                  Set<String> externLibs,
                                  List<FeatureResource> externResources) {
    reset(featureRegistry);
    GadgetContext gadgetContext = gadget.getContext();
    List<String> gadgetFeatures = Lists.newArrayList(gadget.getDirectFeatureDeps());
    List<String> allFeatures = Lists.newArrayList(gadgetFeatures);
    allFeatures.addAll(externLibs);
    List<String> emptyList = Lists.newArrayList();
    expect(featureRegistry.getFeatureResources(same(gadgetContext), eq(externLibs), eq(emptyList)))
View Full Code Here


      String country, boolean isDebug, boolean ignoreCache, Map<String, String> specPrefs,
      Map<String, String> inPrefs, boolean needsPrefSubst, List<String> features) {
    View view = createMock(View.class);
    ModulePrefs modulePrefs = createMock(ModulePrefs.class);
    GadgetSpec spec = createMock(GadgetSpec.class);
    GadgetContext context = createMock(GadgetContext.class);
    Gadget gadget = createMock(Gadget.class);
   
    // Base URL/view.
    Uri targetUri = Uri.parse(targetUrl);
    if (isTypeUrl) {
      expect(view.getType()).andReturn(ContentType.URL).anyTimes();
      expect(view.getHref()).andReturn(targetUri).anyTimes();
    } else {
      expect(view.getType()).andReturn(ContentType.HTML).anyTimes();
      expect(spec.getUrl()).andReturn(targetUri).anyTimes();
    }
    expect(view.getName()).andReturn(viewStr).anyTimes();
   
    // Basic context info
    Locale locale = new Locale(lang, country);
    expect(context.getUrl()).andReturn(SPEC_URI).anyTimes();
    expect(context.getContainer()).andReturn(CONTAINER).anyTimes();
    expect(context.getLocale()).andReturn(locale).anyTimes();
    expect(context.getDebug()).andReturn(isDebug).anyTimes();
    expect(context.getIgnoreCache()).andReturn(ignoreCache).anyTimes();
   
    // All Features (doesn't distinguish between transitive and not)
    expect(gadget.getAllFeatures()).andReturn(features).anyTimes();
   
    // User prefs
    List<UserPref> specPrefList = Lists.newLinkedList();
    for (Map.Entry<String, String> specPref : specPrefs.entrySet()) {
      UserPref up = createMock(UserPref.class);
      expect(up.getName()).andReturn(specPref.getKey()).anyTimes();
      expect(up.getDefaultValue()).andReturn(specPref.getValue()).anyTimes();
      replay(up);
      specPrefList.add(up);
    }
    expect(spec.getUserPrefs()).andReturn(specPrefList).anyTimes();
    UserPrefs ctxPrefs = new UserPrefs(inPrefs);
    expect(context.getUserPrefs()).andReturn(ctxPrefs).anyTimes();
    expect(view.needsUserPrefSubstitution()).andReturn(needsPrefSubst).anyTimes();
   
    // Link all the mocks together
    expect(spec.getModulePrefs()).andReturn(modulePrefs).anyTimes();
    expect(gadget.getCurrentView()).andReturn(view).anyTimes();
View Full Code Here

public class HttpGadgetContextTest extends ServletTestFixture {
  @Test
  public void testIgnoreCacheParam() {
    expect(request.getParameter("nocache")).andReturn(Integer.toString(Integer.MAX_VALUE));
    replay();
    GadgetContext context = new HttpGadgetContext(request);
    assertTrue(context.getIgnoreCache());
  }
View Full Code Here

  @Test
  public void testLocale() {
    expect(request.getParameter("lang")).andReturn(Locale.CHINA.getLanguage());
    expect(request.getParameter("country")).andReturn(Locale.CHINA.getCountry());
    replay();
    GadgetContext context = new HttpGadgetContext(request);
    assertEquals(Locale.CHINA, context.getLocale());
  }
View Full Code Here

  @Test
  public void testDebug() {
    expect(request.getParameter("debug")).andReturn("1");
    replay();
    GadgetContext context = new HttpGadgetContext(request);
    assertTrue(context.getDebug());
  }
View Full Code Here

  @Test
  public void testGetParameter() {
    expect(request.getParameter("foo")).andReturn("bar");
    replay();
    GadgetContext context = new HttpGadgetContext(request);
    assertEquals("bar", context.getParameter("foo"));
  }
View Full Code Here

  @Test
  public void testGetHost() {
    expect(request.getHeader("Host")).andReturn("foo.org");
    replay();
    GadgetContext context = new HttpGadgetContext(request);
    assertEquals("foo.org", context.getHost());
  }
View Full Code Here

  @Test
  public void testGetUserIp() {
    expect(request.getRemoteAddr()).andReturn("2.3.4.5");
    replay();
    GadgetContext context = new HttpGadgetContext(request);
    assertEquals("2.3.4.5", context.getUserIp());
  }
View Full Code Here

  @Test
  public void testGetSecurityToken() throws Exception {
    SecurityToken expected = new AnonymousSecurityToken();
    expect(request.getAttribute(AuthInfo.Attribute.SECURITY_TOKEN.getId())).andReturn(expected);
    replay();
    GadgetContext context = new HttpGadgetContext(request);
    assertEquals(expected, context.getToken());
  }
View Full Code Here

  private void setupGadget(String gadgetXml) throws SpecParserException {
    gadgetSpec = new GadgetSpec(GADGET_URI, gadgetXml);
    gadget = new Gadget();
    gadget.setSpec(gadgetSpec);
    gadget.setContext(new GadgetContext() {});
    gadget.setCurrentView(gadgetSpec.getView("default"));

    content = new MutableContent(new NekoSimplifiedHtmlParser(
        new ParseModule.DOMImplementationProvider().get()), gadget.getCurrentView().getContent());
  }
View Full Code Here

TOP

Related Classes of org.apache.shindig.gadgets.GadgetContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.