Package org.apache.shindig.gadgets.spec

Examples of org.apache.shindig.gadgets.spec.View


  }

  private Gadget makeHrefGadget(String authz) throws Exception {
    Gadget gadget = makeGadget("");
    String doc = "<Content href='" + PROXIED_HTML_HREF + "' authz='" + authz + "'/>";
    View view = new View("proxied", Arrays.asList(XmlUtil.parse(doc)), SPEC_URL);
    gadget.setCurrentView(view);
    return gadget;
  }
View Full Code Here


  public void baseElementInsertedWhenContentIsProxied() throws Exception {
    Gadget gadget = makeDefaultGadget();

    String viewUrl = "http://example.org/view.html";
    String xml = "<Content href='" + viewUrl + "'/>";
    View fakeView = new View("foo", Arrays.asList(XmlUtil.parse(xml)), SPEC_URL);
    gadget.setCurrentView(fakeView);

    config.data.put(INSERT_BASE_ELEMENT_KEY, true);

    String rewritten = rewrite(gadget, BODY_CONTENT);
View Full Code Here

 
  // Actually generates the mock gadget. Used for error (null value) tests.
  private Gadget mockGadget(String targetUrl, boolean isTypeUrl, String viewStr, String lang,
      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();
    expect(gadget.getSpec()).andReturn(spec).anyTimes();
View Full Code Here

        throw exception;
      }

      try {
        GadgetSpec spec = new GadgetSpec(Uri.parse("#"), gadgets.get(context.getUrl()));
        View view = spec.getView(context.getView());
        return new Gadget()
            .setContext(context)
            .setSpec(spec)
            .setCurrentView(view);
      } catch (GadgetException e) {
View Full Code Here

  public void baseElementInsertedWhenContentIsProxied() throws Exception {
    Gadget gadget = makeDefaultGadget();

    String viewUrl = "http://example.org/view.html";
    String xml = "<Content href='" + viewUrl + "'/>";
    View fakeView = new View("foo", Arrays.asList(XmlUtil.parse(xml)), SPEC_URL);
    gadget.setCurrentView(fakeView);

    config.data.put(INSERT_BASE_ELEMENT_KEY, true);

    String rewritten = rewrite(gadget, BODY_CONTENT);
View Full Code Here

    expect(ctx.getParameter(Param.REFRESH.getKey())).andReturn(null).anyTimes();
    expect(ctx.getDebug()).andReturn(debug).anyTimes();
    expect(ctx.getIgnoreCache()).andReturn(ignoreCache).anyTimes();
    expect(ctx.getContainer()).andReturn(CONTAINER).anyTimes();
    expect(gadget.getContext()).andReturn(ctx).anyTimes();
    View currentView = createMock(View.class);
    expect(currentView.getHref()).andReturn(curviewHref).anyTimes();
    expect(gadget.getCurrentView()).andReturn(currentView).anyTimes();
    replay(ctx, spec, currentView, gadget);
    return gadget;
  }
View Full Code Here

  }

  private Gadget makeHrefGadget(String authz) throws Exception {
    Gadget gadget = makeGadget("");
    String doc = "<Content href='" + PROXIED_HTML_HREF + "' authz='" + authz + "'/>";
    View view = new View("proxied", Arrays.asList(XmlUtil.parse(doc)), SPEC_URL);
    gadget.setCurrentView(view);
    return gadget;
  }
View Full Code Here

 
  // Actually generates the mock gadget. Used for error (null value) tests.
  protected Gadget mockGadget(String targetUrl, boolean isTypeUrl, String viewStr, String lang,
      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();
    expect(context.getToken()).andReturn(null).anyTimes();
   
    // All Features (doesn't distinguish between transitive and not)
    expect(gadget.getAllFeatures()).andReturn(features).anyTimes();
   
    // User prefs
    Map<String,UserPref> specPrefMap = Maps.newLinkedHashMap();
    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);
      specPrefMap.put(up.getName(),up);
    }
    expect(spec.getUserPrefs()).andReturn(specPrefMap).anyTimes();
    UserPrefs ctxPrefs = new UserPrefs(inPrefs);
    expect(context.getUserPrefs()).andReturn(ctxPrefs).anyTimes();
    expect(context.getParameter(Param.REFRESH.getKey())).andReturn(null).anyTimes();
    expect(view.needsUserPrefSubstitution()).andReturn(needsPrefSubst).anyTimes();
   
    // Link all the mocks together
    expect(spec.getModulePrefs()).andReturn(modulePrefs).anyTimes();
    expect(gadget.getCurrentView()).andReturn(view).anyTimes();
    expect(gadget.getSpec()).andReturn(spec).anyTimes();
View Full Code Here

  public void baseElementInsertedWhenContentIsProxied() throws Exception {
    Gadget gadget = makeDefaultGadget();

    String viewUrl = "http://example.org/view.html";
    String xml = "<Content href='" + viewUrl + "'/>";
    View fakeView = new View("foo", Arrays.asList(XmlUtil.parse(xml)), SPEC_URL);
    gadget.setCurrentView(fakeView);

    config.data.put(INSERT_BASE_ELEMENT_KEY, true);

    String rewritten = rewrite(gadget, BODY_CONTENT);
View Full Code Here

  // Actually generates the mock gadget. Used for error (null value) tests.
  protected Gadget mockGadget(String targetUrl, boolean isTypeUrl, String currentViewStr, String lang,
      String country, boolean isDebug, boolean ignoreCache, boolean sanitize, boolean cajoled,
      Map<String, String> specPrefs, Map<String, String> inPrefs, boolean needsPrefSubst, List<String> features) {
    View currentView = createMock(View.class);
    View secondView = 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(currentView.getType()).andReturn(ContentType.URL).anyTimes();
      expect(currentView.getHref()).andReturn(targetUri).anyTimes();
      expect(secondView.getType()).andReturn(ContentType.HTML).anyTimes();
      expect(spec.getUrl()).andReturn(targetUri).anyTimes();
    } else {
      expect(currentView.getType()).andReturn(ContentType.HTML).anyTimes();
      expect(spec.getUrl()).andReturn(targetUri).anyTimes();
      expect(secondView.getType()).andReturn(ContentType.URL).anyTimes();
      expect(secondView.getHref()).andReturn(targetUri).anyTimes();
    }
    expect(currentView.getName()).andReturn(currentViewStr).anyTimes();
    expect(secondView.getName()).andReturn(ANOTHER_VIEW).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();
    expect(context.getToken()).andReturn(null).anyTimes();
    expect(context.getSanitize()).andReturn(sanitize).anyTimes();
    expect(context.getCajoled()).andReturn(cajoled).anyTimes();

    // All Features (doesn't distinguish between transitive and not)
    expect(gadget.getAllFeatures()).andReturn(features).anyTimes();
    Map<String, Feature> featureMap = Maps.newLinkedHashMap();
    for (String feature : features) {
      featureMap.put(feature, null);
    }
    expect(gadget.getViewFeatures()).andReturn(featureMap).anyTimes();
    expect(modulePrefs.getFeatures()).andReturn(featureMap).anyTimes();

    // User prefs
    Map<String, UserPref> specPrefMap = Maps.newLinkedHashMap();
    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);
      specPrefMap.put(up.getName(),up);
    }
    expect(spec.getUserPrefs()).andReturn(specPrefMap).anyTimes();
    UserPrefs ctxPrefs = new UserPrefs(inPrefs);
    expect(context.getUserPrefs()).andReturn(ctxPrefs).anyTimes();
    expect(context.getParameter(Param.REFRESH.getKey())).andReturn(null).anyTimes();
    expect(currentView.needsUserPrefSubstitution()).andReturn(needsPrefSubst).anyTimes();
    expect(secondView.needsUserPrefSubstitution()).andReturn(!needsPrefSubst).anyTimes();

    Map<String, View> views = Maps.newHashMap();
    views.put(VIEW, currentView);
    views.put(ANOTHER_VIEW, secondView);
View Full Code Here

TOP

Related Classes of org.apache.shindig.gadgets.spec.View

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.