more solid broker path analysis and more tests
git-svn-id: http://google-refine.googlecode.com/svn/trunk@1068 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
689d743d0b
commit
31e4f1dff9
@ -96,33 +96,36 @@ public abstract class GridworksBroker extends ButterflyModuleImpl {
|
|||||||
logger.info("process '{}'", path);
|
logger.info("process '{}'", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
response.setCharacterEncoding("UTF-8");
|
|
||||||
response.setHeader("Content-Type", "application/json");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String uid = getUserId(request);
|
|
||||||
logger.debug("uid: {}", uid);
|
|
||||||
String pid = getParameter(request, "pid");
|
|
||||||
logger.debug("pid: {}", pid);
|
|
||||||
|
|
||||||
// NOTE: conditionals should be ordered by call frequency estimate to (slightly) improve performance
|
|
||||||
// we could be using a hashtable and some classes that implement the commands, but the complexity overhead
|
|
||||||
// doesn't seem to justify the marginal benefit.
|
|
||||||
|
|
||||||
if ("get_state".equals(path)) {
|
if ("get_state".equals(path)) {
|
||||||
getState(response, pid, uid, getInteger(request, "rev"));
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.setHeader("Content-Type", "application/json");
|
||||||
|
getState(response, getParameter(request, "pid"), getUserId(request), getInteger(request, "rev"));
|
||||||
} else if ("expire".equals(path)) {
|
} else if ("expire".equals(path)) {
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.setHeader("Content-Type", "application/json");
|
||||||
expire(response);
|
expire(response);
|
||||||
} else if ("obtain_lock".equals(path)) {
|
} else if ("obtain_lock".equals(path)) {
|
||||||
obtainLock(response, pid, uid, getInteger(request, "locktype"), getParameter(request, "lockvalue"));
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.setHeader("Content-Type", "application/json");
|
||||||
|
obtainLock(response, getParameter(request, "pid"), getUserId(request), getInteger(request, "locktype"), getParameter(request, "lockvalue"));
|
||||||
} else if ("release_lock".equals(path)) {
|
} else if ("release_lock".equals(path)) {
|
||||||
releaseLock(response, pid, uid, getParameter(request, "lock"));
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.setHeader("Content-Type", "application/json");
|
||||||
|
releaseLock(response, getParameter(request, "pid"), getUserId(request), getParameter(request, "lock"));
|
||||||
} else if ("transform".equals(path)) {
|
} else if ("transform".equals(path)) {
|
||||||
addTransformations(response, pid, uid, getParameter(request, "lock"), getList(request, "transformations"));
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.setHeader("Content-Type", "application/json");
|
||||||
|
addTransformations(response, getParameter(request, "pid"), getUserId(request), getParameter(request, "lock"), getList(request, "transformations"));
|
||||||
} else if ("start".equals(path)) {
|
} else if ("start".equals(path)) {
|
||||||
startProject(response, pid, uid, getParameter(request, "lock"), getData(request), getParameter(request, "metadata"), getInteger(request, "rev"));
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.setHeader("Content-Type", "application/json");
|
||||||
|
startProject(response, getParameter(request, "pid"), getUserId(request), getParameter(request, "lock"), getData(request), getParameter(request, "metadata"), getInteger(request, "rev"));
|
||||||
} else if ("open".equals(path)) {
|
} else if ("open".equals(path)) {
|
||||||
openProject(response, pid);
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.setHeader("Content-Type", "application/json");
|
||||||
|
openProject(response, getParameter(request, "pid"));
|
||||||
} else {
|
} else {
|
||||||
boolean value = super.process(path, request, response);
|
boolean value = super.process(path, request, response);
|
||||||
if (logger.isDebugEnabled()) logger.debug("< process '{}'", path);
|
if (logger.isDebugEnabled()) logger.debug("< process '{}'", path);
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
package com.metaweb.gridworks.broker.tests;
|
package com.metaweb.gridworks.broker.tests;
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import javax.servlet.ServletConfig;
|
import javax.servlet.ServletConfig;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@ -30,7 +36,7 @@ public class GridworksBrokerTests {
|
|||||||
|
|
||||||
@BeforeSuite
|
@BeforeSuite
|
||||||
public void suite_init() {
|
public void suite_init() {
|
||||||
//System.setProperty("log4j.configuration", "tests.log4j.properties");
|
System.setProperty("log4j.configuration", "tests.log4j.properties");
|
||||||
data = new File("data");
|
data = new File("data");
|
||||||
if (!data.exists()) data.mkdirs();
|
if (!data.exists()) data.mkdirs();
|
||||||
}
|
}
|
||||||
@ -51,25 +57,30 @@ public class GridworksBrokerTests {
|
|||||||
HttpServletRequest request = null;
|
HttpServletRequest request = null;
|
||||||
HttpServletResponse response = null;
|
HttpServletResponse response = null;
|
||||||
ServletConfig config = null;
|
ServletConfig config = null;
|
||||||
|
StringWriter writer = null;
|
||||||
|
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
public void setup() throws Exception {
|
public void setup() throws Exception {
|
||||||
|
config = mock(ServletConfig.class);
|
||||||
request = mock(HttpServletRequest.class);
|
request = mock(HttpServletRequest.class);
|
||||||
response = mock(HttpServletResponse.class);
|
response = mock(HttpServletResponse.class);
|
||||||
config = mock(ServletConfig.class);
|
writer = new StringWriter();
|
||||||
|
|
||||||
when(config.getInitParameter("gridworks.data")).thenReturn(data.getAbsolutePath());
|
when(config.getInitParameter("gridworks.data")).thenReturn(data.getAbsolutePath());
|
||||||
|
when(response.getWriter()).thenReturn(new PrintWriter(writer));
|
||||||
|
|
||||||
SUT = new GridworksBrokerImpl();
|
SUT = new GridworksBrokerImpl();
|
||||||
SUT.init(config);
|
SUT.init(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterMethod
|
@AfterMethod
|
||||||
public void teardown() {
|
public void teardown() throws Exception {
|
||||||
|
SUT.destroy();
|
||||||
SUT = null;
|
SUT = null;
|
||||||
|
|
||||||
request = null;
|
writer = null;
|
||||||
response = null;
|
response = null;
|
||||||
|
request = null;
|
||||||
config = null;
|
config = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,8 +88,35 @@ public class GridworksBrokerTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLifeCycle() {
|
public void testLifeCycle() {
|
||||||
|
logger.info("testing lifecycle");
|
||||||
Assert.assertTrue(true);
|
Assert.assertTrue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testService() {
|
||||||
|
try {
|
||||||
|
call(SUT, request, response, "expire", null);
|
||||||
|
logger.info(writer.toString());
|
||||||
|
} catch (Exception e) {
|
||||||
|
Assert.fail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
private void call(GridworksBroker broker, HttpServletRequest request, HttpServletResponse response, String service, Map<String,String> params) throws Exception {
|
||||||
|
if (params != null) {
|
||||||
|
for (Entry<String,String> e : params.entrySet()) {
|
||||||
|
when(request.getParameter(e.getKey())).thenReturn(e.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
broker.process(service, request, response);
|
||||||
|
|
||||||
|
if (params != null) {
|
||||||
|
for (Entry<String,String> e : params.entrySet()) {
|
||||||
|
verify(request,times(1)).getParameter(e.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
6
broker/core/tests/src/tests.log4j.properties
Normal file
6
broker/core/tests/src/tests.log4j.properties
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
log4j.rootLogger=DEBUG, console
|
||||||
|
|
||||||
|
log4j.appender.console=org.apache.log4j.ConsoleAppender
|
||||||
|
|
||||||
|
log4j.appender.console.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.console.layout.ConversionPattern=%-4r %-5p [%t] %m%n
|
Loading…
Reference in New Issue
Block a user