Search in sources :

Example 41 with ContainerResponse

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

the class ProjectServiceTest method testCreateBatchProjects.

@Test
public void testCreateBatchProjects() throws Exception {
    //prepare first project
    final String projectName1 = "testProject1";
    final String projectTypeId1 = "testProjectType1";
    final String projectPath1 = "/testProject1";
    createTestProjectType(projectTypeId1);
    phRegistry.register(createProjectHandlerFor(projectName1, projectTypeId1));
    //prepare inner project
    final String innerProjectName = "innerProject";
    final String innerProjectTypeId = "testProjectType2";
    final String innerProjectPath = "/testProject1/innerProject";
    createTestProjectType(innerProjectTypeId);
    phRegistry.register(createProjectHandlerFor(innerProjectName, innerProjectTypeId));
    //prepare project to import
    final String importProjectName = "testImportProject";
    final String importProjectTypeId = "testImportProjectType";
    final String importProjectPath = "/testImportProject";
    final String importType = "importType";
    final String[] paths = { "a", "b", "test.txt" };
    final List<String> children = new ArrayList<>(Arrays.asList(paths));
    registerImporter(importType, prepareZipArchiveBasedOn(children));
    createTestProjectType(importProjectTypeId);
    Map<String, List<String>> headers = new HashMap<>();
    headers.put("Content-Type", singletonList(APPLICATION_JSON));
    try (InputStream content = getClass().getResourceAsStream("batchNewProjectConfigs.json")) {
        ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/batch", "http://localhost:8080/api", headers, ByteStreams.toByteArray(content), null);
        assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
        final List<ProjectConfigDto> result = (List<ProjectConfigDto>) response.getEntity();
        assertNotNull(result);
        assertEquals(result.size(), 3);
        final ProjectConfigDto importProjectConfig = result.get(0);
        checkProjectIsCreated(importProjectName, importProjectPath, importProjectTypeId, importProjectConfig);
        final ProjectConfigDto config1 = result.get(1);
        checkProjectIsCreated(projectName1, projectPath1, projectTypeId1, config1);
        final ProjectConfigDto innerProjectConfig = result.get(2);
        checkProjectIsCreated(innerProjectName, innerProjectPath, innerProjectTypeId, innerProjectConfig);
    }
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 42 with ContainerResponse

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

the class ProjectServiceTest method testGetMissingItem.

@Test
public void testGetMissingItem() throws Exception {
    ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/item/some_missing_project/a/b", "http://localhost:8080/api", null, null, null);
    assertEquals(response.getStatus(), 404, "Error: " + response.getEntity());
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) Test(org.testng.annotations.Test)

Example 43 with ContainerResponse

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

the class ProjectServiceTest method testSearchParticularSequenceWords.

@SuppressWarnings("unchecked")
@Test
public void testSearchParticularSequenceWords() throws Exception {
    String queryToSearch = "?text=" + URL_ENCODED_QUOTES + "To" + URL_ENCODED_SPACE + "be" + URL_ENCODED_SPACE + "or" + URL_ENCODED_SPACE + "not" + URL_ENCODED_SPACE + "to" + URL_ENCODED_SPACE + "be" + 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("a/b").createFile("test.txt", "Pay attention! To be or to be that is the question".getBytes(Charset.defaultCharset()));
    myProject.getBaseFolder().createFolder("c").createFile("_test", "Pay attention! To be or to not be that is the question".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"));
}
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 44 with ContainerResponse

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

the class ProjectServiceTest method testImportZip.

@Test
public void testImportZip() throws Exception {
    RegisteredProject myProject = pm.getProject("my_project");
    myProject.getBaseFolder().createFolder("a/b");
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ZipOutputStream zipOut = new ZipOutputStream(bout);
    zipOut.putNextEntry(new ZipEntry("folder1/"));
    zipOut.putNextEntry(new ZipEntry("folder1/file1.txt"));
    zipOut.write("to be or not to be".getBytes(Charset.defaultCharset()));
    zipOut.close();
    byte[] zip = bout.toByteArray();
    Map<String, List<String>> headers = new HashMap<>();
    headers.put(CONTENT_TYPE, singletonList(ExtMediaType.APPLICATION_ZIP));
    ContainerResponse response = launcher.service(POST, format("http://localhost:8080/api/project/import/my_project/a/b"), "http://localhost:8080/api", headers, zip, null);
    assertEquals(response.getStatus(), 201, "Error: " + response.getEntity());
    assertEquals(response.getHttpHeaders().getFirst("Location"), URI.create("http://localhost:8080/api/project/children/my_project/a/b"));
    assertNotNull(myProject.getBaseFolder().getChild("a/b/folder1/file1.txt"));
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test)

Example 45 with ContainerResponse

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

the class ProjectServiceTest method testMoveFile.

@Test
public void testMoveFile() 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()));
    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", null, null, 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/test.txt"));
    // new
    assertNotNull(myProject.getBaseFolder().getChild("a/b/c/test.txt"));
    // old
    Assert.assertNull(myProject.getBaseFolder().getChild("a/b/test.txt"));
}
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