Where is Lucene's BaseTokenStreamFactoryTestCase in the Maven repository - java

I am currently writing a Lucene Tokenizer and I want to test my class. For the test, I got inspiration from the Lucene test class TestStandardFactories which is a child class of the testing class BaseTokenStreamTestCase. Accordingly my test class is also a child class of BaseTokenStreamTestCase.
I apply Maven and hence my pom.xml looks like this:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>de.institute.taggedtexttokenizer</groupId>
<artifactId>tagged-text-tokenizer</artifactId>
<version>0.2</version>
<properties>
<lucene-version>7.2.0</lucene-version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/commons-lang/commons-lang -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.lucene/lucene-test-framework -->
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-test-framework</artifactId>
<version>${lucene-version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.lucene/lucene-core -->
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>${lucene-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.lucene/lucene-analyzers-common -->
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-common</artifactId>
<version>${lucene-version}</version>
</dependency>
</dependencies>
</project>
I expected the BaseTokenStreamTestCase to be in the lucene-test-framework and hence my test to run properly. However, the compiler complains that it cannot find the class BaseTokenStreamTestCase. A quick look in the lucene-test-framework assured me that this class is not contained in there.
Which Maven dependency do I need to include to have access to this class?

I double checked and lucene-test-framework artifact contains needed class: org.apache.lucene.analysis.BaseTokenStreamTestCase.
One of the possible reasons, why compiler complaints about this class is, because you are using <scope>test</scope>, which means, that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases.
For example, you may put this test into src/main/java place, so it's test dependency couldn't pick it up.

Related

What is the dependancy for EmbeddedActiveMQBroker?

I'm new to Maven and not sure how to write dependancies for my pom.xml
I am trying to use the following class:
import org.apache.activemq.junit.EmbeddedActiveMQBroker;
And this is my attempt at writing a dependancy:
<dependency>
<groupId>org.apache</groupId>
<artifactId>activemq-junit</artifactId>
<version>5.15.9</version>
</dependency>
But I am still getting an error
Try with the following.
<dependency>
<groupId>org.apache.activemq.tooling</groupId>
<artifactId>activemq-junit</artifactId>
<version>5.13.1</version>
<scope>test</scope>
</dependency>
You can get the details from mvnrepository.com.
First of all we go to the official Maven Dependencies Page of ActiveMQ - https://mvnrepository.com/artifact/org.apache.activemq/activemq-broker/5.15.9.
Then, we go to the "Test Dependencies" category, where we clearly can see the JUnit artifact.
so, use in your pom.xml file next dependency for version 5.15.19:
<!-- https://mvnrepository.com/artifact/org.apache.activemq/activemq-broker -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
<version>5.15.9</version>
</dependency>
UPDATE
Add also the next dependency:
<!-- https://mvnrepository.com/artifact/org.apache.activemq.tooling/activemq-junit -->
<dependency>
<groupId>org.apache.activemq.tooling</groupId>
<artifactId>activemq-junit</artifactId>
<version>5.15.9</version>
<scope>test</scope>
</dependency>

How to include multiple jar in type from type field in pom dependency?

I have the following pom definition
<dependencies>
<dependency>
<groupId>com.my.stuff</groupId>
<artifactId>my-stuff</artifactId>
<version>${my-stuff.version}</version>
<type>test-jar</type>
</dependency>
I want to use both jar and test-jar , is there a way to do that?
I guess that test-jar is not a type, but a classifier. You probably want something like:
<dependencies>
<dependency>
<groupId>com.my.stuff</groupId>
<artifactId>my-stuff</artifactId>
<version>${my-stuff.version}</version>
<classifier>test-jar</classifier>
</dependency>
<dependency>
<groupId>com.my.stuff</groupId>
<artifactId>my-stuff</artifactId>
<version>${my-stuff.version}</version>
</dependency>
</dependencies>

Configuring Geb and Spock with Maven in Eclipse

Disclaimer: I've gone through so many different sources before I came here to ask this question. I've referenced the GitHub project for geb with maven, book of geb, numerous YouTube tutorials, etc. Nothing has worked.
I'm simply trying to just get a project up and running that does a very simple automated search engine test, just so I can play with the tools.
Here is my pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>nope</groupId>
<artifactId>nope</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>testing this</name>
<description>testing this</description>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.spockframework/spock-core -->
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.1-groovy-2.4</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.13</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.gebish/geb-spock -->
<dependency>
<groupId>org.gebish</groupId>
<artifactId>geb-spock</artifactId>
<version>2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-firefox-driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-support -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>3.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.9.1</version>
</dependency>
</dependencies>
</project>
Main Groovy test class:
package com.na.tests
import spock.lang.Specification
import geb.*
class MyBaseTests extends Specification {
def "search 'Groovy Browser Automation' in duckduckgo"() {
given: "we are on the duckduckgo search-engine"
go "http://duckduckgo.com"
when: "we search for 'Groovy Browser Automation'"
$("#search_form_homepage").q = "Groovy Browser Automation"
$("#search_button_homepage").click()
then: "the first result is the geb website"
assert $("#links").find(".links_main a", 0).attr("href") == "http://www.gebish.org/"
}
}
This is the exception I get in the test. I've run a really simple assert Hello World test that has passed, I eliminated that for the sake of clarity.:
groovy.lang.MissingMethodException: No signature of method:
com.na.tests.MyBaseTests.go() is applicable for argument types:
(java.lang.String) values: [http://duckduckgo.com] Possible solutions:
is(java.lang.Object), Mock(), Spy(), any(), grep(),
Mock(groovy.lang.Closure) at com.na.tests.MyBaseTests.search 'Groovy
Browser Automation' in duckduckgo(MyBaseTests.groovy:22)
Edit
It's worth noting that in my IDE (Eclipse), it seems some of the keywords are either not recognized or are not legit (ie: go "http://duckduckgo.com"). Makes me feel like I haven't configured something.
You need to extend geb.spock.GebSpec and not Specification if you want to use geb. See also gebish.org/manual/current/#spock-junit-testng
On GitHub I have a set of three Maven projects which together set up Spock, Geb and multi-browser testing via Maven configuration. You can switch the browser used easily among HtmlUnit, PhantomJS, Chrome, Firefox, IE, Edge, Opera. It comes with a small series of sample tests and a prepared Geb configuration:
Maven BoM
Test resources
Sample tests
Just clone and build them all mvn clean install in the order listed here and run the tests from the third. You can, of course, put everything into one module, but I think it makes more sense to keep version management and dependency management separate from the actual application so as to be able to re-use those test dependencies, as is good Maven practice.
Update:
Then just add your test to the sample project and run it. I renamed the class so as to end with *Test instead of *Tests because this is how Maven by default finds unit tests via Surefire. If you rather like it to run as an integration test because it opens a browser and basically is slow, rename it to *IT.
I also fixed the base class as Leonard suggested correctly and changed the explicit to an implicit assert.
package com.na.tests
import geb.spock.GebSpec
class MyBaseTest extends GebSpec {
def "search 'Groovy Browser Automation' in duckduckgo"() {
given: "we are on the duckduckgo search-engine"
go "http://duckduckgo.com"
when: "we search for 'Groovy Browser Automation'"
$("#search_form_homepage").q = "Groovy Browser Automation"
$("#search_button_homepage").click()
then: "the first result (excluding ads) is the geb website"
$("#links").$(".links_main a", 0).attr("href") == "http://www.gebish.org/"
}
}

Automatic resolve dependency hierarchy for a custom jar

I am struggling with the maven dependencies. The maven dependency hierarchy is not resolved in my projects where I add my custom build jar. This is a little bit confusing, because all the dependencies of other externally provided dependencies (like org.json, reasteasy-jaxrs ) are nicely shown in the dependency hierarchy view.I am using Eclipse EE IDE for Web Developers with maven plugin.
The project structure: The project is a platform consisting of several services using the same project-support module. Further, the project-support will be used in external projects (here project-consumer) as well.
project-parent (pom)
project-support (jar)
project-service-a (war)
project-service-b (jar)
project-consumer (war)
project support (jar)
Extract of project-parent.pom
<modules>
<module>../project-support</module>
<module>../project-serviceA</module>
<module>../project-serviceB</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<tomcat.version>7.0.50</tomcat.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>${tomcat.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.6.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
Extract of project-support.pom
<parent>
<groupId>com.somecompany.project</groupId>
<artifactId>project-parent</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../project-parent</relativePath>
</parent>
<artifactId>project-support</artifactId>
<name>projectsupport</name>
<dependencies>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
</dependencies>
Extract of project-service-a.pom
<parent>
<groupId>com.somecompany.project</groupId>
<artifactId>project-serviceA</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../project-parent</relativePath>
</parent>
<artifactId>project-service-a</artifactId>
<name>projectsupport</name>
<dependencies>
<dependency>
<groupId>com.somecompany.project</groupId>
<artifactId>project-support</artifactId>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
</dependencies>
So, when looking at the project-serviceA dependency hierarchy (and also in the effective pom), the required dependencies of project-support are not included which results in code compilation errors. Further the project-support is used in projects outside the scope of project-parent.
So my question: Why does maven not resolve the dependencies tree of project-support and adds them into the effective pom?
Thanks in advance.
You have set the scope of the dependencies to provided in you parent's dependency management section. According to the introduction to the dependency mechanism, the dependency scope is used to limit the transitivity of a dependency.
The above linked introduction also includes a table that declares which scopes play in the transitivity game and which do not. The provided scope is not part of the transitivity.
So the solution is to not declare any scope in the dependency management but declare a reasonable scope in the dependency usage.

Why Cannot I import the class from hbase.io.hfile package

I have a HFile that I am trying to read/deserialize using Java.
Looks like this HFile.reader is very promising but however, I am having a hard time even getting the library imported in Maven.
This is how my POM looks like:
<dependencies>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-common</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
And somehow I don't see that many classes or objects when I tried to import.
This class can be found in the hbase-server artifact, so you need to depend on that one instead of hbase-common and hbase-client:
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-server</artifactId>
<version>1.2.1</version>
</dependency>
But do note that this class is not intended to be used by 3rd parties. It is annotated #InterfaceAudience.Private, which means:
Intended for use only within Hadoop itself.

Categories