use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testUpdateProject.
@Test
public void testUpdateProject() throws Exception {
Map<String, List<String>> headers = new HashMap<>();
headers.put("Content-Type", singletonList(APPLICATION_JSON));
ProjectTypeDef pt = new ProjectTypeDef("testUpdateProject", "my project type", true, false) {
};
ptRegistry.registerProjectType(pt);
pm.createProject(DtoFactory.getInstance().createDto(ProjectConfigDto.class).withDescription("created project").withType("testUpdateProject").withPath("/testUpdateProject"), null);
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).withName("module1").withType("testUpdateProject").withDescription("updated project").withAttributes(attributeValues);
ContainerResponse response = launcher.service(PUT, "http://localhost:8080/api/project/testUpdateProject", "http://localhost:8080/api", headers, DtoFactory.getInstance().toJson(descriptor).getBytes(Charset.defaultCharset()), null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
RegisteredProject project = pm.getProject("/testUpdateProject");
assertNotNull(project);
//ProjectConfig config = project.getConfig();
assertEquals(project.getDescription(), "updated project");
assertEquals(project.getProjectType().getId(), "testUpdateProject");
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testGetProject.
@Test
public void testGetProject() throws Exception {
ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/my_project", "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
ProjectConfigDto result = (ProjectConfigDto) response.getEntity();
assertNotNull(result);
assertEquals(result.getDescription(), "my test project");
assertEquals(result.getType(), "my_project_type");
Map<String, List<String>> attributes = result.getAttributes();
assertNotNull(attributes);
assertEquals(attributes.size(), 1);
assertEquals(attributes.get("my_attribute"), singletonList("attribute value 1"));
validateProjectLinks(result);
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testCopyFolderWithRenameAndOverwrite.
@Test
public void testCopyFolderWithRenameAndOverwrite() 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";
// new name for folder
final String renamedFolder = "renamedFolder";
((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(renamedFolder);
descriptor.setOverWrite(true);
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)));
assertEquals(myProject.getBaseFolder().getChild("a/b/test.txt").getName(), myProject.getBaseFolder().getChild(format("a/b/c/%s/%s", renamedFolder, originFileName)).getName());
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testCreateProject.
@Test
public void testCreateProject() throws Exception {
final String projectName = "new_project";
final String projectType = "testCreateProject";
phRegistry.register(createProjectHandlerFor(projectName, projectType));
Map<String, List<String>> headers = new HashMap<>();
headers.put("Content-Type", singletonList(APPLICATION_JSON));
ProjectTypeDef pt = new ProjectTypeDef("testCreateProject", "my project type", true, false) {
{
addConstantDefinition("new_project_attribute", "attr description", "to be or not to be");
}
};
ptRegistry.registerProjectType(pt);
Map<String, List<String>> attributeValues = new LinkedHashMap<>();
attributeValues.put("new_project_attribute", singletonList("to be or not to be"));
final ProjectConfigDto newProjectConfig = DtoFactory.getInstance().createDto(ProjectConfigDto.class).withPath("/new_project").withName(projectName).withDescription("new project").withType(projectType).withAttributes(attributeValues).withSource(DtoFactory.getInstance().createDto(SourceStorageDto.class));
projects.add(newProjectConfig);
ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project", "http://localhost:8080/api", headers, DtoFactory.getInstance().toJson(newProjectConfig).getBytes(Charset.defaultCharset()), null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
ProjectConfigDto result = (ProjectConfigDto) response.getEntity();
assertNotNull(result);
assertEquals(result.getName(), projectName);
assertEquals(result.getPath(), "/new_project");
assertEquals(result.getDescription(), newProjectConfig.getDescription());
assertEquals(result.getType(), newProjectConfig.getType());
assertEquals(result.getType(), projectType);
Map<String, List<String>> attributes = result.getAttributes();
assertNotNull(attributes);
assertEquals(attributes.size(), 1);
assertEquals(attributes.get("new_project_attribute"), singletonList("to be or not to be"));
validateProjectLinks(result);
RegisteredProject project = pm.getProject("new_project");
assertNotNull(project);
//ProjectConfig config = project.getConfig();
assertEquals(project.getDescription(), newProjectConfig.getDescription());
assertEquals(project.getProjectType().getId(), newProjectConfig.getType());
String attributeVal = project.getAttributeEntries().get("new_project_attribute").getString();
assertNotNull(attributeVal);
assertEquals(attributeVal, "to be or not to be");
assertNotNull(project.getBaseFolder().getChild("a"));
assertNotNull(project.getBaseFolder().getChild("b"));
assertNotNull(project.getBaseFolder().getChild("test.txt"));
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testDeleteFile.
@Test
public void testDeleteFile() throws Exception {
pm.getProject("my_project").getBaseFolder().createFile("test.txt", "to be or not to be".getBytes(Charset.defaultCharset()));
ContainerResponse response = launcher.service(DELETE, "http://localhost:8080/api/project/my_project/test.txt", "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 204, "Error: " + response.getEntity());
Assert.assertNull(pm.getProject("my_project").getBaseFolder().getChild("test.txt"));
}
Aggregations