Search in sources :

Example 26 with RenderResult

use of cn.bran.japid.template.RenderResult in project Japid by branaway.

the class RenderResultCacheTest method testExpirationSoon.

@Test
public void testExpirationSoon() {
    RenderResultCache.setAltCache(new AltCacheSimpleImpl());
    RenderResult rr = new RenderResult(null, null, 0);
    RenderResultCache.set(KEY1, rr, "2s");
    RenderResult rrr;
    try {
        rrr = RenderResultCache.get(KEY1);
        assertNotNull(rrr);
    } catch (ShouldRefreshException e1) {
        throw new RuntimeException(e1);
    }
    waitfor(1500);
    try {
        rrr = RenderResultCache.get(KEY1);
    } catch (ShouldRefreshException e) {
        assertNotNull(e.renderResult);
    }
    final AtomicBoolean b = new AtomicBoolean(false);
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                RenderResult rrr = RenderResultCache.get(KEY1);
                b.set(rrr != null);
            } catch (ShouldRefreshException e) {
                fail();
            }
        }
    });
    t.start();
    waitfor(100);
    assertTrue(b.get());
    // the second time in refreshing zone should get the item
    try {
        rrr = RenderResultCache.get(KEY1);
        assertNotNull(rrr);
    } catch (ShouldRefreshException e) {
        fail("should not get this");
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RenderResult(cn.bran.japid.template.RenderResult) Test(org.junit.Test)

Example 27 with RenderResult

use of cn.bran.japid.template.RenderResult in project Japid by branaway.

the class ControllerUtilsTest method testRender.

@Test
public void testRender() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    RenderResult render;
    render = (RenderResult) RenderInvokerUtils.render(new Foo(null), "hi", new Integer(12));
    assertNotNull(render);
    render = (RenderResult) RenderInvokerUtils.render(new Foo(null), "hi", 12);
    assertNotNull(render);
    render = (RenderResult) RenderInvokerUtils.render(new Foo(null), "hi", null);
    assertNotNull(render);
    try {
        render = (RenderResult) RenderInvokerUtils.render(new Foo2(null), 12);
    } catch (Exception e) {
        System.out.println(e);
    }
    render = (RenderResult) RenderInvokerUtils.render(new Foo2(null), new ArrayList<String>());
    assertNotNull(render);
    testSingleNull();
    testEmptyArgs();
}
Also used : RenderResult(cn.bran.japid.template.RenderResult) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.Test)

Example 28 with RenderResult

use of cn.bran.japid.template.RenderResult in project Japid by branaway.

the class ControllerUtilsTest method testSingleNull.

/**
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 * @throws IllegalArgumentException 
	 * 
	 */
@Test
public void testSingleNull() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    RenderResult render;
    // if cast to Object, the null is treated as an argument.
    // Otherwise the varargs is set to null. 
    render = (RenderResult) RenderInvokerUtils.render(new Foo2(null), (Object) null);
    assertNotNull(render);
}
Also used : RenderResult(cn.bran.japid.template.RenderResult) Test(org.junit.Test)

Aggregations

RenderResult (cn.bran.japid.template.RenderResult)28 Test (org.junit.Test)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 ExecutionException (java.util.concurrent.ExecutionException)3 InternetAddress (javax.mail.internet.InternetAddress)3 Email (org.apache.commons.mail.Email)3 EmailAttachment (org.apache.commons.mail.EmailAttachment)3 EmailException (org.apache.commons.mail.EmailException)3 HtmlEmail (org.apache.commons.mail.HtmlEmail)3 MultiPartEmail (org.apache.commons.mail.MultiPartEmail)3 JapidCompilationException (cn.bran.japid.compiler.JapidCompilationException)2 JapidTemplateException (cn.bran.japid.exceptions.JapidTemplateException)2 JapidTemplateBaseWithoutPlay (cn.bran.japid.template.JapidTemplateBaseWithoutPlay)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 MailException (play.exceptions.MailException)2 UnexpectedException (play.exceptions.UnexpectedException)2