Search in sources :

Example 1 with GET

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);
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) DELETE(javax.ws.rs.HttpMethod.DELETE) Arrays(java.util.Arrays) Listeners(org.testng.annotations.Listeners) GET(javax.ws.rs.HttpMethod.GET) Path(org.eclipse.che.api.vfs.Path) Test(org.testng.annotations.Test) AfterMethod(org.testng.annotations.AfterMethod) Collections.singletonList(java.util.Collections.singletonList) HttpJsonRequest(org.eclipse.che.api.core.rest.HttpJsonRequest) FileWatcherManager(org.eclipse.che.api.vfs.watcher.FileWatcherManager) Future(java.util.concurrent.Future) CreateProjectHandler(org.eclipse.che.api.project.server.handlers.CreateProjectHandler) ResourceBinderImpl(org.everrest.core.impl.ResourceBinderImpl) Map(java.util.Map) HttpJsonRequestFactory(org.eclipse.che.api.core.rest.HttpJsonRequestFactory) RequestDispatcher(org.everrest.core.impl.RequestDispatcher) ProviderBinder(org.everrest.core.impl.ProviderBinder) APPLICATION_ZIP(org.eclipse.che.commons.lang.ws.rs.ExtMediaType.APPLICATION_ZIP) Attribute(org.eclipse.che.api.core.model.project.type.Attribute) HttpJsonResponse(org.eclipse.che.api.core.rest.HttpJsonResponse) Set(java.util.Set) EverrestProcessor(org.everrest.core.impl.EverrestProcessor) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) Executors(java.util.concurrent.Executors) ResourceLauncher(org.everrest.core.tools.ResourceLauncher) IoUtil(org.eclipse.che.commons.lang.IoUtil) Matchers.any(org.mockito.Matchers.any) CountDownLatch(java.util.concurrent.CountDownLatch) ApiExceptionMapper(org.eclipse.che.api.core.rest.ApiExceptionMapper) UserDao(org.eclipse.che.api.user.server.spi.UserDao) EverrestConfiguration(org.everrest.core.impl.EverrestConfiguration) Assert.assertFalse(org.junit.Assert.assertFalse) ApplicationContext(org.everrest.core.ApplicationContext) ByteStreams(com.google.common.io.ByteStreams) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) TEXT_PLAIN(javax.ws.rs.core.MediaType.TEXT_PLAIN) Mockito.mock(org.mockito.Mockito.mock) ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Mock(org.mockito.Mock) ResourceBinder(org.everrest.core.ResourceBinder) ProjectImporterRegistry(org.eclipse.che.api.project.server.importer.ProjectImporterRegistry) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ProjectTypeDef(org.eclipse.che.api.project.server.type.ProjectTypeDef) FSLuceneSearcherProvider(org.eclipse.che.api.vfs.search.impl.FSLuceneSearcherProvider) LinkedHashSet(java.util.LinkedHashSet) ProjectImporter(org.eclipse.che.api.project.server.importer.ProjectImporter) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) File(java.io.File) ValueHolder(org.eclipse.che.api.core.util.ValueHolder) ServerException(org.eclipse.che.api.core.ServerException) ValueStorageException(org.eclipse.che.api.project.server.type.ValueStorageException) SourceEstimation(org.eclipse.che.api.project.shared.dto.SourceEstimation) ByteArrayContainerResponseWriter(org.everrest.core.tools.ByteArrayContainerResponseWriter) Assert(org.junit.Assert) Assert.assertEqualsNoOrder(org.testng.Assert.assertEqualsNoOrder) ApplicationContext.anApplicationContext(org.everrest.core.ApplicationContext.anApplicationContext) LineConsumerFactory(org.eclipse.che.api.core.util.LineConsumerFactory) Scanner(java.util.Scanner) ProjectTypeRegistry(org.eclipse.che.api.project.server.type.ProjectTypeRegistry) FileWatcherNotificationHandler(org.eclipse.che.api.vfs.impl.file.FileWatcherNotificationHandler) Application(javax.ws.rs.core.Application) ProjectHandlerRegistry(org.eclipse.che.api.project.server.handlers.ProjectHandlerRegistry) ByteArrayInputStream(java.io.ByteArrayInputStream) PathMatcher(java.nio.file.PathMatcher) LocalVirtualFileSystemProvider(org.eclipse.che.api.vfs.impl.file.LocalVirtualFileSystemProvider) URI(java.net.URI) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) ZipEntry(java.util.zip.ZipEntry) EventService(org.eclipse.che.api.core.notification.EventService) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) BeforeMethod(org.testng.annotations.BeforeMethod) Assert.assertNotNull(org.testng.Assert.assertNotNull) SourceStorage(org.eclipse.che.api.core.model.project.SourceStorage) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) ItemReference(org.eclipse.che.api.project.shared.dto.ItemReference) List(java.util.List) POST(javax.ws.rs.HttpMethod.POST) PUT(javax.ws.rs.HttpMethod.PUT) ValueProviderFactory(org.eclipse.che.api.project.server.type.ValueProviderFactory) IntStream(java.util.stream.IntStream) ReadonlyValueProvider(org.eclipse.che.api.project.server.type.ReadonlyValueProvider) Link(org.eclipse.che.api.core.rest.shared.dto.Link) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) Assert.assertEquals(org.testng.Assert.assertEquals) HashMap(java.util.HashMap) ProjectTypeConstraintException(org.eclipse.che.api.project.server.type.ProjectTypeConstraintException) DependencySupplierImpl(org.everrest.core.tools.DependencySupplierImpl) FileTreeWatcher(org.eclipse.che.api.vfs.impl.file.FileTreeWatcher) HashSet(java.util.HashSet) Charset(java.nio.charset.Charset) ConflictException(org.eclipse.che.api.core.ConflictException) LinkedList(java.util.LinkedList) DefaultFileWatcherNotificationHandler(org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler) DtoFactory(org.eclipse.che.dto.server.DtoFactory) ExecutorService(java.util.concurrent.ExecutorService) ContainerResponse(org.everrest.core.impl.ContainerResponse) RequestHandlerImpl(org.everrest.core.impl.RequestHandlerImpl) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) ExtMediaType(org.eclipse.che.commons.lang.ws.rs.ExtMediaType) SelfReturningAnswer(org.eclipse.che.commons.test.mockito.answer.SelfReturningAnswer) Mockito.when(org.mockito.Mockito.when) TreeElement(org.eclipse.che.api.project.shared.dto.TreeElement) NotFoundException(org.eclipse.che.api.core.NotFoundException) MoveOptions(org.eclipse.che.api.project.shared.dto.MoveOptions) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) CopyOptions(org.eclipse.che.api.project.shared.dto.CopyOptions) Collections(java.util.Collections) InputStream(java.io.InputStream) ServerException(org.eclipse.che.api.core.ServerException) ContainerResponse(org.everrest.core.impl.ContainerResponse) ProjectTypeDef(org.eclipse.che.api.project.server.type.ProjectTypeDef) ValueStorageException(org.eclipse.che.api.project.server.type.ValueStorageException) SourceEstimation(org.eclipse.che.api.project.shared.dto.SourceEstimation) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ReadonlyValueProvider(org.eclipse.che.api.project.server.type.ReadonlyValueProvider) ValueProviderFactory(org.eclipse.che.api.project.server.type.ValueProviderFactory) Test(org.testng.annotations.Test)

Example 2 with GET

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());
}
Also used : GET(javax.ws.rs.HttpMethod.GET) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) TimeoutException(java.util.concurrent.TimeoutException) ArrayList(java.util.ArrayList) RepositoryTag(org.eclipse.linuxtools.internal.docker.core.RepositoryTag) ClientBuilder(javax.ws.rs.client.ClientBuilder) ImageSearchResultV1(org.eclipse.linuxtools.internal.docker.core.ImageSearchResultV1) Map(java.util.Map) Status(javax.ws.rs.core.Response.Status) ObjectMapperProvider(com.spotify.docker.client.ObjectMapperProvider) CancellationException(java.util.concurrent.CancellationException) NLS(org.eclipse.osgi.util.NLS) JacksonFeature(org.glassfish.jersey.jackson.JacksonFeature) Collectors(java.util.stream.Collectors) ImageSearchResultV2(org.eclipse.linuxtools.internal.docker.core.ImageSearchResultV2) BearerTokenResponse(org.eclipse.linuxtools.internal.docker.core.OAuth2Utils.BearerTokenResponse) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) GenericType(javax.ws.rs.core.GenericType) List(java.util.List) ImageSearchResult(com.spotify.docker.client.messages.ImageSearchResult) Response(javax.ws.rs.core.Response) DockerImageSearchResult(org.eclipse.linuxtools.internal.docker.core.DockerImageSearchResult) RepositoryTagV2(org.eclipse.linuxtools.internal.docker.core.RepositoryTagV2) APPLICATION_JSON_TYPE(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE) WebTarget(javax.ws.rs.client.WebTarget) OAuth2Utils(org.eclipse.linuxtools.internal.docker.core.OAuth2Utils) GenericType(javax.ws.rs.core.GenericType) RepositoryTag(org.eclipse.linuxtools.internal.docker.core.RepositoryTag) WebTarget(javax.ws.rs.client.WebTarget) Map(java.util.Map)

Example 3 with GET

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;
}
Also used : GET(javax.ws.rs.HttpMethod.GET) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) TimeoutException(java.util.concurrent.TimeoutException) ArrayList(java.util.ArrayList) RepositoryTag(org.eclipse.linuxtools.internal.docker.core.RepositoryTag) ClientBuilder(javax.ws.rs.client.ClientBuilder) ImageSearchResultV1(org.eclipse.linuxtools.internal.docker.core.ImageSearchResultV1) Map(java.util.Map) Status(javax.ws.rs.core.Response.Status) ObjectMapperProvider(com.spotify.docker.client.ObjectMapperProvider) CancellationException(java.util.concurrent.CancellationException) NLS(org.eclipse.osgi.util.NLS) JacksonFeature(org.glassfish.jersey.jackson.JacksonFeature) Collectors(java.util.stream.Collectors) ImageSearchResultV2(org.eclipse.linuxtools.internal.docker.core.ImageSearchResultV2) BearerTokenResponse(org.eclipse.linuxtools.internal.docker.core.OAuth2Utils.BearerTokenResponse) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) GenericType(javax.ws.rs.core.GenericType) List(java.util.List) ImageSearchResult(com.spotify.docker.client.messages.ImageSearchResult) Response(javax.ws.rs.core.Response) DockerImageSearchResult(org.eclipse.linuxtools.internal.docker.core.DockerImageSearchResult) RepositoryTagV2(org.eclipse.linuxtools.internal.docker.core.RepositoryTagV2) APPLICATION_JSON_TYPE(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE) WebTarget(javax.ws.rs.client.WebTarget) OAuth2Utils(org.eclipse.linuxtools.internal.docker.core.OAuth2Utils) ImageSearchResultV2(org.eclipse.linuxtools.internal.docker.core.ImageSearchResultV2) GenericType(javax.ws.rs.core.GenericType) ImageSearchResultV1(org.eclipse.linuxtools.internal.docker.core.ImageSearchResultV1) ArrayList(java.util.ArrayList) ImageSearchResult(com.spotify.docker.client.messages.ImageSearchResult) DockerImageSearchResult(org.eclipse.linuxtools.internal.docker.core.DockerImageSearchResult) DockerImageSearchResult(org.eclipse.linuxtools.internal.docker.core.DockerImageSearchResult) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with GET

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;
}
Also used : Response(io.restassured.response.Response) KeyPair(java.security.KeyPair) Arrays(java.util.Arrays) StubServer(com.xebialabs.restito.server.StubServer) GET(javax.ws.rs.HttpMethod.GET) Enumeration(java.util.Enumeration) Date(java.util.Date) PREFERRED_USERNAME(org.pac4j.oidc.profile.OidcProfileDefinition.PREFERRED_USERNAME) HttpStatus(org.apache.http.HttpStatus) GsonBuilder(com.google.gson.GsonBuilder) Algorithm(com.auth0.jwt.algorithms.Algorithm) NONCE(org.pac4j.oidc.profile.OidcProfileDefinition.NONCE) RSAPublicKey(java.security.interfaces.RSAPublicKey) Gson(com.google.gson.Gson) Duration(java.time.Duration) Map(java.util.Map) Base64URL(com.nimbusds.jose.util.Base64URL) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest) URI(java.net.URI) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) KeyPairGenerator(java.security.KeyPairGenerator) Awaitility.await(org.awaitility.Awaitility.await) ImmutableMap(com.google.common.collect.ImmutableMap) JWTCreator(com.auth0.jwt.JWTCreator) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) Condition.parameter(com.xebialabs.restito.semantics.Condition.parameter) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) JWK(com.nimbusds.jose.jwk.JWK) StandardCharsets(java.nio.charset.StandardCharsets) HOST(javax.ws.rs.core.HttpHeaders.HOST) PerSuite(org.ops4j.pax.exam.spi.reactors.PerSuite) List(java.util.List) JSONObject(org.json.simple.JSONObject) Action.bytesContent(com.xebialabs.restito.semantics.Action.bytesContent) KeyUse(com.nimbusds.jose.jwk.KeyUse) URLEncodedUtils(org.apache.http.client.utils.URLEncodedUtils) SECURE_ROOT(org.codice.ddf.itests.common.AbstractIntegrationTest.DynamicUrl.SECURE_ROOT) Action.ok(com.xebialabs.restito.semantics.Action.ok) RestAssured.given(io.restassured.RestAssured.given) Matchers.is(org.hamcrest.Matchers.is) Condition.withHeader(com.xebialabs.restito.semantics.Condition.withHeader) AfterExam(org.codice.ddf.test.common.annotations.AfterExam) NameValuePair(org.apache.http.NameValuePair) Dictionary(java.util.Dictionary) StubHttp.whenHttp(com.xebialabs.restito.builder.stub.StubHttp.whenHttp) PaxExam(org.ops4j.pax.exam.junit.PaxExam) JWT(com.auth0.jwt.JWT) Call(com.xebialabs.restito.semantics.Call) MessageDigest(java.security.MessageDigest) RunWith(org.junit.runner.RunWith) BeforeExam(org.codice.ddf.test.common.annotations.BeforeExam) AZP(org.pac4j.oidc.profile.OidcProfileDefinition.AZP) REFRESH_TOKEN(org.pac4j.oidc.profile.OidcProfileDefinition.REFRESH_TOKEN) LOCATION(javax.ws.rs.core.HttpHeaders.LOCATION) Condition.post(com.xebialabs.restito.semantics.Condition.post) ImmutableList(com.google.common.collect.ImmutableList) Configuration(org.osgi.service.cm.Configuration) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Condition.get(com.xebialabs.restito.semantics.Condition.get) AUTHORIZATION(javax.ws.rs.core.HttpHeaders.AUTHORIZATION) GsonTypeAdapters(org.codice.gsonsupport.GsonTypeAdapters) Hashtable(java.util.Hashtable) Before(org.junit.Before) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) PublicClaims(com.auth0.jwt.impl.PublicClaims) Assert.assertTrue(org.junit.Assert.assertTrue) AUTH_TIME(org.pac4j.oidc.profile.OidcProfileDefinition.AUTH_TIME) Test(org.junit.Test) USER_AGENT(javax.ws.rs.core.HttpHeaders.USER_AGENT) EMAIL_VERIFIED(org.pac4j.oidc.profile.OidcProfileDefinition.EMAIL_VERIFIED) TimeUnit(java.util.concurrent.TimeUnit) ExamReactorStrategy(org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy) RSAKey(com.nimbusds.jose.jwk.RSAKey) Response(io.restassured.response.Response) Action.contentType(com.xebialabs.restito.semantics.Action.contentType) ACCESS_TOKEN(org.pac4j.oidc.profile.OidcProfileDefinition.ACCESS_TOKEN) LoggingUtils(org.codice.ddf.test.common.LoggingUtils) Call(com.xebialabs.restito.semantics.Call)

Example 5 with GET

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);
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) DELETE(javax.ws.rs.HttpMethod.DELETE) Arrays(java.util.Arrays) Listeners(org.testng.annotations.Listeners) GET(javax.ws.rs.HttpMethod.GET) Path(org.eclipse.che.api.vfs.Path) Test(org.testng.annotations.Test) AfterMethod(org.testng.annotations.AfterMethod) Collections.singletonList(java.util.Collections.singletonList) HttpJsonRequest(org.eclipse.che.api.core.rest.HttpJsonRequest) FileWatcherManager(org.eclipse.che.api.vfs.watcher.FileWatcherManager) Future(java.util.concurrent.Future) CreateProjectHandler(org.eclipse.che.api.project.server.handlers.CreateProjectHandler) ResourceBinderImpl(org.everrest.core.impl.ResourceBinderImpl) Map(java.util.Map) HttpJsonRequestFactory(org.eclipse.che.api.core.rest.HttpJsonRequestFactory) RequestDispatcher(org.everrest.core.impl.RequestDispatcher) ProviderBinder(org.everrest.core.impl.ProviderBinder) APPLICATION_ZIP(org.eclipse.che.commons.lang.ws.rs.ExtMediaType.APPLICATION_ZIP) Attribute(org.eclipse.che.api.core.model.project.type.Attribute) HttpJsonResponse(org.eclipse.che.api.core.rest.HttpJsonResponse) Set(java.util.Set) EverrestProcessor(org.everrest.core.impl.EverrestProcessor) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) Executors(java.util.concurrent.Executors) ResourceLauncher(org.everrest.core.tools.ResourceLauncher) IoUtil(org.eclipse.che.commons.lang.IoUtil) Matchers.any(org.mockito.Matchers.any) CountDownLatch(java.util.concurrent.CountDownLatch) ApiExceptionMapper(org.eclipse.che.api.core.rest.ApiExceptionMapper) UserDao(org.eclipse.che.api.user.server.spi.UserDao) EverrestConfiguration(org.everrest.core.impl.EverrestConfiguration) Assert.assertFalse(org.junit.Assert.assertFalse) ApplicationContext(org.everrest.core.ApplicationContext) ByteStreams(com.google.common.io.ByteStreams) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) TEXT_PLAIN(javax.ws.rs.core.MediaType.TEXT_PLAIN) Mockito.mock(org.mockito.Mockito.mock) ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Mock(org.mockito.Mock) ResourceBinder(org.everrest.core.ResourceBinder) ProjectImporterRegistry(org.eclipse.che.api.project.server.importer.ProjectImporterRegistry) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ProjectTypeDef(org.eclipse.che.api.project.server.type.ProjectTypeDef) FSLuceneSearcherProvider(org.eclipse.che.api.vfs.search.impl.FSLuceneSearcherProvider) LinkedHashSet(java.util.LinkedHashSet) ProjectImporter(org.eclipse.che.api.project.server.importer.ProjectImporter) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) File(java.io.File) ValueHolder(org.eclipse.che.api.core.util.ValueHolder) ServerException(org.eclipse.che.api.core.ServerException) ValueStorageException(org.eclipse.che.api.project.server.type.ValueStorageException) SourceEstimation(org.eclipse.che.api.project.shared.dto.SourceEstimation) ByteArrayContainerResponseWriter(org.everrest.core.tools.ByteArrayContainerResponseWriter) Assert(org.junit.Assert) Assert.assertEqualsNoOrder(org.testng.Assert.assertEqualsNoOrder) ApplicationContext.anApplicationContext(org.everrest.core.ApplicationContext.anApplicationContext) LineConsumerFactory(org.eclipse.che.api.core.util.LineConsumerFactory) Scanner(java.util.Scanner) ProjectTypeRegistry(org.eclipse.che.api.project.server.type.ProjectTypeRegistry) FileWatcherNotificationHandler(org.eclipse.che.api.vfs.impl.file.FileWatcherNotificationHandler) Application(javax.ws.rs.core.Application) ProjectHandlerRegistry(org.eclipse.che.api.project.server.handlers.ProjectHandlerRegistry) ByteArrayInputStream(java.io.ByteArrayInputStream) PathMatcher(java.nio.file.PathMatcher) LocalVirtualFileSystemProvider(org.eclipse.che.api.vfs.impl.file.LocalVirtualFileSystemProvider) URI(java.net.URI) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) ZipEntry(java.util.zip.ZipEntry) EventService(org.eclipse.che.api.core.notification.EventService) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) BeforeMethod(org.testng.annotations.BeforeMethod) Assert.assertNotNull(org.testng.Assert.assertNotNull) SourceStorage(org.eclipse.che.api.core.model.project.SourceStorage) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) ItemReference(org.eclipse.che.api.project.shared.dto.ItemReference) List(java.util.List) POST(javax.ws.rs.HttpMethod.POST) PUT(javax.ws.rs.HttpMethod.PUT) ValueProviderFactory(org.eclipse.che.api.project.server.type.ValueProviderFactory) IntStream(java.util.stream.IntStream) ReadonlyValueProvider(org.eclipse.che.api.project.server.type.ReadonlyValueProvider) Link(org.eclipse.che.api.core.rest.shared.dto.Link) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) Assert.assertEquals(org.testng.Assert.assertEquals) HashMap(java.util.HashMap) ProjectTypeConstraintException(org.eclipse.che.api.project.server.type.ProjectTypeConstraintException) DependencySupplierImpl(org.everrest.core.tools.DependencySupplierImpl) FileTreeWatcher(org.eclipse.che.api.vfs.impl.file.FileTreeWatcher) HashSet(java.util.HashSet) Charset(java.nio.charset.Charset) ConflictException(org.eclipse.che.api.core.ConflictException) LinkedList(java.util.LinkedList) DefaultFileWatcherNotificationHandler(org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler) DtoFactory(org.eclipse.che.dto.server.DtoFactory) ExecutorService(java.util.concurrent.ExecutorService) ContainerResponse(org.everrest.core.impl.ContainerResponse) RequestHandlerImpl(org.everrest.core.impl.RequestHandlerImpl) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) ExtMediaType(org.eclipse.che.commons.lang.ws.rs.ExtMediaType) SelfReturningAnswer(org.eclipse.che.commons.test.mockito.answer.SelfReturningAnswer) Mockito.when(org.mockito.Mockito.when) TreeElement(org.eclipse.che.api.project.shared.dto.TreeElement) NotFoundException(org.eclipse.che.api.core.NotFoundException) MoveOptions(org.eclipse.che.api.project.shared.dto.MoveOptions) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) CopyOptions(org.eclipse.che.api.project.shared.dto.CopyOptions) Collections(java.util.Collections) InputStream(java.io.InputStream) ServerException(org.eclipse.che.api.core.ServerException) ContainerResponse(org.everrest.core.impl.ContainerResponse) ValueStorageException(org.eclipse.che.api.project.server.type.ValueStorageException) SourceEstimation(org.eclipse.che.api.project.shared.dto.SourceEstimation) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ProjectTypeDef(org.eclipse.che.api.project.server.type.ProjectTypeDef) ReadonlyValueProvider(org.eclipse.che.api.project.server.type.ReadonlyValueProvider) ValueProviderFactory(org.eclipse.che.api.project.server.type.ValueProviderFactory) Test(org.testng.annotations.Test)

Aggregations

List (java.util.List)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 GET (javax.ws.rs.HttpMethod.GET)5 ArrayList (java.util.ArrayList)4 URI (java.net.URI)3 Arrays (java.util.Arrays)3 TimeUnit (java.util.concurrent.TimeUnit)3 APPLICATION_JSON (javax.ws.rs.core.MediaType.APPLICATION_JSON)3 ByteStreams (com.google.common.io.ByteStreams)2 ObjectMapperProvider (com.spotify.docker.client.ObjectMapperProvider)2 ImageSearchResult (com.spotify.docker.client.messages.ImageSearchResult)2 CancellationException (java.util.concurrent.CancellationException)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 Client (javax.ws.rs.client.Client)2 ClientBuilder (javax.ws.rs.client.ClientBuilder)2 WebTarget (javax.ws.rs.client.WebTarget)2 GenericType (javax.ws.rs.core.GenericType)2 APPLICATION_JSON_TYPE (javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE)2