Importing RestAssured in Spring Boot Test - spring-boot

I have developed a Spring Boot Application.
I am using RestAssured to test the same
following are the dependencies in build.gradle
dependencies {
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.springframework.boot:spring-boot-starter-aop")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-mail")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.thymeleaf.extras:thymeleaf-extras-springsecurity3:2.1.2.RELEASE")
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-freemarker")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
runtime("mysql:mysql-connector-java")
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile('com.jayway.restassured:rest-assured:2.4.1')
}
I am facing a problem while importing RestAssured in a Integration Test class for Spring Boot
import static com.jayway.restassured.RestAssured.*;
When I try to run the application using gradle I am getting the following error
Error:(15, 37) java: package com.jayway.restassured does not exist
Why is this problem and how to solve it ?

Related

How to setup AI in springboot kotlin poject

I want to use Deep learning java lib in my project. But I am not able
to setup AI DJL in my spring boot kotlin Gradle based project. I Use
Buildgradle.kts , but I don't know how to add ai.djl in
buildgradle.kts.
DJL provides springboot starter package, you can add the following section in your build.gradle.kts:
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("ai.djl.spring:djl-spring-boot-starter-pytorch-auto:0.11")
implementation("org.springframework.boot:spring-boot-starter-actuator")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
// See: https://github.com/awslabs/djl/blob/master/mxnet/mxnet-engine/README.md for MXNet library selection
}
You can find DJL springboot starter demo project from github: https://github.com/deepjavalibrary/djl-spring-boot-starter-demo

How to use spring boot in gradle without the spring boot gradle plugin

Can anyone show me or point me to a spring boot gradle project that does not make use of the spring boot gradle plugin.
I'm looking for something like a spring boot starter web hello world example that doesn't use the gradle plugin.
I can't imagine that the plugin is a requirement, but a search for examples all seem to lean on the gradle plugin, which lets just say is not an option in my environment, and no I can't switch to maven either.
Ideally the gradle build would work by adding something like the following:
gradle.properties
springBootVersion=2.1.3.RELEASE
build.gradle
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion
}
I used the spring dependency management plugin, and it works
buildscript {
ext {
springDepManagementVersion = '1.0.10.RELEASE'
springBootVersion = '2.6.6'
springCloudVersion = "2021.0.1"
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:${springDepManagementVersion}"
}
}
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
}
}
dependencies {
implementation "org.springframework.cloud:spring-cloud-starter-sleuth"
implementation 'org.springframework.boot:spring-boot-starter-json'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-security'
...
}
I can't use spring boot gradle plugin, since I can only use gradle 6.7.1, while spring boot gradle plugin requires gradle version at least 6.8 to support spring boot 2.6. I was inspired by the spring cloud bom solution.

error when upgrading Spring Boot version in Vaadin Gradle project

I have a Gradle project that uses Spring Boot + Vaadin.
The Gradle plugins for Spring Boot and Vaadin configured as follows:
buildscript {
ext {
springBootVersion = '1.3.7.RELEASE'
}
...
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath "fi.jasoft.plugin:gradle-vaadin-plugin:0.11.1"
}
}
The Vaadin version is specified as follows:
vaadin {
version '7.6.8'
widgetset 'com.vaadin.DefaultWidgetSet'
}
Vaadin dependencies are specified as follows:
dependencies {
compile 'com.vaadin:vaadin-spring-boot-starter:1.0.0'
compile 'com.vaadin:vaadin-server:${vaadin.version}'
compile 'com.vaadin:vaadin-client:${vaadin.version}'
...
}
This works fine, but as soon as I change the Spring Boot version to
springBootVersion = '1.4.0.RELEASE'
then I get the error:
Illegal character in path at index 89:
https://oss.sonatype.org/content/repositories/vaadin-snapshots/com/vaadin/vaadin-server/${vaadin.version}/vaadin-server-${vaadin.version}.pom
Update
Groovy (which Gradle uses) supports String interpolation only when using double quotes (") so changing the Vaadin dependencies to
dependencies {
compile "com.vaadin:vaadin-spring-boot-starter:1.0.0"
compile "com.vaadin:vaadin-server:${vaadin.version}"
compile "com.vaadin:vaadin-client:${vaadin.version}"
...
}
fixes it. Now the real question is why the single quotes work fine if I downgrade Spring Boot to 1.3.7-RELEASE.
If you are using a recent Spring Boot version you should upgrade your Gradle Vaadin plugin. Recent versions of the plugin has much better support for Spring Boot.
Here is a guide to get you started https://github.com/johndevs/gradle-vaadin-plugin/wiki/Creating-a-Spring-Boot-Project

How to exclude jersey 1.x dependencies when running tests with gradle

We have a web service project that relies on Netflix's Eureka and it has a dependency on Jersey client 1.x.
Our project is using gradle and in the project we have our src, unit, integration, and functional tests. For our functional tests we have a jar that we import in the testCompile gradle section that wraps a Jersey client to send requests to the web service.
Now my question is how can I get the netflix Jersey client dependency to be ignored in the testCompile so I can use the new Jersey 2.x client for the functional tests?
Build Scripts below:
Main service build script excerpt:
dependencies {
compile 'com.netflix.eureka:eureka-client:1.1.97'
compile 'com.sun.jersey:jersey-bundle:1.18'
testCompile 'some.domain:service-test-client:1.0.1'
}
service test client relevant parts:
dependencies {
compile 'org.glassfish.jersey.core:jersey-client:2.19'
compile 'org.glassfish.jersey.connectors:jeresey-apache-connector:2.19'
}
Relevant parts of the Eureka Client gradle script from github:
ext {
githubProjectName = 'eureka'
awsVersion='1.9.3'
servletVersion='2.5'
jerseyVersion='1.11'
governatorVersion='1.3.3'
archaiusVersion='0.6.5'
blitzVersion='1.34'
mockitoVersion='1.9.5'
junit_version='4.10'
mockserverVersion='3.9.2'
jetty_version='7.2.0.v20101020'
}
dependencies {
compile "com.sun.jersey:jersey-core:$jerseyVersion"
compile "com.sun.jersey:jersey-client:$jerseyVersion"
compile 'com.sun.jersey.contribs:jersey-apache-client4:1.11'
compile 'org.apache.httpcomponents:httpclient:4.2.1'
}
With the above setup I get method not found errors because when the tests are running some of the jersey 1.x classes are taking precedence over the classes brought in with the test-client jar.
You can use gradle dependency monitoring to find out what libraries are bringing in jersey.
./gradlew dependencies
You can pipe that into a file, and less your way into finding out who's bringing in jersey 1.*.
Then, just exclude it from those specifically, and compile your own:
compile("com.example.library:artifactId:x.y.z"){
exclude group:'org.glassfish.jersey', module:jersey-common
}
compile('org.glassfish.jersey.core:jersey-common:2.4.1')
I got same problem with jersey 1.x vs glassfish 2.x with Eureka (but with Spring Cloud). I'm trying this:
compile ("org.springframework.cloud:spring-cloud-starter-eureka:1.0.0.RELEASE")
{
exclude group:'com.sun.jersey', module: 'jsr311-api'
}
But then Eureka doesn't work for me...
I think I will try to switch to Eureka 2.0 with different jersey, but without spring cloud:
https://github.com/Netflix/eureka/wiki/Eureka-2.0-Architecture-Overview
http://mvnrepository.com/artifact/com.netflix.eureka check Eureka2 dependencies
maybe you can use them?

Grails 3.0.2 cannot resolve #Secured annotation in controller

I try upgrade my application from Grails 2.4.4 to Grails 3.0.2 and I have problem with spring annotation.
I have controller, like this:
import grails.plugins.springsecurity.annotation.Secured
class MyController {
#Secured(['ROLE_ADMINS_GROUP'])
def index() {
// some code
}
}
In depencencies block in build.gradle I have this:
dependencies {
provided 'org.springframework.boot:spring-boot-starter-logging'
provided "org.springframework.boot:spring-boot-starter-actuator"
provided "org.springframework.boot:spring-boot-autoconfigure"
provided "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.springframework.boot:spring-boot-starter-security"
provided "org.grails:grails-web-boot"
provided "org.grails:grails-dependencies"
provided 'javax.servlet:javax.servlet-api:3.1.0'
testCompile "org.grails:grails-plugin-testing"
console "org.grails:grails-console"
compile "org.grails.plugins:wslite:0.7.2.0"
}
When i try compile my application, I get error message.
MyController.groovy: 4: unable to resolve class grails.plugins.springsecurity.annotation.Secured
# line 4, column 1.
import grails.plugins.springsecurity.annotation.Secured
^
Spring Security Core Plugin has already been updated and is now compatible with Grails 3.0 see the docs: What's New in Version 3.0
Just add following dependency to the dependencies block of the build.gradle file:
compile "org.grails.plugins:spring-security-core:3.0.0.M1"

Resources