public void handleDoGet(final String fromURL, final String fromURLName,
final String fromRelValue, final String toURL,
final String toURLName, final String toRelValue, final String action,
final String applyToBoth, final String jsonResponse)
{
Mockery context = new Mockery();
final HttpServletRequest httpRequest = context.mock(HttpServletRequest.class);
final HttpServletResponse httpResponse = context.mock(HttpServletResponse.class);
final HttpSession httpSession = context.mock(HttpSession.class);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final PrintWriter httpResponseWriter = new PrintWriter(out);
try
{
context.checking(new Expectations()
{{
// Expectations for servlet.doGet invocation
one(httpRequest).getParameter("fromURL");
will(returnValue(fromURL));
one(httpRequest).getParameter("fromName");
will(returnValue(fromURLName));
one(httpRequest).getParameter("fromRelValue");
will(returnValue(fromRelValue));
one(httpRequest).getParameter("toURL");
will(returnValue(toURL));
one(httpRequest).getParameter("toName");
will(returnValue(toURLName));
one(httpRequest).getParameter("toRelValue");
will(returnValue(toRelValue));
one(httpRequest).getParameter("action");
will(returnValue(action));
one(httpRequest).getAttribute(SSOSubject.SSOSUBJECT_KEY);
will(returnValue(new SSOSubject("r0wKz8K8U7En3pvets6KCJ4wT8Q= ~ 10129 ~ test ~ Test ~ Test ~ "+new Date().getTime()+" ~ 1800000")));
one(httpRequest).getParameter("applyToBoth");
will(returnValue(applyToBoth));
if(jsonResponse == null)
{
if("generateGig".equals(action))
{
one(httpRequest).getAttribute("X-Downloading-GEDCOM");
will(returnValue(null));
/*one(httpRequest).getSession(true);
will(returnValue(httpSession));
one(httpSession).getId();
will(returnValue("http_session_"+Thread.currentThread().getId()));
one(httpRequest).getAttribute("X-Downloading-GEDCOM");
will(returnValue(null));
one(httpRequest).getSession(true);
will(returnValue(httpSession));
one(httpSession).getId();
will(returnValue("http_session_"+Thread.currentThread().getId()));
one(httpRequest).getSession(true);
will(returnValue(httpSession));
one(httpSession).getId();
will(returnValue("http_session_"+Thread.currentThread().getId()));*/
// TODO: figure out how to use the jMock framework to ignore the
// following setAttribute method call rather than matching it
//File[] files = new File[2];
//files[0] = new File(Environment.getProperty("CentralSiteRoot")+"/http~~~_3~~~1localhost~~~_38081/gedapi/export.ged.generated.http_session_"+Thread.currentThread().getId());
//files[1] = new File(Environment.getProperty("CentralSiteRoot")+"/http~~~_3~~~1localhost~~~_38081/gedapi/export.ged.generated.http_session_"+Thread.currentThread().getId()+".generated.http_session_"+Thread.currentThread().getId());
//one(httpRequest).setAttribute("generatedFiles", files);
one(httpRequest).setAttribute("fromGedcomURL", fromURL.substring(0, fromURL.lastIndexOf('/')));
one(httpRequest).getSession(true);
will(returnValue(httpSession));
one(httpSession).getId();
will(returnValue("http_session_"+Thread.currentThread().getId()));
one(httpRequest).setAttribute("fromGeneratedGigFile", new File(Environment.getProperty("CentralSiteRoot")+"/http~~~_3~~~1localhost~~~_38081/gedapi/"+GLinkURL.hashFilename("export.ged.generated.http_session_"+Thread.currentThread().getId())));
one(httpRequest).getAttribute("X-Downloading-GEDCOM");
will(returnValue(null));
one(httpRequest).setAttribute("toGedcomURL", toURL.substring(0, toURL.lastIndexOf('/')));
one(httpRequest).getSession(true);
will(returnValue(httpSession));
one(httpSession).getId();
will(returnValue("http_session_"+Thread.currentThread().getId()));
one(httpRequest).setAttribute("toGeneratedGigFile", new File(Environment.getProperty("CentralSiteRoot")+"/http~~~_3~~~1localhost~~~_38081/gedapi/"+GLinkURL.hashFilename("export.ged.generated.http_session_"+Thread.currentThread().getId()+"_toURL")));
//ignoring(httpRequest).setAttribute("generatedFiles", anything());
one(httpRequest).getRequestDispatcher("generateGig.jsp");
//files[0].deleteOnExit();
//files[1].deleteOnExit();
}
else if("generateGeg".equals(action))
{
one(httpRequest).setAttribute("fromGLinkURL", "http://localhost:8081/gedapi/export.ged.I1.glink.xml");
one(httpRequest).getSession(true);
will(returnValue(httpSession));
one(httpSession).getId();
will(returnValue("http_session_"+Thread.currentThread().getId()));
one(httpRequest).setAttribute("fromGeneratedGegFile", new File(Environment.getProperty("CentralSiteRoot")+"/http~~~_3~~~1localhost~~~_38081/gedapi/"+GLinkURL.hashFilename("export.ged.I1.glink.xml.generated.http_session_"+Thread.currentThread().getId())));
one(httpRequest).setAttribute("toGLinkURL", "http://localhost:8081/gedapi/export.ged.I2.glink.xml");
one(httpRequest).getSession(true);
will(returnValue(httpSession));
one(httpSession).getId();
will(returnValue("http_session_"+Thread.currentThread().getId()));
one(httpRequest).setAttribute("toGeneratedGegFile", new File(Environment.getProperty("CentralSiteRoot")+"/http~~~_3~~~1localhost~~~_38081/gedapi/"+GLinkURL.hashFilename("export.ged.I2.glink.xml.generated.http_session_"+Thread.currentThread().getId())));
// TODO: figure out how to use the jMock framework to ignore the
// following setAttribute method call rather than matching it
//File[] files = new File[2];
//files[0] = null;
//files[1] = null;
//one(httpRequest).setAttribute("generatedFiles", files);
//ignoring(httpRequest).setAttribute("generatedFiles", anything());
one(httpRequest).getRequestDispatcher("generateGeg.jsp");
}
}
else
{
one(httpResponse).setHeader("Cache-Control", "max-age=0");
one(httpResponse).setContentType("application/json");
one(httpResponse).getWriter();
will(returnValue(httpResponseWriter));
}
}});
servlet.doGet(httpRequest, httpResponse);
httpResponseWriter.flush();
httpResponseWriter.close();
context.assertIsSatisfied();
if(jsonResponse != null)
{
String strResponse = out.toString();
//System.out.println("strResponse: "+strResponse);