@Test public void shouldReturnFalseFromIsSameIfTheRepositoryInstanceIsDifferent() throws Exception { // Set up the store ... InMemoryRepositorySource source2 = new InMemoryRepositorySource(); source2.setName("store"); Graph store2 = Graph.create(source2, context); store2 .importXmlFrom(AbstractJcrTest.class.getClassLoader().getResourceAsStream("cars.xml")) .into("/"); JcrSession jcrSession2 = mock(JcrSession.class); when(jcrSession2.nodeTypeManager()).thenReturn(nodeTypes); when(jcrSession2.isLive()).thenReturn(true); SessionCache cache2 = new SessionCache(jcrSession2, store2.getCurrentWorkspaceName(), context, nodeTypes, store2); Workspace workspace2 = mock(Workspace.class); Repository repository2 = mock(JcrRepository.class); when(jcrSession2.getWorkspace()).thenReturn(workspace2); when(jcrSession2.getRepository()).thenReturn(repository2); when(workspace2.getName()).thenReturn("workspace1"); // Use the same id and location ... javax.jcr.Node prius2 = cache2.findJcrNode(null, path("/Cars/Hybrid/Toyota Prius")); assertThat(prius2.isSame(prius), is(false)); // Check the properties ... javax.jcr.Property model = prius.getProperty("vehix:model"); javax.jcr.Property model2 = prius2.getProperty("vehix:model"); assertThat(model.isSame(model2), is(false)); }
@Override @Before public void beforeEach() throws Exception { super.beforeEach(); rootNode = cache.findJcrRootNode(); cars = cache.findJcrNode(null, path("/Cars")); prius = cache.findJcrNode(null, path("/Cars/Hybrid/Toyota Prius")); altima = cache.findJcrNode(null, path("/Cars/Hybrid/Nissan Altima")); altimaModel = cache.findJcrProperty(altima.nodeId, altima.path(), Vehicles.Lexicon.MODEL); }
@Test public void shouldReturnTrueFromIsSameIfTheNodeUuidAndWorkspaceNameAndRepositoryInstanceAreSame() throws Exception { // Set up the store ... InMemoryRepositorySource source2 = new InMemoryRepositorySource(); source2.setName("store"); Graph store2 = Graph.create(source2, context); store2 .importXmlFrom(AbstractJcrTest.class.getClassLoader().getResourceAsStream("cars.xml")) .into("/"); JcrSession jcrSession2 = mock(JcrSession.class); when(jcrSession2.nodeTypeManager()).thenReturn(nodeTypes); when(jcrSession2.isLive()).thenReturn(true); SessionCache cache2 = new SessionCache(jcrSession2, store2.getCurrentWorkspaceName(), context, nodeTypes, store2); Workspace workspace2 = mock(Workspace.class); when(jcrSession2.getWorkspace()).thenReturn(workspace2); when(jcrSession2.getRepository()).thenReturn(repository); when(workspace2.getName()).thenReturn("workspace1"); WorkspaceLockManager lockManager = new WorkspaceLockManager(context, repoLockManager, "workspace2", null); JcrLockManager jcrLockManager = new JcrLockManager(jcrSession2, lockManager); when(jcrSession2.lockManager()).thenReturn(jcrLockManager); // Use the same id and location ... javax.jcr.Node prius2 = cache2.findJcrNode(null, path("/Cars/Hybrid/Toyota Prius")); prius2.addMixin("mix:referenceable"); prius.addMixin("mix:referenceable"); String priusUuid = prius.getIdentifier(); String priusUuid2 = prius2.getIdentifier(); assertThat(priusUuid, is(priusUuid2)); assertThat(prius2.isSame(prius), is(true)); // Check the properties ... javax.jcr.Property model = prius.getProperty("vehix:model"); javax.jcr.Property model2 = prius2.getProperty("vehix:model"); javax.jcr.Property year2 = prius2.getProperty("vehix:year"); assertThat(model.isSame(model2), is(true)); assertThat(model.isSame(year2), is(false)); }
@Test public void shouldReturnFalseFromIsSameIfTheNodeUuidIsDifferent() throws Exception { // Set up the store ... InMemoryRepositorySource source2 = new InMemoryRepositorySource(); source2.setName("store"); Graph store2 = Graph.create(source2, context); store2 .importXmlFrom(AbstractJcrTest.class.getClassLoader().getResourceAsStream("cars.xml")) .into("/"); JcrSession jcrSession2 = mock(JcrSession.class); when(jcrSession2.nodeTypeManager()).thenReturn(nodeTypes); when(jcrSession2.isLive()).thenReturn(true); SessionCache cache2 = new SessionCache(jcrSession2, store2.getCurrentWorkspaceName(), context, nodeTypes, store2); Workspace workspace2 = mock(Workspace.class); JcrRepository repository2 = mock(JcrRepository.class); RepositoryLockManager repoLockManager2 = mock(RepositoryLockManager.class); when(jcrSession2.getWorkspace()).thenReturn(workspace2); when(jcrSession2.getRepository()).thenReturn(repository2); when(workspace2.getName()).thenReturn("workspace1"); WorkspaceLockManager lockManager = new WorkspaceLockManager(context, repoLockManager2, "workspace2", null); JcrLockManager jcrLockManager = new JcrLockManager(jcrSession2, lockManager); when(jcrSession2.lockManager()).thenReturn(jcrLockManager); // Use the same id and location; use 'Nissan Altima' // since the UUIDs will be different (cars.xml doesn't define on this node) ... javax.jcr.Node altima2 = cache2.findJcrNode(null, path("/Cars/Hybrid/Nissan Altima")); altima2.addMixin("mix:referenceable"); altima.addMixin("mix:referenceable"); String altimaUuid = altima.getIdentifier(); String altimaUuid2 = altima2.getIdentifier(); assertThat(altimaUuid, is(not(altimaUuid2))); assertThat(altima2.isSame(altima), is(false)); // Check the properties ... javax.jcr.Property model = altima.getProperty("vehix:model"); javax.jcr.Property model2 = altima2.getProperty("vehix:model"); assertThat(model.isSame(model2), is(false)); }
@FixFor("MODE-1254") @Test public void shouldNotIncludeBinaryContentsInToString() throws Exception { altima = cache.findJcrNode(null, path("/Cars/Hybrid/Nissan Altima")); Node node = rootNode.addNode("nodeWithBinaryProperty", "nt:unstructured"); String value = "This is the string value"; Binary binaryValue = cache.session().getValueFactory().createBinary(new ByteArrayInputStream(value.getBytes())); node.setProperty("binProp", binaryValue); String toString = node.toString(); assertThat(toString.indexOf("**binary-value") > 0, is(true)); }
@FixFor("MODE-1308") @Test public void shouldAllowAnyBinaryImplementation() throws Exception { Node node = rootNode.addNode("nodeWithBinaryProperty", "nt:unstructured"); final String stringValue = "This is the string stringValue"; Binary binaryValue = new Binary() { public InputStream getStream() throws RepositoryException { return new ByteArrayInputStream(stringValue.getBytes()); } public int read(byte[] b, long position) throws IOException, RepositoryException { byte[] content = stringValue.getBytes(); int length = b.length + position < content.length ? b.length : (int) (content.length - position); System.arraycopy(content, (int) position, b, 0, length); return length; } public long getSize() throws RepositoryException { return stringValue.getBytes().length; } public void dispose() {} }; node.setProperty("binProp", binaryValue); Binary nodeValue = node.getProperty("binProp").getBinary(); assertNotNull(nodeValue); assertEquals(stringValue.getBytes().length, nodeValue.getSize()); byte[] buffer = new byte[100]; int available; InputStream inputStream = nodeValue.getStream(); ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); while ((available = inputStream.read(buffer)) != -1) { byteOut.write(buffer, 0, available); } assertArrayEquals(stringValue.getBytes(), byteOut.toByteArray()); }
@Test public void shouldProvidePath() throws Exception { assertThat(altimaModel.getPath(), is(altima.getPath() + "/vehix:model")); }