use of javax.ws.rs.HttpMethod.GET in project che by eclipse.
the class ProjectServiceTest method testResolveSources.
@Test
public void testResolveSources() throws Exception {
VirtualFile root = pm.getProjectsRoot().getVirtualFile();
root.createFolder("testEstimateProjectGood").createFolder("check");
root.createFolder("testEstimateProjectBad");
final ValueProviderFactory vpf1 = projectFolder -> new ReadonlyValueProvider() {
@Override
public List<String> getValues(String attributeName) throws ValueStorageException {
VirtualFileEntry file;
try {
file = projectFolder.getChild("check");
} catch (ServerException e) {
throw new ValueStorageException(e.getMessage());
}
if (file == null) {
throw new ValueStorageException("Check not found");
}
return (List<String>) singletonList("checked");
}
};
ProjectTypeDef pt = new ProjectTypeDef("testEstimateProjectPT", "my testEstimateProject type", true, false) {
{
addVariableDefinition("calculated_attribute", "attr description", true, vpf1);
addVariableDefinition("my_property_1", "attr description", true);
addVariableDefinition("my_property_2", "attr description", false);
}
};
ptRegistry.registerProjectType(pt);
ContainerResponse response = launcher.service(GET, format("http://localhost:8080/api/project/resolve/%s", "testEstimateProjectGood"), "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
List<SourceEstimation> result = (List<SourceEstimation>) response.getEntity();
assertTrue(result.size() > 0);
boolean m = false;
for (SourceEstimation est : result) {
if (est.getType().equals("testEstimateProjectPT")) {
assertTrue(est.isMatched());
m = true;
}
}
assertTrue(m);
}
use of javax.ws.rs.HttpMethod.GET in project linuxtools by eclipse.
the class AbstractRegistry method retrieveTagsFromRegistryV1.
/**
* Retrieves the list of tags for a given repository, assuming that the
* target registry is a registry v2 instance.
*
* @param client
* the client to use
* @param repository
* the repository to look-up
* @return the list of tags for the given repository
* @throws CancellationException
* - if the computation was cancelled
* @throws ExecutionException
* - if the computation threw an exception
* @throws InterruptedException
* - if the current thread was interrupted while waiting
*/
private List<IRepositoryTag> retrieveTagsFromRegistryV1(final Client client, final String repository) throws InterruptedException, ExecutionException {
final GenericType<Map<String, String>> REPOSITORY_TAGS_RESULT_LIST = new GenericType<Map<String, String>>() {
};
final WebTarget queryTagsResource = client.target(getHTTPServerAddress()).path(// $NON-NLS-1$
"v1").path("repositories").path(repository).path(// $NON-NLS-1$ //$NON-NLS-2$
"tags");
return queryTagsResource.request(APPLICATION_JSON_TYPE).async().method(GET, REPOSITORY_TAGS_RESULT_LIST).get().entrySet().stream().map(e -> new RepositoryTag(e.getKey(), e.getValue())).collect(Collectors.toList());
}
use of javax.ws.rs.HttpMethod.GET in project linuxtools by eclipse.
the class AbstractRegistry method getImages.
@Override
public List<IDockerImageSearchResult> getImages(String term) throws DockerException {
final Client client = ClientBuilder.newClient(DEFAULT_CONFIG);
List<IDockerImageSearchResult> result = new ArrayList<>();
WebTarget queryImagesResource;
if (isVersion2()) {
final GenericType<ImageSearchResultV2> IMAGE_SEARCH_RESULT_LIST = new GenericType<ImageSearchResultV2>() {
};
ImageSearchResultV2 cisr = null;
queryImagesResource = client.target(getHTTPServerAddress()).path("v2").path(// $NON-NLS-1$ //$NON-NLS-2$
"_catalog");
try {
cisr = queryImagesResource.request(APPLICATION_JSON_TYPE).async().method(GET, IMAGE_SEARCH_RESULT_LIST).get();
} catch (InterruptedException | ExecutionException e) {
throw new DockerException(e);
}
List<ImageSearchResult> tmp = cisr.getRepositories().stream().filter(e -> e.name().contains(term)).collect(Collectors.toList());
result.addAll(tmp.stream().map(r -> new DockerImageSearchResult(r.description(), r.official(), r.automated(), r.name(), r.starCount())).collect(Collectors.toList()));
} else {
ImageSearchResultV1 pisr = null;
final GenericType<ImageSearchResultV1> IMAGE_SEARCH_RESULT_LIST = new GenericType<ImageSearchResultV1>() {
};
int page = 0;
try {
while (pisr == null || pisr.getPage() < pisr.getTotalPages()) {
page++;
queryImagesResource = client.target(getHTTPServerAddress()).path("v1").path(// $NON-NLS-1$ //$NON-NLS-2$
"search").queryParam("q", // $NON-NLS-1$
term).queryParam("page", // $NON-NLS-1$
page);
pisr = queryImagesResource.request(APPLICATION_JSON_TYPE).async().method(GET, IMAGE_SEARCH_RESULT_LIST).get();
List<ImageSearchResult> tmp = pisr.getResult();
result.addAll(tmp.stream().map(r -> new DockerImageSearchResult(r.description(), r.official(), r.automated(), r.name(), r.starCount())).collect(Collectors.toList()));
}
} catch (InterruptedException | ExecutionException e) {
throw new DockerException(e);
}
}
return result;
}
use of javax.ws.rs.HttpMethod.GET in project ddf by codice.
the class TestOidc method processCredentialFlow.
/**
* Processes a credential flow request/response
*
* <ul>
* <li>Sets up a userinfo endpoint that responds with the given {@param userInfoResponse} when
* given {@param accessToken}
* <li>Sends a request to Intrigue with the {@param accessToken} as a parameter
* <li>Asserts that the response is teh expected response
* <li>Verifies if the userinfo endpoint is hit or not
* </ul>
*
* @return the response for additional verification
*/
private Response processCredentialFlow(String accessToken, String userInfoResponse, boolean isSigned, int expectedStatusCode, boolean userInfoShouldBeHit) {
// Host the user info endpoint with the access token in the auth header
String basicAuthHeader = "Bearer " + accessToken;
String contentType = isSigned ? "application/jwt" : APPLICATION_JSON;
whenHttp(server).match(get(USER_INFO_ENDPOINT_PATH), withHeader(AUTHORIZATION, basicAuthHeader)).then(ok(), contentType(contentType), bytesContent(userInfoResponse.getBytes()));
// Send a request to DDF with the access token
Response response = given().redirects().follow(false).expect().statusCode(expectedStatusCode).when().get(ROOT_URL.getUrl() + "?access_token=" + accessToken);
List<Call> endpointCalls = server.getCalls().stream().filter(call -> call.getMethod().getMethodString().equals(GET)).filter(call -> call.getUrl().equals(URL_START + USER_INFO_ENDPOINT_PATH)).collect(Collectors.toList());
if (userInfoShouldBeHit) {
assertThat(endpointCalls.size(), is(greaterThanOrEqualTo(1)));
} else {
assertThat(endpointCalls.size(), is(0));
}
return response;
}
use of javax.ws.rs.HttpMethod.GET in project che by eclipse.
the class ProjectServiceTest method testEstimateProject.
@Test
public void testEstimateProject() throws Exception {
VirtualFile root = pm.getProjectsRoot().getVirtualFile();
//getVirtualFileSystemRegistry().getProvider("my_ws").getMountPoint(false).getRoot();
root.createFolder("testEstimateProjectGood").createFolder("check");
root.createFolder("testEstimateProjectBad");
String errMessage = "File /check not found";
final ValueProviderFactory vpf1 = projectFolder -> new ReadonlyValueProvider() {
@Override
public List<String> getValues(String attributeName) throws ValueStorageException {
VirtualFileEntry file;
try {
file = projectFolder.getChild("check");
} catch (ServerException e) {
throw new ValueStorageException(e.getMessage());
}
if (file == null) {
throw new ValueStorageException(errMessage);
}
return (List<String>) singletonList("checked");
}
};
ProjectTypeDef pt = new ProjectTypeDef("testEstimateProjectPT", "my testEstimateProject type", true, false) {
{
addVariableDefinition("calculated_attribute", "attr description", true, vpf1);
addVariableDefinition("my_property_1", "attr description", true);
addVariableDefinition("my_property_2", "attr description", false);
}
};
ptRegistry.registerProjectType(pt);
ContainerResponse response = launcher.service(GET, format("http://localhost:8080/api/project/estimate/%s?type=%s", "testEstimateProjectGood", "testEstimateProjectPT"), "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
//noinspection unchecked
SourceEstimation result = (SourceEstimation) response.getEntity();
assertTrue(result.isMatched());
assertEquals(result.getAttributes().size(), 1);
assertEquals(result.getAttributes().get("calculated_attribute").get(0), "checked");
// if project not matched
response = launcher.service(GET, format("http://localhost:8080/api/project/estimate/%s?type=%s", "testEstimateProjectBad", "testEstimateProjectPT"), "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
//noinspection unchecked
result = (SourceEstimation) response.getEntity();
assertFalse(result.isMatched());
assertEquals(result.getAttributes().size(), 0);
}
Aggregations