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
4 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
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
41 changes: 41 additions & 0 deletions
41
fcrepo-http-commons/src/test/java/org/fcrepo/responses/HtmlProviderTest.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,41 @@ | ||
|
||
package org.fcrepo.responses; | ||
|
||
import static javax.ws.rs.core.MediaType.TEXT_HTML_TYPE; | ||
import static javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
|
||
import com.hp.hpl.jena.query.Dataset; | ||
|
||
public class HtmlProviderTest { | ||
|
||
final HtmlProvider htmlProvider = new HtmlProvider(); | ||
|
||
@Test | ||
public void testIsWriteable() { | ||
assertTrue( | ||
"Gave false response to HtmlProvider.isWriteable() that contained a legitimate combination of parameters!", | ||
htmlProvider.isWriteable(Dataset.class, Dataset.class, null, | ||
TEXT_HTML_TYPE)); | ||
assertFalse( | ||
"HtmlProvider.isWriteable() should return false if asked to serialize anything other than Dataset!", | ||
htmlProvider.isWriteable(HtmlProvider.class, | ||
HtmlProvider.class, null, TEXT_HTML_TYPE)); | ||
assertFalse( | ||
"HtmlProvider.isWriteable() should return false to text/plain!", | ||
htmlProvider.isWriteable(Dataset.class, Dataset.class, null, | ||
TEXT_PLAIN_TYPE)); | ||
} | ||
|
||
@Test | ||
public void testGetSize() { | ||
assertEquals("Returned wrong size from HtmlProvider!", htmlProvider | ||
.getSize(null, null, null, null, null), -1); | ||
|
||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
fcrepo-http-commons/src/test/java/org/fcrepo/responses/RdfProviderTest.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,41 @@ | ||
|
||
package org.fcrepo.responses; | ||
|
||
import static javax.ws.rs.core.MediaType.TEXT_HTML_TYPE; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.junit.Test; | ||
|
||
import com.hp.hpl.jena.query.Dataset; | ||
|
||
public class RdfProviderTest { | ||
|
||
final RdfProvider rdfProvider = new RdfProvider(); | ||
|
||
@Test | ||
public void testIsWriteable() { | ||
assertTrue( | ||
"Gave false response to RdfProvider.isWriteable() that contained a legitimate combination of parameters!", | ||
rdfProvider.isWriteable(Dataset.class, Dataset.class, null, | ||
MediaType.valueOf("application/rdf+xml"))); | ||
assertFalse( | ||
"RdfProvider.isWriteable() should return false if asked to serialize anything other than Dataset!", | ||
rdfProvider.isWriteable(RdfProvider.class, RdfProvider.class, | ||
null, MediaType.valueOf("application/rdf+xml"))); | ||
assertFalse( | ||
"RdfProvider.isWriteable() should return false to text/html!", | ||
rdfProvider.isWriteable(Dataset.class, Dataset.class, null, | ||
TEXT_HTML_TYPE)); | ||
} | ||
|
||
@Test | ||
public void testGetSize() { | ||
assertEquals("Returned wrong size from HtmlProvider!", rdfProvider | ||
.getSize(null, null, null, null, null), -1); | ||
|
||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
fcrepo-http-commons/src/test/java/org/fcrepo/responses/RdfSerializationUtilsTest.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 |
---|---|---|
@@ -1,6 +1,50 @@ | ||
|
||
package org.fcrepo.responses; | ||
|
||
import static com.hp.hpl.jena.graph.Node.createLiteral; | ||
import static com.hp.hpl.jena.graph.Node.createURI; | ||
import static com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel; | ||
import static org.fcrepo.responses.RdfSerializationUtils.getFirstValueForPredicate; | ||
import static org.fcrepo.responses.RdfSerializationUtils.setCachingHeaders; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import javax.ws.rs.core.MultivaluedMap; | ||
|
||
import org.junit.Test; | ||
|
||
import com.hp.hpl.jena.graph.Triple; | ||
import com.hp.hpl.jena.query.Dataset; | ||
import com.hp.hpl.jena.sparql.core.DatasetImpl; | ||
import com.sun.jersey.core.util.MultivaluedMapImpl; | ||
|
||
public class RdfSerializationUtilsTest { | ||
|
||
Dataset testData = new DatasetImpl(createDefaultModel()); | ||
|
||
{ | ||
testData.asDatasetGraph().getDefaultGraph().add( | ||
new Triple(createURI("test:subject"), | ||
createURI("test:predicate"), | ||
createLiteral("test:object"))); | ||
|
||
} | ||
|
||
@Test | ||
public void testGetFirstValueForPredicate() { | ||
final String foundValue = | ||
getFirstValueForPredicate(testData, createURI("test:predicate")); | ||
assertEquals("Didn't find correct value for predicate!", foundValue, | ||
"test:object"); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Test | ||
public void testSetCachingHeaders() { | ||
final MultivaluedMap<?, ?> headers = new MultivaluedMapImpl(); | ||
setCachingHeaders((MultivaluedMap<String, Object>) headers, testData); | ||
assertTrue(headers.get("Cache-Control").size() > 0); | ||
} | ||
|
||
} |