Package org.opensocial.explorer.specserver.api

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


public class DefaultGadgetSpecTest {

  @Test
  public void testSimpleSpec() throws Exception {
    GadgetSpec spec = new DefaultGadgetSpec("specs/simple/spec.json");
    assertEquals("Simple Test", spec.getTitle());
    assertEquals(true, spec.isDefault());
   
    assertNotNull(spec.getGadgetResource());
    assertEquals("GadgetContent", spec.getGadgetResource().getContent());
   
    assertNull(spec.getCssResources());
    assertNull(spec.getHtmlResources());
    assertNull(spec.getJsResources());
    assertNull(spec.getEEResource());
   
    assertEquals("specs/simple/spec.json", spec.getPathToSpec());
  }
View Full Code Here


    assertEquals("specs/simple/spec.json", spec.getPathToSpec());
  }
 
  @Test
  public void testComplexSpec() throws Exception {
    GadgetSpec spec = new DefaultGadgetSpec("specs/complex/spec.json");
    assertEquals("Complex Test", spec.getTitle());
    assertEquals(false, spec.isDefault());
   
    assertNotNull(spec.getGadgetResource());
    assertEquals("GadgetContent", spec.getGadgetResource().getContent());
   
    GadgetResource eeResource = spec.getEEResource();
    assertNotNull(eeResource);
   
    Map<String, GadgetResource> cssResources = spec.getCssResources();
    Map<String, GadgetResource> htmlResources = spec.getHtmlResources();
    Map<String, GadgetResource> jsResources = spec.getJsResources();
   
    assertNotNull(cssResources);
    assertNotNull(htmlResources);
    assertNotNull(jsResources);
   
View Full Code Here

    }
  }
 
  @Test
  public void testNoIsDefaultInSpec() throws Exception {
    GadgetSpec spec = new DefaultGadgetSpec("specs/no-isdefault/spec.json");
    assertFalse(spec.isDefault());
  }
View Full Code Here

    }
  }
 
  @Test
  public void testToString() throws Exception {
    GadgetSpec spec = new DefaultGadgetSpec("specs/complex/spec.json");
    assertEquals(new JSONObject("{\"isDefault\":false," +
                                  "\"gadget\":\"gadget.xml\"," +
                                  "\"htmlFiles\":[\"complex.html\",\"complex2.html\"]," +
                                  "\"cssFiles\":[\"complex.css\",\"complex2.css\"]," +
                                  "\"jsFiles\":[\"complex.js\",\"complex2.js\"]," +
                                  "\"eeDataModel\":\"complex.json\"," +
                                  "\"title\":\"Complex Test\"}"),
            new JSONObject(spec.toString()));
  }
View Full Code Here

            new JSONObject(spec.toString()));
  }
 
  @Test
  public void testToJSON() throws Exception {
    GadgetSpec spec = new DefaultGadgetSpec("specs/complex/spec.json");
    JSONObject json = spec.toJSON();
    // FIXME: Actually test the results from this
   
    spec = new DefaultGadgetSpec("specs/simple/spec.json");
    json = spec.toJSON();
    // FIXME: Actually test the results from this
  }
View Full Code Here

public class DefaultGadgetSpecFactoryTest {
 
  @Test
  public void testCreate() throws Exception {
    GadgetSpec spec = new DefaultGadgetSpecFactory().create("specs/simple/spec.json");
    assertNotNull(spec);
  }
View Full Code Here

    assertNotNull(spec);
  }
 
  @Test
  public void testCreateWithException() throws Exception {
    GadgetSpec spec = new DefaultGadgetSpecFactory().create("specs/simple");
    assertNull(spec);
  }
View Full Code Here

      // FIXME: If there's only one spec, we should force it to be the default. This might be easier
      // to do client-side
      // TODO: What if two specs want to be the default? Last one wins? This also might be easier to
      // do client-side
      for (String specPath : getSpecRegistryContents()) {
        GadgetSpec gadgetSpec = specFactory.create(specPath);
        if (gadgetSpec == null) {
          LOG.logp(Level.WARNING, CLASS, method, "Unable to load gadget at path {0}", specPath);
          continue;
        }
        specs.put(gadgetSpec.getId(), gadgetSpec);
        if (gadgetSpec.isDefault()) {
          defaultSpec = gadgetSpec;
        }
        addToTree(gadgetSpec, specTree);
      }
    } catch (Exception e) {
View Full Code Here

      writer.flush();
      return;
    }

    if ("default".equalsIgnoreCase(specId)) { // /gadgetspec/default
      GadgetSpec spec = registry.getDefaultGadget();
      if (spec == null) {
        resp.sendError(HttpServletResponse.SC_NOT_FOUND, "No default gadget spec was found.");
      } else {
        returnJSONResult(spec, resp);
      }
      return;
    }

    // /gadgetspec/{id}[/{resource}]
    GadgetSpec spec;
    // Check the tempSpecs first then go to the registry
    if (this.tempSpecs.containsKey(specId)) {
      spec = this.tempSpecs.get(specId);
    } else {
      spec = registry.getGadgetSpec(specId);
View Full Code Here

    }
    String jsonString = getRequestBody(req);
    PrintWriter writer = null;
    try {
      JSONObject json = new JSONObject(jsonString);
      GadgetSpec tempSpec = TempGadgetSpec.parse(json);
      String tempSpecId = tempSpec.getId();
      this.tempSpecs.put(tempSpecId, tempSpec);

      // Respond with the ID of the temp spec
      JSONObject respObj = new JSONObject();
      respObj.put(GadgetSpec.SPEC_ID, tempSpecId);
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.