Skip to content

Writing Test cases  #10

Description

@bavly

Hello,

I have seen that the project gives a good example, but I do not see test cases written.
I have written a code for test cases.

I have written a test case for the home page, it is working fine.
but I face an issue that there is an issue related to function obtain tokens.

It returns status code 401 although it should return status code 200 Ok

`

   private String obtainAccessToken(String username, String password) throws Exception {     
   MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
    params.add("grant_type", "password");
   params.add("client_id", "my-trusted-client");
    params.add("username", "user");
    params.add("password", "user");

    ResultActions result 
      = mockMvcURLAuthenication.perform(post("/oauth/token")
      .params(params)
      .with(httpBasic("my-trusted-client",passwordEncoder.encode("secret")))
      .accept("application/json;charset=UTF-8"))
      .andExpect(status().isOk());
      
    String resultString = result.andReturn().getResponse().getContentAsString();
 
    JacksonJsonParser jsonParser = new JacksonJsonParser();
    return jsonParser.parseMap(resultString).get("access_token").toString();
}

`
Thanks

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions