Package org.opensocial.explorer.specserver.api

Examples of org.opensocial.explorer.specserver.api.GadgetSpec


  @Test
  public void testGetDefaultSpec() throws Exception {
    expectRequestAndResponse("/default");
    niceControl.replay();

    GadgetSpec mockSpec = createMock(GadgetSpec.class);
    JSONObject defaultGadgetJson = new JSONObject("{'foo':'bar'}");
    expect(mockSpec.toJSON()).andReturn(defaultGadgetJson);

    expect(registry.getDefaultGadget()).andReturn(mockSpec);
    replay(registry, mockSpec);

    servlet.doGet(request, response);
View Full Code Here


  @Test
  public void testGetSpecById() throws Exception {
    expectRequestAndResponse("/-1");
    niceControl.replay();

    GadgetSpec mockSpec = createMock(GadgetSpec.class);
    JSONObject defaultGadgetJson = new JSONObject("{'foo':'bar'}");
    expect(mockSpec.toJSON()).andReturn(defaultGadgetJson);

    expect(registry.getGadgetSpec("-1")).andReturn(mockSpec);
    replay(registry, mockSpec);

    servlet.doGet(request, response);
View Full Code Here

  @Test
  public void testGetResourceById() throws Exception {
    expectRequestAndResponse("GET", "/-1/foo.css", 200, "text/css");
    niceControl.replay();

    GadgetSpec mockSpec = createMock(GadgetSpec.class);
    Map<String, GadgetResource> cssResources = Maps.newLinkedHashMap();

    String resourceContent = "The quick brown fox jumps over the lazy dog";
    GadgetResource mockResource = createMock(GadgetResource.class);
    expect(mockResource.getName()).andReturn("foo.css");
    expect(mockResource.getContent()).andReturn(resourceContent);
    expect(mockResource.getContentType()).andReturn("text/css");

    GadgetResource mockResource2 = createMock(GadgetResource.class);
    expect(mockResource2.getName()).andStubReturn("bar.css");

    cssResources.put("bar.css", mockResource2);
    cssResources.put("foo.css", mockResource);
    expect(mockSpec.getCssResources()).andReturn(cssResources);

    expect(registry.getGadgetSpec("-1")).andReturn(mockSpec);
    replay(registry, mockSpec, mockResource, mockResource2);

    servlet.doGet(request, response);
View Full Code Here

    response.sendError(eq(404), isA(String.class));
    expectLastCall().once();

    niceControl.replay();

    GadgetSpec mockSpec = createMock(GadgetSpec.class);

    expect(mockSpec.getCssResources()).andReturn(null);
    expect(registry.getGadgetSpec("-1")).andReturn(mockSpec);
    replay(registry, mockSpec);

    servlet.doGet(request, response);
View Full Code Here

  @Test
  public void testGetTempSpec() throws Exception {
    expectRequestAndResponse("/-1");
    niceControl.replay();
   
    GadgetSpec mockSpec = createMock(GadgetSpec.class);
    JSONObject defaultGadgetJson = new JSONObject("{'foo':'bar'}");
    expect(mockSpec.toJSON()).andReturn(defaultGadgetJson);
    Map<String, GadgetSpec> tempSpecs = Maps.newConcurrentMap();
    tempSpecs.put("-1", mockSpec);
    Whitebox.setInternalState(servlet, "tempSpecs", tempSpecs);
   
    replay(registry, mockSpec);
View Full Code Here

    response.sendError(500);
    expectLastCall().once();

    niceControl.replay();

    GadgetSpec mockSpec = createMock(GadgetSpec.class);
    expect(mockSpec.toJSON()).andThrow(new JSONException("This is not JSON"));

    expect(registry.getGadgetSpec("-1")).andReturn(mockSpec);
    replay(registry, mockSpec);

    servlet.doGet(request, response);
View Full Code Here

   *
   * @throws Exception
   */
  @Test
  public void testFindResource() throws Exception {
    GadgetSpec mockSpec = createMock(GadgetSpec.class);
    Map<String, GadgetResource> jsResources, htmlResources, cssResources;
    jsResources = Maps.newLinkedHashMap();
    htmlResources = Maps.newLinkedHashMap();
    cssResources = Maps.newLinkedHashMap();

    GadgetResource jsResource = createMock(GadgetResource.class);
    expect(jsResource.getName()).andReturn("foo.js");
    jsResources.put("foo.js", jsResource);

    GadgetResource htmlResource = createMock(GadgetResource.class);
    expect(htmlResource.getName()).andReturn("bar.html");
    htmlResources.put("bar.html", htmlResource);

    GadgetResource cssResource = createMock(GadgetResource.class);
    expect(cssResource.getName()).andReturn("baz.css");
    cssResources.put("baz.css", cssResource);

    GadgetResource xmlResource = createMock(GadgetResource.class);
    expect(xmlResource.getName()).andReturn("gadget.xml").atLeastOnce();

    expect(mockSpec.getJsResources()).andReturn(jsResources);
    expect(mockSpec.getHtmlResources()).andReturn(htmlResources);
    expect(mockSpec.getCssResources()).andReturn(cssResources);
    expect(mockSpec.getGadgetResource()).andReturn(xmlResource).atLeastOnce();

    replay(mockSpec, jsResource, htmlResource, cssResource, xmlResource, registry);
    niceControl.replay();

    assertEquals(jsResource, servlet.findResource(mockSpec, "foo.js"));
View Full Code Here

  }
 
  protected void setupDefaultGadgetSpecCreation(final String specPath, final String id, final String title) {
    expect(specFactory.create(specPath)).andStubAnswer(new IAnswer<GadgetSpec>(){
      public GadgetSpec answer() throws Throwable {
        GadgetSpec mockSpec = createMock(GadgetSpec.class);
        expect(mockSpec.getPathToSpec()).andReturn(specPath).anyTimes();
        expect(mockSpec.getTitle()).andReturn(title).anyTimes();
        expect(mockSpec.getId()).andReturn(id).anyTimes();
        expect(mockSpec.isDefault()).andReturn(true).anyTimes();
        replay(mockSpec);
        return mockSpec;
      }});
  }
View Full Code Here

  }
 
  protected void setupGadgetSpecCreation(final String specPath, final String id, final String title) {
    expect(specFactory.create(specPath)).andStubAnswer(new IAnswer<GadgetSpec>(){
      public GadgetSpec answer() throws Throwable {
        GadgetSpec mockSpec = createMock(GadgetSpec.class);
        expect(mockSpec.getPathToSpec()).andReturn(specPath).anyTimes();
        expect(mockSpec.getTitle()).andReturn(title).anyTimes();
        expect(mockSpec.getId()).andReturn(id).anyTimes();
        expect(mockSpec.isDefault()).andReturn(false).anyTimes();
        replay(mockSpec);
        return mockSpec;
      }});
  }
View Full Code Here

  private static final String CLASS = DefaultGadgetSpecFactory.class.getName();
  private static final Logger LOG = Logger.getLogger(CLASS);
  private static final String METHOD = "create";
 
  public GadgetSpec create(String specPath) {
    GadgetSpec created = null;
    try {
      created = new DefaultGadgetSpec(specPath);
    } catch (Exception e) {
      LOG.logp(Level.SEVERE, CLASS, METHOD, e.getMessage(), e);
    }
View Full Code Here

TOP

Related Classes of org.opensocial.explorer.specserver.api.GadgetSpec

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.