@Override public void create() { String identifier = "test-create-product"; String indexName = "index-name"; String indexCategory = "category"; String indexValue = "test"; MetadataIndex mi = new MetadataIndex(); mi.setName(indexName); mi.setCategory(indexCategory); mi.setQueryable(null); mi.setValue(indexValue); Product product = new Product(); product.setIdentifier(identifier); product.setLocked(false); product.setProcessed(true); product.setIndexes(Arrays.asList(mi)); try { product.setPath(new URL("file:/titi/tata")); } catch (MalformedURLException e) { Assert.fail(e.getMessage(), e); } Product createdProduct = dao.create(product); Assert.assertNotNull(createdProduct); Assert.assertEquals(dao.count(), (howMany() + 1)); Assert.assertEquals(createdProduct.getUuid(), product.getUuid()); List<MetadataIndex> indexes = createdProduct.getIndexes(); Assert.assertEquals(indexes.size(), 1); Assert.assertEquals(indexes.get(0), mi); }
public void addProduct( URL path, User owner, final List<Collection> collections, String origin, Scanner scanner, FileScannerWrapper wrapper) throws DataStoreAlreadyExistException { if (productDao.exists(path)) { throw new DataStoreAlreadyExistException( "Product \"" + path.toExternalForm() + "\" already present in the system."); } /* **** CRITICAL SECTION *** */ /** THIS SECTION SHALL NEVER BE STOPPED BY CNTRL-C OR OTHER SIGNALS */ /* TODO: check if shutdownHook can protect this section */ Product product = new Product(); product.setPath(path); product.setOrigin(origin); List<User> users = new ArrayList<User>(); if (owner != null) { product.setOwner(owner); users.add(userDao.read(owner.getId())); product.setAuthorizedUsers(new HashSet<User>(users)); } product = productDao.create(product); // FIX product = productDao.read(product.getId()); /* **** CRITICAL SECTION *** */ processProduct(product, owner, collections, scanner, wrapper); }
@Test(groups = {"non-regression"}) public void testChecksumUpdate() throws MalformedURLException { Product product = new Product(); product.setPath(new URL("file:/product/path")); Download download = new Product.Download(); download.setPath("/no/path/file"); download.setSize(0L); download.setType("application/octet-stream"); download.setChecksums( Maps.newHashMap( ImmutableMap.of( "MD5", "54ABCDEF98765", "SHA-1", "9876FEDCBA1234"))); product.setDownload(download); // First create the defined product: try { product = dao.create(product); } catch (Exception e) { Assert.fail("Creation of product fails", e); } /** Clear/putAll feature testing */ product.getDownload().getChecksums().clear(); product .getDownload() .getChecksums() .putAll( Maps.newHashMap( ImmutableMap.of( "SHA-256", "4554ABCDEF98765", "SHA-512", "ABDEFFE9876FEDCBA1234"))); try { dao.update(product); } catch (Exception e) { Assert.fail("Modifying checksums with map clear/put fails", e); } /** Set feature testing */ product .getDownload() .setChecksums( Maps.newHashMap( ImmutableMap.of( "MD5", "54ABCDEF98765", "SHA-1", "9876FEDCBA1234"))); try { dao.update(product); } catch (Exception e) { Assert.fail("Modifying checksums with \"set\" fails", e); } /** Remove residuals for this test */ cancelListeners(getHibernateDao()); dao.delete(product); }