1

I have a problem with running Cucumber tests in a khipster project (I can reproduce it with jhipster as well) when I configure it to use oauth2.

I create the project with the following configuration file (I call it mono.jdl):

application {
  config {
    applicationType monolith
    authenticationType oauth2
    baseName helloworld
    buildTool maven
    packageName com.example.helloworld
    testFrameworks [cucumber]
  }
  entities *
}

I generate the project with a command: khipster import-jdl mono.jdl.

I create a very simple Cucumber test. I create a feature file (src/test/features/kuku/kuku.feature):

Feature: just a test

    Scenario: my scenario
        And one two three

and a file with steps (src/test/kotlin/com/example/helloworld/cucumber/stepdefs/KukuStepDefs.kt):

package com.example.helloworld.cucumber.stepdefs

import io.cucumber.java.en.When

class KukuStepDefs : StepDefs() {

    @When("one two three")
    fun magic() {
        println("four five six")
    }
}

I try to run the integration test with a command ./mvnw integration-test. However, it fails with a following error:

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in com.example.helloworld.web.rest.LogoutResource required a bean of type 'org.springframework.security.oauth2.client.registration.ClientRegistrationRepository' that could not be found.

The following candidates were found but could not be injected:
    - Bean method 'clientRegistrationRepository' in 'OAuth2ClientRegistrationRepositoryConfiguration' not loaded because OAuth2 Clients Configured Condition registered clients is not available


Action:

Consider revisiting the entries above or defining a bean of type 'org.springframework.security.oauth2.client.registration.ClientRegistrationRepository' in your configuration.

How can I fix this problem?

user983447
  • 1,598
  • 4
  • 19
  • 36

1 Answers1

2

The solution is to find CucumberContextConfiguration class. It contains such annotation:

@ContextConfiguration(classes = [HelloworldApp::class])

We must change it to:

import com.example.helloworld.config.TestSecurityConfiguration
(...)
@ContextConfiguration(classes = [HelloworldApp::class, TestSecurityConfiguration::class])
user983447
  • 1,598
  • 4
  • 19
  • 36