public BinaryContains( Binary expectedContent ) { try { expectedContent.acquire(); this.expectedContent = expectedContent.getBytes(); } finally { expectedContent.release(); } }
@Test public void shouldCompareBinaryAndStringValues() { String strValue = "Jack and Jill went up the hill"; Binary binaryValue = factories.getBinaryFactory().create(strValue); Binary binarySpy = spy(binaryValue); // The values should compare to each other ... assertThat(ValueComparators.OBJECT_COMPARATOR.compare(strValue, binarySpy), is(0)); assertThat(ValueComparators.OBJECT_COMPARATOR.compare(binarySpy, strValue), is(0)); // Verify that the binary value was not obtained, but that we just used the hash verify(binarySpy, times(0)).getBytes(); verify(binarySpy, times(0)).getStream(); verify(binarySpy, atLeastOnce()).getHash(); }
@Override public boolean matchesSafely( Binary content ) { try { content.acquire(); byte[] actualContents = content.getBytes(); if (actualContents.length != expectedContent.length) return false; for (int i = 0, len = actualContents.length; i != len; ++i) { if (actualContents[i] != expectedContent[i]) return false; } return true; } finally { content.release(); } }
@FixFor( "MODE-966" ) @Test public void shouldStoreLargeBinaryValue() throws Exception { File file = new File("src/test/resources/testdata/test1.xmi"); assertThat(file.exists(), is(true)); BinaryFactory binaryFactory = context.getValueFactories().getBinaryFactory(); Binary binaryValue = binaryFactory.create(file); graph.batch() .create("/someFile.xmi") .with("jcr:primaryType", "nt:file") .and() .create("/someFile.xmi/jcr:content") .with("jcr:priamryType", "nt:resource") .and("jcr:data", binaryValue) .and() .execute(); // Now read the content back out ... Property data = graph.getProperty("jcr:data").on("/someFile.xmi/jcr:content"); Binary readValue = binaryFactory.create(data.getFirstValue()); // and verify the content matches ... assertThat(binaryValue.getHash(), is(readValue.getHash())); assertThat(binaryValue.getBytes(), is(readValue.getBytes())); }