TestContext always Null - citrus-framework

Is there any way I can inject TestContext in my cucumber step class?
I am using citrus, spring, and cucumber together with the latest version. But when I use the below injection I always get null pointer exception of the TestContext. For TestDesigner and TestRunner I have no issue to get.
#CitrusResource private TestContext tContext;
and in the log i am seeing
Failed to get proper TestContext from Cucumber Spring application context: No qualifying bean of type 'com.consol.citrus.context.TestContext' available

You are obviously using the setting
cucumber.api.java.ObjectFactory=cucumber.runtime.java.spring.CitrusSpringObjectFactory
in the cucumber.properties.
When doing so you need to manually add the Citrus Spring configuration with #ContextConfiguration annotation on your steps class.
#ContextConfiguration(classes = CitrusSpringConfig.class)
public class MySteps {
#CitrusResource
private TestDesigner designer;
[...]
}
In case you are using the default cucumber.xml Spring XML application context you need to add the Citrus Spring config as bean to that file:
<!-- JavaConfig bean post-processor -->
<bean class="org.springframework.context.annotation.ConfigurationClassPostProcessor"/>
<!-- Citrus Java config -->
<bean id="citrusSpringConfig" class="com.consol.citrus.config.CitrusSpringConfig"/>

Related

Unable to create Spring AOP aspect on Spring Data JPA Repository when CGLIB proxies are used

I'm trying to apply an aspect on a Spring Data JPA Repository and it works fine with default Spring AOP config
#EnableAspectJAutoProxy
(when Spring uses standard Java interface-based proxies).
However, when I switch to CGLIB proxies:
#EnableAspectJAutoProxy(proxyTargetClass = true)
I get this exception:
Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.sun.proxy.$Proxy59]:
Looks like Spring tries to wrap a CGLIB proxy on a repository class, which is already a CGLIB proxy (generated by Spring Data) and fails.
Any ideas how to make it work?
My Spring Data Repository:
import org.springframework.data.jpa.repository.JpaRepository;
public interface DummyEntityRepository extends JpaRepository<DummyEntity, Integer> {
}
and the aspect:
#Aspect
public class DummyCrudRepositoryAspect {
#After("this(org.springframework.data.repository.CrudRepository)")
public void onCrud(JoinPoint pjp) {
System.out.println("I'm there!");
}
}

drools #KSession throws exception when using kmodule in separate jar

using Drools 6.2.0.Final
i am using drools with a kmodules.xml and decisiontable inside a separate jar file. when i attempt to bind the #KSession to the spring application context it throws an nullpointer exception deep inside the annotation.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oft.onlineservice.business.FeeRulesEngineTest': Injection of kie dependencies failed; nested exception is java.lang.NullPointerException
at org.kie.spring.annotations.AnnotationsPostProcessor.postProcessPropertyValues(AnnotationsPostProcessor.java:109)
using a simple junittest shows the problem.
public class FeeRulesEngineTest {
#KSession( "ksession1")
private StatelessKieSession ksession;
#KBase("feeDecisionTable")
private KieBase kbase;
the kmodule.xml
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<kbase name="feeDecisionTable" packages="oft.rulesengine" default="true">
<ksession name="ksession1" type="stateless" default="true" >
</ksession>
</kbase>
</kmodule>
the spring config is using the annonation postprocessor.
<kie:import />
<bean id="kiePostProcessor"
class="org.kie.spring.annotations.KModuleAnnotationPostProcessor"/>
my curent work around to is to use #Autowire for the KSession and KBase.
any idea what i am doing wrong?
thanks
-lp
It's a bug in Kie Services / Spring integration. The annotation assumes there's always a ReleaseId.
I created a Pull Request some weeks ago, so it should be solved in an upcoming version.
Ticket link: https://issues.jboss.org/browse/DROOLS-845

OpenEJB + EclipseLink are not able to create tables on HSQL database

I have a vanilla maven WAR project, using the Java EE web profile, that executes its unit/integration tests using OpenEJB. During the OpenEJB start-up, instead of using the data source defined in jndi.properties, OpenEJB creates its own:
INFO - Auto-creating a Resource with id 'Default JDBC Database' of type 'DataSource for 'scmaccess-unit'.
INFO - Creating Resource(id=Default JDBC Database)
INFO - Configuring Service(id=Default Unmanaged JDBC Database, type=Resource, provider-id=Default Unmanaged JDBC Database)
INFO - Auto-creating a Resource with id 'Default Unmanaged JDBC Database' of type 'DataSource for 'scmaccess-unit'.
INFO - Creating Resource(id=Default Unmanaged JDBC Database)
INFO - Adjusting PersistenceUnit scmaccess-unit <jta-data-source> to Resource ID 'Default JDBC Database' from 'jdbc/scmaccess'
INFO - Adjusting PersistenceUnit scmaccess-unit <non-jta-data-source> to Resource ID 'Default Unmanaged JDBC Database' from 'null'
And then, further below, when it's time to create the table - as per the create-drop strategy defined on the app's persistence.xml file - I see several errors like this:
(...) Internal Exception: java.sql.SQLSyntaxErrorException: type not found or user lacks privilege: NUMBER
Error Code: -5509
The jndi.properties file:
##
# Context factory to use during tests
##
java.naming.factory.initial=org.apache.openejb.client.LocalInitialContextFactory
##
# The DataSource to use for testing
##
scmDatabase=new://Resource?type=DataSource
scmDatabase.JdbcDriver=org.hsqldb.jdbcDriver
scmDatabase.JdbcUrl=jdbc:hsqldb:mem:scmaccess
##
# Override persistence unit properties
##
scmaccess-unit.eclipselink.jdbc.batch-writing=JDBC
scmaccess-unit.eclipselink.target-database=Auto
scmaccess-unit.eclipselink.ddl-generation=drop-and-create-tables
scmaccess-unit.eclipselink.ddl-generation.output-mode=database
And, the test case:
public class PersistenceTest extends TestCase {
#EJB
private GroupManager ejb;
#Resource
private UserTransaction transaction;
#PersistenceContext
private EntityManager emanager;
public void setUp() throws Exception {
EJBContainer.createEJBContainer().getContext().bind("inject", this);
}
public void test() throws Exception {
transaction.begin();
try {
Group g = new Group("Saas Automation");
emanager.persist(g);
} finally {
transaction.commit();
}
}
}
Looks like eclipselink is trying to create a column with the type NUMBER and that type does not exist in HSQL. Did you specify that type in your mappings? If yes then fix that.
Otherwise it might help to add
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.create-ddl-jdbc-file-name" value="createDDL_ddlGeneration.jdbc"/>
<property name="eclipselink.drop-ddl-jdbc-file-name" value="dropDDL_ddlGeneration.jdbc"/>
<property name="eclipselink.ddl-generation.output-mode" value="both"/>
to your persistence.xml so you can see what create table statements are exactly generated. If eclipselink is using NUMBER on it's own for certain columns you can tell it to use something else by using the following annotations on the corresponding fields.
#Column(columnDefinition="NUMERIC")

Interceptors are not intercepting

I am having problems setting up a Java EE 6 CDI interceptors. I am using embedded glassfish, I have specified the interceptor in beans.xml in the web application.
<beans
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
<interceptors>
<class>ServiceInterceptor</class>
</interceptors>
</beans>
I am trying to secure this bean:
#Named
//#Stateless
#RequestScoped
public class SecuredMethodJSFBean /*implements Serializable*/{
#Inject
protected SecuredMethodSample securedMethodSample;
/*
#CurrentUser
#SessionScoped
#Inject
protected RuntimePrincipalAware principal;
//protected JSFLoginBean jsfLoginBean;
*/
public SecuredMethodJSFBean()
{
super();
System.out.println("creating secured method jsf bean");
}
#Secured("adfadfafd")
public void doSomething()
{
//System.out.println("\n\n\n\nprincipal:" + principal);
//System.out.println("principal:" + jsfLoginBean.getPrincipal());
//securedMethodSample.doSomething(jsfLoginBean.getPrincipal().getName());
//return(jsfLoginBean.getPrincipal().getName());
//securedMethodSample.doSomething(principal.getName());
//return(principal.getName());
//return("secured-method");
securedMethodSample.doSomething("testing ...");
}
}
What do I need to do to get my interceptors running?
Also, I am trying to use interceptors to intercept method invocations on beans used by servlets. Since those beans are beans, I should be able to intercept them. However, I am unable to do so. I was originally trying to intercept method invocations in servlets directly, but they're not CDI beans so that does not make sense.
Thanks,
Walter
"I have specified the interceptor in beans.xml in the web application"
Is #Secured defined in another project / jar? In that case you need to enable it in that beans.xml.
To answer my question better, I did the following:
I made the project ejb instead of jar (inside maven).
I created an ejb-jar.xml file specifying / declaring my interceptor (src/main/resources/META-INF).
in projects using this interceptor, I specified the type as ejb to it would pick it up correctly.
Walter

arquillian persistence extension doesn't work

I'm trying to get my webservice tested. This webservice uses ejb with jpa to retrieve its data. So i want to use the arquillian extension to get this done.
This is my arquillian test class:
#RunWith(Arquillian.class)
public class PersonWebServiceIT {
private PersonWebService service;
#Deployment(testable = false)
public static Archive<?> createDeployment() {
return ShrinkWrap
.create(ZipImporter.class, "test.ear")
.importFrom(new File("simple-webservice-ear-1.0.0-SNAPSHOT.ear"))
.as(EnterpriseArchive.class);
}
#Test
#UsingDataSet("dataset.yml")
#SneakyThrows
public void testFindPersons(#ArquillianResource final URL deploymentUrl) {
loadService(deploymentUrl);
Assert.assertEquals(2, service.findPersons().size());
}
private void loadService(final URL deploymentUrl)
//load webservice
}
}
This is my datasets/dataset.yml file:
person:
- id: 1
firstName: "stijn"
- id: 2
firstName: "cremers"
my arquillian.xml:
<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.com/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://jboss.org/schema/arquillian
http://jboss.org/schema/arquillian/arquillian-1.0.xsd">
<extension qualifier="persistence">
<property name="defaultDataSource">java:/DefaultDS</property>
</extension>
</arquillian>
My test data never gets loaded. I even tried with a wrongly formatted yml file, but even then i get no error.
The problem is with your test run mode. When you define your #Deployment with the attribute testable=false, all tests are run in the client mode, i.e. they're not run in-container.
The Arquillian Persistence Extension (as of 1.0.0.Alpha5) does not support running tests in client mode; only in-container tests are supported for now. Support for client mode tests in APE may come in a future release.
<property name="defaultDataSource">java:/DefaultDS</property>
U're specifying the Datasource which is defined in the server.
In client mode, test cases are run outside the Container(ie. Other JVM)
So that only persistence extension can not make use of data source and hence you can not use arquillian persistence extension client mode.
If there is anyway to specify jdbc url instead of datasource name in arquillian.xml file.Then u may use persistence extension