@Test
public void testPostAccessTokenRequestInvalidRequest() {

    SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true);
    store.processDomain(signedDomain, false);
    Principal principal = SimplePrincipal.create("user_domain", "user",
            "v=U1;d=user_domain;n=user;s=signature", 0, null);
    ResourceContext context = createResourceContext(principal);
    try {
        zts.postAccessTokenRequest(context, null);
        fail();
    } catch (ResourceException ex) {
        assertEquals(400, ex.getCode());
    }
    try {
        zts.postAccessTokenRequest(context, "");
        fail();
    } catch (ResourceException ex) {
        assertEquals(400, ex.getCode());
    }
    try {
        zts.postAccessTokenRequest(context, "grant_type=unknown_type&scope=openid");
        fail();
    } catch (ResourceException ex) {
        assertEquals(400, ex.getCode());
        assertTrue(ex.getMessage().contains("Invalid grant request"));
    }
    try {
        zts.postAccessTokenRequest(context, "grant_type%=client_credentials");
        fail();
    } catch (ResourceException ex) {
        assertEquals(400, ex.getCode());
        assertTrue(ex.getMessage().contains("Invalid grant request"));
    }
    try {
        zts.postAccessTokenRequest(context, "grant_type=client_credentials%");
        fail();
    } catch (ResourceException ex) {
        assertEquals(400, ex.getCode());
        assertTrue(ex.getMessage().contains("Invalid grant request"));
    }
    try {
        zts.postAccessTokenRequest(context, "grant_type");
        fail();
    } catch (ResourceException ex) {
        assertEquals(400, ex.getCode());
        assertTrue(ex.getMessage().contains("Invalid grant request"));
    }
    try {
        zts.postAccessTokenRequest(context, "grant_type=client_credentials");
        fail();
    } catch (ResourceException ex) {
        assertEquals(400, ex.getCode());
        assertTrue(ex.getMessage().contains("no scope provided"));
    }
    try {
        zts.postAccessTokenRequest(context, "grant_type=client_credentials&scope=");
        fail();
    } catch (ResourceException ex) {
        assertEquals(400, ex.getCode());
        assertTrue(ex.getMessage().contains("no scope provided"));
    }
}