@Test
public void testGenerateAccessTokenRequestBody() throws UnsupportedEncodingException {

    Principal principal = SimplePrincipal.create("user_domain", "user",
            "auth_creds", PRINCIPAL_AUTHORITY);
    ZTSClient client = new ZTSClient("http://localhost:4080", principal);
    assertEquals("grant_type=client_credentials&scope=coretech%3Adomain",
            client.generateAccessTokenRequestBody("coretech", null, null, null, 0));
    assertEquals("grant_type=client_credentials&expires_in=100&scope=coretech%3Adomain",
            client.generateAccessTokenRequestBody("coretech", null, null, null, 100));
    assertEquals("grant_type=client_credentials&expires_in=100&scope=coretech%3Adomain",
            client.generateAccessTokenRequestBody("coretech", null, "", null, 100));
    assertEquals("grant_type=client_credentials&expires_in=100&scope=coretech%3Adomain+openid+coretech%3Aservice.api",
            client.generateAccessTokenRequestBody("coretech", null, "api", null, 100));
    assertEquals("grant_type=client_credentials&expires_in=100&scope=coretech%3Arole.readers+openid+coretech%3Aservice.api",
            client.generateAccessTokenRequestBody("coretech", Collections.singletonList("readers"), "api", null, 100));
    assertEquals("grant_type=client_credentials&expires_in=100&scope=coretech%3Arole.readers+openid+coretech%3Aservice.api",
            client.generateAccessTokenRequestBody("coretech", Collections.singletonList("readers"), "api", "", 100));
    assertEquals("grant_type=client_credentials&expires_in=100&scope=coretech%3Arole.readers+openid+coretech%3Aservice.api&proxy_for_principal=user.proxy",
            client.generateAccessTokenRequestBody("coretech", Collections.singletonList("readers"), "api", "user.proxy", 100));
    List<String> roles = new ArrayList<>();
    roles.add("readers");
    roles.add("writers");
    assertEquals("grant_type=client_credentials&expires_in=100&scope=coretech%3Arole.readers+coretech%3Arole.writers+openid+coretech%3Aservice.api",
            client.generateAccessTokenRequestBody("coretech", roles, "api", null, 100));
    client.close();
}