@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); }
@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); }