Esempio n. 1
0
  @Test
  public void testGetLegacyPodcasts()
      throws JsonGenerationException, JsonMappingException, IOException {

    ClientConfig clientConfig = new ClientConfig();
    clientConfig.register(JacksonFeature.class);

    Client client = ClientBuilder.newClient(clientConfig);

    WebTarget webTarget =
        client.target("http://localhost:8888/demo-rest-jersey-spring/legacy/podcasts/");

    Builder request = webTarget.request();
    request.header("Content-type", MediaType.APPLICATION_JSON);

    Response response = request.get();
    Assert.assertTrue(response.getStatus() == 200);

    List<Podcast> podcasts = response.readEntity(new GenericType<List<Podcast>>() {});

    ObjectMapper mapper = new ObjectMapper();
    System.out.print(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(podcasts));

    Assert.assertTrue("At least one podcast is present in the LEGACY", podcasts.size() > 0);
  }
  /**
   * Returns the information of an specific board.
   *
   * @param boardId Board identifier.
   * @return Board information.
   */
  public Board getBoard(String boardId) {
    String uri = getConfiguration().getHostAndContext() + ALL_BOARDS_RESOURCE + "/{boardId}";
    WebTarget target = getClient().target(uri).resolveTemplate("boardId", boardId);
    Builder builder = getBuilder(target);

    return builder.get(Board.class);
  }
 @Test(expected = ClientErrorException.class)
 public void testGetReturns403() throws Exception {
   // Arrange
   Mockito.when(response.getStatus()).thenReturn(403);
   Mockito.when(response.getStatusInfo().getFamily())
       .thenReturn(Response.Status.Family.CLIENT_ERROR);
   Mockito.when(builder.get()).thenReturn(response);
   // Act
   classUnderTest.getOne(builder);
   // Assert
   fail("Should have thrown an Exception");
 }
  @Test
  @SuppressWarnings("unchecked")
  public void testGetReturns200() throws Exception {
    // Arrange
    Issue expected = new Issue(new Project("1"), "sum", "desc", new IssueType("1", "A"));
    Mockito.when(response.getStatus()).thenReturn(200);

    String jsonstring = ClientUtils.getGson().toJson(expected);
    Mockito.when(response.readEntity(Mockito.any(Class.class))).thenReturn(jsonstring);
    Mockito.when(builder.get()).thenReturn(response);
    // Act
    Issue actual = classUnderTest.getOne(builder);
    // Assert
    assertEquals(expected, actual);
  }
Esempio n. 5
0
  @Test
  public void shouldGetVdbXml() throws Exception {
    loadVdbs();

    Properties settings =
        _uriBuilder.createSettings(SettingNames.VDB_NAME, TestUtilities.PORTFOLIO_VDB_NAME);
    URI uri = _uriBuilder.buildVdbUri(LinkType.SELF, settings);
    Builder request = this.client.target(uri.toString()).request(MediaType.APPLICATION_XML);
    this.response = request.get();
    final String entity = this.response.readEntity(String.class);
    assertThat(entity, is(notNullValue()));

    // System.out.println("Response:\n" + entity);
    assertTrue(entity.contains("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
    assertTrue(entity.contains("<vdb name=\"Portfolio\" version=\"1\">"));
    assertTrue(entity.contains("</vdb>"));
  }
Esempio n. 6
0
  @Test
  public void shouldNotGetVdbsXml() throws Exception {
    loadVdbs();

    URI uri = _uriBuilder.generateVdbsUri();
    Builder request = this.client.target(uri.toString()).request(MediaType.APPLICATION_XML);
    this.response = request.get();

    assertTrue(response.hasEntity());

    //
    // Internal server error since the server does not support
    // '/vdbs' url returning anything in xml
    //
    assertEquals(500, response.getStatus());

    final String entity = response.readEntity(String.class);
    assertThat(entity, is(notNullValue()));

    assertEquals("No match for accept header", entity);
  }
Esempio n. 7
0
  @Test
  public void testGetPodcast() throws JsonGenerationException, JsonMappingException, IOException {

    ClientConfig clientConfig = new ClientConfig();
    clientConfig.register(JacksonFeature.class);

    Client client = ClientBuilder.newClient(clientConfig);

    WebTarget webTarget = client.target("http://localhost:8888/demo-rest-jersey-spring/podcasts/2");

    Builder request = webTarget.request(MediaType.APPLICATION_JSON);

    Response response = request.get();
    Assert.assertTrue(response.getStatus() == 200);

    Podcast podcast = response.readEntity(Podcast.class);

    ObjectMapper mapper = new ObjectMapper();
    System.out.print(
        "Received podcast from database *************************** "
            + mapper.writerWithDefaultPrettyPrinter().writeValueAsString(podcast));
  }
 public static Response get(URI uri, MediaType acceptType) {
   WebTarget target = builder.build().target(uri);
   Builder httpRequest = target.request();
   if (acceptType != null) httpRequest.accept(acceptType);
   return httpRequest.get();
 }
  /**
   * Returns all the boards on the Jira instance.
   *
   * @return List of all boards.
   */
  public ResponseList<Board> getAllBoards() {
    String uri = getConfiguration().getHostAndContext() + ALL_BOARDS_RESOURCE;

    Builder builder = getBuilder(getClient().target(uri));
    return builder.get(new GenericType<ResponseList<Board>>() {});
  }