use of com.auth0.jwt.UserPojo in project java-jwt by auth0.
the class JsonNodeClaimTest method shouldGetAsMapValue.
@SuppressWarnings({ "unchecked", "RedundantCast" })
@Test
public void shouldGetAsMapValue() {
JsonNode value = mapper.valueToTree(Collections.singletonMap("key", new UserPojo("john", 123)));
Claim claim = claimFromNode(value);
assertThat(claim, is(notNullValue()));
Map map = claim.as(Map.class);
assertThat(((Map<String, Object>) map.get("key")), hasEntry("name", (Object) "john"));
assertThat(((Map<String, Object>) map.get("key")), hasEntry("id", (Object) 123));
}
use of com.auth0.jwt.UserPojo in project java-jwt by auth0.
the class JsonNodeClaimTest method shouldConvertToString.
@Test
public void shouldConvertToString() {
JsonNode value = mapper.valueToTree(new UserPojo("john", 123));
JsonNode nullValue = mapper.valueToTree(null);
JsonNode missingValue = MissingNode.getInstance();
Claim claim = claimFromNode(value);
Claim nullClaim = claimFromNode(nullValue);
Claim missingClaim = claimFromNode(missingValue);
assertThat(claim.toString(), is("{\"name\":\"john\",\"id\":123}"));
assertThat(nullClaim.isNull(), is(true));
assertThat(nullClaim.toString(), is("Null claim"));
assertThat(missingClaim.isMissing(), is(true));
assertThat(missingClaim.toString(), is("Missing claim"));
}
use of com.auth0.jwt.UserPojo in project java-jwt by auth0.
the class JsonNodeClaimTest method shouldGetArrayValueOfCustomClass.
@Test
public void shouldGetArrayValueOfCustomClass() {
JsonNode value = mapper.valueToTree(new UserPojo[] { new UserPojo("George", 1), new UserPojo("Mark", 2) });
Claim claim = claimFromNode(value);
assertThat(claim.asArray(UserPojo.class), is(notNullValue()));
assertThat(claim.asArray(UserPojo.class), is(arrayContaining(new UserPojo("George", 1), new UserPojo("Mark", 2))));
}
use of com.auth0.jwt.UserPojo in project java-jwt by auth0.
the class PayloadSerializerTest method shouldSerializeCustomListOfObject.
@Test
public void shouldSerializeCustomListOfObject() throws Exception {
UserPojo user1 = new UserPojo("Michael", 1);
UserPojo user2 = new UserPojo("Lucas", 2);
PayloadClaimsHolder holder = holderFor("users", Arrays.asList(user1, user2));
serializer.serialize(holder, jsonGenerator, serializerProvider);
jsonGenerator.flush();
assertThat(writer.toString(), is(equalTo("{\"users\":[{\"name\":\"Michael\",\"id\":1},{\"name\":\"Lucas\",\"id\":2}]}")));
}
use of com.auth0.jwt.UserPojo in project java-jwt by auth0.
the class PayloadSerializerTest method shouldSerializeCustomArrayOfObject.
@Test
public void shouldSerializeCustomArrayOfObject() throws Exception {
UserPojo user1 = new UserPojo("Michael", 1);
UserPojo user2 = new UserPojo("Lucas", 2);
PayloadClaimsHolder holder = holderFor("users", new UserPojo[] { user1, user2 });
serializer.serialize(holder, jsonGenerator, serializerProvider);
jsonGenerator.flush();
assertThat(writer.toString(), is(equalTo("{\"users\":[{\"name\":\"Michael\",\"id\":1},{\"name\":\"Lucas\",\"id\":2}]}")));
}