Created
June 8, 2011 13:50
-
-
Save mgenov/1014458 to your computer and use it in GitHub Desktop.
LearnToUseTaskQueueApiTest
This file contains hidden or 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
import com.google.appengine.api.taskqueue.Queue; | |
import com.google.appengine.api.taskqueue.QueueFactory; | |
import com.google.appengine.api.taskqueue.TaskQueuePb; | |
import com.google.appengine.api.taskqueue.dev.LocalTaskQueueCallback; | |
import com.google.appengine.api.urlfetch.URLFetchServicePb; | |
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig; | |
import com.google.appengine.tools.development.testing.LocalServiceTestHelper; | |
import com.google.appengine.tools.development.testing.LocalTaskQueueTestConfig; | |
import com.google.apphosting.api.ApiProxy; | |
import org.junit.After; | |
import org.junit.Before; | |
import org.junit.Test; | |
import java.io.UnsupportedEncodingException; | |
import java.net.URLDecoder; | |
import java.util.HashMap; | |
import java.util.Map; | |
import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl; | |
/** | |
* @author Miroslav Genov ([email protected]) | |
*/ | |
public class LearnToUseTaskQueueApiTest { | |
public static class TestingTaskQueueCallback implements com.google.appengine.api.taskqueue.dev.LocalTaskQueueCallback { | |
public static Map<String, String> parameters = new HashMap<String, String>(); | |
@Override | |
public int execute(URLFetchServicePb.URLFetchRequest req) { | |
String requestBody = req.getPayload().toStringUtf8(); | |
String[] params = requestBody.split("&"); | |
TaskQueuePb.TaskQueueQueryAndOwnTasksResponse.Task task = null; | |
try { | |
for (String param : params) { | |
String[] pair = param.split("="); | |
String name = pair[0]; | |
String value = pair[1]; | |
String decodedValue = URLDecoder.decode(value, "UTF8"); | |
parameters.put(name, decodedValue); | |
} | |
} catch (UnsupportedEncodingException e) { | |
e.printStackTrace(); | |
} | |
return 0; | |
} | |
} | |
private LocalServiceTestHelper helper; | |
public LearnToUseTaskQueueApiTest() { | |
LocalTaskQueueTestConfig taskQueueConfig = new LocalTaskQueueTestConfig(); | |
taskQueueConfig.setCallbackClass(TestingTaskQueueCallback.class); | |
taskQueueConfig.setDisableAutoTaskExecution(false); | |
helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig(), taskQueueConfig); | |
} | |
@Before | |
public void setUp() throws Exception { | |
helper.setUp(); | |
} | |
@After | |
public void tearDown() throws Exception { | |
helper.tearDown(); | |
} | |
@Test | |
public void testSomething() { | |
Queue queue = QueueFactory.getDefaultQueue(); | |
queue.add(withUrl("/test").param("test","bbb")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment