Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
fcrepo-http-api/src/test/java/org/fcrepo/api/FedoraExportTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.fcrepo.api; | ||
|
||
import org.fcrepo.FedoraObject; | ||
import org.fcrepo.serialization.FedoraObjectSerializer; | ||
import org.fcrepo.serialization.SerializerUtil; | ||
import org.fcrepo.services.ObjectService; | ||
import org.fcrepo.test.util.TestHelpers; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import javax.jcr.RepositoryException; | ||
import javax.jcr.Session; | ||
import javax.ws.rs.core.StreamingOutput; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
import static org.fcrepo.test.util.PathSegmentImpl.createPathList; | ||
import static org.fcrepo.test.util.TestHelpers.mockSession; | ||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Matchers.eq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class FedoraExportTest { | ||
|
||
FedoraExport testObj; | ||
|
||
Session mockSession; | ||
|
||
SerializerUtil mockSerializers; | ||
|
||
FedoraObjectSerializer mockSerializer; | ||
ObjectService mockObjects; | ||
|
||
@Before | ||
public void setUp() throws RepositoryException { | ||
|
||
testObj = new FedoraExport(); | ||
|
||
mockSession = mockSession(testObj); | ||
mockSerializers = mock(SerializerUtil.class); | ||
mockSerializer = mock(FedoraObjectSerializer.class); | ||
when(mockSerializers.getSerializer("fake-format")).thenReturn( | ||
mockSerializer); | ||
mockObjects = mock(ObjectService.class); | ||
testObj.setSerializers(mockSerializers); | ||
testObj.setObjectService(mockObjects); | ||
testObj.setSession(mockSession); | ||
testObj.setUriInfo(TestHelpers.getUriInfoImpl()); | ||
} | ||
|
||
@Test | ||
public void testExportObject() throws Exception { | ||
FedoraObject mockObject = mock(FedoraObject.class); | ||
when(mockObjects.getObject(mockSession, "/test/object")).thenReturn(mockObject); | ||
|
||
((StreamingOutput)testObj.exportObject(createPathList("test", "object"), "fake-format").getEntity()).write(new ByteArrayOutputStream()); | ||
verify(mockSerializer).serialize(eq(mockObject), any(OutputStream.class)); | ||
|
||
} | ||
|
||
|
||
} |