@Override public void delete() { Long id = 1L; FileScanner element = dao.read(id); Set<Collection> collections = element.getCollections(); Hibernate.initialize(collections); dao.delete(element); assertEquals(dao.count(), (howMany() - 1)); assertNull(dao.read(id)); for (Collection collection : collections) { assertNotNull(cdao.read(collection.getUUID())); } }
@Test public void getUserFromScanner() { Long fid0 = Long.valueOf(0); // scanner of koko Long fid1 = Long.valueOf(1); // scanner of riko User u = dao.getUserFromScanner(dao.read(fid0)); Assert.assertNotNull(u); Assert.assertEquals(u.getUsername(), "koko"); u = dao.getUserFromScanner(dao.read(fid1)); Assert.assertNotNull(u); Assert.assertEquals(u.getUsername(), "riko"); u = dao.getUserFromScanner(null); Assert.assertNull(u); }
@Test public void getScannerCollections() { List<String> list = dao.getScannerCollections(0L); assertNotNull(list); assertEquals(list.size(), 2); assertTrue(list.contains("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1")); assertTrue(list.contains("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2")); }
@Override public void first() { String hql = "FROM FileScanner WHERE status = 'running' ORDER BY id DESC"; FileScanner fs = dao.first(hql); assertNotNull(fs); assertEquals(fs.getId(), Long.valueOf(3)); assertEquals(fs.getStatusMessage(), "running..."); }
@Test public void deleteProductReferences() { Long fid0 = Long.valueOf(0); Long fid1 = Long.valueOf(1); FileScanner fs0 = dao.read(fid0); FileScanner fs1 = dao.read(fid1); Collection c = cdao.read("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1"); assertTrue(fs0.getCollections().contains(c)); assertTrue(fs1.getCollections().contains(c)); int updated = dao.deleteCollectionReferences(c); dao.getSessionFactory().getCurrentSession().refresh(fs0); dao.getSessionFactory().getCurrentSession().refresh(fs1); assertEquals(updated, 2); assertFalse(fs0.getCollections().contains(c)); assertFalse(fs1.getCollections().contains(c)); }
@Override public void update() { String cid = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa3"; Long fid = Long.valueOf(0); String username = "******"; String collection_name = "testCollection"; FileScanner fs = dao.read(fid); Collection collection = new Collection(); collection.setUUID(cid); collection.setName(collection_name); assertNotEquals(fs.getUsername(), username); fs.setUsername(username); fs.getCollections().add(collection); dao.update(fs); fs = dao.read(fid); assertEquals(fs.getUsername(), username); assertEquals(fs.getCollections().size(), 3); assertTrue(fs.getCollections().contains(collection)); }
@Override public void create() { String message = "testSuccess"; String collection_name = "testCollection"; Collection collection = new Collection(); collection.setUUID("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa5"); collection.setName(collection_name); HashSet<Collection> collections = new HashSet<>(); collections.add(collection); FileScanner fs = new FileScanner(); fs.setActive(true); fs.setStatus("ok"); fs.setStatusMessage(message); fs.setCollections(collections); fs = dao.create(fs); assertNotNull(fs); assertEquals(dao.count(), (howMany() + 1)); assertEquals(fs.getStatusMessage(), message); assertEquals(fs.getCollections().size(), 1); }
@Override public void read() { FileScanner fs = dao.read(0L); assertNotNull(fs); assertEquals(fs.getUrl(), "coco-abricot"); }
@Override public void scroll() { String hql = "WHERE status = 'running'"; Iterator<FileScanner> it = dao.scroll(hql, -1, -1).iterator(); assertTrue(CheckIterator.checkElementNumber(it, 2)); }