Search in sources :

Example 31 with ContainerResponse

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

the class ProjectServiceTest method testSearchFromWSRoot.

@SuppressWarnings("unchecked")
@Test
public void testSearchFromWSRoot() throws Exception {
    RegisteredProject myProject = pm.getProject("my_project");
    myProject.getBaseFolder().createFolder("a/b").createFile("test", "test".getBytes(Charset.defaultCharset()));
    myProject.getBaseFolder().createFolder("x/y").createFile("test", "test".getBytes(Charset.defaultCharset()));
    myProject.getBaseFolder().createFolder("c").createFile("test.txt", "test".getBytes(Charset.defaultCharset()));
    ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/search/?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(), 1);
    Assert.assertTrue(result.get(0).getPath().equals("/my_project/c/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 32 with ContainerResponse

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

the class ProjectServiceTest method testSearchByName.

@SuppressWarnings("unchecked")
@Test
public void testSearchByName() throws Exception {
    RegisteredProject myProject = pm.getProject("my_project");
    myProject.getBaseFolder().createFolder("a/b").createFile("test.txt", "hello".getBytes(Charset.defaultCharset()));
    myProject.getBaseFolder().createFolder("x/y").createFile("test.txt", "test".getBytes(Charset.defaultCharset()));
    myProject.getBaseFolder().createFolder("c").createFile("exclude", "test".getBytes(Charset.defaultCharset()));
    ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/search/my_project?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);
    Set<String> paths = new LinkedHashSet<>(2);
    for (ItemReference itemReference : result) {
        paths.add(itemReference.getPath());
    }
    Assert.assertTrue(paths.contains("/my_project/a/b/test.txt"));
    Assert.assertTrue(paths.contains("/my_project/x/y/test.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 33 with ContainerResponse

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

the class ProjectServiceTest method testMoveFileWithRenameAndOverwrite.

@Test
public void testMoveFileWithRenameAndOverwrite() throws Exception {
    RegisteredProject myProject = pm.getProject("my_project");
    myProject.getBaseFolder().createFolder("a/b/c");
    // File names
    String originFileName = "test.txt";
    String destinationFileName = "overwriteMe.txt";
    // File contents
    String originContent = "to be or not no be";
    String overwrittenContent = "that is the question";
    ((FolderEntry) myProject.getBaseFolder().getChild("a/b")).createFile(originFileName, originContent.getBytes(Charset.defaultCharset()));
    ((FolderEntry) myProject.getBaseFolder().getChild("a/b/c")).createFile(destinationFileName, overwrittenContent.getBytes(Charset.defaultCharset()));
    Map<String, List<String>> headers = new HashMap<>();
    headers.put(CONTENT_TYPE, singletonList(APPLICATION_JSON));
    MoveOptions descriptor = DtoFactory.getInstance().createDto(MoveOptions.class);
    descriptor.setName(destinationFileName);
    descriptor.setOverWrite(true);
    ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/move/my_project/a/b/" + originFileName + "?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("http://localhost:8080/api/project/file/my_project/a/b/c/" + destinationFileName));
    // new
    assertNotNull(myProject.getBaseFolder().getChild("a/b/c/" + destinationFileName));
    Scanner inputStreamScanner = null;
    String theFirstLineFromDestinationFile;
    try {
        inputStreamScanner = new Scanner(myProject.getBaseFolder().getChild("a/b/c/" + destinationFileName).getVirtualFile().getContent());
        theFirstLineFromDestinationFile = inputStreamScanner.nextLine();
        // destination should contain original file's content
        assertEquals(theFirstLineFromDestinationFile, originContent);
    } catch (ForbiddenException | ServerException e) {
        Assert.fail(e.getMessage());
    } finally {
        if (inputStreamScanner != null) {
            inputStreamScanner.close();
        }
    }
}
Also used : Scanner(java.util.Scanner) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) 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)

Example 34 with ContainerResponse

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

the class ProjectServiceTest method testMoveFolderWithRenameAndOverwrite.

@Test
public void testMoveFolderWithRenameAndOverwrite() throws Exception {
    RegisteredProject myProject = pm.getProject("my_project");
    myProject.getBaseFolder().createFolder("a/b/c");
    // File names
    String originFileName = "test.txt";
    String destinationFileName = "overwriteMe.txt";
    // File contents
    String originContent = "to be or not no be";
    String overwritenContent = "that is the question";
    // new name for folder
    final String renamedFolder = "renamedFolder";
    ((FolderEntry) myProject.getBaseFolder().getChild("a/b")).createFile(originFileName, originContent.getBytes(Charset.defaultCharset()));
    ((FolderEntry) myProject.getBaseFolder().getChild("a/b/c")).createFile(destinationFileName, overwritenContent.getBytes(Charset.defaultCharset()));
    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(true);
    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)

Example 35 with ContainerResponse

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

the class ProjectServiceTest method testSearchByTextWhenFileWasNotIndexed.

@SuppressWarnings("unchecked")
@Test
public void testSearchByTextWhenFileWasNotIndexed() throws Exception {
    RegisteredProject myProject = pm.getProject("my_project");
    myProject.getBaseFolder().createFolder("a/b").createFile("test.txt", "hello".getBytes(Charset.defaultCharset()));
    myProject.getBaseFolder().createFolder("x/y").createFile("__test.txt", "searchhit".getBytes(Charset.defaultCharset()));
    myProject.getBaseFolder().createFolder(EXCLUDE_SEARCH_PATH).createFile("_test", "searchhit".getBytes(Charset.defaultCharset()));
    ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/search/my_project?text=searchhit", "http://localhost:8080/api", null, null, null);
    assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
    List<ItemReference> result = (List<ItemReference>) response.getEntity();
    assertEquals(result.size(), 1);
    Set<String> paths = new LinkedHashSet<>(1);
    paths.addAll(result.stream().map(ItemReference::getPath).collect(Collectors.toList()));
    Assert.assertTrue(paths.contains("/my_project/x/y/__test.txt"));
    Assert.assertFalse(paths.contains("/my_project/" + EXCLUDE_SEARCH_PATH + "/_test"));
}
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)

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