package org.fcrepo.serialization.jcrxml;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import javax.jcr.ImportUUIDBehavior;
import javax.jcr.Node;
import javax.jcr.Session;

import org.fcrepo.FedoraObject;
import org.fcrepo.serialization.JcrXmlSerializer;
import org.junit.Test;

public class JcrXmlSerializerTest {
	@Test
	public void testSerialize() throws Exception {
		final Session mockSession = mock(Session.class);
		final Node mockNode = mock(Node.class);
		final FedoraObject mockObject = mock(FedoraObject.class);
		when(mockObject.getNode()).thenReturn(mockNode);
		when(mockNode.getSession()).thenReturn(mockSession);
		when(mockNode.getPath()).thenReturn("/path/to/node");

		final OutputStream os = new ByteArrayOutputStream();

		new JcrXmlSerializer().serialize(mockObject, os);

		verify(mockSession).exportSystemView("/path/to/node", os, false, false);
	}

	@Test
	public void testDeserialize() throws Exception {
		final Session mockSession = mock(Session.class);
		final InputStream mockIS = mock(InputStream.class);

		new JcrXmlSerializer().deserialize(mockSession, "/objects", mockIS);
		verify(mockSession).importXML("/objects", mockIS, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);

	}
}

@@ -35,16 +35,61 @@
 crxml;%0A%0A
+import static org.junit.Assert.assertEquals;%0A
 import s
@@ -1425,11 +1425,259 @@
 OW);%0A%0A%09%7D
+%0A%0A    @Test%0A    public void testGetKey() %7B%0A        assertEquals(%22jcr/xml%22, new JcrXmlSerializer().getKey());%0A    %7D%0A%0A    @Test%0A    public void testGetMediaType() %7B%0A        assertEquals(%22application/xml%22, new JcrXmlSerializer().getMediaType());%0A    %7D
 %0A%7D%0A

add tests for trivial jcr xml serialization methods