Home » Java » java – Assertj-swagger throws org.assertj.core.error.AssertJMultipleFailuresError Multiple Failures when executing test-Exceptionshub

java – Assertj-swagger throws org.assertj.core.error.AssertJMultipleFailuresError Multiple Failures when executing test-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have a spring boot api application and I used springfox to generate swaggerv2 api documentation and I created a test to see if my api definitions are correct.

Heres how my configuration looks like:

@Configuration
@EnableSwagger2
public class SpringFoxConfig {  

    @Value("${my.app.version}")
    private String appVersion;

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("My App").select()
                .apis(RequestHandlerSelectors.basePackage("my.com.app.controller"))
                .paths(regex("/api/MyAppName.*")).build()
                .globalOperationParameters(
                        Arrays.asList(new ParameterBuilder().name("UserKey").description("Unique user key.")
                                .modelRef(new ModelRef("string")).parameterType("header").required(true).build()))
                .apiInfo(apiInfo()).securitySchemes(Arrays.asList(apiKey()));
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("My App API Documentaion")
                .description("This documentation is for the MyApp.").version(appVersion)
                .license("MyApp.cc").licenseUrl("https://myapp.com/").build();
    }

    private ApiKey apiKey() {
        return new ApiKey("apiKey", "APIKEY", "header");
    }
}

Here’s how my test looks:

    @Test
    public void shouldFindNoDifferences() {
        File implFirstSwaggerLocation = new File(
            MyTest.class.getResource("/swagger.json").getFile());
        File designFirstSwaggerLocation = new File(
            MyTest.class.getResource("/swagger.yaml").getFile());
        SwaggerAssertions.assertThat(implFirstSwaggerLocation.getAbsolutePath())
            .isEqualTo(designFirstSwaggerLocation.getAbsolutePath());
    }

It’s exactly what they have from their examples. When I run my test It throws this exception below:

Stack trace:
org.assertj.core.error.AssertJMultipleFailuresError: 
Multiple Failures (1 failure)
-- failure 1 --
[Checking Paths] 
Expecting:
  <["/api/myAppName",
    "/api/myAppName/eventTypes",
    "/api/myAppName/initialize",
    "/api/myAppName/latest/{type}/{user}",
    "/api/myAppName/stats/due/{ids}/custom/{days}",
    "/api/myAppName/stats/due/{ids}/{period}",
    "/api/myAppName/stats/orgs/most/{ids}/{period}",
    "/api/myAppName/stats/orgs/{id}/{period}",
    "/api/myAppName/stats/{ids}/{period}",
    "/api/myAppName/stats/{ids}/{period}/{days}",
    "/api/myAppName/summarize",
    "/api/myAppName/{id}",
    "/api/myAppName/{source}/events",
    "/api/myAppName/{source}/events/batch"]>
to contain only:
  <["/v2/api/myAppName/stats/orgs/{id}/{period}",
    "/v2/api/myAppName/{source}/events/batch",
    "/v2/api/myAppName/initialize",
    "/v2/api/myAppName/eventTypes",
    "/v2/api/myAppName/stats/due/{ids}/{period}",
    "/v2/api/myAppName/stats/orgs/most/{ids}/{period}",
    "/v2/api/myAppName/{source}/events",
    "/v2/api/myAppName/{id}",
    "/v2/api/myAppName/latest/{type}/{user}",
    "/v2/api/myAppName/stats/due/{ids}/custom/{days}",
    "/v2/api/myAppName/stats/{ids}/{period}",
    "/v2/api/myAppName",
    "/v2/api/myAppName/summarize",
    "/v2/api/myAppName/stats/{ids}/{period}/{days}"]>
elements not found:
  <["/v2/api/myAppName/stats/orgs/{id}/{period}",
    "/v2/api/myAppName/{source}/events/batch",
    "/v2/api/myAppName/initialize",
    "/v2/api/myAppName/eventTypes",
    "/v2/api/myAppName/stats/due/{ids}/{period}",
    "/v2/api/myAppName/stats/orgs/most/{ids}/{period}",
    "/v2/api/myAppName/{source}/events",
    "/v2/api/myAppName/{id}",
    "/v2/api/myAppName/latest/{type}/{user}",
    "/v2/api/myAppName/stats/due/{ids}/custom/{days}",
    "/v2/api/myAppName/stats/{ids}/{period}",
    "/v2/api/myAppName",
    "/v2/api/myAppName/summarize",
    "/v2/api/myAppName/stats/{ids}/{period}/{days}"]>
and elements not expected:
  <["/api/myAppName",
    "/api/myAppName/eventTypes",
    "/api/myAppName/initialize",
    "/api/myAppName/latest/{type}/{user}",
    "/api/myAppName/stats/due/{ids}/custom/{days}",
    "/api/myAppName/stats/due/{ids}/{period}",
    "/api/myAppName/stats/orgs/most/{ids}/{period}",
    "/api/myAppName/stats/orgs/{id}/{period}",
    "/api/myAppName/stats/{ids}/{period}",
    "/api/myAppName/stats/{ids}/{period}/{days}",
    "/api/myAppName/summarize",
    "/api/myAppName/{id}",
    "/api/myAppName/{source}/events",
    "/api/myAppName/{source}/events/batch"]>
at DocumentationDrivenValidator.validatePaths(DocumentationDrivenValidator.java:108)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at io.github.robwin.swagger.test.DocumentationDrivenValidator.validateSwagger(DocumentationDrivenValidator.java:88)
    at io.github.robwin.swagger.test.SwaggerAssert.isEqualTo(SwaggerAssert.java:75)
    at io.github.robwin.swagger.test.SwaggerAssert.isEqualTo(SwaggerAssert.java:87)
    at my.com.app.definitions.MyTest.shouldFindNoDifferences(MyTest.java:58)
    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:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
    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.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:542)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)

I think I’m missing something.

How to&Answers:

It was my carelessness that resulted to this problem but thanks to Roddy’s comment I was able to notice my mistake.

In my assertj-swagger.properties file there contains assertj.swagger.pathsPrependExpected=/v2 property that causes this issue.