Search in sources :

Example 11 with ProjectImports

use of org.guvnor.common.services.project.model.ProjectImports in project kie-wb-common by kiegroup.

the class ProjectScreenModelTests method testHashCode.

@Test
public void testHashCode() {
    final ProjectScreenModel model = new ProjectScreenModel();
    model.setPOM(new POM("test", "test", "url", new GAV("groupID", "artifactID", "version")));
    final MavenRepository repository = new MavenRepository();
    repository.setId("guvnor-m2-repo");
    repository.setName("Guvnor M2 Repo");
    repository.setUrl("http://localhost/maven2/");
    model.getPOM().addRepository(repository);
    model.setPOMMetaData(new Metadata());
    model.setKModule(new KModuleModel());
    model.setKModuleMetaData(new Metadata());
    model.setProjectTagsMetaData(new Metadata());
    model.setProjectImports(new ProjectImports());
    model.setProjectImportsMetaData(new Metadata());
    final int hashCode1 = model.hashCode();
    assertTrue(hashCode1 <= Integer.MAX_VALUE);
    assertTrue(hashCode1 >= Integer.MIN_VALUE);
    model.getProjectImports().getImports().addImport(new Import("java.lang.List"));
    final int hashCode2 = model.hashCode();
    assertTrue(hashCode2 <= Integer.MAX_VALUE);
    assertTrue(hashCode2 >= Integer.MIN_VALUE);
    assertNotEquals(hashCode1, hashCode2);
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) MavenRepository(org.guvnor.common.services.project.model.MavenRepository) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) ProjectImports(org.guvnor.common.services.project.model.ProjectImports) GAV(org.guvnor.common.services.project.model.GAV) POM(org.guvnor.common.services.project.model.POM) KModuleModel(org.kie.workbench.common.services.shared.kmodule.KModuleModel) Test(org.junit.Test)

Example 12 with ProjectImports

use of org.guvnor.common.services.project.model.ProjectImports in project kie-wb-common by kiegroup.

the class ProjectImportsServiceImpl method createProjectImports.

private ProjectImports createProjectImports() {
    ProjectImports projectImports = new ProjectImports();
    final Imports imports = projectImports.getImports();
    imports.addImport(new Import(java.lang.Number.class.getName()));
    imports.addImport(new Import(java.lang.Boolean.class.getName()));
    imports.addImport(new Import(java.lang.String.class.getName()));
    imports.addImport(new Import(java.lang.Integer.class.getName()));
    imports.addImport(new Import(java.lang.Double.class.getName()));
    imports.addImport(new Import(java.util.List.class.getName()));
    imports.addImport(new Import(java.util.Collection.class.getName()));
    imports.addImport(new Import(java.util.ArrayList.class.getName()));
    return projectImports;
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) ProjectImports(org.guvnor.common.services.project.model.ProjectImports) ProjectImports(org.guvnor.common.services.project.model.ProjectImports) Imports(org.kie.soup.project.datamodel.imports.Imports)

Example 13 with ProjectImports

use of org.guvnor.common.services.project.model.ProjectImports in project kie-wb-common by kiegroup.

the class ProjectImportsServiceImpl method load.

@Override
public ProjectImports load(final Path path) {
    try {
        final org.uberfire.java.nio.file.Path nioPath = Paths.convert(path);
        if (!ioService.exists(nioPath)) {
            saveProjectImports(path);
        }
        final String content = ioService.readAllString(Paths.convert(path));
        final ProjectImports projectImports = projectConfigurationContentHandler.toModel(content);
        // java.lang.Number imported by default in new guided rule
        // include it into project imports if not present already
        final Import javaLangNumber = new Import(Number.class);
        if (projectImports.getImports().getImports().stream().noneMatch(anImport -> Objects.equals(anImport, javaLangNumber))) {
            projectImports.getImports().addImport(javaLangNumber);
        }
        return projectImports;
    } catch (Exception e) {
        throw ExceptionUtilities.handleException(e);
    }
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) ProjectImports(org.guvnor.common.services.project.model.ProjectImports) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 14 with ProjectImports

use of org.guvnor.common.services.project.model.ProjectImports in project kie-wb-common by kiegroup.

the class ProjectImportsServiceImplTest method testProjectImportsLoad_NotExists.

@Test
public void testProjectImportsLoad_NotExists() throws URISyntaxException {
    when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(false);
    final ProjectImports projectImports = projectImportsService.load(pathToImports);
    verify(ioService, times(1)).write(any(org.uberfire.java.nio.file.Path.class), importsArgumentCaptor.capture());
    assertExternalDataObjects(importsArgumentCaptor.getValue());
    // projects imports need always to contain java.lang.Number
    // because of the guided rule editor
    assertTrue(projectImports.getImports().contains(new Import(Number.class)));
}
Also used : Path(org.uberfire.backend.vfs.Path) Import(org.kie.soup.project.datamodel.imports.Import) ProjectImports(org.guvnor.common.services.project.model.ProjectImports) Test(org.junit.Test)

Example 15 with ProjectImports

use of org.guvnor.common.services.project.model.ProjectImports in project kie-wb-common by kiegroup.

the class ProjectImportsServiceImplTest method testProjectImportsLoad_Exists.

@Test
public void testProjectImportsLoad_Exists() throws URISyntaxException {
    when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(true);
    final ProjectImports projectImports = projectImportsService.load(pathToImports);
    verify(ioService, never()).write(any(org.uberfire.java.nio.file.Path.class), any(String.class));
    verify(ioService, times(1)).readAllString(any(org.uberfire.java.nio.file.Path.class));
    // projects imports need always to contain java.lang.Number
    // because of the guided rule editor
    assertTrue(projectImports.getImports().contains(new Import(Number.class)));
}
Also used : Path(org.uberfire.backend.vfs.Path) Import(org.kie.soup.project.datamodel.imports.Import) ProjectImports(org.guvnor.common.services.project.model.ProjectImports) Test(org.junit.Test)

Aggregations

ProjectImports (org.guvnor.common.services.project.model.ProjectImports)18 Test (org.junit.Test)12 Import (org.kie.soup.project.datamodel.imports.Import)8 Path (org.uberfire.backend.vfs.Path)8 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)6 ProjectScreenModel (org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel)4 InputStream (java.io.InputStream)2 ConversionResult (org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult)2 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)2 GAV (org.guvnor.common.services.project.model.GAV)2 MavenRepository (org.guvnor.common.services.project.model.MavenRepository)2 POM (org.guvnor.common.services.project.model.POM)2 Imports (org.kie.soup.project.datamodel.imports.Imports)2 KModuleModel (org.kie.workbench.common.services.shared.kmodule.KModuleModel)2 KieModule (org.kie.workbench.common.services.shared.project.KieModule)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 PomModel (org.appformer.maven.support.PomModel)1