use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.
the class MappingTestHelper method testOpenMappingDiagram.
public void testOpenMappingDiagram() {
final Object[] persClasses = getPersistenceClasses(true);
final ConsoleConfiguration consCFG = getConsoleConfig();
for (int i = 0; i < persClasses.length; i++) {
Assert.assertTrue(persClasses[i] instanceof IPersistentClass);
IPersistentClass persClass = (IPersistentClass) persClasses[i];
IEditorPart editor = null;
Throwable ex = null;
try {
editor = new OpenDiagramActionDelegate().openEditor(persClass, consCFG);
} catch (PartInitException e) {
ex = e;
}
if (ex == null) {
ex = Utils.getExceptionIfItOccured(editor);
}
if (ex != null) {
ex.printStackTrace();
String out = NLS.bind(TestConsoleMessages.OpenMappingDiagramTest_mapping_diagram_for_not_opened, new Object[] { persClass.getClassName(), ex.getMessage() });
Assert.fail(out);
}
}
}
use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.
the class MappingTestHelper 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 MappingTestHelper method testOpenSourceFileTest.
public void testOpenSourceFileTest() {
// fail("test fail");
final Object[] persClasses = getPersistenceClasses(true);
final ConsoleConfiguration consCFG = getConsoleConfig();
for (int i = 0; i < persClasses.length; i++) {
Assert.assertTrue(persClasses[i] instanceof IPersistentClass);
IPersistentClass persClass = (IPersistentClass) persClasses[i];
String fullyQualifiedName = persClass.getClassName();
// test PersistentClasses
openTest(persClass, consCFG, fullyQualifiedName);
Object[] fields = pcWorkbenchAdapter.getChildren(persClass);
for (int j = 0; j < fields.length; j++) {
if (!(fields[j] instanceof IProperty && ((IProperty) fields[j]).classIsPropertyClass())) {
continue;
}
fullyQualifiedName = persClass.getClassName();
// test Properties
openTest(fields[j], consCFG, fullyQualifiedName);
if (fields[j] instanceof IProperty && ((IProperty) fields[j]).isComposite()) {
fullyQualifiedName = ((IProperty) fields[j]).getValue().getComponentClassName();
Object[] compProperties = propertyWorkbenchAdapter.getChildren(fields[j]);
for (int k = 0; k < compProperties.length; k++) {
if (!(compProperties[k] instanceof IProperty && ((IProperty) compProperties[k]).classIsPropertyClass())) {
continue;
}
// test Composite properties
openTest(compProperties[k], consCFG, fullyQualifiedName);
}
}
}
}
// close all editors
}
use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.
the class MappingTestHelper method testHbmExportExceptionTest.
public void testHbmExportExceptionTest() 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 (Exception)e.getCause();
throw e;
}
//
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);
}
}
use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.
the class HQLEditorTest 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);
}
Aggregations