Search in sources :

Example 21 with ItemReference

use of org.eclipse.che.api.project.shared.dto.ItemReference in project che by eclipse.

the class ProjectServiceTest method testCreateFolderInRoot.

// any folder created in the root of the workspace automatically becomes project
@Test
public void testCreateFolderInRoot() throws Exception {
    String folder = "my_folder";
    ContainerResponse response = launcher.service(POST, format("http://localhost:8080/api/project/folder/%s", folder), "http://localhost:8080/api", null, null, null);
    assertEquals(response.getStatus(), 201, "Error: " + response.getEntity());
    ItemReference fileItem = (ItemReference) response.getEntity();
    assertEquals(fileItem.getType(), "project");
    assertEquals(fileItem.getName(), folder);
    assertEquals(fileItem.getPath(), "/" + folder);
    validateFolderLinks(fileItem);
    assertEquals(response.getHttpHeaders().getFirst("Location"), URI.create(format("http://localhost:8080/api/project/children/%s", folder)));
}
Also used : ItemReference(org.eclipse.che.api.project.shared.dto.ItemReference) ContainerResponse(org.everrest.core.impl.ContainerResponse) Test(org.testng.annotations.Test)

Example 22 with ItemReference

use of org.eclipse.che.api.project.shared.dto.ItemReference in project che by eclipse.

the class ProjectServiceTest method testGetChildren.

@Test
@SuppressWarnings("unchecked")
public void testGetChildren() throws Exception {
    RegisteredProject myProject = pm.getProject("my_project");
    FolderEntry a = myProject.getBaseFolder().createFolder("a");
    a.createFolder("b");
    a.createFile("test.txt", "test".getBytes(Charset.defaultCharset()));
    ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/children/my_project/a", "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> names = new LinkedHashSet<>(2);
    names.addAll(result.stream().map(ItemReference::getName).collect(Collectors.toList()));
    Assert.assertTrue(names.contains("b"));
    Assert.assertTrue(names.contains("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 23 with ItemReference

use of org.eclipse.che.api.project.shared.dto.ItemReference 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 24 with ItemReference

use of org.eclipse.che.api.project.shared.dto.ItemReference 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 25 with ItemReference

use of org.eclipse.che.api.project.shared.dto.ItemReference in project che by eclipse.

the class ProjectServiceTest method testSearchTextWhenExcludeSomeText.

@SuppressWarnings("unchecked")
@Test
public void testSearchTextWhenExcludeSomeText() throws Exception {
    String queryToSearch = "?text=" + "question" + URL_ENCODED_SPACE + NOT_OPERATOR + URL_ENCODED_SPACE + URL_ENCODED_QUOTES + "attention!" + URL_ENCODED_QUOTES;
    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("b").createFile("notContainsSearchText", "Pay attention! To be or not to be that is the question".getBytes(Charset.defaultCharset()));
    myProject.getBaseFolder().createFolder("c").createFile("alsoNotContainsSearchText", "To be or to not be that is the ...".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(), 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/containsSearchText.txt"));
    Assert.assertFalse(paths.contains("/my_project/b/notContainsSearchText.txt"));
    Assert.assertFalse(paths.contains("/my_project/c/alsoContainsSearchText"));
}
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

ItemReference (org.eclipse.che.api.project.shared.dto.ItemReference)26 Test (org.testng.annotations.Test)22 ContainerResponse (org.everrest.core.impl.ContainerResponse)20 ArrayList (java.util.ArrayList)14 LinkedHashSet (java.util.LinkedHashSet)13 List (java.util.List)13 Collections.singletonList (java.util.Collections.singletonList)11 LinkedList (java.util.LinkedList)11 TreeElement (org.eclipse.che.api.project.shared.dto.TreeElement)4 Link (org.eclipse.che.api.core.rest.shared.dto.Link)2 UiHandler (com.google.gwt.uibinder.client.UiHandler)1 Command (com.google.gwt.user.client.Command)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ConflictException (org.eclipse.che.api.core.ConflictException)1 NotFoundException (org.eclipse.che.api.core.NotFoundException)1 Function (org.eclipse.che.api.promises.client.Function)1