use of org.eclipse.che.api.project.server.FileEntry in project che by eclipse.
the class SimpleGeneratorStrategyTest method testGeneratingProject.
@Test
public void testGeneratingProject() throws Exception {
prepareProject();
final Path pomXml = Paths.get(Thread.currentThread().getContextClassLoader().getResource("test-pom.xml").toURI());
Map<String, AttributeValue> attributeValues = new HashMap<>();
attributeValues.put(MavenAttributes.ARTIFACT_ID, new AttributeValue("my_artifact"));
attributeValues.put(MavenAttributes.GROUP_ID, new AttributeValue("my_group"));
attributeValues.put(MavenAttributes.PACKAGING, new AttributeValue("jar"));
attributeValues.put(MavenAttributes.VERSION, new AttributeValue("1.0-SNAPSHOT"));
attributeValues.put(SOURCE_FOLDER, new AttributeValue("src/main/java"));
attributeValues.put(MavenAttributes.TEST_SOURCE_FOLDER, new AttributeValue("src/test/java"));
pm.getProject("my_project").getBaseFolder();
simple.generateProject(org.eclipse.che.api.vfs.Path.of("my_project"), attributeValues, null);
VirtualFileEntry pomFile = pm.getProject("my_project").getBaseFolder().getChild("pom.xml");
Assert.assertTrue(pomFile.isFile());
Assert.assertEquals(new String(((FileEntry) pomFile).contentAsBytes()), new String(Files.readAllBytes(pomXml)));
VirtualFileEntry srcFolder = pm.getProject("my_project").getBaseFolder().getChild("src/main/java");
Assert.assertTrue(srcFolder.isFolder());
VirtualFileEntry testFolder = pm.getProject("my_project").getBaseFolder().getChild("src/test/java");
Assert.assertTrue(testFolder.isFolder());
}
use of org.eclipse.che.api.project.server.FileEntry in project che by eclipse.
the class JavaValueProviderFactoryTest method checkFoundJavaButNotInRootFolder.
/**
* In this case we have a folder with a javascript file, but some sub folders contains java files
*/
@Test
public void checkFoundJavaButNotInRootFolder() 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));
FileEntry javaFileEntry = mock(FileEntry.class);
when(javaFileEntry.getName()).thenReturn("helloworld.java");
FolderEntry subFolder = mock(FolderEntry.class);
when(subFolder.getChildFiles()).thenReturn(Collections.singletonList(javaFileEntry));
when(rootProjectFolder.getChildFolders()).thenReturn(Collections.singletonList(subFolder));
ValueProvider javaPropertiesValueProvider = new JavaValueProviderFactory().newInstance(rootProjectFolder);
List<String> hasJavaFiles = javaPropertiesValueProvider.getValues(CONTAINS_JAVA_FILES);
assertNotNull(hasJavaFiles);
assertEquals(hasJavaFiles, Collections.singletonList("true"));
}
use of org.eclipse.che.api.project.server.FileEntry in project che by eclipse.
the class JavaValueProviderFactoryTest method checkFoundJavaFilesInCurrentFolder.
/**
* In this case we have a folder with a java file, so it should find a java file
*/
@Test
public void checkFoundJavaFilesInCurrentFolder() throws Throwable {
// we return a file entry that is a java file
FileEntry fileEntry = mock(FileEntry.class);
when(fileEntry.getName()).thenReturn("helloworld.java");
when(rootProjectFolder.getChildFiles()).thenReturn(Collections.singletonList(fileEntry));
ValueProvider javaPropertiesValueProvider = new JavaValueProviderFactory().newInstance(rootProjectFolder);
List<String> hasJavaFiles = javaPropertiesValueProvider.getValues(CONTAINS_JAVA_FILES);
assertNotNull(hasJavaFiles);
assertEquals(hasJavaFiles, Collections.singletonList("true"));
}
use of org.eclipse.che.api.project.server.FileEntry 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.FileEntry in project che by eclipse.
the class JavaValueProviderFactoryTest method checkFoundJavaDeepFolder.
/**
* In this case we have java file in a very deep folder
*/
@Test
public void checkFoundJavaDeepFolder() 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));
FolderEntry subFolder = mock(FolderEntry.class);
when(subFolder.getChildFiles()).thenReturn(Collections.emptyList());
when(rootProjectFolder.getChildFolders()).thenReturn(Collections.singletonList(subFolder));
FileEntry javaFileEntry = mock(FileEntry.class);
when(javaFileEntry.getName()).thenReturn("helloworld.java");
FolderEntry subSubFolder = mock(FolderEntry.class);
when(subSubFolder.getChildFiles()).thenReturn(Collections.singletonList(javaFileEntry));
when(subFolder.getChildFolders()).thenReturn(Collections.singletonList(subSubFolder));
ValueProvider javaPropertiesValueProvider = new JavaValueProviderFactory().newInstance(rootProjectFolder);
List<String> hasJavaFiles = javaPropertiesValueProvider.getValues(CONTAINS_JAVA_FILES);
assertNotNull(hasJavaFiles);
assertEquals(hasJavaFiles, Collections.singletonList("true"));
}
Aggregations