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);
}
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;
}
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);
}
}
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)));
}
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)));
}
Aggregations