Search in sources :

Example 36 with ContainerResponse

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

the class ProjectServiceTest method testDeleteProjectsConcurrently.

@Test
public void testDeleteProjectsConcurrently() throws Exception {
    int threadNumber = 5 * (Runtime.getRuntime().availableProcessors() + 1);
    ExecutorService executor = Executors.newFixedThreadPool(threadNumber);
    CountDownLatch countDownLatch = new CountDownLatch(threadNumber);
    List<Future<ContainerResponse>> futures = new LinkedList<>();
    for (int i = 0; i < threadNumber; i++) {
        addMockedProjectConfigDto(ptRegistry.getProjectType("my_project_type"), "my_project_name" + i);
    }
    IntStream.range(0, threadNumber).forEach(i -> {
        futures.add(executor.submit(() -> {
            countDownLatch.countDown();
            countDownLatch.await();
            try {
                return launcher.service(DELETE, "http://localhost:8080/api/project/my_project_name" + i, "http://localhost:8080/api", null, null, null);
            } catch (Exception e) {
                throw new IllegalStateException(e);
            }
        }));
    });
    boolean isNotDone;
    do {
        isNotDone = false;
        for (Future<ContainerResponse> future : futures) {
            if (!future.isDone()) {
                isNotDone = true;
            }
        }
    } while (isNotDone);
    for (Future<ContainerResponse> future : futures) {
        assertEquals(future.get().getStatus(), 204, "Error: " + future.get().getEntity());
    }
    executor.shutdown();
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) CountDownLatch(java.util.concurrent.CountDownLatch) LinkedList(java.util.LinkedList) IOException(java.io.IOException) ServerException(org.eclipse.che.api.core.ServerException) ValueStorageException(org.eclipse.che.api.project.server.type.ValueStorageException) ProjectTypeConstraintException(org.eclipse.che.api.project.server.type.ProjectTypeConstraintException) ConflictException(org.eclipse.che.api.core.ConflictException) NotFoundException(org.eclipse.che.api.core.NotFoundException) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) Test(org.testng.annotations.Test)

Example 37 with ContainerResponse

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

the class ProjectServiceTest method testGetTreeWithDepthAndIncludeFiles.

@Test
public void testGetTreeWithDepthAndIncludeFiles() throws Exception {
    RegisteredProject myProject = pm.getProject("my_project");
    FolderEntry a = myProject.getBaseFolder().createFolder("a");
    a.createFolder("b/c");
    a.createFolder("x").createFile("test.txt", "test".getBytes(Charset.defaultCharset()));
    ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/tree/my_project/a?depth=100&includeFiles=true", "http://localhost:8080/api", null, null, null);
    assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
    TreeElement tree = (TreeElement) response.getEntity();
    ItemReference a_node = tree.getNode();
    assertEquals(a_node.getName(), "a");
    List<TreeElement> children = tree.getChildren();
    assertNotNull(children);
    Set<String> names = new LinkedHashSet<>(4);
    for (TreeElement subTree : children) {
        ItemReference _node = subTree.getNode();
        validateFolderLinks(_node);
        String name = _node.getName();
        names.add(name);
        for (TreeElement subSubTree : subTree.getChildren()) {
            ItemReference __node = subSubTree.getNode();
            if (__node.getType().equals("folder")) {
                validateFolderLinks(__node);
            } else if (__node.getType().equals("file")) {
                validateFileLinks(__node);
            }
            names.add(name + "/" + __node.getName());
        }
    }
    Assert.assertTrue(names.contains("b"));
    Assert.assertTrue(names.contains("x"));
    Assert.assertTrue(names.contains("b/c"));
    Assert.assertTrue(names.contains("x/test.txt"));
}
Also used : ItemReference(org.eclipse.che.api.project.shared.dto.ItemReference) LinkedHashSet(java.util.LinkedHashSet) ContainerResponse(org.everrest.core.impl.ContainerResponse) TreeElement(org.eclipse.che.api.project.shared.dto.TreeElement) Test(org.testng.annotations.Test)

Example 38 with ContainerResponse

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

the class ProjectServiceTest method testGetNotValidProject.

@Test
public void testGetNotValidProject() throws Exception {
    //MountPoint mountPoint = pm.getProjectsRoot(workspace).getVirtualFile().getMountPoint();
    vfsProvider.getVirtualFileSystem().getRoot().createFolder("not_project");
    // to refresh
    projectRegistry.initProjects();
    ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/not_project", "http://localhost:8080/api", null, null, null);
    assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
    ProjectConfigDto badProject = (ProjectConfigDto) response.getEntity();
    assertNotNull(badProject);
    assertEquals(badProject.getName(), "not_project");
    assertNotNull(badProject.getProblems());
    assertTrue(badProject.getProblems().size() > 0);
    assertEquals(11, badProject.getProblems().get(0).getCode());
    validateProjectLinks(badProject);
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) Test(org.testng.annotations.Test)

Example 39 with ContainerResponse

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

the class ProjectServiceTest method testCopyFile.

@Test
public void testCopyFile() 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/copy/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
    assertNotNull(myProject.getBaseFolder().getChild("a/b/test.txt"));
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) Test(org.testng.annotations.Test)

Example 40 with ContainerResponse

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

the class ProjectServiceTest method testRenameFile.

@Test
public void testRenameFile() 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()));
    // 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", "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/%s", destinationName)));
    VirtualFileEntry theTargetFile = myProject.getBaseFolder().getChild(format("a/b/%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)

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