Search in sources :

Example 1 with AbstractForeignKeyFacade

use of org.jboss.tools.hibernate.runtime.common.AbstractForeignKeyFacade in project jbosstools-hibernate by jbosstools.

the class ForeignKeyFacadeTest method testGetReferencedColumns.

@Test
public void testGetReferencedColumns() {
    List<IColumn> list = foreignKeyFacade.getReferencedColumns();
    Assert.assertTrue(list.isEmpty());
    Assert.assertEquals("getReferencedColumns", methodName);
    Assert.assertArrayEquals(new Object[] {}, arguments);
    // recreate facade to reinitialize the instance variables
    foreignKeyFacade = new AbstractForeignKeyFacade(FACADE_FACTORY, foreignKey) {
    };
    Column column = new Column();
    ArrayList<Column> columns = new ArrayList<Column>();
    columns.add(column);
    foreignKey.addReferencedColumns(columns.iterator());
    reset();
    list = foreignKeyFacade.getReferencedColumns();
    Assert.assertFalse(list.isEmpty());
    Assert.assertEquals("getReferencedColumns", methodName);
    Assert.assertArrayEquals(new Object[] {}, arguments);
}
Also used : IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Column(org.hibernate.mapping.Column) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) AbstractForeignKeyFacade(org.jboss.tools.hibernate.runtime.common.AbstractForeignKeyFacade) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with AbstractForeignKeyFacade

use of org.jboss.tools.hibernate.runtime.common.AbstractForeignKeyFacade in project jbosstools-hibernate by jbosstools.

the class ForeignKeyFacadeTest method setUp.

@Before
public void setUp() throws Exception {
    Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(ForeignKey.class);
    enhancer.setCallback(new MethodInterceptor() {

        @Override
        public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
            if (methodName == null) {
                methodName = method.getName();
            }
            if (arguments == null) {
                arguments = args;
            }
            return proxy.invokeSuper(obj, args);
        }
    });
    foreignKey = (ForeignKey) enhancer.create();
    foreignKeyFacade = new AbstractForeignKeyFacade(FACADE_FACTORY, foreignKey) {
    };
    reset();
}
Also used : MethodInterceptor(net.sf.cglib.proxy.MethodInterceptor) Enhancer(net.sf.cglib.proxy.Enhancer) MethodProxy(net.sf.cglib.proxy.MethodProxy) AbstractForeignKeyFacade(org.jboss.tools.hibernate.runtime.common.AbstractForeignKeyFacade) Method(java.lang.reflect.Method) Before(org.junit.Before)

Example 3 with AbstractForeignKeyFacade

use of org.jboss.tools.hibernate.runtime.common.AbstractForeignKeyFacade in project jbosstools-hibernate by jbosstools.

the class ForeignKeyFacadeTest method testGetReferencedColumns.

@Test
public void testGetReferencedColumns() {
    List<IColumn> list = foreignKeyFacade.getReferencedColumns();
    Assert.assertTrue(list.isEmpty());
    Assert.assertEquals("getReferencedColumns", methodName);
    Assert.assertArrayEquals(new Object[] {}, arguments);
    // recreate facade to reinitialize the instance variables
    foreignKeyFacade = new AbstractForeignKeyFacade(FACADE_FACTORY, foreignKey) {
    };
    Column column = new Column();
    ArrayList<Column> columns = new ArrayList<Column>();
    columns.add(column);
    foreignKey.addReferencedColumns(columns.iterator());
    reset();
    list = foreignKeyFacade.getReferencedColumns();
    Assert.assertFalse(list.isEmpty());
    Assert.assertEquals("getReferencedColumns", methodName);
    Assert.assertArrayEquals(new Object[] {}, arguments);
}
Also used : IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Column(org.hibernate.mapping.Column) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) AbstractForeignKeyFacade(org.jboss.tools.hibernate.runtime.common.AbstractForeignKeyFacade) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with AbstractForeignKeyFacade

use of org.jboss.tools.hibernate.runtime.common.AbstractForeignKeyFacade in project jbosstools-hibernate by jbosstools.

the class ForeignKeyFacadeTest method setUp.

@Before
public void setUp() throws Exception {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setSuperclass(ForeignKey.class);
    Class<?> proxyClass = proxyFactory.createClass();
    foreignKey = (ForeignKey) proxyClass.newInstance();
    ((ProxyObject) foreignKey).setHandler(new MethodHandler() {

        @Override
        public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Throwable {
            if (methodName == null) {
                methodName = m.getName();
            }
            if (arguments == null) {
                arguments = args;
            }
            return proceed.invoke(self, args);
        }
    });
    foreignKeyFacade = new AbstractForeignKeyFacade(FACADE_FACTORY, foreignKey) {
    };
    reset();
}
Also used : ProxyObject(javassist.util.proxy.ProxyObject) MethodHandler(javassist.util.proxy.MethodHandler) ProxyFactory(javassist.util.proxy.ProxyFactory) AbstractForeignKeyFacade(org.jboss.tools.hibernate.runtime.common.AbstractForeignKeyFacade) ProxyObject(javassist.util.proxy.ProxyObject) Method(java.lang.reflect.Method) Before(org.junit.Before)

Example 5 with AbstractForeignKeyFacade

use of org.jboss.tools.hibernate.runtime.common.AbstractForeignKeyFacade in project jbosstools-hibernate by jbosstools.

the class ForeignKeyFacadeTest method testGetReferencedColumns.

@Test
public void testGetReferencedColumns() {
    List<IColumn> list = foreignKeyFacade.getReferencedColumns();
    Assert.assertTrue(list.isEmpty());
    Assert.assertEquals("getReferencedColumns", methodName);
    Assert.assertArrayEquals(new Object[] {}, arguments);
    // recreate facade to reinitialize the instance variables
    foreignKeyFacade = new AbstractForeignKeyFacade(FACADE_FACTORY, foreignKey) {
    };
    Column column = new Column();
    ArrayList<Column> columns = new ArrayList<Column>();
    columns.add(column);
    foreignKey.addReferencedColumns(columns.iterator());
    reset();
    list = foreignKeyFacade.getReferencedColumns();
    Assert.assertFalse(list.isEmpty());
    Assert.assertEquals("getReferencedColumns", methodName);
    Assert.assertArrayEquals(new Object[] {}, arguments);
}
Also used : IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Column(org.hibernate.mapping.Column) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) AbstractForeignKeyFacade(org.jboss.tools.hibernate.runtime.common.AbstractForeignKeyFacade) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

AbstractForeignKeyFacade (org.jboss.tools.hibernate.runtime.common.AbstractForeignKeyFacade)16 Method (java.lang.reflect.Method)8 ArrayList (java.util.ArrayList)8 Column (org.hibernate.mapping.Column)8 IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)8 Before (org.junit.Before)8 Test (org.junit.Test)8 MethodHandler (javassist.util.proxy.MethodHandler)6 ProxyFactory (javassist.util.proxy.ProxyFactory)6 ProxyObject (javassist.util.proxy.ProxyObject)6 Enhancer (net.sf.cglib.proxy.Enhancer)2 MethodInterceptor (net.sf.cglib.proxy.MethodInterceptor)2 MethodProxy (net.sf.cglib.proxy.MethodProxy)2