【发布时间】:2011-07-11 19:26:49
【问题描述】:
我是 GAE 新手,正在尝试设置一些 JUnit 测试。在谷歌提供的这个例子中:
public class LocalDatastoreTest {
private final LocalServiceTestHelper helper =
new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
@Before
public void setUp() {
helper.setUp();
}
@After
public void tearDown() {
helper.tearDown();
}
// run this test twice to prove we're not leaking any state across tests
private void doTest() {
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
assertEquals(0, ds.prepare(new Query("yam")).countEntities(withLimit(10)));
ds.put(new Entity("yam"));
ds.put(new Entity("yam"));
assertEquals(2, ds.prepare(new Query("yam")).countEntities(withLimit(10)));
}
@Test
public void testInsert1() {
doTest();
}
@Test
public void testInsert2() {
doTest();
}
}
以下行用于将实体添加到本地数据存储:
ds.put(new Entity("yam"));
这对我来说很好用。但是,我正在使用 JDO 并希望保留一个我自己的 POJO(例如 Cars),但 Cars 不是实体类型,这是该方法所需要的。我可以使用其他方法或服务来完成此操作吗?
【问题讨论】:
-
你的 POJO 可以扩展实体吗?
-
@citizen com.google.appengine.api.datastore.Entity 被标记为 Final。