|
1 | 1 | package org.oidc.msg; |
2 | 2 |
|
| 3 | +import org.junit.Test; |
| 4 | + |
| 5 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 6 | + |
| 7 | +import java.util.ArrayList; |
| 8 | +import java.util.HashMap; |
| 9 | +import java.util.List; |
| 10 | +import java.util.Map; |
| 11 | + |
| 12 | +import org.junit.Assert; |
| 13 | + |
3 | 14 | /** |
4 | 15 | * Unit tests for {@link JsonResponseDescriptor}. |
5 | 16 | */ |
6 | 17 | public class JsonResponseDescriptorTest { |
| 18 | + |
| 19 | + @Test |
| 20 | + public void testFromJson() throws InvalidClaimException, JsonProcessingException { |
| 21 | + String json = "{ \"subject\" : \"acct:juliet%[email protected]\",\n" + |
| 22 | + " \"links\":\n" + |
| 23 | + " [\n" + |
| 24 | + " {\n" + |
| 25 | + " \"rel\": \"http://openid.net/specs/connect/1.0/issuer\",\n" + |
| 26 | + " \"href\": \"https://server.example.com\"\n" + |
| 27 | + " }\n" + |
| 28 | + " ]\n" + |
| 29 | + " }"; |
| 30 | + JsonResponseDescriptor jrd = new JsonResponseDescriptor(); |
| 31 | + jrd.fromJson(json); |
| 32 | + Map<String, Object> claims = jrd.getClaims(); |
| 33 | + Assert. assertEquals( "acct:juliet%[email protected]", claims. get( "subject")); |
| 34 | + List<Link> links = (List<Link>) claims.get("links"); |
| 35 | + Assert.assertNotNull(links); |
| 36 | + Assert.assertEquals(links.size(), 1); |
| 37 | + Map<String, Object> linkClaims = links.get(0).getClaims(); |
| 38 | + Assert.assertEquals("http://openid.net/specs/connect/1.0/issuer", linkClaims.get("rel")); |
| 39 | + Assert.assertEquals("https://server.example.com", linkClaims.get("href")); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + public void testFromClaims() throws JsonProcessingException, InvalidClaimException { |
| 44 | + Map<String, Object> claims = new HashMap<String, Object>(); |
| 45 | + claims. put( "subject", "acct:juliet%[email protected]"); |
| 46 | + List<Link> links = new ArrayList<Link>(); |
| 47 | + Link link = new Link(); |
| 48 | + link.addClaim("rel", "http://openid.net/specs/connect/1.0/issuer"); |
| 49 | + link.addClaim("href", "https://server.example.com"); |
| 50 | + links.add(link); |
| 51 | + claims.put("links", links); |
| 52 | + JsonResponseDescriptor jrd = new JsonResponseDescriptor(claims); |
| 53 | + Map<String, Object> parsedClaims = jrd.getClaims(); |
| 54 | + Assert. assertEquals( "acct:juliet%[email protected]", parsedClaims. get( "subject")); |
| 55 | + List<Link> parsedLinks = (List<Link>) parsedClaims.get("links"); |
| 56 | + Assert.assertNotNull(parsedLinks); |
| 57 | + Assert.assertEquals(parsedLinks.size(), 1); |
| 58 | + Map<String, Object> linkClaims = parsedLinks.get(0).getClaims(); |
| 59 | + Assert.assertEquals("http://openid.net/specs/connect/1.0/issuer", linkClaims.get("rel")); |
| 60 | + Assert.assertEquals("https://server.example.com", linkClaims.get("href")); |
| 61 | + } |
7 | 62 |
|
8 | 63 | } |
0 commit comments