📄 testdb4ostorage.java
字号:
q.descend("name").constrain(account.getName()); set = q.execute(); assertEquals(0, set.size()); try { storage.deleteAccount("notstored"); fail("account not stored"); } catch (Exception e) { // } try { storage.deleteAccount(null); fail("name is null"); } catch (Exception e) { // } container.close(); } /* * Test method for * 'org.apache.lucene.gdata.storage.db4o.DB4oStorage.storeFeed(ServerBaseFeed, * String)' */ public void testStoreFeed() throws StorageException { ObjectContainer container = getContainer(); ServerBaseFeed feed = new ServerBaseFeed(); feed.setId(FEEDID); ProvidedServiceConfig conf = new ProvidedServiceConfig(); conf.setName(SERVICENAME); feed.setServiceConfig(conf); Storage storage = this.controller.getStorage(); try { storage.storeFeed(feed, ACCOUNTNAME); fail("no accoutn stored"); } catch (Exception e) { // } GDataAccount account = new GDataAccount(); account.setName(ACCOUNTNAME); account.setPassword("somePass"); container.set(account); container.commit(); container.close(); storage.storeFeed(feed, ACCOUNTNAME); container = getContainer(); Query query = container.query(); query.constrain(ServerBaseFeed.class); query.descend("feed").descend("id").constrain(FEEDID); ObjectSet set = query.execute(); assertEquals(1, set.size()); assertEquals(feed.getId(), ((ServerBaseFeed) set.next()).getId()); container.close(); } /* * Test method for * 'org.apache.lucene.gdata.storage.db4o.DB4oStorage.deleteFeed(String)' */ public void testDeleteFeed() throws StorageException { ServerBaseFeed feed = new ServerBaseFeed(); feed.setId(FEEDID); GDataAccount account = new GDataAccount(); account.setName(ACCOUNTNAME); account.setPassword("somePass"); ObjectContainer container = getContainer(); container.set(account); container.commit(); container.close(); Storage storage = this.controller.getStorage(); ProvidedServiceConfig conf = new ProvidedServiceConfig(); conf.setName(SERVICENAME); feed.setServiceConfig(conf); storage.storeFeed(feed, ACCOUNTNAME); storage.deleteFeed(FEEDID); container = getContainer(); Query query = container.query(); query.constrain(ServerBaseFeed.class); query.descend("feed").descend("id").constrain(FEEDID); ObjectSet set = query.execute(); assertEquals(0, set.size()); query = getContainer().query(); query.constrain(BaseFeed.class); query.descend("id").constrain(FEEDID); set = query.execute(); assertEquals(0, set.size()); container.close(); } /* * Test method for * 'org.apache.lucene.gdata.storage.db4o.DB4oStorage.getServiceForFeed(String)' */ public void testGetServiceForFeed() throws StorageException { ServerBaseFeed feed = new ServerBaseFeed(); ProvidedServiceConfig conf = new ProvidedServiceConfig(); conf.setName(SERVICENAME); feed.setServiceConfig(conf); feed.setId(FEEDID); GDataAccount account = new GDataAccount(); account.setName(ACCOUNTNAME); account.setPassword("somePass"); ObjectContainer container = getContainer(); container.set(account); container.commit(); container.close(); Storage storage = this.controller.getStorage(); storage.storeFeed(feed, ACCOUNTNAME); assertEquals(SERVICENAME, storage.getServiceForFeed(FEEDID)); try { storage.getServiceForFeed(null); fail("ID is null"); } catch (Exception e) { // } try { storage.getServiceForFeed("someOtherId"); fail("feed for id is not stored"); } catch (Exception e) { // } } /* * Test method for * 'org.apache.lucene.gdata.storage.db4o.DB4oStorage.getAccount(String)' */ public void testGetAccount() throws StorageException { GDataAccount account = new GDataAccount(); account.setName(ACCOUNTNAME); account.setPassword("somePass"); ObjectContainer container = getContainer(); container.set(account); container.commit(); container.close(); Storage storage = this.controller.getStorage(); assertNotNull(storage.getAccount(ACCOUNTNAME)); assertEquals(account.getPassword(), storage.getAccount(ACCOUNTNAME) .getPassword()); try { storage.getAccount(null); fail("accountname is null"); } catch (Exception e) { // } try { storage.getAccount("someOtherAccount"); fail("accountname is not stored"); } catch (Exception e) { // } } /* * Test method for * 'org.apache.lucene.gdata.storage.db4o.DB4oStorage.updateFeed(ServerBaseFeed, * String)' */ public void testUpdateFeed() throws StorageException { ObjectContainer container = getContainer(); ServerBaseFeed feed = new ServerBaseFeed(); ProvidedServiceConfig conf = new ProvidedServiceConfig(); conf.setName(SERVICENAME); feed.setId(FEEDID); feed.setServiceConfig(conf); Storage storage = this.controller.getStorage(); GDataAccount account = new GDataAccount(); account.setName(ACCOUNTNAME); account.setPassword("somePass"); container.set(account); container.commit(); container.close(); storage.storeFeed(feed, ACCOUNTNAME); assertNull(feed.getTitle()); ServerBaseFeed feedU = new ServerBaseFeed(); feedU.setServiceConfig(conf); feedU.setId(FEEDID); feedU.setTitle(new PlainTextConstruct("someText")); feedU.setServiceType(SERVICENAME); storage.updateFeed(feedU, ACCOUNTNAME); ServerBaseFeed requestFeed = new ServerBaseFeed(); requestFeed.setId(FEEDID); requestFeed.setServiceType(SERVICENAME); assertNotNull(storage.getFeed(requestFeed)); assertEquals(feedU.getTitle(), storage.getFeed(requestFeed).getTitle()); try { storage.updateFeed(null, ACCOUNTNAME); fail("feed is null"); } catch (Exception e) { // } try { storage.updateFeed(feedU, null); fail("accountname is null"); } catch (Exception e) { // } try { feedU.setServiceType(null); storage.updateFeed(feedU, ACCOUNTNAME); fail("servicetype is null"); } catch (Exception e) { // } } private static ServerBaseEntry createServerBaseEntry() { ServerBaseEntry e = new ServerBaseEntry(); e.setId(System.currentTimeMillis() + ""); ProvidedServiceConfig conf = new ProvidedServiceConfig(); conf.setName(SERVICENAME); e.setServiceConfig(conf); e.setUpdated(DateTime.now()); e.setFeedId(FEEDID); try { Thread.sleep(2); } catch (InterruptedException e1) { e1.printStackTrace(); } return e; } private ServerBaseFeed storeServerBaseFeed() { ServerBaseFeed f = new ServerBaseFeed(); ProvidedServiceConfig conf = new ProvidedServiceConfig(); conf.setName(SERVICENAME); f.setServiceConfig(conf); f.setId(System.currentTimeMillis() + ""); f.setId(FEEDID); f.setUpdated(DateTime.now()); ObjectContainer con = this.controller.releaseContainer(); con.set(f); con.commit(); con.close(); return f; } static class Runner implements Runnable { Storage s; StorageController c; ServerBaseEntry e; boolean expConf; StorageOperation op; public Runner(StorageController c, ServerBaseEntry e, boolean expectConflict, StorageOperation op) { this.c = c; this.e = e; this.expConf = expectConflict; this.op = op; } public void run() { try { ((DB4oController) this.c).visiteInitialize(); this.s = this.c.getStorage(); } catch (StorageException e1) { e1.printStackTrace(); } try { if (this.op == StorageOperation.DELETE) this.s.deleteEntry(e); if (this.op == StorageOperation.UPDATE) this.s.updateEntry(e); if (expConf) fail = true; } catch (ModificationConflictException ex) { if (!expConf) fail = true; ex.printStackTrace(); } catch (StorageException ex) { ex.printStackTrace(); fail = true; } finally { ((DB4oController) this.c).visiteDestroy(); } } } public void testFeedLastModified() { ServerBaseFeed feed = storeServerBaseFeed(); Storage s = this.controller.getStorage(); assertEquals(feed.getUpdated().getValue(), s .getFeedLastModified(FEEDID).longValue()); try { s.getFeedLastModified(null); fail("id is null"); } catch (StorageException e) { } try { s.getFeedLastModified("someOtherid"); fail("no such feed"); } catch (StorageException e) { } } public void testEntryLastModified() { ServerBaseFeed feed = storeServerBaseFeed(); Storage s = this.controller.getStorage(); ServerBaseEntry en = createServerBaseEntry(); s.storeEntry(en); assertEquals(en.getUpdated().getValue(), s.getEntryLastModified( en.getId(), FEEDID).longValue()); try { s.getEntryLastModified(null, null); fail("id is null"); } catch (StorageException e) { } try { s.getEntryLastModified("someOtherid", "notinstorage"); fail("no such Entry"); } catch (StorageException e) { } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -