use of org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter 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);
}
}
use of org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter 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.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter in project jbosstools-hibernate by jbosstools.
the class FacadeFactoryTest method testCreateHibernateMappingExporter.
@Test
public void testCreateHibernateMappingExporter() {
HibernateMappingExporter hibernateMappingExporter = new HibernateMappingExporter();
IHibernateMappingExporter facade = facadeFactory.createHibernateMappingExporter(hibernateMappingExporter);
Assert.assertSame(hibernateMappingExporter, ((IFacade) facade).getTarget());
}
use of org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter in project jbosstools-hibernate by jbosstools.
the class FacadeFactoryTest method testCreateHibernateMappingExporter.
@Test
public void testCreateHibernateMappingExporter() {
HibernateMappingExporter hibernateMappingExporter = new HibernateMappingExporter();
IHibernateMappingExporter facade = facadeFactory.createHibernateMappingExporter(hibernateMappingExporter);
Assert.assertSame(hibernateMappingExporter, ((IFacade) facade).getTarget());
}
use of org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter in project jbosstools-hibernate by jbosstools.
the class FacadeFactoryTest method testCreateHibernateMappingExporter.
@Test
public void testCreateHibernateMappingExporter() {
HibernateMappingExporter hibernateMappingExporter = new HibernateMappingExporter();
IHibernateMappingExporter facade = facadeFactory.createHibernateMappingExporter(hibernateMappingExporter);
Assert.assertSame(hibernateMappingExporter, ((IFacade) facade).getTarget());
}
Aggregations