-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#37 : handle errors and timeouts tbc
- Loading branch information
Showing
5 changed files
with
125 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
stripes/src/main/java/net/sourceforge/stripes/mock/MockAsyncContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package net.sourceforge.stripes.mock; | ||
|
||
/** | ||
* Created by vankeisb on 13/01/16. | ||
*/ | ||
public class MockAsyncContext { | ||
} |
54 changes: 54 additions & 0 deletions
54
stripes/src/test/java/net/sourceforge/stripes/mock/TestMockAsync.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package net.sourceforge.stripes.mock; | ||
|
||
import net.sourceforge.stripes.FilterEnabledTestBase; | ||
import net.sourceforge.stripes.action.*; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import javax.servlet.AsyncContext; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
public class TestMockAsync extends FilterEnabledTestBase { | ||
|
||
@Test(groups="fast") | ||
public void testDefaultEvent() throws Exception { | ||
MockRoundtrip trip = new MockRoundtrip(getMockServletContext(), AsyncActionBean.class); | ||
trip.execute(); | ||
|
||
AsyncActionBean bean = trip.getActionBean(AsyncActionBean.class); | ||
Assert.assertNotNull(bean); | ||
} | ||
|
||
|
||
@UrlBinding("/async") | ||
public static class AsyncActionBean implements ActionBean { | ||
|
||
private boolean completed = false; | ||
private ActionBeanContext context; | ||
|
||
public ActionBeanContext getContext() { | ||
return context; | ||
} | ||
|
||
public void setContext(ActionBeanContext context) { | ||
this.context = context; | ||
} | ||
|
||
@DefaultHandler | ||
public Resolution doAsync() { | ||
return new AsyncResolution() { | ||
public void execute(HttpServletRequest request, HttpServletResponse response) throws Exception { | ||
Thread.sleep(5000); | ||
AsyncContext asyncContext = getAsyncContext(); | ||
asyncContext.getResponse().getWriter().write("DONE"); | ||
asyncContext.complete(); | ||
} | ||
}; | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
} |