use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testGetFileContent.
@Test
public void testGetFileContent() throws Exception {
String myContent = "to be or not to be";
pm.getProject("my_project").getBaseFolder().createFile("test.txt", myContent.getBytes(Charset.defaultCharset()));
ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/file/my_project/test.txt", "http://localhost:8080/api", null, null, writer, null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
assertEquals(response.getContentType().toString(), TEXT_PLAIN);
assertEquals(new String(writer.getBody()), myContent);
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testDeletePath.
@Test
public void testDeletePath() throws Exception {
pm.getProject("my_project").getBaseFolder().createFolder("a/b/c");
ContainerResponse response = launcher.service(DELETE, "http://localhost:8080/api/project/my_project/a/b/c", "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 204, "Error: " + response.getEntity());
Assert.assertNull(pm.getProject("my_project").getBaseFolder().getChild("a/b/c"));
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testCopyFileWithRenameAndOverwrite.
@Test
public void testCopyFileWithRenameAndOverwrite() throws Exception {
RegisteredProject myProject = pm.getProject("my_project");
myProject.getBaseFolder().createFolder("a/b/c");
// File names
String originFileName = "test.txt";
String destinationFileName = "overwriteMe.txt";
// File contents
String originContent = "to be or not no be";
String overwrittenContent = "that is the question";
((FolderEntry) myProject.getBaseFolder().getChild("a/b")).createFile(originFileName, originContent.getBytes(Charset.defaultCharset()));
((FolderEntry) myProject.getBaseFolder().getChild("a/b/c")).createFile(destinationFileName, overwrittenContent.getBytes(Charset.defaultCharset()));
Map<String, List<String>> headers = new HashMap<>();
headers.put(CONTENT_TYPE, singletonList(APPLICATION_JSON));
CopyOptions descriptor = DtoFactory.getInstance().createDto(CopyOptions.class);
descriptor.setName(destinationFileName);
descriptor.setOverWrite(true);
ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/copy/my_project/a/b/" + originFileName + "?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("http://localhost:8080/api/project/file/my_project/a/b/c/" + destinationFileName));
// new
assertNotNull(myProject.getBaseFolder().getChild("a/b/c/" + destinationFileName));
// old
assertNotNull(myProject.getBaseFolder().getChild("a/b/" + originFileName));
Scanner inputStreamScanner = null;
String theFirstLineFromDestinationFile;
try {
inputStreamScanner = new Scanner(myProject.getBaseFolder().getChild("a/b/c/" + destinationFileName).getVirtualFile().getContent());
theFirstLineFromDestinationFile = inputStreamScanner.nextLine();
// destination should contain original file's content
assertEquals(theFirstLineFromDestinationFile, originContent);
} catch (ForbiddenException | ServerException e) {
Assert.fail(e.getMessage());
} finally {
if (inputStreamScanner != null) {
inputStreamScanner.close();
}
}
}
use of org.everrest.core.impl.ContainerResponse 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"));
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testImportProject.
@Test
public void testImportProject() throws Exception {
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();
final InputStream zip = new ByteArrayInputStream(bout.toByteArray());
final String importType = "_123_";
registerImporter(importType, zip);
final String myType = "chuck_project_type";
final ProjectConfigDto newProjectConfig = DtoFactory.getInstance().createDto(ProjectConfigDto.class).withPath("/new_project").withName("new_project").withDescription("import test").withType(myType);
projects.add(newProjectConfig);
Map<String, List<String>> headers = new HashMap<>();
headers.put("Content-Type", singletonList(APPLICATION_JSON));
String json = "{\n" + " \"location\": null,\n" + " \"type\": \"%s\"\n" + "}";
byte[] b = format(json, importType).getBytes(Charset.defaultCharset());
ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/import/new_project", "http://localhost:8080/api", headers, b, null);
assertEquals(response.getStatus(), 204);
RegisteredProject newProject = pm.getProject("new_project");
assertNotNull(newProject);
//assertNotNull(newProject.getConfig());
}
Aggregations