Search in sources :

Example 56 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class OrderingTest method testAbsoluteOrdering2.

@Test
public void testAbsoluteOrdering2() throws Exception {
    // C,B,A
    List<Resource> resources = new ArrayList<Resource>();
    MetaData metaData = new MetaData();
    metaData._ordering = new AbsoluteOrdering(metaData);
    ((AbsoluteOrdering) metaData._ordering).add("C");
    ((AbsoluteOrdering) metaData._ordering).add("B");
    ((AbsoluteOrdering) metaData._ordering).add("A");
    TestResource jar1 = new TestResource("A");
    resources.add(jar1);
    TestResource r1 = new TestResource("A/web-fragment.xml");
    FragmentDescriptor f1 = new FragmentDescriptor(r1);
    f1._name = "A";
    metaData._webFragmentNameMap.put(f1._name, f1);
    metaData._webFragmentResourceMap.put(jar1, f1);
    TestResource jar2 = new TestResource("B");
    resources.add(jar2);
    TestResource r2 = new TestResource("B/web-fragment.xml");
    FragmentDescriptor f2 = new FragmentDescriptor(r2);
    f2._name = "B";
    metaData._webFragmentNameMap.put(f2._name, f2);
    metaData._webFragmentResourceMap.put(jar2, f2);
    TestResource jar3 = new TestResource("C");
    resources.add(jar3);
    TestResource r3 = new TestResource("C/web-fragment.xml");
    FragmentDescriptor f3 = new FragmentDescriptor(r3);
    f3._name = "C";
    metaData._webFragmentNameMap.put(f3._name, f3);
    metaData._webFragmentResourceMap.put(jar3, f3);
    TestResource jar4 = new TestResource("D");
    resources.add(jar4);
    TestResource r4 = new TestResource("D/web-fragment.xml");
    FragmentDescriptor f4 = new FragmentDescriptor(r4);
    f4._name = "D";
    metaData._webFragmentNameMap.put(f4._name, f4);
    metaData._webFragmentResourceMap.put(jar4, f4);
    TestResource jar5 = new TestResource("E");
    resources.add(jar5);
    TestResource r5 = new TestResource("E/web-fragment.xml");
    FragmentDescriptor f5 = new FragmentDescriptor(r5);
    f5._name = "E";
    metaData._webFragmentNameMap.put(f5._name, f5);
    metaData._webFragmentResourceMap.put(jar5, f5);
    TestResource jar6 = new TestResource("plain");
    resources.add(jar6);
    TestResource r6 = new TestResource("plain/web-fragment.xml");
    FragmentDescriptor f6 = new FragmentDescriptor(r6);
    f6._name = FragmentDescriptor.NAMELESS + "1";
    metaData._webFragmentNameMap.put(f6._name, f6);
    metaData._webFragmentResourceMap.put(jar6, f6);
    List<Resource> list = metaData._ordering.order(resources);
    String[] outcomes = { "CBA" };
    String result = "";
    for (Resource r : list) result += ((TestResource) r)._name;
    if (!checkResult(result, outcomes))
        fail("No outcome matched " + result);
}
Also used : ArrayList(java.util.ArrayList) Resource(org.eclipse.jetty.util.resource.Resource) Test(org.junit.Test)

Example 57 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class OrderingTest method testRelativeOrderingWithPlainJars.

@Test
public void testRelativeOrderingWithPlainJars() throws Exception {
    //B,A,C other jars with no fragments
    List<Resource> resources = new ArrayList<Resource>();
    MetaData metaData = new MetaData();
    metaData._ordering = new RelativeOrdering(metaData);
    //A: after others, before C
    TestResource jar1 = new TestResource("A");
    resources.add(jar1);
    TestResource r1 = new TestResource("A/web-fragment.xml");
    FragmentDescriptor f1 = new FragmentDescriptor(r1);
    f1._name = "A";
    metaData._webFragmentNameMap.put(f1._name, f1);
    metaData._webFragmentResourceMap.put(jar1, f1);
    //((RelativeOrdering)metaData._ordering).addAfterOthers(f1);
    f1._otherType = FragmentDescriptor.OtherType.After;
    f1._befores.add("C");
    //B: before others, before C
    TestResource jar2 = new TestResource("B");
    resources.add(jar2);
    TestResource r2 = new TestResource("B/web-fragment.xml");
    FragmentDescriptor f2 = new FragmentDescriptor(r2);
    f2._name = "B";
    metaData._webFragmentNameMap.put(f2._name, f2);
    metaData._webFragmentResourceMap.put(jar2, f2);
    //((RelativeOrdering)metaData._ordering).addBeforeOthers(f2);
    f2._otherType = FragmentDescriptor.OtherType.Before;
    f2._befores.add("C");
    //C: after A
    TestResource jar3 = new TestResource("C");
    resources.add(jar3);
    TestResource r3 = new TestResource("C/web-fragment.xml");
    FragmentDescriptor f3 = new FragmentDescriptor(r3);
    f3._name = "C";
    metaData._webFragmentNameMap.put(f3._name, f3);
    metaData._webFragmentResourceMap.put(jar3, f3);
    //((RelativeOrdering)metaData._ordering).addNoOthers(f3);
    f3._otherType = FragmentDescriptor.OtherType.None;
    f3._afters.add("A");
    //No fragment jar 1
    TestResource r4 = new TestResource("plain1");
    resources.add(r4);
    //No fragment jar 2
    TestResource r5 = new TestResource("plain2");
    resources.add(r5);
    //result: BAC
    String[] outcomes = { "Bplain1plain2AC" };
    List<Resource> orderedList = metaData._ordering.order(resources);
    String result = "";
    for (Resource r : orderedList) result += (((TestResource) r)._name);
    if (!checkResult(result, outcomes))
        fail("No outcome matched " + result);
}
Also used : ArrayList(java.util.ArrayList) Resource(org.eclipse.jetty.util.resource.Resource) Test(org.junit.Test)

Example 58 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class OrderingTest method testOrderFragments.

@Test
public void testOrderFragments() throws Exception {
    final MetaData metadata = new MetaData();
    final Resource jarResource = new TestResource("A");
    metadata.setOrdering(new RelativeOrdering(metadata));
    metadata.addWebInfJar(jarResource);
    metadata.orderFragments();
    assertEquals(1, metadata.getOrderedWebInfJars().size());
    metadata.orderFragments();
    assertEquals(1, metadata.getOrderedWebInfJars().size());
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) Test(org.junit.Test)

Example 59 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class OrderingTest method testRelativeOrderingWithPlainJars2.

@Test
public void testRelativeOrderingWithPlainJars2() throws Exception {
    //web.xml has no ordering, jar A has fragment after others, jar B is plain, jar C is plain
    List<Resource> resources = new ArrayList<Resource>();
    MetaData metaData = new MetaData();
    metaData._ordering = new RelativeOrdering(metaData);
    //A has after others
    TestResource jar1 = new TestResource("A");
    resources.add(jar1);
    TestResource r1 = new TestResource("A/web-fragment.xml");
    FragmentDescriptor f1 = new FragmentDescriptor(r1);
    f1._name = "A";
    metaData._webFragmentNameMap.put(f1._name, f1);
    metaData._webFragmentResourceMap.put(jar1, f1);
    f1._otherType = FragmentDescriptor.OtherType.After;
    //No fragment jar B
    TestResource r4 = new TestResource("plainB");
    resources.add(r4);
    //No fragment jar C
    TestResource r5 = new TestResource("plainC");
    resources.add(r5);
    List<Resource> orderedList = metaData._ordering.order(resources);
    String[] outcomes = { "plainBplainCA" };
    String result = "";
    for (Resource r : orderedList) result += (((TestResource) r)._name);
    if (!checkResult(result, outcomes))
        fail("No outcome matched " + result);
}
Also used : ArrayList(java.util.ArrayList) Resource(org.eclipse.jetty.util.resource.Resource) Test(org.junit.Test)

Example 60 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class OrderingTest method testAbsoluteOrderingWithPlainJars.

@Test
public void testAbsoluteOrderingWithPlainJars() throws Exception {
    //
    // A,B,C,others
    //
    List<Resource> resources = new ArrayList<Resource>();
    MetaData metaData = new MetaData();
    metaData._ordering = new AbsoluteOrdering(metaData);
    ((AbsoluteOrdering) metaData._ordering).add("A");
    ((AbsoluteOrdering) metaData._ordering).add("B");
    ((AbsoluteOrdering) metaData._ordering).add("C");
    ((AbsoluteOrdering) metaData._ordering).addOthers();
    TestResource jar1 = new TestResource("A");
    resources.add(jar1);
    TestResource r1 = new TestResource("A/web-fragment.xml");
    FragmentDescriptor f1 = new FragmentDescriptor(r1);
    f1._name = "A";
    metaData._webFragmentNameMap.put(f1._name, f1);
    metaData._webFragmentResourceMap.put(jar1, f1);
    TestResource jar2 = new TestResource("B");
    resources.add(jar2);
    TestResource r2 = new TestResource("B/web-fragment.xml");
    FragmentDescriptor f2 = new FragmentDescriptor(r2);
    f2._name = "B";
    metaData._webFragmentNameMap.put(f2._name, f2);
    metaData._webFragmentResourceMap.put(jar2, f2);
    TestResource jar3 = new TestResource("C");
    resources.add(jar3);
    TestResource r3 = new TestResource("C/web-fragment.xml");
    FragmentDescriptor f3 = new FragmentDescriptor(r3);
    f3._name = "C";
    metaData._webFragmentNameMap.put(f3._name, f3);
    metaData._webFragmentResourceMap.put(jar3, f3);
    TestResource jar4 = new TestResource("D");
    resources.add(jar4);
    TestResource r4 = new TestResource("D/web-fragment.xml");
    FragmentDescriptor f4 = new FragmentDescriptor((Resource) null);
    f4._name = "D";
    metaData._webFragmentNameMap.put(f4._name, f4);
    metaData._webFragmentResourceMap.put(jar4, f4);
    TestResource jar5 = new TestResource("E");
    resources.add(jar5);
    TestResource r5 = new TestResource("E/web-fragment.xml");
    FragmentDescriptor f5 = new FragmentDescriptor((Resource) null);
    f5._name = "E";
    metaData._webFragmentNameMap.put(f5._name, f5);
    metaData._webFragmentResourceMap.put(jar5, f5);
    TestResource jar6 = new TestResource("plain");
    resources.add(jar6);
    TestResource r6 = new TestResource("plain/web-fragment.xml");
    FragmentDescriptor f6 = new FragmentDescriptor((Resource) null);
    f6._name = FragmentDescriptor.NAMELESS + "1";
    metaData._webFragmentNameMap.put(f6._name, f6);
    metaData._webFragmentResourceMap.put(jar6, f6);
    //plain jar
    TestResource r7 = new TestResource("plain1");
    resources.add(r7);
    TestResource r8 = new TestResource("plain2");
    resources.add(r8);
    List<Resource> list = metaData._ordering.order(resources);
    String[] outcomes = { "ABCDEplainplain1plain2" };
    String result = "";
    for (Resource r : list) result += ((TestResource) r)._name;
    if (!checkResult(result, outcomes))
        fail("No outcome matched " + result);
}
Also used : ArrayList(java.util.ArrayList) Resource(org.eclipse.jetty.util.resource.Resource) Test(org.junit.Test)

Aggregations

Resource (org.eclipse.jetty.util.resource.Resource)196 Test (org.junit.Test)79 File (java.io.File)46 URL (java.net.URL)39 ArrayList (java.util.ArrayList)38 Matchers.containsString (org.hamcrest.Matchers.containsString)31 IOException (java.io.IOException)28 ResourceCollection (org.eclipse.jetty.util.resource.ResourceCollection)18 JarResource (org.eclipse.jetty.util.resource.JarResource)16 XmlConfiguration (org.eclipse.jetty.xml.XmlConfiguration)16 Server (org.eclipse.jetty.server.Server)13 HashSet (java.util.HashSet)12 InputStream (java.io.InputStream)9 HashMap (java.util.HashMap)9 URI (java.net.URI)8 MalformedURLException (java.net.MalformedURLException)7 StringTokenizer (java.util.StringTokenizer)7 URISyntaxException (java.net.URISyntaxException)6 Properties (java.util.Properties)6 Set (java.util.Set)6