Search in sources :

Example 76 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class JavaHBMQueryTest method setUp.

protected void setUp() throws Exception {
    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.setDefaultConsoleConfiguration(CONSOLE_NAME);
    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$
    assertNotNull("Console Configuration not found", cc);
    cc.build();
}
Also used : SimpleTestProjectWithMapping(org.hibernate.eclipse.console.test.project.SimpleTestProjectWithMapping) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 77 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class OpenMappingDiagramTest method testOpenMappingDiagram.

public void testOpenMappingDiagram() {
    final Object[] persClasses = getPersistenceClasses(false);
    final ConsoleConfiguration consCFG = getConsoleConfig();
    for (int i = 0; i < persClasses.length; i++) {
        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(ConsoleTestMessages.OpenMappingDiagramTest_mapping_diagram_for_not_opened, new Object[] { persClass.getClassName(), ex.getMessage() });
            fail(out);
        }
    }
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IEditorPart(org.eclipse.ui.IEditorPart) OpenDiagramActionDelegate(org.jboss.tools.hibernate.ui.view.OpenDiagramActionDelegate) PartInitException(org.eclipse.ui.PartInitException) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 78 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class OpenMappingFileTest method testOpenMappingFileTest.

public void testOpenMappingFileTest() {
    final Object[] persClasses = getPersistenceClasses(false);
    final ConsoleConfiguration consCFG = getConsoleConfig();
    // $NON-NLS-1$
    final String testClass = "class";
    for (int i = 0; i < persClasses.length; i++) {
        assertTrue(persClasses[i] instanceof IPersistentClass);
        IPersistentClass persClass = (IPersistentClass) persClasses[i];
        openTest(persClass, consCFG);
        Object[] props = pcWorkbenchAdapter.getChildren(persClass);
        for (int j = 0; j < props.length; j++) {
            if (!(props[j] instanceof IProperty && ((IProperty) props[j]).classIsPropertyClass())) {
                continue;
            }
            openTest(props[j], consCFG);
            Object[] compProperties = propertyWorkbenchAdapter.getChildren(props[j]);
            for (int k = 0; k < compProperties.length; k++) {
                // test Composite properties
                if (!(compProperties[k] instanceof IProperty && ((IProperty) props[j]).classIsPropertyClass())) {
                    continue;
                }
                final IProperty prop = (IProperty) compProperties[k];
                if (testClass.equals(prop.getName()) || testClass.equals(prop.getName())) {
                    continue;
                }
                openPropertyTest((IProperty) compProperties[k], (IProperty) props[j], consCFG);
            }
        }
    }
// close all editors
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 79 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class OpenSourceFileTest method testOpenSourceFileTest.

public void testOpenSourceFileTest() {
    // fail("test fail");
    final Object[] persClasses = getPersistenceClasses(false);
    final ConsoleConfiguration consCFG = getConsoleConfig();
    for (int i = 0; i < persClasses.length; i++) {
        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
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 80 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class HibernateJpaModelTests method testNamigStrategyMapping.

@Test
public void testNamigStrategyMapping() {
    ConsoleConfiguration cc = KnownConfigurations.getInstance().find(PROJECT_NAME);
    assertNotNull("Console configuration not found for project " + PROJECT_NAME, cc);
    cc.build();
    assertNotNull("Console configuration build problem", cc.getConfiguration());
    IConfiguration configuration = cc.getConfiguration();
    assertNotNull("Naming Strategy not found", cc.getConfiguration().getNamingStrategy());
    assertEquals("ns.NamingStrategy", cc.getConfiguration().getNamingStrategy().getStrategyClassName());
    try {
        jpaProject = ((Reference) project.getAdapter(Reference.class)).getValue();
    } catch (InterruptedException e) {
        fail(e.getMessage());
    }
    assertNotNull(jpaProject);
    JpaContextRoot rootContextNode = jpaProject.getContextRoot();
    Persistence p = rootContextNode.getPersistenceXml().getRoot();
    assertTrue(p.getPersistenceUnits().iterator().hasNext());
    assertTrue(p.getPersistenceUnits().iterator().next() instanceof HibernatePersistenceUnit);
    HibernatePersistenceUnit hpu = (HibernatePersistenceUnit) p.getPersistenceUnits().iterator().next();
    List<ClassRef> crs = IterableTools.list(hpu.getClassRefs());
    assertTrue(crs.size() == 2);
    if (crs.get(0).isFor("entity.ManyToMany1")) {
        checkManyToManyNS1(crs.get(0));
        checkManyToManyNS2(crs.get(1));
    } else {
        checkManyToManyNS1(crs.get(1));
        checkManyToManyNS2(crs.get(0));
    }
    cc.reset();
}
Also used : JpaContextRoot(org.eclipse.jpt.jpa.core.context.JpaContextRoot) Persistence(org.eclipse.jpt.jpa.core.context.persistence.Persistence) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ClassRef(org.eclipse.jpt.jpa.core.context.persistence.ClassRef) HibernatePersistenceUnit(org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Test(org.junit.Test)

Aggregations

ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)107 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)19 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)17 CoreException (org.eclipse.core.runtime.CoreException)16 PartInitException (org.eclipse.ui.PartInitException)13 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)12 KnownConfigurations (org.hibernate.console.KnownConfigurations)11 JavaModelException (org.eclipse.jdt.core.JavaModelException)10 TreePath (org.eclipse.jface.viewers.TreePath)10 Test (org.junit.Test)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 FileNotFoundException (java.io.FileNotFoundException)8 IPath (org.eclipse.core.runtime.IPath)8 TreeSelection (org.eclipse.jface.viewers.TreeSelection)8 IService (org.jboss.tools.hibernate.runtime.spi.IService)8 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)7 IEditorPart (org.eclipse.ui.IEditorPart)7 ConsoleConfigurationPreferences (org.hibernate.console.preferences.ConsoleConfigurationPreferences)7 GridLayout (org.eclipse.swt.layout.GridLayout)6