Search in sources :

Example 56 with ContainerResponse

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

the class ProjectServiceTest method testSearchParticularSequenceWordsWithAnyEnding.

@SuppressWarnings("unchecked")
@Test
public void testSearchParticularSequenceWordsWithAnyEnding() throws Exception {
    String queryToSearch = "?text=" + URL_ENCODED_QUOTES + "that" + URL_ENCODED_SPACE + "is" + URL_ENCODED_SPACE + "the" + URL_ENCODED_QUOTES + URL_ENCODED_SPACE + AND_OPERATOR + URL_ENCODED_SPACE + "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 57 with ContainerResponse

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

the class ProjectServiceTest method testCreateFile.

@Test
public void testCreateFile() throws Exception {
    String myContent = "to be or not to be";
    ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/file/my_project?name=test.txt", "http://localhost:8080/api", null, myContent.getBytes(Charset.defaultCharset()), null);
    assertEquals(response.getStatus(), 201, "Error: " + response.getEntity());
    ItemReference fileItem = (ItemReference) response.getEntity();
    assertEquals(fileItem.getType(), "file");
    //        assertEquals(fileItem.getMediaType(), TEXT_PLAIN);
    assertEquals(fileItem.getName(), "test.txt");
    assertEquals(fileItem.getPath(), "/my_project/test.txt");
    validateFileLinks(fileItem);
    assertEquals(response.getHttpHeaders().getFirst("Location"), URI.create("http://localhost:8080/api/project/file/my_project/test.txt"));
    VirtualFileEntry file = pm.getProject("my_project").getBaseFolder().getChild("test.txt");
    Assert.assertTrue(file.isFile());
    FileEntry _file = (FileEntry) file;
    //assertEquals(_file.getMediaType(), TEXT_PLAIN);
    assertEquals(new String(_file.contentAsBytes()), myContent);
}
Also used : ItemReference(org.eclipse.che.api.project.shared.dto.ItemReference) ContainerResponse(org.everrest.core.impl.ContainerResponse) Test(org.testng.annotations.Test)

Example 58 with ContainerResponse

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

the class ProjectServiceTest method testRenameFolder.

@Test
public void testRenameFolder() throws Exception {
    RegisteredProject myProject = pm.getProject("my_project");
    myProject.getBaseFolder().createFolder("a/b");
    ((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/move/my_project/a/b", "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/%s", renamedFolder)));
    assertNotNull(myProject.getBaseFolder().getChild(format("a/%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 59 with ContainerResponse

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

the class ProjectServiceTest method testMoveFileWithRename.

@Test
public void testMoveFileWithRename() 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()));
    // name for file after move
    final String destinationName = "copyOfTestForMove.txt";
    Map<String, List<String>> headers = new HashMap<>();
    headers.put(CONTENT_TYPE, singletonList(APPLICATION_JSON));
    MoveOptions descriptor = DtoFactory.getInstance().createDto(MoveOptions.class);
    descriptor.setName(destinationName);
    descriptor.setOverWrite(false);
    ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/move/my_project/a/b/test.txt?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/file/my_project/a/b/c/%s", destinationName)));
    VirtualFileEntry theTargetFile = myProject.getBaseFolder().getChild(format("a/b/c/%s", destinationName));
    // new
    assertNotNull(theTargetFile);
}
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 60 with ContainerResponse

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

the class ProjectServiceTest method testMoveFolder.

@Test
public void testMoveFolder() throws Exception {
    RegisteredProject myProject = pm.getProject("my_project");
    myProject.getBaseFolder().createFolder("a/b/c");
    ((FolderEntry) myProject.getBaseFolder().getChild("a/b/c")).createFile("test.txt", "to be or not no be".getBytes(Charset.defaultCharset()));
    ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/move/my_project/a/b/c?to=/my_project/a", "http://localhost:8080/api", null, null, null);
    assertEquals(response.getStatus(), 201, "Error: " + response.getEntity());
    assertEquals(response.getHttpHeaders().getFirst("Location"), URI.create("http://localhost:8080/api/project/children/my_project/a/c"));
    assertNotNull(myProject.getBaseFolder().getChild("a/c/test.txt"));
    Assert.assertNull(myProject.getBaseFolder().getChild("a/b/c/test.txt"));
    Assert.assertNull(myProject.getBaseFolder().getChild("a/b/c"));
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) 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