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

	}
}

package org.fcrepo.serialization.jcrxml;

import static org.junit.Assert.assertEquals;
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);

	}

    @Test
    public void testGetKey() {
        assertEquals("jcr/xml", new JcrXmlSerializer().getKey());
    }

    @Test
    public void testGetMediaType() {
        assertEquals("application/xml", new JcrXmlSerializer().getMediaType());
    }
}

add tests for trivial jcr xml serialization methods