use of org.eclipse.che.api.project.server.type.ValueStorageException in project che by eclipse.
the class JavaValueProviderFactoryTest method checkNotFoundJavaFilesInCurrentFolder.
/**
* In this case we have a folder with a javascript file, so it shouldn't find any java files
*/
@Test
public void checkNotFoundJavaFilesInCurrentFolder() throws Throwable {
// we return a file entry that is a javascript file
FileEntry fileEntry = mock(FileEntry.class);
when(fileEntry.getName()).thenReturn("helloworld.js");
when(rootProjectFolder.getChildFiles()).thenReturn(Collections.singletonList(fileEntry));
ValueProvider javaPropertiesValueProvider = new JavaValueProviderFactory().newInstance(rootProjectFolder);
try {
javaPropertiesValueProvider.getValues(CONTAINS_JAVA_FILES);
} catch (ValueStorageException e) {
assertEquals(e.getMessage(), "There are no Java files inside the project");
}
}
use of org.eclipse.che.api.project.server.type.ValueStorageException 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.ValueStorageException in project che by eclipse.
the class RegisteredProject method initAttributes.
/**
* Initialize project attributes.
* Note: the problem with {@link Problem#code} = 13 will be added when a value for some attribute is not initialized
*/
private void initAttributes() {
// we take only defined attributes, others ignored
for (Map.Entry<String, Attribute> entry : types.getAttributeDefs().entrySet()) {
final Attribute definition = entry.getValue();
final String name = entry.getKey();
AttributeValue value = new AttributeValue(config.getAttributes().get(name));
if (!definition.isVariable()) {
// constant, value always assumed as stated in definition
attributes.put(name, definition.getValue());
} else {
// variable
final Variable variable = (Variable) definition;
// value provided
if (variable.isValueProvided()) {
final ValueProvider valueProvider = variable.getValueProviderFactory().newInstance(folder);
if (folder != null) {
try {
if (!valueProvider.isSettable() || value.isEmpty()) {
// get provided value
value = new AttributeValue(valueProvider.getValues(name));
} else {
// set provided (not empty) value
valueProvider.setValues(name, value.getList());
}
} catch (ValueStorageException e) {
final Problem problem = new Problem(ATTRIBUTE_NAME_PROBLEM, format("Value for attribute %s is not initialized, caused by: %s", variable.getId(), e.getLocalizedMessage()));
this.problems.add(problem);
}
} else {
continue;
}
}
if (value.isEmpty() && variable.isRequired()) {
final Problem problem = new Problem(ATTRIBUTE_NAME_PROBLEM, "Value for required attribute is not initialized " + variable.getId());
this.problems.add(problem);
//throw new ProjectTypeConstraintException("Value for required attribute is not initialized " + variable.getId());
}
if (!value.isEmpty()) {
this.attributes.put(name, value);
}
}
}
}
use of org.eclipse.che.api.project.server.type.ValueStorageException in project che by eclipse.
the class ProjectServiceTest method testEstimateProject.
@Test
public void testEstimateProject() throws Exception {
VirtualFile root = pm.getProjectsRoot().getVirtualFile();
//getVirtualFileSystemRegistry().getProvider("my_ws").getMountPoint(false).getRoot();
root.createFolder("testEstimateProjectGood").createFolder("check");
root.createFolder("testEstimateProjectBad");
String errMessage = "File /check not found";
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(errMessage);
}
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/estimate/%s?type=%s", "testEstimateProjectGood", "testEstimateProjectPT"), "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
//noinspection unchecked
SourceEstimation result = (SourceEstimation) response.getEntity();
assertTrue(result.isMatched());
assertEquals(result.getAttributes().size(), 1);
assertEquals(result.getAttributes().get("calculated_attribute").get(0), "checked");
// if project not matched
response = launcher.service(GET, format("http://localhost:8080/api/project/estimate/%s?type=%s", "testEstimateProjectBad", "testEstimateProjectPT"), "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
//noinspection unchecked
result = (SourceEstimation) response.getEntity();
assertFalse(result.isMatched());
assertEquals(result.getAttributes().size(), 0);
}
Aggregations