use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testCreateFolder.
@Test
public void testCreateFolder() throws Exception {
ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/folder/my_project/test", "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 201, "Error: " + response.getEntity());
ItemReference fileItem = (ItemReference) response.getEntity();
assertEquals(fileItem.getName(), "test");
assertEquals(fileItem.getPath(), "/my_project/test");
validateFolderLinks(fileItem);
assertEquals(response.getHttpHeaders().getFirst("Location"), URI.create("http://localhost:8080/api/project/children/my_project/test"));
VirtualFileEntry folder = pm.getProject("my_project").getBaseFolder().getChild("test");
Assert.assertTrue(folder.isFolder());
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testGetProjectInvalidPath.
@Test
public void testGetProjectInvalidPath() throws Exception {
ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/my_project_invalid", "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 404);
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testCopyFolderWithRename.
@Test
public void testCopyFolderWithRename() 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()));
// new name for folder
final String renamedFolder = "renamedFolder";
Map<String, List<String>> headers = new HashMap<>();
headers.put(CONTENT_TYPE, singletonList(APPLICATION_JSON));
CopyOptions descriptor = DtoFactory.getInstance().createDto(CopyOptions.class);
descriptor.setName(renamedFolder);
descriptor.setOverWrite(false);
ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/copy/my_project/a/b?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/children/my_project/a/b/c/%s", renamedFolder)));
assertNotNull(myProject.getBaseFolder().getChild("a/b/test.txt"));
assertNotNull(myProject.getBaseFolder().getChild(format("a/b/c/%s/test.txt", renamedFolder)));
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testSearchTextWithEscapedCharachters.
@SuppressWarnings("unchecked")
@Test
public void testSearchTextWithEscapedCharachters() throws Exception {
String queryToSearch = "?text=http" + URL_ENCODED_BACKSLASH + ':' + URL_ENCODED_BACKSLASH + '/' + URL_ENCODED_BACKSLASH + '/' + "localhost" + URL_ENCODED_BACKSLASH + ':' + "8080" + URL_ENCODED_BACKSLASH + '/' + "ide" + URL_ENCODED_BACKSLASH + '/' + "dev6" + URL_ENCODED_BACKSLASH + '?' + "action=createProject" + URL_ENCODED_BACKSLASH + ':' + "projectName=test";
RegisteredProject myProject = pm.getProject("my_project");
myProject.getBaseFolder().createFolder("x/y").createFile("test.txt", "http://localhost:8080/ide/dev6?action=createProject:projectName=test".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/test.txt"));
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testUpdateProjectInvalidPath.
@Test
public void testUpdateProjectInvalidPath() throws Exception {
Map<String, List<String>> headers = new HashMap<>();
headers.put("Content-Type", singletonList(APPLICATION_JSON));
Map<String, List<String>> attributeValues = new LinkedHashMap<>();
attributeValues.put("my_attribute", singletonList("to be or not to be"));
ProjectConfigDto descriptor = DtoFactory.getInstance().createDto(ProjectConfigDto.class).withType("my_project_type").withDescription("updated project").withAttributes(attributeValues);
ContainerResponse response = launcher.service(PUT, "http://localhost:8080/api/project/my_project_invalid", "http://localhost:8080/api", headers, DtoFactory.getInstance().toJson(descriptor).getBytes(Charset.defaultCharset()), null);
assertEquals(response.getStatus(), 404);
}
Aggregations