コード例 #1
0
ファイル: TestParser.java プロジェクト: bdaw/gatein-portal
  public void testAdapter() throws Exception {
    String config =
        ""
            + "<gatein-resources>"
            + "<module>"
            + "<name>foo_module</name>"
            + "<script><name>foo</name>"
            + "<adapter>aaa;<include>/foo_module.js</include>bbb;</adapter>"
            + "</script>"
            + "</module>"
            + "</gatein-resources>";

    JavascriptConfigParser parser =
        new JavascriptConfigParser(
            new MockServletContext("mypath"), new ByteArrayInputStream(config.getBytes("UTF-8")));
    List<ScriptResourceDescriptor> scripts = parseScripts(parser);

    ScriptResourceDescriptor des = scripts.get(0);
    Javascript.Local module = (Javascript.Local) des.getModules().get(0);
    Content[] contents = module.getContents();

    assertNotNull(contents);
    assertEquals(3, contents.length);
    assertEquals("aaa;", contents[0].getSource());
    assertFalse(contents[0].isPath());
    assertEquals("/foo_module.js", contents[1].getSource());
    assertTrue(contents[1].isPath());
  }
コード例 #2
0
ファイル: TestParser.java プロジェクト: bdaw/gatein-portal
  public void testResourceBundle() throws Exception {
    String config =
        ""
            + "<gatein-resources>"
            + "<portal>"
            + "<name>foo</name>"
            + "<module>"
            + "<script>"
            + "<name>foo_module</name>"
            + "<path>/foo_module.js</path>"
            + "<resource-bundle>my_bundle</resource-bundle>"
            + "</script>"
            + "</module>"
            + "</portal>"
            + "</gatein-resources>";

    //
    JavascriptConfigParser parser =
        new JavascriptConfigParser(
            new MockServletContext("mypath"), new ByteArrayInputStream(config.getBytes("UTF-8")));
    List<ScriptResourceDescriptor> scripts = parseScripts(parser);
    assertEquals(1, scripts.size());
    ScriptResourceDescriptor desc = scripts.get(0);
    assertEquals(new ResourceId(ResourceScope.PORTAL, "foo"), desc.getId());
    assertEquals(1, desc.getModules().size());
    Javascript.Local js = (Javascript.Local) desc.getModules().get(0);
    assertEquals("my_bundle", js.getResourceBundle());
  }
コード例 #3
0
ファイル: TestParser.java プロジェクト: bdaw/gatein-portal
  public void testLoadGroupRestriction() throws Exception {
    String config =
        ""
            + "<gatein-resources>"
            + "<scripts>"
            + "<name>foo_scripts</name>"
            + "<load-group>foo_group</load-group>"
            + "<script>"
            + "<name>foo_module</name>"
            + "<path>/foo_module.js</path>"
            + "</script>"
            + "</scripts>"
            + "<module>"
            + "<name>foo_module</name>"
            + "<load-group>foo_group</load-group>"
            + "<url>testURL</url>"
            + "</module>"
            + "</gatein-resources>";
    JavascriptConfigParser parser =
        new JavascriptConfigParser(
            new MockServletContext("mypath"), new ByteArrayInputStream(config.getBytes("UTF-8")));
    List<ScriptResourceDescriptor> scripts = parseScripts(parser);

    assertEquals(2, scripts.size());
    for (ScriptResourceDescriptor des : scripts) {
      assertNull(des.getGroup());
    }
  }
コード例 #4
0
ファイル: TestParser.java プロジェクト: bdaw/gatein-portal
  public void testModules() throws Exception {
    String config =
        ""
            + "<gatein-resources>"
            + "<portal>"
            + "<name>foo</name>"
            + "<module>"
            + "<script>"
            + "<name>local_module</name>"
            + "<path>/local_module.js</path>"
            + "</script>"
            + "</module>"
            + "</portal>"
            + "</gatein-resources>";

    //
    JavascriptConfigParser parser =
        new JavascriptConfigParser(
            new MockServletContext("mypath"), new ByteArrayInputStream(config.getBytes("UTF-8")));
    List<ScriptResourceDescriptor> scripts = parseScripts(parser);
    assertEquals(1, scripts.size());
    ScriptResourceDescriptor desc = scripts.get(0);

    List<Javascript> modules = desc.getModules();
    assertEquals(1, modules.size());

    Javascript local = modules.get(0);
    assertTrue(local instanceof Javascript.Local);
    assertEquals("/local_module.js", ((Javascript.Local) local).getContents()[0].getSource());
  }
コード例 #5
0
ファイル: TestParser.java プロジェクト: bdaw/gatein-portal
  public void testPortlet() throws Exception {
    String config =
        ""
            + "<gatein-resources>"
            + "<portlet>"
            + "<name>foo</name>"
            + "<module>"
            + "<script>"
            + "<name>foo_module</name>"
            + "<path>/foo_module.js</path>"
            + "</script>"
            + "<depends>"
            + "<module>bar</module>"
            + "</depends>"
            + "<depends>"
            + "<module>juu</module>"
            + "</depends>"
            + "</module>"
            + "</portlet>"
            + "</gatein-resources>";

    JavascriptConfigParser parser =
        new JavascriptConfigParser(
            new MockServletContext("mypath"), new ByteArrayInputStream(config.getBytes("UTF-8")));
    List<ScriptResourceDescriptor> scripts = parseScripts(parser);
    assertEquals(1, scripts.size());
    ScriptResourceDescriptor desc = scripts.get(0);
    assertEquals(new ResourceId(ResourceScope.PORTLET, "mypath/foo"), desc.getId());
    assertNull(desc.getAlias());
    assertEquals(
        Arrays.asList(
            new DependencyDescriptor(new ResourceId(ResourceScope.SHARED, "bar")),
            new DependencyDescriptor(new ResourceId(ResourceScope.SHARED, "juu"))),
        desc.getDependencies());
  }
コード例 #6
0
ファイル: TestParser.java プロジェクト: bdaw/gatein-portal
  public void testRemoteResource() throws Exception {

    String validConfig =
        ""
            + "<gatein-resources xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.gatein.org/xml/ns/gatein_resources_1_3 http://www.gatein.org/xml/ns/gatein_resources_1_3\" xmlns=\"http://www.gatein.org/xml/ns/gatein_resources_1_3\">"
            + "<module><name>foo</name><url>http://jquery.com/jquery.js</url></module>"
            + "</gatein-resources>";

    JavascriptConfigParser parser =
        new JavascriptConfigParser(
            new MockServletContext("mypath"),
            new ByteArrayInputStream(validConfig.getBytes("UTF-8")));
    List<ScriptResourceDescriptor> descs = parseScripts(parser);

    assertEquals(1, descs.size());
    ScriptResourceDescriptor desc = descs.get(0);
    List<Javascript> scripts = desc.getModules();
    assertEquals(1, scripts.size());
    assertTrue(scripts.get(0) instanceof Javascript.Remote);
  }
コード例 #7
0
ファイル: TestParser.java プロジェクト: bdaw/gatein-portal
  public void testSupportedLocales() throws Exception {
    String config =
        ""
            + "<gatein-resources>"
            + "<portal>"
            + "<name>foo</name>"
            + "<module>"
            + "<supported-locale>EN</supported-locale>"
            + "<supported-locale>FR-fr</supported-locale>"
            + "</module>"
            + "</portal>"
            + "</gatein-resources>";

    //
    JavascriptConfigParser parser =
        new JavascriptConfigParser(
            new MockServletContext("mypath"), new ByteArrayInputStream(config.getBytes("UTF-8")));
    List<ScriptResourceDescriptor> scripts = parseScripts(parser);
    assertEquals(1, scripts.size());
    ScriptResourceDescriptor desc = scripts.get(0);
    List<Locale> locales = desc.getSupportedLocales();
    assertEquals(Arrays.asList(Locale.ENGLISH, Locale.FRANCE), locales);
  }
コード例 #8
0
ファイル: TestParser.java プロジェクト: bdaw/gatein-portal
  public void testAlias() throws Exception {
    String config =
        ""
            + "<gatein-resources>"
            + "<module>"
            + "<name>foo</name>"
            + "<as>f</as>"
            + "<depends>"
            + "<module>bar</module>"
            + "<as>b</as>"
            + "</depends>"
            + "</module>"
            + "</gatein-resources>";

    //
    JavascriptConfigParser parser =
        new JavascriptConfigParser(
            new MockServletContext("mypath"), new ByteArrayInputStream(config.getBytes("UTF-8")));
    List<ScriptResourceDescriptor> scripts = parseScripts(parser);
    ScriptResourceDescriptor desc = scripts.get(0);
    assertEquals("f", desc.getAlias());
    assertEquals("b", desc.getDependencies().get(0).getAlias());

    config =
        ""
            + "<gatein-resources>"
            + "<portal>"
            + "<name>zoo</name>"
            + "<as>z</as>"
            + "<module>"
            + "<depends>"
            + "<module>zozo</module>"
            + "<as>zz</as>"
            + "</depends>"
            + "</module>"
            + "</portal>"
            + "</gatein-resources>";

    JavascriptConfigParser parser1 =
        new JavascriptConfigParser(
            new MockServletContext("mypath"), new ByteArrayInputStream(config.getBytes("UTF-8")));
    List<ScriptResourceDescriptor> ptScripts = parseScripts(parser1);
    ScriptResourceDescriptor portalDesc = ptScripts.get(0);
    assertEquals("z", portalDesc.getAlias());
    assertEquals("zz", portalDesc.getDependencies().get(0).getAlias());
  }