use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.
the class CriteriaEditorTest method testCriteriaCodeCompletion.
@Test
public void testCriteriaCodeCompletion() throws CoreException, NoSuchFieldException, IllegalAccessException, IOException {
cleanUpProject();
project = new SimpleTestProjectWithMapping(PROJ_NAME);
IPackageFragmentRoot sourceFolder = project.createSourceFolder();
IPackageFragment pf = sourceFolder.createPackageFragment(SimpleTestProject.PACKAGE_NAME, false, null);
ConsoleConfigUtils.customizeCfgXmlForPack(pf);
List<IPath> libs = new ArrayList<IPath>();
project.generateClassPath(libs, sourceFolder);
project.fullBuild();
// setup console configuration
IPath cfgFilePath = new Path(project.getIProject().getName() + File.separator + TestProject.SRC_FOLDER + File.separator + ConsoleConfigUtils.CFG_FILE_NAME);
ConsoleConfigUtils.createConsoleConfig(PROJ_NAME, cfgFilePath, CONSOLE_NAME);
ConsoleConfiguration cc = KnownConfigurations.getInstance().find(CONSOLE_NAME);
// $NON-NLS-1$
Assert.assertNotNull("Console Configuration not found", cc);
cc.build();
String query = // $NON-NLS-1$
"Object o = new Object();\n" + // $NON-NLS-1$
"System.out.print(o.toString());";
IEditorPart editorPart = HibernateConsolePlugin.getDefault().openCriteriaEditor(CONSOLE_NAME, query);
// $NON-NLS-1$
Assert.assertTrue("Opened editor is not CriteriaEditor", editorPart instanceof CriteriaEditor);
CriteriaEditor editor = (CriteriaEditor) editorPart;
Assert.assertEquals(editor.getEditorText(), query);
QueryInputModel model = editor.getQueryInputModel();
Assert.assertTrue(model.getParameterCount() == 0);
editor.setConsoleConfigurationName(CONSOLE_NAME);
JavaCompletionProcessor processor = new JavaCompletionProcessor(editor);
// $NON-NLS-1$
int position = query.indexOf("toString()");
ICompletionProposal[] proposals = processor.computeCompletionProposals(null, position);
Assert.assertTrue(// $NON-NLS-1$
"Class java.lang.Object has at least 9 methods. But " + proposals.length + " code completion proposals where provided.", // $NON-NLS-1$
proposals.length >= 9);
cc.reset();
}
use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.
the class CriteriaEditorTest method setUp.
@Before
public void setUp() throws Exception {
cfgXmlFile = new File(temporaryFolder.getRoot(), "hibernate.cfg.xml");
FileWriter fw = new FileWriter(cfgXmlFile);
fw.write(HIBERNATE_CFG_XML);
fw.close();
consolePrefs = new TestConsoleConfigurationPreferences(cfgXmlFile);
consoleConfiguration = new ConsoleConfiguration(consolePrefs);
KnownConfigurations.getInstance().addConfiguration(consoleConfiguration, false);
}
use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.
the class ExporterAttributesTest method setUp.
@Before
public void setUp() throws Exception {
cfgXmlFile = new File(temporaryFolder.getRoot(), "hibernate.cfg.xml");
FileWriter fw = new FileWriter(cfgXmlFile);
fw.write(HIBERNATE_CFG_XML);
fw.close();
this.project = new LaunchConfigTestProject();
TestConsoleConfigurationPreferences cfgprefs = new TestConsoleConfigurationPreferences(cfgXmlFile);
consoleCfg = new ConsoleConfiguration(cfgprefs);
service = consoleCfg.getHibernateExtension().getHibernateService();
KnownConfigurations.getInstance().addConfiguration(consoleCfg, true);
}
use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.
the class CoreMappingTestHelper method getPersistenceClasses.
private Object[] getPersistenceClasses(boolean resetCC) {
final ConsoleConfiguration consCFG = getConsoleConfig();
if (resetCC) {
consCFG.reset();
consCFG.build();
}
Assert.assertTrue(consCFG.hasConfiguration());
if (resetCC) {
consCFG.buildMappings();
}
Object[] configs = null;
Object[] persClasses = null;
try {
configs = ccWorkbenchAdapter.getChildren(consCFG);
Assert.assertNotNull(configs);
Assert.assertEquals(3, configs.length);
Assert.assertTrue(configs[0] instanceof IConfiguration);
persClasses = configWorkbenchAdapter.getChildren(configs[0]);
} catch (Exception ex) {
String out = NLS.bind(TestConsoleMessages.OpenMappingDiagramTest_mapping_diagrams_for_package_cannot_be_opened, new Object[] { testName.getMethodName(), ex.getMessage() });
Assert.fail(out);
}
return persClasses;
}
use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.
the class CoreMappingTestHelper method testHbmExportExceptionTest.
public void testHbmExportExceptionTest(String packageName) throws Exception {
String projectName = testProject.getIProject().getName();
String pathName = "/" + projectName + "/src/" + packageName.replace('.', '/');
IPackageFragment testPackage = testProject.getIJavaProject().findPackageFragment(new Path(pathName));
try {
Object[] persClassesInit = getPersistenceClasses(true);
final ConsoleConfiguration consCFG = getConsoleConfig();
IConfiguration config = consCFG.getConfiguration();
// delete old hbm files
Assert.assertNotNull(testPackage);
int nDeleted = 0;
if (testPackage.getNonJavaResources().length > 0) {
Object[] ress = testPackage.getNonJavaResources();
for (int i = 0; i < ress.length; i++) {
if (ress[i] instanceof IFile) {
IFile res = (IFile) ress[i];
if (res.getName().endsWith(".hbm.xml")) {
// $NON-NLS-1$
res.delete(true, false, null);
nDeleted++;
}
}
}
}
String[] versions = ServiceLookup.getVersions();
IService service = ServiceLookup.findService(versions[0]);
File srcFolder = testProject.getIProject().getFolder(TestProject.SRC_FOLDER).getLocation().toFile();
IHibernateMappingExporter hce = service.newHibernateMappingExporter(config, srcFolder);
try {
hce.start();
IArtifactCollector collector = service.newArtifactCollector();
collector.formatFiles();
try {
// build generated configuration
testPackage.getResource().refreshLocal(IResource.DEPTH_INFINITE, null);
testPackage.getJavaProject().getProject().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
ConsoleConfigUtils.customizeCfgXmlForPack(testPackage);
Assert.assertNotNull(consCFG);
consCFG.reset();
consCFG.build();
Assert.assertTrue(consCFG.hasConfiguration());
consCFG.getConfiguration().buildMappings();
config = consCFG.getConfiguration();
} catch (CoreException e) {
String out = NLS.bind(TestConsoleMessages.UpdateConfigurationTest_error_customising_file_for_package, new Object[] { ConsoleConfigUtils.CFG_FILE_NAME, testPackage.getPath(), e.getMessage() });
Assert.fail(out);
}
} catch (Exception e) {
throw e;
// throw (Exception)e.getCause();
}
//
Object[] persClassesReInit = getPersistenceClasses(false);
//
int nCreated = 0;
if (testPackage.getNonJavaResources().length > 0) {
Object[] ress = testPackage.getNonJavaResources();
for (int i = 0; i < ress.length; i++) {
if (ress[i] instanceof IFile) {
IFile res = (IFile) ress[i];
if (res.getName().endsWith(".hbm.xml")) {
// $NON-NLS-1$
nCreated++;
}
}
}
}
//
Assert.assertTrue(persClassesInit.length == persClassesReInit.length);
Assert.assertTrue(nCreated > 0);
Assert.assertTrue(nDeleted >= 0 && persClassesInit.length > 0);
Assert.assertTrue(nCreated <= persClassesInit.length);
} catch (Exception e) {
// $NON-NLS-1$ //$NON-NLS-2$
String newMessage = "\nPackage " + testPackage.getElementName() + ":";
throw new WrapperException(newMessage, e);
}
}
Aggregations