Ivan provided neat Python example, here's a solution for Java.
Supppose here's the code we want to test
public class ClientChannelService {
private ChannelService channelService = ChannelServiceFactory.getChannelService();
public String createToken(){
return channelService.createChannel(UUID.randomUUID().toString());
}
public void sendMessage(String token, String message){
channelService.sendMessage(new ChannelMessage(token, message));
}
}
First, add appengine-testing.jar
to the classpath:
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-testing</artifactId>
<version>${appengine.version}</version>
<scope>test</scope>
</dependency>
Next, create a test as follows. I'm assuming JUnit here, but generaly you are free to use any test framework, it doesn't matter for GAE.
private ClientChannelService service;
private LocalServiceTestHelper helper = new LocalServiceTestHelper(
new LocalChannelServiceTestConfig());
private ChannelManager channelManager;
@Before
public void setUp() {
helper.setUp();
channelManager = LocalChannelServiceTestConfig.getLocalChannelService()
.getChannelManager();
service = new ClientChannelService();
}
@After
public void tearDown() {
helper.tearDown();
}
@Test
public void testSendMessage() {
String token = service.createToken();
connectionId = channelManager.connectClient(token); //emulate client connection
service.sendMessage(token, "message");
String message = channelManager.getNextClientMessage(token, connectionId);
assertEquals("message", message);
}