|
| 1 | +package io.micronaut.starter.feature.other |
| 2 | + |
| 3 | +import io.micronaut.starter.ApplicationContextSpec |
| 4 | +import io.micronaut.starter.application.ApplicationType |
| 5 | +import io.micronaut.starter.application.generator.GeneratorContext |
| 6 | +import io.micronaut.starter.feature.Features |
| 7 | +import io.micronaut.starter.fixture.CommandOutputFixture |
| 8 | + |
| 9 | +class ScalarSpec extends ApplicationContextSpec implements CommandOutputFixture { |
| 10 | + |
| 11 | + void "test scalar features"() { |
| 12 | + when: |
| 13 | + Features features = getFeatures(['scalar']) |
| 14 | + |
| 15 | + then: |
| 16 | + features.contains("openapi") |
| 17 | + } |
| 18 | + |
| 19 | + void "test config without security feature"() { |
| 20 | + when: |
| 21 | + GeneratorContext ctx = buildGeneratorContext(['scalar']) |
| 22 | + def output = generate(ApplicationType.DEFAULT, ctx) |
| 23 | + |
| 24 | + then: |
| 25 | + ctx.configuration.get('micronaut.router.static-resources.swagger.paths') == "classpath:META-INF/swagger" |
| 26 | + ctx.configuration.get('micronaut.router.static-resources.swagger.mapping') == "/swagger/**" |
| 27 | + ctx.configuration.get('micronaut.router.static-resources.scalar.paths') == "classpath:META-INF/swagger/views/scalar" |
| 28 | + ctx.configuration.get('micronaut.router.static-resources.scalar.mapping') == "/scalar/**" |
| 29 | + |
| 30 | + output["openapi.properties"].readLines()[0] == "swagger-ui.enabled=false" |
| 31 | + output["openapi.properties"].readLines()[1] == "redoc.enabled=false" |
| 32 | + output["openapi.properties"].readLines()[2] == "openapi-explorer.enabled=false" |
| 33 | + output["openapi.properties"].readLines()[3] == "scalar.enabled=true" |
| 34 | + output["openapi.properties"].readLines()[4] == "rapidoc.enabled=false" |
| 35 | + output["openapi.properties"].readLines()[5] == "rapidoc.bg-color=#14191f" |
| 36 | + output["openapi.properties"].readLines()[6] == "rapidoc.text-color=#aec2e0" |
| 37 | + output["openapi.properties"].readLines()[7] == "rapidoc.sort-endpoints-by=method" |
| 38 | + |
| 39 | + output.containsKey("src/main/java/example/micronaut/FooController.java") |
| 40 | + output.containsKey("src/test/java/example/micronaut/FooTest.java") |
| 41 | + } |
| 42 | + |
| 43 | + void "test config with security feature"() { |
| 44 | + when: |
| 45 | + GeneratorContext ctx = buildGeneratorContext(['scalar', 'security']) |
| 46 | + def output = generate(ApplicationType.DEFAULT, ctx) |
| 47 | + |
| 48 | + then: |
| 49 | + ctx.configuration.get('micronaut.router.static-resources.swagger.paths') == "classpath:META-INF/swagger" |
| 50 | + ctx.configuration.get('micronaut.router.static-resources.swagger.mapping') == "/swagger/**" |
| 51 | + ctx.configuration.get('micronaut.router.static-resources.scalar.paths') == "classpath:META-INF/swagger/views/scalar" |
| 52 | + ctx.configuration.get('micronaut.router.static-resources.scalar.mapping') == "/scalar/**" |
| 53 | + |
| 54 | + List<Map<String, String>> swaggerSec = ctx.configuration.get('micronaut.security.intercept-url-map') as List<Map<String, String>> |
| 55 | + |
| 56 | + swaggerSec.any { it.access == "isAnonymous()" && it.pattern == "/swagger/**" } |
| 57 | + swaggerSec.any { it.access == "isAnonymous()" && it.pattern == "/scalar/**" } |
| 58 | + |
| 59 | + output["openapi.properties"].readLines()[0] == "swagger-ui.enabled=false" |
| 60 | + output["openapi.properties"].readLines()[1] == "redoc.enabled=false" |
| 61 | + output["openapi.properties"].readLines()[2] == "openapi-explorer.enabled=false" |
| 62 | + output["openapi.properties"].readLines()[3] == "scalar.enabled=true" |
| 63 | + output["openapi.properties"].readLines()[4] == "rapidoc.enabled=false" |
| 64 | + output["openapi.properties"].readLines()[5] == "rapidoc.bg-color=#14191f" |
| 65 | + output["openapi.properties"].readLines()[6] == "rapidoc.text-color=#aec2e0" |
| 66 | + output["openapi.properties"].readLines()[7] == "rapidoc.sort-endpoints-by=method" |
| 67 | + |
| 68 | + output.containsKey("src/main/java/example/micronaut/FooController.java") |
| 69 | + output.containsKey("src/test/java/example/micronaut/FooTest.java") |
| 70 | + |
| 71 | + } |
| 72 | + |
| 73 | + void "test scalar has third party docs"() { |
| 74 | + when: |
| 75 | + GeneratorContext ctx = buildGeneratorContext(['scalar']) |
| 76 | + def output = generate(ApplicationType.DEFAULT, ctx) |
| 77 | + |
| 78 | + then: |
| 79 | + output["README.md"].contains("https://github.com/scalar/scalar") |
| 80 | + } |
| 81 | + |
| 82 | + void "test scalar has Micronaut docs"() { |
| 83 | + when: |
| 84 | + GeneratorContext ctx = buildGeneratorContext(['scalar']) |
| 85 | + def output = generate(ApplicationType.DEFAULT, ctx) |
| 86 | + |
| 87 | + then: |
| 88 | + output["README.md"].contains("https://micronaut-projects.github.io/micronaut-openapi/latest/guide/#scalar") |
| 89 | + } |
| 90 | + |
| 91 | +} |
0 commit comments