Restassured Kotlin Spring compilation error with the Kotlin DSL

36 views
Skip to first unread message

branco12321

unread,
Oct 31, 2023, 2:39:25 AM10/31/23
to REST assured
The following works, even though not ideally:

        println("123 <----> " +
        (When {
            get(API_ROOT + "/title/" + book.title)
        } Then {
            statusCode(200)
            //body("title", equalTo(book.title))
        } Extract {
            path("title")
        }))
        //prints '[test title]'

The following fails:

        val titleResponse : String =
        (When {
            get(API_ROOT + "/title/" + book.title)
        } Then {
            statusCode(200)
            //body("title", equalTo(book.title))
        } Extract { // <---- not enough information to infer type variable T
            path("title") // <---- not enough information to infer type variable T
        }).contentToString()

The following is the class definition:

@Entity
class Book(
   
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    var id: Long,
   
    @Column(nullable = false, unique = true)
    var title: String,
   
    @Column(nullable = false)
    var author: String

)

If someone could suggest some modifications to fix my code I would appreciate.
Have a nice day.

Johan Haleby

unread,
Oct 31, 2023, 2:41:58 AM10/31/23
to rest-a...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rest-assured/920022db-ce7f-4a7a-b1ad-de4d2d52b243n%40googlegroups.com.

branco12321

unread,
Nov 3, 2023, 5:04:52 PM11/3/23
to REST assured
On Tuesday, October 31, 2023 at 6:41:58 AM UTC Johan Haleby wrote:
I don't know why you're using surrounding parentheses.

The problem is that I encountered a different type of error that I can't reason about
in the following that fails at runtime:

       val titleResponse: String =
       //val titleResponse : String? = // <---- same error String? as with String
        When { // <---- java.lang.ClassCastException on this line of code

            get(API_ROOT + "/title/" + book.title)
        } Then {
            statusCode(200)
        } Extract {
            path("title")
        }

branco12321

unread,
Nov 3, 2023, 5:37:09 PM11/3/23
to REST assured
On Friday, November 3, 2023 at 9:04:52 PM UTC branco12321 wrote:
The problem is that I encountered a different type of error that I can't reason about
in the following that fails at runtime:

I fixed it by changing 'titleResponse : String' to 'titleResponse : List<String>'.
I guess I should have transmitted the code for the Spring controller I coded in as well:

@GetMapping("/title/{bookTitle}")
    public fun findByTitle(@PathVariable bookTitle: String): List<Book> {
        var bTitle = bookRepository.findByTitle(bookTitle)
        return bTitle
    }
Reply all
Reply to author
Forward
0 new messages