NiFi Processor JUnit Test with ControllerService - java

I am developing a NiFi processor and want to test it with JUnit, but one of the properties of Processor is a ControllerService, which is DBCPConnectionPool, but I don't know how to add this service to the JUnit Test?
I try to new DBCPConnectionPool(), but there no object named like that, although I have added all dependencies to my pom file, like the followings:
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-dbcp-service-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-utils</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-standard-services-api-nar</artifactId>
<type>nar</type>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-dbcp-service-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-mock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-processor-utils</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-utils</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-dbcp-service-api</artifactId>
</dependency>
runner.addControllerService(...);
Please give some recommendation about how to write this unit test, thanks.

It looks like you included the nifi-dbcp-service-api module twice, but one of those should be nifi-dbcp-service, which contains the implementation classes.
Then look at DBCPServiceTest for examples of how to use the DBCPConnectionPool in a unit test.

Related

Correct the classpath of your application so that it contains a single, compatible version of org.apache.camel.impl.converter.DefaultTypeContent

I encountered this error on the console on my eclipse-workspace while setting up my pom.xml on my spring boot app. I'm currently using spring-boot version 2.5.6
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.apache.camel.impl.converter.DefaultTypeConverter
And the code below are the dependencies that i have added.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>3.13.0</version>
</dependency>
<dependency>
<groupId>org-apache.camel</groupId>
<artifactId>camel-jackson-starter</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-swagger-java-starter</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-servlet</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>java.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
</dependency>
<dependencies>
I just don't know if some of my dependencies if there are incompatibilities.
Thank you for your help in advance.
Edit:
Additional Logs
Description
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.apache.camel.impl.engine.SimpleCamelContext.createTypeConverter(SimpleCamelContext.java:138)
referring to this code
135: protected TypeConverter createTypeConverter(){
136: return new DefaultTypeConverter(
137: getCamelContextReference(), getPackageScanClassResolver(), getInjector(),
138: isLoadTypeConverter());
The following method did not exist:
org.apache.camel.impl.converter.DefaultTypeConverter. <init>(Lorg/apache/camel/CamelContext;Lorg/apache/camel/spi/PackageScanClassResolver;Lorg/apache/camel/spi/Injector:V
The method’s class, org.apache.camel.impl.converter.DefaultTypeConverter, is available from the following locations:
jar:file:/apache/camel/camel-base/3.0.0-M4/camel-base-3.0.0-M4.jar!/org/apache/camel/impl/converter/DefaultTypeConverter.class
The class hierarchy was loaded from the following locations:
org.apache.camel.impl.converter.DefaultTypeConverter: camel/camel-base/3.0.0-M4/camel-base-3.0.0-M4.jar
org.apache.camel.impl.concerter.BaseTypeConverterRegistry file: camel/camel-base/3.0.0-M4/camel-base-3.0.0-M4.jar
org.apache.camel.support.service.ServiceSupport: file:/camel/camel-api/3.13.0/camel-api-3.13.0.jar
org.apache.camel.support.service.BaseService: file:/camel/camel-api/3.13.0/camel-api-3.13.0.jar
You are mixing different version of Camel's jars. You have some at version 3.13.0 and others at 3.0.0-M4 and they are not compatible with each other.
You haven't shared all of your pom.xml so I can't tell for certain, but I would guess that the camel.version property is set to 3.0.0.M4 which is not aligned with your dependency on the Camel starter where the version is 3.13.0:
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>3.13.0</version>
</dependency>
You should update your pom so that a consistent version is used for all of Camel's modules. You can check their versions by running mvn dependency:list on the command line.

Why #Secured is not working in Tapestry 5.4.0?

I just upgraded Tapestry 5.3.8 to 5.4.0, and then I found the #Secured annotation has an issue. If I go to page which has this #Secured, the exception org/apache/tapestry5/services/TransformMethodSignature and could not initialize class nu.localhost.tapestry5.springsecurity.services.internal.TransformConstants2 will thrown (with no detail). Is it no longer supported in 5.4.0? Or do I need to upgrade something in my pom.xml?
pom.xml
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-core</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-hibernate</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-upload</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>4.2.0.Final</version>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-spring</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-kaptcha</artifactId>
<version>${tapestry-release-version}</version>
</dependency>
<dependency>
<groupId>org.got5</groupId>
<artifactId>tapestry5-jquery</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>com.github.lltyk</groupId>
<artifactId>tapestry-spring-security</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.0.RELEASE</version>
<scope>test</scope>
</dependency>
Well, after struggling for days, I'm finally figured out that this library:
<dependency>
<groupId>com.github.lltyk</groupId>
<artifactId>tapestry-spring-security</artifactId>
<version>3.0.3</version>
</dependency>
Can not keep up with Tapesty 5.4, because it has a class: nu.localhost.tapestry5.springsecurity.services.internal.TransformConstants2 that refers to org.apache.tapestry5.services.TransformMethodSignature which is not available any longer in Tapestry 5.4.
I've tried to upgrade tapestry-spring-security to highest version: 3.0.5, but still can't keep up with Tapestry 5.4, so the only way to solve it, is to remove it. And to replace all the functionalities which was provided by tapestry-spring-security, I need to add 4 new libs to pom (in your case you might need to add more or less than 4): spring-security-core: 4.0.0.M1, spring-security-web: 4.2.3.RELEASE, spring-dao: 2.0.8, servlet-api: 2.5
In my case, I need to copy the code from the original source for these classes: LogoutService (interface), LogoutServiceImpl, IfRole and IfLoggedIn. Create the files and paste the code.

javax.enterprise.inject.Vetoed Open web beans, which jar?

I'm wanting to try out Open Web Beans 1.6.2, but the jars it lists on it's website for adding CDI support to a Java SE application
openwebbeans-spi.jar
openwebbeans-impl.jar
geronimo-jcdi_1.0_spec.jar
geronimo-atinject_1.0_spec.jar
geronimo-interceptor_1.2_spec.jar
geronimo-annotation_1.2_spec.jar
Don't seem to contain the javax.enterprise.inject.Vetoed annotation, I've had to add cdi-api 1.2 as a dependency to resolve the issue, but I'm not sure if this is correct as all other CDI dependencies were resolved by the above? Here are the dependencies I have in my pom, is this correct?
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-impl</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-spi</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jcdi_1.0_spec</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-interceptor_1.2_spec</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-annotation_1.2_spec</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.2</version>
</dependency>
This link seems to suggest support for #Vetoed was added in Open Web Beans 1.5.0
Please upgrade geronimo-jcdi_1.0_spec to jcdi_1.1 version
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jcdi_1.1_spec</artifactId>
<version>1.0</version>
</dependency>
Although your problem is weird, because you have also following entry:
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.2</version>
</dependency
which also contains #Vetoed and thus should be enough. Does maven ignore it somehow?

elasticsearch ElasticsearchIntegrationTest

I have written an integration test for ElasticSearch by extending ElasticsearchIntegrationTest. Top section of the test below:
import org.junit.*;
import static org.junit.Assert.assertEquals;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
public class ProductSearchTest extends ElasticsearchIntegrationTest
I'm seeing this error from JUnit when trying to run the test via maven
java.lang.NoSuchMethodError: com.carrotsearch.randomizedtesting.RandomizedContext.runWithPrivateRandomness(Lcom/carrotsearch/randomizedtesting/Randomness;Ljava/util/concurrent/Callable;)Ljava/lang/Object;
at __randomizedtesting.SeedInfo.seed([9DE685AB75B54F0A:10B1B129F9E3CB67]:0)
I've included the dependencies in the pom as described on the elasticsearch site
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-test-framework</artifactId>
<version>4.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.4.0</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.4.0</version>
<scope>test</scope>
</dependency>
Has anyone seen this before? It looks like i'm missing a dependency (i've tried adding a couple of the carrotsearch maven dependencies into the pom without success). Alternatively, does anyone have the integration tests working with the versions I am using, so at least if I expend hours trying to locate the dependency issue I can be confident it will work once identified.
Thank you for your time.
Indeed, it seems there is a mismatch between the randomizedtesting jar Lucene uses and the one ES uses. Try this in your pom.xml:
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-test-framework</artifactId>
<version>4.10.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>randomizedtesting-runner</artifactId>
<groupId>
com.carrotsearch.randomizedtesting
</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.4.0</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.carrotsearch.randomizedtesting</groupId>
<artifactId>randomizedtesting-runner</artifactId>
<version>2.1.10</version>
<scope>test</scope>
</dependency>

NoSuchMethodError: JsonFactory.fromInputStream

I am trying to get a clean code sample of Google API OAuth2 authentication.
My code is mostly based on the explanation at https://code.google.com/p/google-api-java-client/wiki/OAuth2
I deviate from this tutorial because I want my libraries be managed by Maven and because I want to create a project without Google Apps Engine dependencies.
Each time I try to the run the project on my Glassfish server, I get the following error, probably indicating a dependency conflict.
java.lang.NoSuchMethodError: com.google.api.client.json.JsonFactory.fromInputStream(Ljava/io/InputStream;Ljava/lang/Class;)Ljava/lang/Object;
The relevant piece of my pom.xml:
<dependencies>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.14.1-beta</version>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
<version>1.14.1-beta</version>
</dependency>
<dependency>
<groupId>com.google.api-jackson2</groupId>
<artifactId>google-api-jackson2</artifactId>
<version>1.14.1-beta</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-calendar</artifactId>
<version>v3-rev34-1.14.1-beta</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client</artifactId>
<version>1.14.1-beta</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-servlet</artifactId>
<version>1.14.1-beta</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.CR2</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.1-PRD</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
</dependency>
</dependencies>
Please help me find the root cause of this error, because the used dependencies seem just fine to me and there's no similar problem case I could find.
The correct dependency for jackson2 is:
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-jackson2</artifactId>
<version>1.14.1-beta</version>
</dependency>
Once I changed that, the project built successfully, and I was able to call the method in question just fine.
There could be something else on the classpath that's interfering. I suggest you run the program with -verbose: class (see here for a more detailed explanation), which will show any conflicts.

Categories

Resources