use of org.eclipse.che.api.project.server.type.ProjectTypeDef 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.eclipse.che.api.project.server.type.ProjectTypeDef in project che by eclipse.
the class ProjectServiceTest method createTestProjectType.
private void createTestProjectType(final String projectTypeId) throws ProjectTypeConstraintException {
final ProjectTypeDef pt = new ProjectTypeDef(projectTypeId, "my project type", true, false) {
{
addConstantDefinition("new_test_attribute", "attr description", "some_attribute_value");
}
};
ptRegistry.registerProjectType(pt);
}
use of org.eclipse.che.api.project.server.type.ProjectTypeDef in project che by eclipse.
the class ProjectTypesTest method testGetMixinsShouldNotReturnNotPersistedMixin.
@Test
public void testGetMixinsShouldNotReturnNotPersistedMixin() throws Exception {
Set<ProjectTypeDef> pts = new HashSet<>();
pts.add(new PrimaryType());
pts.add(new PersistedMixin());
pts.add(new NotPersistedMixin());
ProjectTypeRegistry reg = new ProjectTypeRegistry(pts);
List<RegisteredProject.Problem> problems = new ArrayList<>();
ProjectTypes projectTypes = new ProjectTypes(generate("projectPath-", 5), PrimaryType.PRIMARY_ID, Arrays.asList(PersistedMixin.PERSISTED_MIXIN_ID, NotPersistedMixin.NOT_PERSISTED_MIXIN_ID), reg, problems);
assertFalse(projectTypes.getMixins().containsKey(NotPersistedMixin.NOT_PERSISTED_MIXIN_ID));
assertEquals(problems.size(), 0);
}
use of org.eclipse.che.api.project.server.type.ProjectTypeDef in project che by eclipse.
the class ProjectTypesTest method testGetMixinsShouldReturnNotFoundException.
//@Test(expectedExceptions = NotFoundException.class)
public void testGetMixinsShouldReturnNotFoundException() throws Exception {
final String notFoundMixin = generate("notFoundMixin-", 5);
Set<ProjectTypeDef> pts = new HashSet<>();
pts.add(new PrimaryType());
pts.add(new PersistedMixin());
pts.add(new NotPersistedMixin());
ProjectTypeRegistry reg = new ProjectTypeRegistry(pts);
List<RegisteredProject.Problem> problems = new ArrayList<>();
new ProjectTypes(generate("projectPath-", 5), PrimaryType.PRIMARY_ID, Arrays.asList(notFoundMixin, PersistedMixin.PERSISTED_MIXIN_ID, NotPersistedMixin.NOT_PERSISTED_MIXIN_ID), reg, problems);
assertEquals(problems.size(), 1);
assertEquals(problems.get(0).code, 12);
}
use of org.eclipse.che.api.project.server.type.ProjectTypeDef 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");
}
Aggregations