Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work with spring-restdocs 2.0.1.RELEASE #3

Open
Odyldzhon opened this issue Oct 26, 2018 · 7 comments
Open

Doesn't work with spring-restdocs 2.0.1.RELEASE #3

Odyldzhon opened this issue Oct 26, 2018 · 7 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Odyldzhon
Copy link

Thanks for the project! Unfortunately looks like the project cannot be used with spring-docs 2+ version.

I have add to test basic config:

mockMvc.
...
.andDo(createDocumentation())
.andDo(postmanImport("By Username and Company"));

And get the error during test execution
Found interface org.springframework.restdocs.RestDocumentationContext, but class was expected.

@aglassman
Copy link
Member

@Odyldzhon Thanks for reporting! I'll take a look at this over the weekend.

@aglassman aglassman self-assigned this Oct 26, 2018
@aglassman aglassman added the bug Something isn't working label Oct 26, 2018
@aglassman aglassman added this to the 0.0.2 milestone Oct 26, 2018
@aglassman
Copy link
Member

@Odyldzhon Can you post the other dependencies you are using? I was not able to recreate this issue with org.springframework.restdocs:spring-restdocs-mockmvc:2.0.1.RELEASE

I pushed a test to master that works with version 2.0.1.RELEASE. Maybe there is an issue with the createDocumentation() method you are calling. Posting a stack trace may also help me track down any possible issues. Thanks!

@Odyldzhon
Copy link
Author

Additional information

About versions
spring-restdocs-mockmvc managed version is 2.0.1.RELEASE The artifact is managed in org.springframework.boot:spring-boot-dependencies:2.0.3.RELEASE

spring-restdocs-asciidoctor version is 2.0.1.RELEASE

This is plugin configuration

  <build>
    <plugins>
      <plugin>
        <groupId>org.asciidoctor</groupId>
        <artifactId>asciidoctor-maven-plugin</artifactId>
        <version>${asciidoctor-maven-plugin.version}</version>
        <executions>
          <execution>
            <id>generate-docs</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>process-asciidoc</goal>
            </goals>
            <configuration>
              <backend>html</backend>
              <doctype>book</doctype>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.springframework.restdocs</groupId>
            <artifactId>spring-restdocs-asciidoctor</artifactId>
            <version>${spring-restdocs-asciidoctor.version}</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

Maybe it can be important to mentioned that configured goal is post-integration-test but with pre-integration-test I get the same result.

This is dependencies

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <!--https://github.com/jirutka/rsql-parser -->
    <dependency>
      <groupId>cz.jirutka.rsql</groupId>
      <artifactId>rsql-parser</artifactId>
      <version>${rsql-parser.version}</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->
    <dependency>
      <groupId>commons-beanutils</groupId>
      <artifactId>commons-beanutils</artifactId>
      <version>${commons-beanutils.version}</version>
    </dependency>

    <dependency>
      <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <scope>runtime</scope>
    </dependency>

    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.springframework.restdocs</groupId>
      <artifactId>spring-restdocs-mockmvc</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.github.greatermkemeetup</groupId>
      <artifactId>spring-restdocs-postman</artifactId>
      <version>0.0.1</version>
    </dependency>
  </dependencies>

I have simplified documentation to exclude the case with incorrect document configuration.

this.mockMvc()
...
.andDo(document("some_document"))
.andDo(PostmanSnippet.postmanImport("By Username and Company"));

The rest documentation generated correctly. When I added spring-restdocs-postman plugin then the test start to fail.

The stack-trace of exception

java.lang.IncompatibleClassChangeError: Found interface org.springframework.restdocs.RestDocumentationContext, but class was expected
  at org.gmjm.springrestdocspostman.PostmanSnippet.write(PostmanSnippet.java:564)
  at org.gmjm.springrestdocspostman.PostmanSnippet.document(PostmanSnippet.java:557)
  at org.springframework.restdocs.generate.RestDocumentationGenerator.handle(RestDocumentationGenerator.java:206)
  at org.springframework.restdocs.mockmvc.RestDocumentationResultHandler.handle(RestDocumentationResultHandler.java:55)
  at org.springframework.test.web.servlet.MockMvc$1.andDo(MockMvc.java:183)

  at HERE IS TEST METHOD LINE WHERE WE CALL POSTMAN_SNIPPET

  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
  at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
  at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
  at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
  at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
  at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
  at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
  at org.springframework.restdocs.JUnitRestDocumentation$1.evaluate(JUnitRestDocumentation.java:63)
  at org.junit.rules.RunRules.evaluate(RunRules.java:20)
  at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
  at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
  at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
  at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
  at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)

@kschulst
Copy link

kschulst commented Nov 1, 2018

Version 0.0.1 of spring-restdocs-postman is compiled against spring-restdocs 1.1.2.RELEASE. In this version of spring-restdocs org.springframework.restdocs.RestDocumentationContext is a class. However, this has been changed to an interface in newer versions of spring-restdocs. This is the reason that we see the IncompatibleClassChangeError.

Since, the master branch of spring-restdocs-postman have updated the dependency to spring-restdocs, you will not be able to reproduce the error internally. However, if you create a separate application that pulls in the 0.0.1 version, you will see the error.

The solution is simply to create a new release of spring-restdocs-postman, (against the updated version of spring-restdocs).

@kschulst
Copy link

kschulst commented Nov 1, 2018

I tried to use jitpack to create a temporary release, but this fails due to #4.

I have therefore created a fork that can be used until we get a 0.0.2 version of this excellent library into maven central :)

To use:

Gradle:

	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}
	dependencies {
	        implementation 'com.github.kschulst:spring-restdocs-postman:ff027bb33c'
	}

Maven:

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>
	<dependency>
	    <groupId>com.github.kschulst</groupId>
	    <artifactId>spring-restdocs-postman</artifactId>
	    <version>ff027bb33c</version>
	</dependency>

@aglassman
Copy link
Member

Thank you, I'll work on getting 0.0.2 built and released with the minor revisions. I'm happy other people are finding the library useful!

@aglassman
Copy link
Member

aglassman commented Feb 13, 2019

@kschulst I believe I may have resolved the issue with the release of 0.0.3, which is now available on Maven Central.

-- EDIT --
Sorry, I haven't confirmed this, so don't spend too much time here. I am going to spend some time on this! My last release I was just getting the auto build / release with TravisCI working again, and may not have actually resolved this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants