use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ETagResponseFilterTest method filterListEntityTestWithEtag.
/**
* Check if ETag sent with header is redirecting to NOT_MODIFIED
*/
@Test
public void filterListEntityTestWithEtag() throws Exception {
Map<String, List<String>> headers = new HashMap<>();
headers.put("If-None-Match", Collections.singletonList(new EntityTag("900150983cd24fb0d6963f7d28e17f72").toString()));
final ContainerResponse response = resourceLauncher.service(HttpMethod.GET, SERVICE_PATH + "/list", BASE_URI, headers, null, null);
assertEquals(response.getStatus(), NOT_MODIFIED.getStatusCode());
// check null body
Assert.assertNull(response.getEntity());
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testSearchByNameAndText.
@SuppressWarnings("unchecked")
@Test
public void testSearchByNameAndText() throws Exception {
RegisteredProject myProject = pm.getProject("my_project");
myProject.getBaseFolder().createFolder("a/b").createFile("test.txt", "test".getBytes(Charset.defaultCharset()));
myProject.getBaseFolder().createFolder("x/y").createFile("test.txt", "test".getBytes(Charset.defaultCharset()));
myProject.getBaseFolder().createFolder("c").createFile("test", "test".getBytes(Charset.defaultCharset()));
ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/search/my_project?text=test&name=test.txt", "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
List<ItemReference> result = (List<ItemReference>) response.getEntity();
assertEquals(result.size(), 2);
assertEqualsNoOrder(new Object[] { result.get(0).getPath(), result.get(1).getPath() }, new Object[] { "/my_project/a/b/test.txt", "/my_project/x/y/test.txt" });
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testSearchWordWithAnyEnding.
@SuppressWarnings("unchecked")
@Test
public void testSearchWordWithAnyEnding() throws Exception {
String queryToSearch = "?text=" + "question" + URL_ENCODED_ASTERISK;
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("containsSearchTextAlso.txt", "Pay attention! To be or not to be that is the questionS".getBytes(Charset.defaultCharset()));
myProject.getBaseFolder().createFolder("c").createFile("notContainsSearchText", "Pay attention! To be or to not be that is the questEon".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(), 2);
Set<String> paths = new LinkedHashSet<>(2);
paths.addAll(result.stream().map(ItemReference::getPath).collect(Collectors.toList()));
Assert.assertTrue(paths.contains("/my_project/x/y/containsSearchText.txt"));
Assert.assertTrue(paths.contains("/my_project/a/b/containsSearchTextAlso.txt"));
Assert.assertFalse(paths.contains("/my_project/c/notContainsSearchText.txt"));
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testResolveSources.
@Test
public void testResolveSources() throws Exception {
VirtualFile root = pm.getProjectsRoot().getVirtualFile();
root.createFolder("testEstimateProjectGood").createFolder("check");
root.createFolder("testEstimateProjectBad");
final ValueProviderFactory vpf1 = projectFolder -> new ReadonlyValueProvider() {
@Override
public List<String> getValues(String attributeName) throws ValueStorageException {
VirtualFileEntry file;
try {
file = projectFolder.getChild("check");
} catch (ServerException e) {
throw new ValueStorageException(e.getMessage());
}
if (file == null) {
throw new ValueStorageException("Check not found");
}
return (List<String>) singletonList("checked");
}
};
ProjectTypeDef pt = new ProjectTypeDef("testEstimateProjectPT", "my testEstimateProject type", true, false) {
{
addVariableDefinition("calculated_attribute", "attr description", true, vpf1);
addVariableDefinition("my_property_1", "attr description", true);
addVariableDefinition("my_property_2", "attr description", false);
}
};
ptRegistry.registerProjectType(pt);
ContainerResponse response = launcher.service(GET, format("http://localhost:8080/api/project/resolve/%s", "testEstimateProjectGood"), "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
List<SourceEstimation> result = (List<SourceEstimation>) response.getEntity();
assertTrue(result.size() > 0);
boolean m = false;
for (SourceEstimation est : result) {
if (est.getType().equals("testEstimateProjectPT")) {
assertTrue(est.isMatched());
m = true;
}
}
assertTrue(m);
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testMoveFolderWithRename.
@Test
public void testMoveFolderWithRename() 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));
MoveOptions descriptor = DtoFactory.getInstance().createDto(MoveOptions.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(format("a/b/c/%s/test.txt", renamedFolder)));
}
Aggregations