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