Search in sources :

Example 1 with FileEntry

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());
}
Also used : Path(java.nio.file.Path) AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) HashMap(java.util.HashMap) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) FileEntry(org.eclipse.che.api.project.server.FileEntry) Test(org.junit.Test)

Example 2 with FileEntry

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"));
}
Also used : FolderEntry(org.eclipse.che.api.project.server.FolderEntry) FileEntry(org.eclipse.che.api.project.server.FileEntry) ValueProvider(org.eclipse.che.api.project.server.type.ValueProvider) Test(org.testng.annotations.Test)

Example 3 with FileEntry

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"));
}
Also used : FileEntry(org.eclipse.che.api.project.server.FileEntry) ValueProvider(org.eclipse.che.api.project.server.type.ValueProvider) Test(org.testng.annotations.Test)

Example 4 with FileEntry

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");
    }
}
Also used : ValueStorageException(org.eclipse.che.api.project.server.type.ValueStorageException) FileEntry(org.eclipse.che.api.project.server.FileEntry) ValueProvider(org.eclipse.che.api.project.server.type.ValueProvider) Test(org.testng.annotations.Test)

Example 5 with FileEntry

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"));
}
Also used : FolderEntry(org.eclipse.che.api.project.server.FolderEntry) FileEntry(org.eclipse.che.api.project.server.FileEntry) ValueProvider(org.eclipse.che.api.project.server.type.ValueProvider) Test(org.testng.annotations.Test)

Aggregations

FileEntry (org.eclipse.che.api.project.server.FileEntry)9 ValueProvider (org.eclipse.che.api.project.server.type.ValueProvider)5 Test (org.testng.annotations.Test)5 FolderEntry (org.eclipse.che.api.project.server.FolderEntry)4 VirtualFileEntry (org.eclipse.che.api.project.server.VirtualFileEntry)3 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)2 ServerException (org.eclipse.che.api.core.ServerException)2 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 ConflictException (org.eclipse.che.api.core.ConflictException)1 RegisteredProject (org.eclipse.che.api.project.server.RegisteredProject)1 AttributeValue (org.eclipse.che.api.project.server.type.AttributeValue)1 ValueStorageException (org.eclipse.che.api.project.server.type.ValueStorageException)1 IResourceStatus (org.eclipse.core.resources.IResourceStatus)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1