Permalink
Please sign in to comment.
Showing
with
38 additions
and 1 deletion.
@@ -0,0 +1,32 @@ | |||
package org.wikidata.history.web; | |||
|
|||
import org.junit.Assert; | |||
import org.junit.Test; | |||
|
|||
import java.util.Arrays; | |||
import java.util.List; | |||
import java.util.Optional; | |||
|
|||
public class ContentNegotiationTest { | |||
|
|||
@Test | |||
public void testNegotiateAccept() { | |||
testAcceptNegotiation(null, Optional.of("application/ld+json")); | |||
testAcceptNegotiation("application/ld+json", Optional.of("application/ld+json")); | |||
testAcceptNegotiation("application/*", Optional.of("application/ld+json")); | |||
testAcceptNegotiation("*/*", Optional.of("application/ld+json")); | |||
testAcceptNegotiation("application/json", Optional.of("application/json")); | |||
testAcceptNegotiation("application/ld+json; charset=UTF-8", Optional.of("application/ld+json")); | |||
testAcceptNegotiation("application/*; charset=UTF-8", Optional.of("application/ld+json")); | |||
testAcceptNegotiation("*/*; charset=UTF-8", Optional.of("application/ld+json")); | |||
testAcceptNegotiation("application/json; charset=UTF-8", Optional.of("application/json")); | |||
testAcceptNegotiation("application/xml", Optional.empty()); | |||
|
|||
} | |||
|
|||
private void testAcceptNegotiation(String header, Optional<String> expected) { | |||
List<String> possibles = Arrays.asList("application/ld+json", "application/json"); | |||
Assert.assertEquals(expected, ContentNegotiation.negotiateAccept(header, possibles)); | |||
} | |||
} | |||
|
0 comments on commit
3dc4cf9