public void getSimpleParam() throws Exception {
    HttpTester request = makeRequest("GET", "/a/simple?var=Salomon");
    HttpTester response = getResponse(request);

    assertEquals(response.getStatus(), 200);
    assertEquals(response.getContent(), "v:Salomon");
  }
  public void getMatch() throws Exception {
    HttpTester request = makeRequest("GET", "/b/match-one-two-three");
    HttpTester response = getResponse(request);

    assertEquals(response.getStatus(), 200);
    assertEquals(response.getContent(), "get:one:two:three");
  }
  public void getHello() throws Exception {
    HttpTester request = makeRequest("GET", "/a/hello");
    HttpTester response = getResponse(request);

    assertEquals(response.getStatus(), 200);
    assertEquals(response.getContent(), "Hello, world");
  }
  public void getSimpleProduces() throws Exception {
    HttpTester request = makeRequest("GET", "/a/simple");
    request.addHeader("accept", "x-sj-test,xml;");
    HttpTester response = getResponse(request);

    assertEquals(response.getStatus(), 200);
    assertEquals(response.getContent(), "Produces");
  }
  public void getSimpleConsumes() throws Exception {
    HttpTester request = makeRequest("GET", "/a/simple");
    request.addHeader("content-type", "x-sj-test");
    HttpTester response = getResponse(request);

    assertEquals(response.getStatus(), 200);
    assertEquals(response.getContent(), "Consumes");
  }
  public void getSimpleHeader() throws Exception {
    HttpTester request = makeRequest("GET", "/a/simple");
    request.addHeader("x-sj-test", "Salomon");
    HttpTester response = getResponse(request);

    assertEquals(response.getStatus(), 200);
    assertEquals(response.getContent(), "h:Salomon");
  }
  public void getPrint() throws Exception {
    HttpTester request = makeRequest("POST", "/a/print");
    addPost(request, "txt", "hello the world");
    HttpTester response = getResponse(request);

    assertEquals(response.getStatus(), 200);
    assertEquals(response.getContent(), "hello the world");
  }
示例#8
0
  @Test
  public void testCreateTokenWithPassword() throws Exception {
    when(ServiceLocator.getInstance()
            .getCredentialAuth()
            .authenticate(any(PasswordCredentials.class)))
        .thenReturn(claim);

    HttpTester req = new HttpTester();
    req.setMethod("POST");
    req.setHeader("Content-Type", "application/x-www-form-urlencoded");
    req.setContent(DIRECT_AUTH);
    req.setURI(CONTEXT + TokenEndpoint.TOKEN_GRANT_ENDPOINT);
    req.setVersion("HTTP/1.0");

    HttpTester resp = new HttpTester();
    resp.parse(server.getResponses(req.generate()));
    assertEquals(201, resp.getStatus());
    assertTrue(resp.getContent().contains("expires_in\":10"));
    assertTrue(resp.getContent().contains("Bearer"));
  }
示例#9
0
  @Test
  public void testCreateTokenWithRefreshToken() throws Exception {
    when(ServiceLocator.getInstance().getTokenStore().get(anyString()))
        .thenReturn(new AuthenticationBuilder(claim).build());
    when(ServiceLocator.getInstance().getIdmService().listRoles(anyString(), anyString()))
        .thenReturn(Arrays.asList("admin", "user"));

    HttpTester req = new HttpTester();
    req.setMethod("POST");
    req.setHeader("Content-Type", "application/x-www-form-urlencoded");
    req.setContent(REFRESH_TOKEN);
    req.setURI(CONTEXT + TokenEndpoint.TOKEN_GRANT_ENDPOINT);
    req.setVersion("HTTP/1.0");

    HttpTester resp = new HttpTester();
    resp.parse(server.getResponses(req.generate()));
    assertEquals(201, resp.getStatus());
    assertTrue(resp.getContent().contains("expires_in\":10"));
    assertTrue(resp.getContent().contains("Bearer"));
  }