Getting java.lang.AbstractMethodError when I test using REST Assured

pgngp
:

I'm trying to test a REST api defined in my controller class using REST Assured v4.3.0, but I get java.lang.AbstractMethodError when I run the test. I understand this error is occurring because I'm calling an abstract method, but I'm having a hard time resolving it.

It seems that the error is occurring due to .body(is(equalTo("success"))) in SampleControllerTest.java because when I remove this line, the test succeeds. I tried a few things to resolve it, but didn't get any success:

  • Searched online for suggestions and examples, but they are either for older versions or not related to io.rest-assured/spring-mock-mvc
  • Tried different matchers (org.hamcrest.Matchers.* and org.hamcrest.CoreMatchers.*)
  • Tried adding org.hamcrest/hamcrest dependency in the pom file explicitly

Here's my code for your reference:

Code structure:

test
|- src/
|  |- main/
|  |  |- java/
|  |  |  |- org/
|  |  |  |  |- example/
|  |  |  |  |  |- Application.java
|  |  |  |  |  |- SampleController.java
|  |- test/
|  |  |- java/
|  |  |  |- org/
|  |  |  |  |- example/
|  |  |  |  |  |- SampleControllerTest.java
|- target/
|- pom.xml

Application.java

package org.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

SampleController.java

package org.example;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SampleController {
    @RequestMapping(value = "/sample")
    @ResponseStatus(value = HttpStatus.OK)
    public String getSample() {
        return "success";
    }
}

SampleControllerTest.java

package org.example;

import org.junit.Test;

import static io.restassured.module.mockmvc.RestAssuredMockMvc.*;
import static org.hamcrest.Matchers.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

public class SampleControllerTest {
    @Test
    public void testGetSample() {
        given()
            .standaloneSetup(new SampleController())
            .when()
            .get("/sample")
            .then()
            .assertThat(status().isOk())
            .body(is(equalTo("success")));
    }
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <packaging>jar</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>org.example</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <java.version>8</java.version>
        <start-class>org.example.Application</start-class>
    </properties>

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

        <!-- JUnit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.rest-assured/spring-mock-mvc -->
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>spring-mock-mvc</artifactId>
            <version>4.3.0</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.rest-assured/json-path -->
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>json-path</artifactId>
            <version>4.3.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.rest-assured/xml-path -->
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>xml-path</artifactId>
            <version>4.3.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>4.3.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

When I run the test using mvn test, this is the error I get:

[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.325 s <<< FAILURE! - in org.example.SampleControllerTest
[ERROR] testGetSample(org.example.SampleControllerTest)  Time elapsed: 1.288 s  <<< ERROR!
java.lang.AbstractMethodError: Method io/restassured/internal/ResponseSpecificationImpl.getProperty(Ljava/lang/String;)Ljava/lang/Object; is abstract
        at org.example.SampleControllerTest.testGetSample(SampleControllerTest.java:20)

Thanks for any help in advance!

pgngp
:

It turns out that io.rest-assured/spring-mock-mvc dependency was conflicting with io.rest-assured/rest-assured dependency. Once I removed the io.rest-assured/rest-assured from pom.xml, the test worked successfully.

A few years ago when I was using REST Assured version 3.1.1, I could keep both of these dependencies, but perhaps newer versions don't allow this.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

java.lang.AbstractMethodError while using Jersey rest webservice

From Dev

java.lang.AbstractMethodError on lint when using gradle build

From Dev

Getting root cause java.lang.AbstractMethodError while using Jersey ContainerRequestFilter

From Dev

Getting root cause java.lang.AbstractMethodError while using Jersey ContainerRequestFilter

From Dev

Using PowerMock to mock static class in a rest-assured test

From Dev

Why do I get java.lang.AbstractMethodError when I try to call org.apache.activemq.ActiveMQSession.createDurableConsumer

From Dev

java.lang.AbstractMethodError when spy the LinkedList in Android

From Dev

Internal Server Error when making POST request using Rest Assured

From Dev

java.lang.NoClassDefFoundError with REST-assured 3.0.0 and Java 11 (not observed with Java 8)

From Dev

Grails 3 - Spring Rest Docs using Rest assured giving SnippetException when using JSON views

From Dev

POST request fails (rest-assured test)

From Dev

Rest Assured :- Getting 404 response from Post request created using Pathparam and FormParam

From Dev

Spring-boot : how to execute multiple test classes by just starting the service once using rest-assured

From Dev

Java Exception java.lang.AbstractMethodError

From Dev

Why I am getting java.lang.NoSuchMethodError while running spring based camel junit test case

From Dev

java.lang.AbstractMethodError during createQuery

From Dev

java.lang.AbstractMethodError: com.mysql.jdbc.Connection.isValid(I)Z

From Dev

Why am I getting a java.lang.StringIndexOutOfBoundsException error when I run?

From Dev

I am getting "java.lang.ArithmeticException: / by zero" when I run my program

From Dev

Why am I getting a java.lang.NullPointerException error when I try to switch activities in studio?

From Dev

using a Json file in Rest-assured for payload

From Dev

How to invoke a webservice using rest assured

From Dev

How to validate nested response using REST Assured?

From Dev

RestApi testing using Rest-Assured

From Dev

How to invoke a webservice using rest assured

From Dev

create dynamic xml payload using rest assured

From Dev

how I can use global header request through all tests using rest assured

From Dev

Getting java.lang.NumberFormatException When Outputting

From Dev

I am getting unexpected behaviour when using Java Streams and Scanners

Related Related

  1. 1

    java.lang.AbstractMethodError while using Jersey rest webservice

  2. 2

    java.lang.AbstractMethodError on lint when using gradle build

  3. 3

    Getting root cause java.lang.AbstractMethodError while using Jersey ContainerRequestFilter

  4. 4

    Getting root cause java.lang.AbstractMethodError while using Jersey ContainerRequestFilter

  5. 5

    Using PowerMock to mock static class in a rest-assured test

  6. 6

    Why do I get java.lang.AbstractMethodError when I try to call org.apache.activemq.ActiveMQSession.createDurableConsumer

  7. 7

    java.lang.AbstractMethodError when spy the LinkedList in Android

  8. 8

    Internal Server Error when making POST request using Rest Assured

  9. 9

    java.lang.NoClassDefFoundError with REST-assured 3.0.0 and Java 11 (not observed with Java 8)

  10. 10

    Grails 3 - Spring Rest Docs using Rest assured giving SnippetException when using JSON views

  11. 11

    POST request fails (rest-assured test)

  12. 12

    Rest Assured :- Getting 404 response from Post request created using Pathparam and FormParam

  13. 13

    Spring-boot : how to execute multiple test classes by just starting the service once using rest-assured

  14. 14

    Java Exception java.lang.AbstractMethodError

  15. 15

    Why I am getting java.lang.NoSuchMethodError while running spring based camel junit test case

  16. 16

    java.lang.AbstractMethodError during createQuery

  17. 17

    java.lang.AbstractMethodError: com.mysql.jdbc.Connection.isValid(I)Z

  18. 18

    Why am I getting a java.lang.StringIndexOutOfBoundsException error when I run?

  19. 19

    I am getting "java.lang.ArithmeticException: / by zero" when I run my program

  20. 20

    Why am I getting a java.lang.NullPointerException error when I try to switch activities in studio?

  21. 21

    using a Json file in Rest-assured for payload

  22. 22

    How to invoke a webservice using rest assured

  23. 23

    How to validate nested response using REST Assured?

  24. 24

    RestApi testing using Rest-Assured

  25. 25

    How to invoke a webservice using rest assured

  26. 26

    create dynamic xml payload using rest assured

  27. 27

    how I can use global header request through all tests using rest assured

  28. 28

    Getting java.lang.NumberFormatException When Outputting

  29. 29

    I am getting unexpected behaviour when using Java Streams and Scanners

HotTag

Archive