How can I make Powermock work with dropwizard version 1.0.5. I have tried to include all kinds of versions of powermock to my project each time a get a different kind of error.
For example when I use:
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.1</version>
<scope>test</scope>
</dependency>
I get:
java.lang.AbstractMethodError: org.powermock.api.mockito.internal.mockmaker.PowerMockMaker.isTypeMockable(Ljava/lang/Class;)Lorg/mockito/plugins/MockMaker$TypeMockability;
at org.mockito.internal.util.MockUtil.typeMockabilityOf(MockUtil.java:26)
Using version 1.5.4 gives me:
org.powermock.reflect.exceptions.FieldNotFoundException: Field 'fTestClass' was not found in class org.junit.internal.runners.MethodValidator.
I have even tried to use version 1.7.3 and <artifactId>powermock-api-mockito2</artifactId>
My test class is as simple as this
#RunWith(PowerMockRunner.class)
#PrepareForTest(MyStaticMethodClass.class)
public class TestStaticMethods {
#Test
public void testMyStatic() {
PowerMockito.mockStatic(MyStaticMethodClass.class);
Mockito.when(MyStaticMethodClass.getString()).thenReturn("Hello World");
String result = MyStaticMethodClass.getString();
Assert.assertEquals("Helo World", result);
}
}
I have looked into the documentation of powermock my junit version is 4.12 https://github.com/powermock/powermock/wiki/Mockito-Maven
I have the following external libraries
Are they fetched from
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-testing</artifactId>
<scope>test</scope>
</dependency>
Tried to exclude them but they don't disappear I am using Intellij as my IDE.
Is it because of these libraries that there might be some conflicting initializations of the testing environment?
EDIT 1
Ok, so I have tried to create a small java project with nothing other than a the following dependencies:
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.7.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.7.3</version>
<scope>test</scope>
</dependency>
my libraries are:
And my test file is exactly the same as above, then it works perfectly fine. So I guess it has to do something with Dropwizard...?
I have created a simple project using DropWizard and PowerMock and the tests execution were successful using all different versions of PM (1.6.1, 1.7.3 and 1.5.4), both using Intellij and Maven.
Having said that, it is strange that the dropwizard-testing artifact is pulling different versions of mockito (1.10.8 for all and 2.0.54-beta for core). You can exclude the mockito-core dependency from the dropwizard-testing artifact and that will at least ensure that there are no conflicting versions of mockito.
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-testing</artifactId>
<version>${dropwizard.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</exclusion>
</exclusions>
</dependency>
I have also tested with versions 1.1.7 and 1.2.4 of DW but both worked fine for me.
Related
I got an error message saying Dataflow 2.5 (Java) is the last supported release and I should use Beam. Is there a migration guide? I can find Dataflow 1.x to 2.x but not Dataflow to Beam.
For example, DataflowPipelineOptions doesn't seem to be installed if you use the maven archetype suggested in the Beam documentation.
Specifically:
import org.apache.beam.runners.dataflow.options.DataflowPipelineOptions
is not found when I use the pom.xml generated using:
mvn archetype:generate \
-DarchetypeGroupId=org.apache.beam \
-DarchetypeArtifactId=beam-sdks-java-maven-archetypes-starter \
-DarchetypeVersion=2.13.0 \
-DgroupId=com.myexample \
-DartifactId=newpackage \
-Dversion="1.1" \
-DinteractiveMode=false
even after adding:
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-runners-google-cloud-dataflow-java</artifactId>
<version>2.13.0</version>
<scope>runtime</scope>
</dependency>
to the generated pom.xml.
You need a few additional Google Cloud dependencies in your pom.xml in order to run your Beam pipeline on Dataflow. Things worked for me after I added:
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-runners-google-cloud-dataflow-java</artifactId>
<version>${beam.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-io-google-cloud-platform</artifactId>
<version>${beam.version}</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-extensions-google-cloud-platform-core</artifactId>
<version>${beam.version}</version>
</dependency>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-extensions-protobuf</artifactId>
<version>${beam.version}</version>
</dependency>
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-io-jdbc</artifactId>
<version>${beam.version}</version>
</dependency>
In addition, you may need to add a few more parameters to your startup script. I had to add:
gcpTempLocation=gs://$BUCKET/tmp
This blog post may be helpful. A user here described their migration.
I believe the package renaming (com.google.cloud.dataflow to org.apache.beam) and new class/method signatures is already done if you're on Dataflow 2.x SDKs.
So I think in this case the migration should be straightforward. Please try removing the Dataflow SDK and introducing org.apache.beam on the lastest version. It may work without modification. You could also try using org.apache.beam on 2.5 first. Then upgrading to 2.13, and see if that goes smoothly as well.
Recently, I faced with some build errors in my project which is using JetBrains/xodus v1.2.3. In project's pom.xml I have such dependecy
<dependency>
<groupId>org.jetbrains.xodus</groupId>
<artifactId>xodus-environment</artifactId>
<version>1.2.3</version>
</dependency>
But during build process I've faced with such error:
[ERROR] Version conflict for artifact org.jetbrains:annotations, selected 13.0, dependencies require 15.0
So I've checked dependency tree in IDEA. I was wondered to see such dependency tree
As you can see library org.jetbrains.xodus:xodus-environment has several dependencies on org.jetbrains:annotations first one is 13.0 and another one is 15.0.
So I solved problem with such configuration
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>1.2.51</version>
<exclusions>
<exclusion>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jetbrains.xodus</groupId>
<artifactId>xodus-environment</artifactId>
<version>1.2.3</version>
<exclusions>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</exclusion>
</exclusions>
</dependency>
But I think there is better way to solve this problem or maybe it is bug in xodus library
Added the dataflow dependency to the project. The project builds , but on start up ( using jetty ) I get a runtime exception
<dependency>
<groupId>com.google.cloud.dataflow</groupId>
<artifactId>google-cloud-dataflow-java-sdk-all</artifactId>
<version>1.9.0</version>
</dependency>
caused by: java.lang.ClassNotFoundException: com.google.auth.http.HttpTransportFactory
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:487)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:428)
if i remove the dependency. The start up has not issues.
Any idea why the dataflow dependency is causing startup error.
Added the exclusion for the conflicting dependency, and it works.
<dependency>
<groupId>com.google.cloud.dataflow</groupId>
<artifactId>google-cloud-dataflow-java-sdk-all</artifactId>
<version>1.9.0</version>
<exclusions>
<exclusion>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
</exclusion>
</exclusions>
</dependency>
Since about a week ago, running tests with InProcessServer on 4.0.0.BUILD-SNAPSHOT results in the following exception:
Caused by: java.lang.NoClassDefFoundError: org/neo4j/ogm/testutil/TestServer
at org.springframework.data.neo4j.server.InProcessServer.<init>(InProcessServer.java:25) ~[spring-data-neo4j-4.0.0.BUILD-SNAPSHOT-tests.jar:na]
at com.ninjasquare.server.test.integration.IntegrationTestConfig.neo4jServer(IntegrationTestConfig.java:43) ~[test-classes/:na]
Swithing the test dependency back to 4.0.0.M1 resolves the issue:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>4.0.0.M1</version>
<type>test-jar</type>
</dependency>
I assume it's something to do with some refactoring work on SDN4/OGM?
Thanks.
Yes, in recent snapshots, the OGM has been separated from SDN. You'll need to include these two dependencies now to use the test utilities.
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm</artifactId>
<version>1.1.0</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j.test</groupId>
<artifactId>neo4j-harness</artifactId>
<version>${neo4j.version}</version>
<scope>test</scope>
</dependency>
When running a Dataflow unittest that uses DataflowAssert I get the exception
java.lang.RuntimeException: DataflowAssert requires that JUnit and Hamcrest be linked in.
What dependencies do I need to add to my pom file to fix this exception?
Add the following dependencies to your pom file to link in the required libraries
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>