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
67 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
...o-http-commons/src/test/java/org/fcrepo/http/commons/responses/RdfStreamProviderTest.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,67 @@ | ||
|
||
package org.fcrepo.http.commons.responses; | ||
|
||
import static com.hp.hpl.jena.graph.NodeFactory.createURI; | ||
import static com.hp.hpl.jena.graph.Triple.create; | ||
import static com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
|
||
import javax.jcr.Session; | ||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.fcrepo.kernel.utils.iterators.RdfStream; | ||
import org.junit.Test; | ||
import com.hp.hpl.jena.graph.Triple; | ||
import com.hp.hpl.jena.rdf.model.Model; | ||
|
||
public class RdfStreamProviderTest { | ||
|
||
private RdfStreamProvider testProvider = new RdfStreamProvider(); | ||
|
||
@Test | ||
public void testGetSize() { | ||
assertEquals(-1, testProvider.getSize(null, null, null, null, null)); | ||
} | ||
|
||
@Test | ||
public void testIsWriteable() { | ||
assertTrue("Should be able to serialize this!", testProvider | ||
.isWriteable(RdfStream.class, null, null, MediaType | ||
.valueOf("application/rdf+xml"))); | ||
assertFalse("Should not be able to serialize this!", testProvider | ||
.isWriteable(RdfStreamProviderTest.class, null, null, MediaType | ||
.valueOf("application/rdf+xml"))); | ||
assertFalse("Should not be able to serialize this!", testProvider | ||
.isWriteable(RdfStream.class, null, null, MediaType | ||
.valueOf("text/html"))); | ||
} | ||
|
||
@Test | ||
public void testWriteTo() throws WebApplicationException, | ||
IllegalArgumentException, IOException { | ||
final Triple t = | ||
create(createURI("info:test"), createURI("property:test"), | ||
createURI("info:test")); | ||
final RdfStream rdfStream = new RdfStream(t).session(mock(Session.class)); | ||
byte[] result; | ||
try (ByteArrayOutputStream entityStream = new ByteArrayOutputStream();) { | ||
testProvider.writeTo(rdfStream, RdfStream.class, null, null, | ||
MediaType.valueOf("application/rdf+xml"), null, | ||
entityStream); | ||
result = entityStream.toByteArray(); | ||
} | ||
final Model postSerialization = | ||
createDefaultModel().read(new ByteArrayInputStream(result), null); | ||
assertTrue("Didn't find our triple!", postSerialization | ||
.contains(postSerialization.asStatement(t))); | ||
} | ||
|
||
} |