}
@Test
public void testCodeGrantJSON() throws Exception {
Client c = new Client("client", "secret", true);
ServerAuthorizationCodeGrant grant = new ServerAuthorizationCodeGrant(c, "code", 1, 2);
JSONProvider<ServerAuthorizationCodeGrant> jsonp = new JSONProvider<ServerAuthorizationCodeGrant>();
jsonp.setMarshallAsJaxbElement(true);
jsonp.setUnmarshallAsJaxbElement(true);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
jsonp.writeTo(grant, ServerAuthorizationCodeGrant.class, new Annotation[]{},
MediaType.APPLICATION_JSON_TYPE,
new MetadataMap<String, Object>(), bos);
String encrypted = EncryptionUtils.encryptSequence(bos.toString(), p.key);
String decrypted = EncryptionUtils.decryptSequence(encrypted, p.key);
ServerAuthorizationCodeGrant grant2 = jsonp.readFrom(ServerAuthorizationCodeGrant.class,
Client.class,
new Annotation[]{}, MediaType.APPLICATION_JSON_TYPE,
new MetadataMap<String, String>(),
new ByteArrayInputStream(decrypted.getBytes()));
assertEquals("code", grant2.getCode());
assertEquals(1, grant2.getExpiresIn());
assertEquals(2, grant2.getIssuedAt());
}