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();
}
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"));
}
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);
}
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"));
}
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);
}
Aggregations