Search in sources :

Example 6 with ContainerResponse

use of org.everrest.core.impl.ContainerResponse in project che by eclipse.

the class ETagResponseFilterTest method filterListEntityTestWithEtag.

/**
     * Check if ETag sent with header is redirecting to NOT_MODIFIED
     */
@Test
public void filterListEntityTestWithEtag() throws Exception {
    Map<String, List<String>> headers = new HashMap<>();
    headers.put("If-None-Match", Collections.singletonList(new EntityTag("900150983cd24fb0d6963f7d28e17f72").toString()));
    final ContainerResponse response = resourceLauncher.service(HttpMethod.GET, SERVICE_PATH + "/list", BASE_URI, headers, null, null);
    assertEquals(response.getStatus(), NOT_MODIFIED.getStatusCode());
    // check null body
    Assert.assertNull(response.getEntity());
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) HashMap(java.util.HashMap) List(java.util.List) EntityTag(javax.ws.rs.core.EntityTag) Test(org.testng.annotations.Test)

Example 7 with ContainerResponse

use of org.everrest.core.impl.ContainerResponse in project che by eclipse.

the class ProjectServiceTest method testSearchByNameAndText.

@SuppressWarnings("unchecked")
@Test
public void testSearchByNameAndText() throws Exception {
    RegisteredProject myProject = pm.getProject("my_project");
    myProject.getBaseFolder().createFolder("a/b").createFile("test.txt", "test".getBytes(Charset.defaultCharset()));
    myProject.getBaseFolder().createFolder("x/y").createFile("test.txt", "test".getBytes(Charset.defaultCharset()));
    myProject.getBaseFolder().createFolder("c").createFile("test", "test".getBytes(Charset.defaultCharset()));
    ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/search/my_project?text=test&name=test.txt", "http://localhost:8080/api", null, null, null);
    assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
    List<ItemReference> result = (List<ItemReference>) response.getEntity();
    assertEquals(result.size(), 2);
    assertEqualsNoOrder(new Object[] { result.get(0).getPath(), result.get(1).getPath() }, new Object[] { "/my_project/a/b/test.txt", "/my_project/x/y/test.txt" });
}
Also used : ItemReference(org.eclipse.che.api.project.shared.dto.ItemReference) ContainerResponse(org.everrest.core.impl.ContainerResponse) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 8 with ContainerResponse

use of org.everrest.core.impl.ContainerResponse in project che by eclipse.

the class ProjectServiceTest method testSearchWordWithAnyEnding.

@SuppressWarnings("unchecked")
@Test
public void testSearchWordWithAnyEnding() throws Exception {
    String queryToSearch = "?text=" + "question" + URL_ENCODED_ASTERISK;
    RegisteredProject myProject = pm.getProject("my_project");
    myProject.getBaseFolder().createFolder("x/y").createFile("containsSearchText.txt", "To be or not to be that is the question".getBytes(Charset.defaultCharset()));
    myProject.getBaseFolder().createFolder("a/b").createFile("containsSearchTextAlso.txt", "Pay attention! To be or not to be that is the questionS".getBytes(Charset.defaultCharset()));
    myProject.getBaseFolder().createFolder("c").createFile("notContainsSearchText", "Pay attention! To be or to not be that is the questEon".getBytes(Charset.defaultCharset()));
    ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/search/my_project" + queryToSearch, "http://localhost:8080/api", null, null, null);
    assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
    List<ItemReference> result = (List<ItemReference>) response.getEntity();
    assertEquals(result.size(), 2);
    Set<String> paths = new LinkedHashSet<>(2);
    paths.addAll(result.stream().map(ItemReference::getPath).collect(Collectors.toList()));
    Assert.assertTrue(paths.contains("/my_project/x/y/containsSearchText.txt"));
    Assert.assertTrue(paths.contains("/my_project/a/b/containsSearchTextAlso.txt"));
    Assert.assertFalse(paths.contains("/my_project/c/notContainsSearchText.txt"));
}
Also used : ItemReference(org.eclipse.che.api.project.shared.dto.ItemReference) LinkedHashSet(java.util.LinkedHashSet) ContainerResponse(org.everrest.core.impl.ContainerResponse) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 9 with ContainerResponse

use of org.everrest.core.impl.ContainerResponse 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 10 with ContainerResponse

use of org.everrest.core.impl.ContainerResponse in project che by eclipse.

the class ProjectServiceTest method testMoveFolderWithRename.

@Test
public void testMoveFolderWithRename() throws Exception {
    RegisteredProject myProject = pm.getProject("my_project");
    myProject.getBaseFolder().createFolder("a/b/c");
    ((FolderEntry) myProject.getBaseFolder().getChild("a/b")).createFile("test.txt", "to be or not no be".getBytes(Charset.defaultCharset()));
    // new name for folder
    final String renamedFolder = "renamedFolder";
    Map<String, List<String>> headers = new HashMap<>();
    headers.put(CONTENT_TYPE, singletonList(APPLICATION_JSON));
    MoveOptions descriptor = DtoFactory.getInstance().createDto(MoveOptions.class);
    descriptor.setName(renamedFolder);
    descriptor.setOverWrite(false);
    ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/copy/my_project/a/b?to=/my_project/a/b/c", "http://localhost:8080/api", headers, DtoFactory.getInstance().toJson(descriptor).getBytes(Charset.defaultCharset()), null);
    assertEquals(response.getStatus(), 201, "Error: " + response.getEntity());
    assertEquals(response.getHttpHeaders().getFirst("Location"), URI.create(format("http://localhost:8080/api/project/children/my_project/a/b/c/%s", renamedFolder)));
    assertNotNull(myProject.getBaseFolder().getChild(format("a/b/c/%s/test.txt", renamedFolder)));
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) MoveOptions(org.eclipse.che.api.project.shared.dto.MoveOptions) Test(org.testng.annotations.Test)

Aggregations

ContainerResponse (org.everrest.core.impl.ContainerResponse)69 Test (org.testng.annotations.Test)68 List (java.util.List)35 LinkedList (java.util.LinkedList)34 ArrayList (java.util.ArrayList)33 Collections.singletonList (java.util.Collections.singletonList)33 HashMap (java.util.HashMap)22 ItemReference (org.eclipse.che.api.project.shared.dto.ItemReference)22 LinkedHashMap (java.util.LinkedHashMap)20 LinkedHashSet (java.util.LinkedHashSet)15 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)12 MoveOptions (org.eclipse.che.api.project.shared.dto.MoveOptions)8 CopyOptions (org.eclipse.che.api.project.shared.dto.CopyOptions)6 TreeElement (org.eclipse.che.api.project.shared.dto.TreeElement)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 EntityTag (javax.ws.rs.core.EntityTag)5 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)5 ServerException (org.eclipse.che.api.core.ServerException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4