use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class BaseTestSetCase method getPersistenceClasses.
public Object[] getPersistenceClasses(boolean resetCC) {
final ConsoleConfiguration consCFG = getConsoleConfig();
if (resetCC) {
consCFG.reset();
consCFG.build();
}
assertTrue(consCFG.hasConfiguration());
if (resetCC) {
consCFG.buildMappings();
}
Object[] configs = null;
Object[] persClasses = null;
try {
configs = ccWorkbenchAdapter.getChildren(consCFG);
assertNotNull(configs);
assertEquals(3, configs.length);
assertTrue(configs[0] instanceof IConfiguration);
persClasses = configWorkbenchAdapter.getChildren(configs[0]);
} catch (Exception ex) {
String out = NLS.bind(ConsoleTestMessages.OpenMappingDiagramTest_mapping_diagrams_for_package_cannot_be_opened, new Object[] { testPackage.getElementName(), ex.getMessage() });
fail(out);
}
return persClasses;
}
use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class ExporterAttributesTest method checkCorrectLaunchConfigurationFile.
private void checkCorrectLaunchConfigurationFile(final String fileName) {
// IWorkspace ws = ResourcesPlugin.getWorkspace();
String str1, str2;
ILaunchConfiguration launchConfig = loadLaunchConfigFromFile(fileName);
Map<String, Object> attrMap = null;
try {
attrMap = launchConfig.getAttributes();
} catch (CoreException e) {
e.printStackTrace();
}
Assert.assertNotNull(attrMap);
ExporterAttributes exporterAttributes = null;
try {
exporterAttributes = new ExporterAttributes(launchConfig);
} catch (CoreException e) {
e.printStackTrace();
}
Assert.assertNotNull(exporterAttributes);
// check is configuration correct
Assert.assertNull(exporterAttributes.checkExporterAttributes());
List<ExporterFactory> exporterFactories = exporterAttributes.getExporterFactories();
Set<ExporterFactory> selectedExporters = new HashSet<ExporterFactory>();
selectedExporters.addAll(exporterFactories);
Set<String> deletedExporterIds = new HashSet<String>();
ILaunchConfigurationWorkingCopy launchConfigWC = null;
try {
launchConfigWC = launchConfig.getWorkingCopy();
} catch (CoreException e) {
e.printStackTrace();
}
Assert.assertNotNull(launchConfigWC);
//
str1 = project.getSample(fileName);
str1 = ResourceReadUtils.adjustXmlText(str1);
//
Assert.assertNotNull(project);
Assert.assertNotNull(project.getIProject());
Assert.assertNotNull(project.getIProject().getFile(fileName));
//
InputStream is = null;
try {
is = project.getIProject().getFile(fileName).getContents();
} catch (CoreException e) {
e.printStackTrace();
}
Assert.assertNotNull(is);
str2 = ResourceReadUtils.readStream(is);
str2 = ResourceReadUtils.adjustXmlText(str2);
Assert.assertEquals(str1, str2);
// update and save lc - so fileName from the project updated
try {
ExporterAttributes.saveExporterFactories(launchConfigWC, exporterFactories, selectedExporters, deletedExporterIds);
launchConfigWC.doSave();
} catch (CoreException e) {
Assert.fail(e.getMessage());
}
//
is = null;
try {
is = project.getIProject().getFile(fileName).getContents();
} catch (CoreException e) {
e.printStackTrace();
}
Assert.assertNotNull(is);
str2 = ResourceReadUtils.readStream(is);
str2 = ResourceReadUtils.adjustXmlText(str2);
Assert.assertEquals(str1, str2);
//
IArtifactCollector artifactCollector = service.newArtifactCollector();
ExporterAttributes expAttr = exporterAttributes;
// Global properties
Properties props = new Properties();
// $NON-NLS-1$
props.put(CodeGenerationStrings.EJB3, "" + expAttr.isEJB3Enabled());
// $NON-NLS-1$
props.put(CodeGenerationStrings.JDK5, "" + expAttr.isJDK5Enabled());
consoleCfg.build();
IConfiguration cfg = consoleCfg.getConfiguration();
Assert.assertNotNull(cfg);
Set<String> outputDirectories = new HashSet<String>();
for (int i = 0; i < exporterFactories.size(); i++) {
Properties globalProperties = new Properties();
globalProperties.putAll(props);
ExporterFactory ef = exporterFactories.get(i);
//
Properties propsForTesting = new Properties();
propsForTesting.putAll(globalProperties);
propsForTesting.putAll(ef.getProperties());
//
IExporter exporter = null;
outputDirectories.clear();
try {
exporter = ef.createConfiguredExporter(cfg, expAttr.getOutputPath(), expAttr.getTemplatePath(), globalProperties, outputDirectories, artifactCollector, service);
} catch (CoreException e) {
e.printStackTrace();
}
Assert.assertNotNull(exporter);
Assert.assertTrue(outputDirectories.size() > 0);
Properties propsFromExporter = exporter.getProperties();
String exporterDefinitionId = ef.getExporterDefinitionId();
// test special handling for GenericExporter
if (exporterDefinitionId.equals("org.hibernate.tools.hbmtemplate")) {
// $NON-NLS-1$
Assert.assertNull(propsFromExporter.getProperty(ExporterFactoryStrings.FILE_PATTERN));
Assert.assertNull(propsFromExporter.getProperty(ExporterFactoryStrings.TEMPLATE_NAME));
Assert.assertNull(propsFromExporter.getProperty(ExporterFactoryStrings.FOR_EACH));
IGenericExporter ge = exporter.getGenericExporter();
Assert.assertNotNull(ge);
Assert.assertEquals(propsForTesting.getProperty(ExporterFactoryStrings.FILE_PATTERN), ge.getFilePattern());
Assert.assertEquals(propsForTesting.getProperty(ExporterFactoryStrings.TEMPLATE_NAME), ge.getTemplateName());
// to test GenericExporter should provide public getter but it doesn't
// assertEquals(propsForTesting.getProperty(ExporterFactoryStrings.FOR_EACH), ge.getForEach());
}
// test special handling for Hbm2DDLExporter
if (exporterDefinitionId.equals("org.hibernate.tools.hbm2ddl")) {
// $NON-NLS-1$
Assert.assertNull(propsFromExporter.getProperty(ExporterFactoryStrings.EXPORTTODATABASE));
IHbm2DDLExporter ddlExporter = exporter.getHbm2DDLExporter();
Assert.assertNotNull(ddlExporter);
// to test Hbm2DDLExporter should provide public getter but it doesn't
// assertEquals(propsForTesting.getProperty(ExporterFactoryStrings.EXPORTTODATABASE), ddlExporter.getExport());
}
// test special handling for QueryExporter
if (exporterDefinitionId.equals("org.hibernate.tools.query")) {
// $NON-NLS-1$
Assert.assertNull(propsFromExporter.getProperty(ExporterFactoryStrings.QUERY_STRING));
Assert.assertNull(propsFromExporter.getProperty(ExporterFactoryStrings.OUTPUTFILENAME));
// IQueryExporter queryExporter = exporter.getQueryExporter();
// to test QueryExporter should provide public getter but it doesn't
// List<String> queryStrings = queryExporter.getQueries();
// assertEquals(1, queryStrings.size());
// assertEquals(propsForTesting.getProperty(ExporterFactoryStrings.QUERY_STRING), queryStrings.get(0));
// assertEquals(propsForTesting.getProperty(ExporterFactoryStrings.OUTPUTFILENAME), queryExporter.getFileName());
}
// try {
// exporter.start();
// } catch (HibernateException he) {
// he.printStackTrace();
// }
}
Assert.assertTrue(artifactCollector.getFileTypes().size() == 0);
}
use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class HbmExporterTest method testList.
public void testList() {
// $NON-NLS-1$
IConfiguration config = getConfigurationFor("pack.A");
// $NON-NLS-1$ //$NON-NLS-2$
checkClassesMaped(config, "pack.A", "pack.B");
// $NON-NLS-1$
IPersistentClass a = config.getClassMapping("pack.A");
// $NON-NLS-1$
IPersistentClass b = config.getClassMapping("pack.B");
// $NON-NLS-1$
IProperty listProp = a.getProperty("list");
assertNotNull(listProp.getValue());
IValue value = listProp.getValue();
assertTrue("Expected to get List-type mapping", value.isList());
assertTrue(value.getCollectionElement().isOneToMany());
assertTrue(value.getCollectionTable().equals(b.getTable()));
assertNotNull(value.getIndex());
assertNotNull(value.getKey());
}
use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class HbmExporterTest method testMap.
public void testMap() {
// $NON-NLS-1$
IConfiguration config = getConfigurationFor("pack.A");
// $NON-NLS-1$ //$NON-NLS-2$
checkClassesMaped(config, "pack.A", "pack.B");
// $NON-NLS-1$
IPersistentClass a = config.getClassMapping("pack.A");
// $NON-NLS-1$
IPersistentClass b = config.getClassMapping("pack.B");
// $NON-NLS-1$
IProperty mapValue = a.getProperty("mapValue");
assertNotNull(mapValue.getValue());
IValue value = mapValue.getValue();
assertTrue("Expected to get Map-type mapping", value.isMap());
assertTrue(value.getCollectionElement().isOneToMany());
assertTrue(value.getCollectionTable().equals(b.getTable()));
assertNotNull(value.getKey());
// $NON-NLS-1$
assertEquals("string", value.getKey().getType().getName());
}
use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.
the class HbmExporterTest method testId.
public void testId() {
// $NON-NLS-1$
IConfiguration config = getConfigurationFor("pack.A");
// $NON-NLS-1$ //$NON-NLS-2$
checkClassesMaped(config, "pack.A", "pack.B");
// $NON-NLS-1$
IPersistentClass a = config.getClassMapping("pack.A");
// $NON-NLS-1$
IPersistentClass b = config.getClassMapping("pack.B");
IProperty aId = a.getIdentifierProperty();
IProperty bId = b.getIdentifierProperty();
assertNotNull(aId);
assertNotNull(bId);
// $NON-NLS-1$
assertEquals("id", aId.getName());
// $NON-NLS-1$
assertEquals("id", bId.getName());
}
Aggregations