Search in sources :

Example 1 with Test

use of org.junit.Test in project photon-core by 1000Memories.

the class PhotoResourceTest method testNoModifications.

@Test
public void testNoModifications() throws Exception {
    when(photoProvider.getPhotoInputStream("mf.jpg")).thenReturn(getImage("mf.jpg"));
    ClientResponse response = client().resource("/mf.jpg").get(ClientResponse.class);
    assertThat(response.getEntity(byte[].class), is(ByteStreams.toByteArray(getImage("mf.jpg"))));
    assertThat(response.getType().toString(), is("image/jpeg"));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Test(org.junit.Test) ResourceTest(com.yammer.dropwizard.testing.ResourceTest)

Example 2 with Test

use of org.junit.Test in project jetty.project by eclipse.

the class TestServletAnnotations method testServletAnnotation.

@Test
public void testServletAnnotation() throws Exception {
    List<String> classes = new ArrayList<String>();
    classes.add("org.eclipse.jetty.annotations.ServletC");
    AnnotationParser parser = new AnnotationParser();
    WebAppContext wac = new WebAppContext();
    List<DiscoveredAnnotation> results = new ArrayList<DiscoveredAnnotation>();
    TestWebServletAnnotationHandler handler = new TestWebServletAnnotationHandler(wac, results);
    parser.parse(Collections.singleton(handler), classes);
    assertEquals(1, results.size());
    assertTrue(results.get(0) instanceof WebServletAnnotation);
    results.get(0).apply();
    ServletHolder[] holders = wac.getServletHandler().getServlets();
    assertNotNull(holders);
    assertEquals(1, holders.length);
    // Verify servlet annotations
    ServletHolder cholder = holders[0];
    assertThat("Servlet Name", cholder.getName(), is("CServlet"));
    assertThat("InitParameter[x]", cholder.getInitParameter("x"), is("y"));
    assertThat("Init Order", cholder.getInitOrder(), is(2));
    assertThat("Async Supported", cholder.isAsyncSupported(), is(false));
    // Verify mappings
    ServletMapping[] mappings = wac.getServletHandler().getServletMappings();
    assertNotNull(mappings);
    assertEquals(1, mappings.length);
    String[] paths = mappings[0].getPathSpecs();
    assertNotNull(paths);
    assertEquals(2, paths.length);
}
Also used : ServletMapping(org.eclipse.jetty.servlet.ServletMapping) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ArrayList(java.util.ArrayList) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) DiscoveredAnnotation(org.eclipse.jetty.webapp.DiscoveredAnnotation) Test(org.junit.Test)

Example 3 with Test

use of org.junit.Test in project jetty.project by eclipse.

the class TestResourceAnnotations method testResourceAnnotations.

@Test
public void testResourceAnnotations() throws Exception {
    new org.eclipse.jetty.plus.jndi.EnvEntry(server, "resA", objA, false);
    new org.eclipse.jetty.plus.jndi.EnvEntry(server, "resB", objB, false);
    AnnotationIntrospector parser = new AnnotationIntrospector();
    ResourceAnnotationHandler handler = new ResourceAnnotationHandler(wac);
    parser.registerHandler(handler);
    parser.introspect(ResourceA.class);
    parser.introspect(ResourceB.class);
    //processing classA should give us these jndi name bindings:
    // java:comp/env/myf
    // java:comp/env/org.eclipse.jetty.annotations.resources.ResourceA/g
    // java:comp/env/mye
    // java:comp/env/org.eclipse.jetty.annotations.resources.ResourceA/h
    // java:comp/env/resA
    // java:comp/env/org.eclipse.jetty.annotations.resources.ResourceB/f
    // java:comp/env/org.eclipse.jetty.annotations.resources.ResourceA/n
    //
    assertEquals(objB, env.lookup("myf"));
    assertEquals(objA, env.lookup("mye"));
    assertEquals(objA, env.lookup("resA"));
    assertEquals(objA, env.lookup("org.eclipse.jetty.annotations.resources.ResourceA/g"));
    assertEquals(objA, env.lookup("org.eclipse.jetty.annotations.resources.ResourceA/h"));
    assertEquals(objB, env.lookup("org.eclipse.jetty.annotations.resources.ResourceB/f"));
    assertEquals(objB, env.lookup("org.eclipse.jetty.annotations.resources.ResourceA/n"));
    //we should have Injections
    assertNotNull(injections);
    List<Injection> resBInjections = injections.getInjections(ResourceB.class.getCanonicalName());
    assertNotNull(resBInjections);
    //only 1 field injection because the other has no Resource mapping
    assertEquals(1, resBInjections.size());
    Injection fi = resBInjections.get(0);
    assertEquals("f", fi.getTarget().getName());
    //3 method injections on class ResourceA, 4 field injections
    List<Injection> resAInjections = injections.getInjections(ResourceA.class.getCanonicalName());
    assertNotNull(resAInjections);
    assertEquals(7, resAInjections.size());
    int fieldCount = 0;
    int methodCount = 0;
    for (Injection x : resAInjections) {
        if (x.isField())
            fieldCount++;
        else
            methodCount++;
    }
    assertEquals(4, fieldCount);
    assertEquals(3, methodCount);
    //test injection
    ResourceB binst = new ResourceB();
    injections.inject(binst);
    //check injected values
    Field f = ResourceB.class.getDeclaredField("f");
    f.setAccessible(true);
    assertEquals(objB, f.get(binst));
    //@Resource(mappedName="resA") //test the default naming scheme but using a mapped name from the environment
    f = ResourceA.class.getDeclaredField("g");
    f.setAccessible(true);
    assertEquals(objA, f.get(binst));
    //@Resource(name="resA") //test using the given name as the name from the environment
    f = ResourceA.class.getDeclaredField("j");
    f.setAccessible(true);
    assertEquals(objA, f.get(binst));
    //@Resource(mappedName="resB") //test using the default name on an inherited field
    f = ResourceA.class.getDeclaredField("n");
    f.setAccessible(true);
    assertEquals(objB, f.get(binst));
}
Also used : Field(java.lang.reflect.Field) AnnotationIntrospector(org.eclipse.jetty.annotations.AnnotationIntrospector) ResourceAnnotationHandler(org.eclipse.jetty.annotations.ResourceAnnotationHandler) Injection(org.eclipse.jetty.plus.annotation.Injection) Test(org.junit.Test)

Example 4 with Test

use of org.junit.Test in project jetty.project by eclipse.

the class TestResourceAnnotations method testResourcesAnnotation.

@Test
public void testResourcesAnnotation() throws Exception {
    new org.eclipse.jetty.plus.jndi.EnvEntry(server, "resA", objA, false);
    new org.eclipse.jetty.plus.jndi.EnvEntry(server, "resB", objB, false);
    AnnotationIntrospector introspector = new AnnotationIntrospector();
    ResourcesAnnotationHandler handler = new ResourcesAnnotationHandler(wac);
    introspector.registerHandler(handler);
    introspector.introspect(ResourceA.class);
    introspector.introspect(ResourceB.class);
    assertEquals(objA, env.lookup("peach"));
    assertEquals(objB, env.lookup("pear"));
}
Also used : ResourcesAnnotationHandler(org.eclipse.jetty.annotations.ResourcesAnnotationHandler) AnnotationIntrospector(org.eclipse.jetty.annotations.AnnotationIntrospector) Test(org.junit.Test)

Example 5 with Test

use of org.junit.Test in project jetty.project by eclipse.

the class TestAnnotationConfiguration method testGetFragmentFromJar.

@Test
public void testGetFragmentFromJar() throws Exception {
    String dir = MavenTestingUtils.getTargetTestingDir("getFragmentFromJar").getAbsolutePath();
    File file = new File(dir);
    file = new File(file.getCanonicalPath());
    URL url = file.toURL();
    Resource jar1 = Resource.newResource(url + "file.jar");
    AnnotationConfiguration config = new AnnotationConfiguration();
    WebAppContext wac = new WebAppContext();
    List<FragmentDescriptor> frags = new ArrayList<FragmentDescriptor>();
    frags.add(new FragmentDescriptor(Resource.newResource("jar:" + url + "file.jar!/fooa.props")));
    frags.add(new FragmentDescriptor(Resource.newResource("jar:" + url + "file2.jar!/foob.props")));
    assertNotNull(config.getFragmentFromJar(jar1, frags));
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Resource(org.eclipse.jetty.util.resource.Resource) ArrayList(java.util.ArrayList) File(java.io.File) FragmentDescriptor(org.eclipse.jetty.webapp.FragmentDescriptor) URL(java.net.URL) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)591606 ArrayList (java.util.ArrayList)32306 QuickTest (com.hazelcast.test.annotation.QuickTest)27910 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)25464 File (java.io.File)24371 HashMap (java.util.HashMap)20598 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)19416 List (java.util.List)16209 IOException (java.io.IOException)13083 Map (java.util.Map)9056 Date (java.util.Date)8811 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8305 InputStream (java.io.InputStream)7624 Properties (java.util.Properties)7365 CountDownLatch (java.util.concurrent.CountDownLatch)7322 ByteArrayInputStream (java.io.ByteArrayInputStream)7230 HashSet (java.util.HashSet)7019 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6379 Response (javax.ws.rs.core.Response)5810 Ignore (org.junit.Ignore)5729