Java Code Examples for javax.ws.rs.core.Response#getLinks()

The following examples show how to use javax.ws.rs.core.Response#getLinks() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommitRestTest.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void getCommitHistoryWithPaginationAndLinksTest() {
    Response response = target().path("commits/" + encode(COMMIT_IRIS[1]) + "/history")
            .queryParam("offset", 1)
            .queryParam("limit", 1)
            .request().get();
    assertEquals(response.getStatus(), 200);
    verify(catalogManager).getCommitChain(vf.createIRI(COMMIT_IRIS[1]));
    MultivaluedMap<String, Object> headers = response.getHeaders();
    assertEquals(headers.get("X-Total-Count").get(0), "" + COMMIT_IRIS.length);
    Set<Link> links = response.getLinks();
    assertEquals(links.size(), 2);
    links.forEach(link -> {
        assertTrue(link.getUri().getRawPath().contains("commits/" + encode(COMMIT_IRIS[1]) + "/history"));
        assertTrue(link.getRel().equals("prev") || link.getRel().equals("next"));
    });
    try {
        JSONArray result = JSONArray.fromObject(response.readEntity(String.class));
        assertEquals(result.size(), 1);
        JSONObject commitObj = result.getJSONObject(0);
        assertTrue(commitObj.containsKey("id"));
        assertEquals(commitObj.getString("id"), COMMIT_IRIS[1]);
    } catch (Exception e) {
        fail("Expected no exception, but got: " + e.getMessage());
    }
}
 
Example 2
Source File: CatalogRestTest.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void getRecordsWithLinksTest() {
    // Setup:
    when(results.getPageNumber()).thenReturn(1);

    Response response = target().path("catalogs/" + encode(LOCAL_IRI) + "/records")
            .queryParam("offset", 1)
            .queryParam("limit", 1).request().get();
    assertEquals(response.getStatus(), 200);
    verify(catalogManager).findRecord(eq(vf.createIRI(LOCAL_IRI)), any(PaginatedSearchParams.class));
    Set<Link> links = response.getLinks();
    assertEquals(links.size(), 2);
    links.forEach(link -> {
        assertTrue(link.getUri().getRawPath().contains("catalogs/" + encode(LOCAL_IRI) + "/records"));
        assertTrue(link.getRel().equals("prev") || link.getRel().equals("next"));
    });
}
 
Example 3
Source File: CatalogRestTest.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void getUnversionedDistributionsWithLinksTest() {
    // Setup:
    Set<Distribution> distributions = IntStream.range(1, 6)
            .mapToObj(i -> DISTRIBUTION_IRI + i)
            .map(s -> distributionFactory.createNew(vf.createIRI(s)))
            .collect(Collectors.toSet());
    distributions.forEach(distribution -> distribution.setProperty(vf.createLiteral("Title"), vf.createIRI(DCTERMS.TITLE.stringValue())));
    when(catalogManager.getUnversionedDistributions(any(Resource.class), any(Resource.class))).thenReturn(distributions);

    Response response = target().path("catalogs/" + encode(LOCAL_IRI) + "/records/" + encode(RECORD_IRI) + "/distributions")
            .queryParam("sort", DCTERMS.TITLE.stringValue())
            .queryParam("offset", 1)
            .queryParam("limit", 1).request().get();
    assertEquals(response.getStatus(), 200);
    verify(catalogManager).getUnversionedDistributions(vf.createIRI(LOCAL_IRI), vf.createIRI(RECORD_IRI));
    Set<Link> links = response.getLinks();
    assertEquals(links.size(), 2);
    links.forEach(link -> {
        assertTrue(link.getUri().getRawPath().contains("catalogs/" + encode(LOCAL_IRI) + "/records/"
                + encode(RECORD_IRI) + "/distributions"));
        assertTrue(link.getRel().equals("prev") || link.getRel().equals("next"));
    });
}
 
Example 4
Source File: CatalogRestTest.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void getVersionsWithLinksTest() {
    // Setup:
    Set<Version> versions = IntStream.range(1, 6)
            .mapToObj(i -> VERSION_IRI + i)
            .map(s -> versionFactory.createNew(vf.createIRI(s)))
            .collect(Collectors.toSet());
    versions.forEach(version -> version.setProperty(vf.createLiteral("Title"), vf.createIRI(DCTERMS.TITLE.stringValue())));
    when(catalogManager.getVersions(vf.createIRI(LOCAL_IRI), vf.createIRI(RECORD_IRI))).thenReturn(versions);

    Response response = target().path("catalogs/" + encode(LOCAL_IRI) + "/records/" + encode(RECORD_IRI) + "/versions")
            .queryParam("sort", DCTERMS.TITLE.stringValue())
            .queryParam("offset", 1)
            .queryParam("limit", 1).request().get();
    assertEquals(response.getStatus(), 200);
    verify(catalogManager).getVersions(vf.createIRI(LOCAL_IRI), vf.createIRI(RECORD_IRI));
    Set<Link> links = response.getLinks();
    assertEquals(links.size(), 2);
    links.forEach(link -> {
        assertTrue(link.getUri().getRawPath().contains("catalogs/" + encode(LOCAL_IRI) + "/records/"
                + encode(RECORD_IRI) + "/versions"));
        assertTrue(link.getRel().equals("prev") || link.getRel().equals("next"));
    });
}
 
Example 5
Source File: CatalogRestTest.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void getVersionedDistributionsWithLinksTest() {
    // Setup:
    Set<Distribution> distributions = IntStream.range(1, 6)
            .mapToObj(i -> DISTRIBUTION_IRI + i)
            .map(s -> distributionFactory.createNew(vf.createIRI(s)))
            .collect(Collectors.toSet());
    distributions.forEach(distribution -> distribution.setProperty(vf.createLiteral("Title"), vf.createIRI(DCTERMS.TITLE.stringValue())));
    when(catalogManager.getVersionedDistributions(vf.createIRI(LOCAL_IRI), vf.createIRI(RECORD_IRI), vf.createIRI(VERSION_IRI))).thenReturn(distributions);

    Response response = target().path("catalogs/" + encode(LOCAL_IRI) + "/records/" + encode(RECORD_IRI)
            + "/versions/" + encode(VERSION_IRI) + "/distributions")
            .queryParam("sort", DCTERMS.TITLE.stringValue())
            .queryParam("offset", 1)
            .queryParam("limit", 1).request().get();
    assertEquals(response.getStatus(), 200);
    verify(catalogManager).getVersionedDistributions(vf.createIRI(LOCAL_IRI), vf.createIRI(RECORD_IRI), vf.createIRI(VERSION_IRI));
    Set<Link> links = response.getLinks();
    assertEquals(links.size(), 2);
    links.forEach(link -> {
        assertTrue(link.getUri().getRawPath().contains("catalogs/" + encode(LOCAL_IRI) + "/records/"
                + encode(RECORD_IRI) + "/versions/" + encode(VERSION_IRI) + "/distributions"));
        assertTrue(link.getRel().equals("prev") || link.getRel().equals("next"));
    });
}
 
Example 6
Source File: CatalogRestTest.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void getBranchesWithLinksTest() {
    // Setup:
    Set<Branch> branches = IntStream.range(1, 6)
            .mapToObj(i -> BRANCH_IRI + i)
            .map(s -> branchFactory.createNew(vf.createIRI(s)))
            .collect(Collectors.toSet());
    branches.forEach(branch -> branch.setProperty(vf.createLiteral("Title"), vf.createIRI(DCTERMS.TITLE.stringValue())));
    when(catalogManager.getBranches(vf.createIRI(LOCAL_IRI), vf.createIRI(RECORD_IRI))).thenReturn(branches);

    Response response = target().path("catalogs/" + encode(LOCAL_IRI) + "/records/" + encode(RECORD_IRI) + "/branches")
            .queryParam("sort", DCTERMS.TITLE.stringValue())
            .queryParam("offset", 1)
            .queryParam("limit", 1).request().get();
    assertEquals(response.getStatus(), 200);
    verify(catalogManager).getBranches(vf.createIRI(LOCAL_IRI), vf.createIRI(RECORD_IRI));
    Set<Link> links = response.getLinks();
    assertEquals(links.size(), 2);
    links.forEach(link -> {
        assertTrue(link.getUri().getRawPath().contains("catalogs/" + encode(LOCAL_IRI) + "/records/"
                + encode(RECORD_IRI) + "/branches"));
        assertTrue(link.getRel().equals("prev") || link.getRel().equals("next"));
    });
}
 
Example 7
Source File: CatalogRestTest.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void getCommitChainWithPaginationAndLinksTest() {
    Response response = target().path("catalogs/" + encode(LOCAL_IRI) + "/records/" + encode(RECORD_IRI)
            + "/branches/" + encode(BRANCH_IRI) + "/commits").queryParam("offset", 1).queryParam("limit", 1)
            .request().get();
    assertEquals(response.getStatus(), 200);
    verify(catalogManager).getCommitChain(vf.createIRI(LOCAL_IRI), vf.createIRI(RECORD_IRI), vf.createIRI(BRANCH_IRI));
    MultivaluedMap<String, Object> headers = response.getHeaders();
    assertEquals(headers.get("X-Total-Count").get(0), "" + COMMIT_IRIS.length);
    Set<Link> links = response.getLinks();
    assertEquals(links.size(), 2);
    links.forEach(link -> {
        assertTrue(link.getUri().getRawPath().contains("catalogs/" + encode(LOCAL_IRI) + "/records/"
                + encode(RECORD_IRI) + "/branches/" + encode(BRANCH_IRI) + "/commits"));
        assertTrue(link.getRel().equals("prev") || link.getRel().equals("next"));
    });
    try {
        JSONArray array = JSONArray.fromObject(response.readEntity(String.class));
        assertEquals(array.size(), 1);
        JSONObject commitObj = array.getJSONObject(0);
        assertTrue(commitObj.containsKey("id"));
        assertEquals(commitObj.getString("id"), COMMIT_IRIS[1]);
    } catch (Exception e) {
        fail("Expected no exception, but got: " + e.getMessage());
    }
}
 
Example 8
Source File: SparqlRestTest.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void getPagedResultsWithLinksTest() {
    Response response = target().path("sparql/page").queryParam("query", ALL_QUERY)
            .queryParam("limit", 1).queryParam("offset", 1).request().get();
    assertEquals(response.getStatus(), 200);
    MultivaluedMap<String, Object> headers = response.getHeaders();
    assertEquals(headers.get("X-Total-Count").get(0), "" + testModel.size());
    Set<Link> links = response.getLinks();
    assertEquals(links.size(), 2);
    links.forEach(link -> {
        assertTrue(link.getUri().getRawPath().contains("sparql/page"));
        assertTrue(link.getRel().equals("prev") || link.getRel().equals("next"));
    });
    JSONObject result = JSONObject.fromObject(response.readEntity(String.class));
    assertTrue(result.containsKey("bindings"));
    assertTrue(result.containsKey("data"));
    JSONArray data = result.getJSONArray("data");
    assertEquals(data.size(), 1);
}
 
Example 9
Source File: DatasetRestTest.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void getDatasetRecordsWithLinksTest() {
    // Setup:
    when(results.getPage()).thenReturn(Collections.singletonList(record2));
    when(results.getPageNumber()).thenReturn(2);
    when(results.getPageSize()).thenReturn(1);

    Response response = target().path("datasets").queryParam("offset", 1).queryParam("limit", 1).request().get();
    assertEquals(response.getStatus(), 200);
    verify(datasetManager).getDatasetRecords(any(DatasetPaginatedSearchParams.class));
    verify(service, atLeastOnce()).skolemize(any(Statement.class));
    MultivaluedMap<String, Object> headers = response.getHeaders();
    assertEquals(headers.get("X-Total-Count").get(0), "3");
    Set<Link> links = response.getLinks();
    assertEquals(links.size(), 2);
    assertTrue(response.hasLink("prev"));
    assertTrue(response.hasLink("next"));
    try {
        JSONArray result = JSONArray.fromObject(response.readEntity(String.class));
        assertEquals(result.size(), 1);
    } catch (Exception e) {
        fail("Expected no exception, but got: " + e.getMessage());
    }
}
 
Example 10
Source File: ProvRestTest.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void getActivitiesWithLinksTest() throws Exception {
    Response response = target().path("provenance-data").queryParam("limit", 2).queryParam("offset", 2).request().get();
    assertEquals(response.getStatus(), 200);
    MultivaluedMap<String, Object> headers = response.getHeaders();
    assertEquals(headers.get("X-Total-Count").get(0), "10");
    Set<Link> links = response.getLinks();
    assertEquals(links.size(), 2);
    assertTrue(response.hasLink("prev"));
    assertTrue(response.hasLink("next"));
    verify(provService, times(2)).getActivity(any(Resource.class));
    try {
        JSONObject result = JSONObject.fromObject(response.readEntity(String.class));
        assertActivities(result, activityIRIs.subList(2, 4));
        assertEntities(result, Stream.of(entityIRIs.get(1), entityIRIs.get(2), entityIRIs.get(3)).collect(Collectors.toList()));
    } catch (Exception e) {
        fail("Expected no exception, but got: " + e.getMessage());
    }
}
 
Example 11
Source File: ExplorableDatasetRestTest.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void getInstanceDetailsWithLinksTest() {
    //Setup:
    String pathString = "explorable-datasets/" + encode(RECORD_ID_STR) + "/classes/" + encode(CLASS_ID_STR)
            + "/instance-details";

    Response response = target().path(pathString).queryParam("offset", 3).queryParam("limit", 3).request().get();
    assertEquals(response.getStatus(), 200);
    JSONArray responseArray = JSONArray.fromObject(response.readEntity(String.class));
    assertEquals(responseArray.size(), 3);
    assertEquals(response.getHeaders().get("X-Total-Count").get(0), "13");
    Set<Link> links = response.getLinks();
    assertEquals(links.size(), 2);
    links.forEach(link -> {
        assertTrue(link.getUri().getRawPath().contains(pathString));
        assertTrue(link.getRel().equals("prev") || link.getRel().equals("next"));
    });
}
 
Example 12
Source File: ShopifySdk.java    From shopify-sdk with Apache License 2.0 5 votes vote down vote up
private <T> ShopifyPage<T> mapPagedResponse(final List<T> items, final Response response) {

		final ShopifyPage<T> shopifyPage = new ShopifyPage<>();
		shopifyPage.addAll(items);

		final Set<Link> links = response.getLinks();
		final String nextLink = links.stream().filter(link -> link.getRel().equals(REL_NEXT_HEADER_KEY))
				.map(link -> getQueryParam(link.getUri(), PAGE_INFO_QUERY_PARAMETER)).findFirst().orElse(null);
		final String previousLink = links.stream().filter(link -> link.getRel().equals(REL_PREVIOUS_HEADER_KEY))
				.map(link -> getQueryParam(link.getUri(), PAGE_INFO_QUERY_PARAMETER)).findFirst().orElse(null);
		shopifyPage.setNextPageInfo(nextLink);
		shopifyPage.setPreviousPageInfo(previousLink);

		return shopifyPage;
	}
 
Example 13
Source File: CommitRestTest.java    From mobi with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void getCommitHistoryWithEntityNoTargetTest() {
    when(catalogManager.getCommitEntityChain(any(Resource.class), any(Resource.class))).thenReturn(entityCommits);
    Response response = target().path("commits/" + encode(COMMIT_IRIS[1]) + "/history")
            .queryParam("entityId", encode(vf.createIRI("http://mobi.com/test/class5")))
            .queryParam("offset", 0)
            .queryParam("limit", 1)
            .request().get();
    assertEquals(response.getStatus(), 200);
    verify(catalogManager).getCommitEntityChain(vf.createIRI(COMMIT_IRIS[1]), vf.createIRI("http://mobi.com/test/class5"));
    MultivaluedMap<String, Object> headers = response.getHeaders();
    assertEquals(headers.get("X-Total-Count").get(0), "" + ENTITY_IRI.length);
    assertEquals(response.getLinks().size(), 0);
    Set<Link> links = response.getLinks();
    assertEquals(links.size(), 0);
    links.forEach(link -> {
        assertTrue(link.getUri().getRawPath().contains("commits/" + encode(COMMIT_IRIS[1]) + "/history"));
        assertTrue(link.getRel().equals("prev") || link.getRel().equals("next"));
    });
    try {
        JSONArray result = JSONArray.fromObject(response.readEntity(String.class));
        assertEquals(result.size(), 1);
        JSONObject commitObj = result.getJSONObject(0);
        assertTrue(commitObj.containsKey("id"));
        assertEquals(commitObj.getString("id"), COMMIT_IRIS[1]);
    } catch (Exception e) {
        fail("Expected no exception, but got: " + e.getMessage());
    }
}
 
Example 14
Source File: CommitRestTest.java    From mobi with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void getCommitHistoryWithEntityAndTargetTest() {
    when(catalogManager.getCommitEntityChain(any(Resource.class), any(Resource.class), any(Resource.class))).thenReturn(entityCommits);
    Response response = target().path("commits/" + encode(COMMIT_IRIS[1]) + "/history")
            .queryParam("targetId", encode(COMMIT_IRIS[0]))
            .queryParam("entityId", encode(vf.createIRI("http://mobi.com/test/class5")))
            .request().get();
    assertEquals(response.getStatus(), 200);
    verify(catalogManager).getCommitEntityChain(vf.createIRI(COMMIT_IRIS[1]), vf.createIRI(COMMIT_IRIS[0]), vf.createIRI("http://mobi.com/test/class5"));
    MultivaluedMap<String, Object> headers = response.getHeaders();
    assertEquals(headers.get("X-Total-Count").get(0), "" + ENTITY_IRI.length);
    Set<Link> links = response.getLinks();
    assertEquals(links.size(), 0);
    links.forEach(link -> {
        assertTrue(link.getUri().getRawPath().contains("commits/" + encode(COMMIT_IRIS[1]) + "/history"));
        assertTrue(link.getRel().equals("prev") || link.getRel().equals("next"));
    });
    try {
        JSONArray result = JSONArray.fromObject(response.readEntity(String.class));
        assertEquals(result.size(), 1);
        JSONObject commitObj = result.getJSONObject(0);
        assertTrue(commitObj.containsKey("id"));
        assertEquals(commitObj.getString("id"), COMMIT_IRIS[1]);
    } catch (Exception e) {
        fail("Expected no exception, but got: " + e.getMessage());
    }
}
 
Example 15
Source File: LinkTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Test
public void get() throws IOException {
    final Response response = ClientBuilder.newClient()
            .target(base.toExternalForm()).path("openejb/link")
            // cxf is not consistent for Link and other headers, see org.apache.cxf.transport.http.Headers.copyToResponse()
            .property("org.apache.cxf.http.header.split", true)
            .request(WILDCARD_TYPE).get();
    assertEquals(2, Collection.class.cast(response.getHeaders().get("a")).size());

    final Set<Link> actual = response.getLinks();
    assertEquals(2, actual.size());

    final Set<Link> expected = new LinkEndpoint().doLink().getLinks();
    assertEquals(expected, actual);
}