|
| 1 | +package org.evomaster.e2etests.spring.openapi.v3.overlay |
| 2 | + |
| 3 | +import com.foo.rest.examples.spring.openapi.v3.overlay.OverlayController |
| 4 | +import com.foo.rest.examples.spring.openapi.v3.stringlength.StringLengthController |
| 5 | +import org.evomaster.ci.utils.JUnitExtra |
| 6 | +import org.evomaster.core.config.ConfigProblemException |
| 7 | +import org.evomaster.core.problem.rest.data.HttpVerb |
| 8 | +import org.evomaster.e2etests.spring.openapi.v3.SpringTestBase |
| 9 | +import org.junit.jupiter.api.Assertions |
| 10 | +import org.junit.jupiter.api.BeforeAll |
| 11 | +import org.junit.jupiter.api.Test |
| 12 | +import org.junit.jupiter.api.assertThrows |
| 13 | + |
| 14 | +class OverlayEMTest : SpringTestBase(){ |
| 15 | + |
| 16 | + companion object { |
| 17 | + @BeforeAll |
| 18 | + @JvmStatic |
| 19 | + fun init() { |
| 20 | + initClass(OverlayController()) |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + //these should be kept in sink with what written in the Overlay files |
| 25 | + private val X = "Some X value like 1234" |
| 26 | + private val Y = "Some Y value like 777" |
| 27 | + |
| 28 | + @Test |
| 29 | + fun testRunEM_Overlay_None() { |
| 30 | + |
| 31 | + runTestHandlingFlakyAndCompilation( |
| 32 | + "Overlay_None", |
| 33 | + 100 |
| 34 | + ) { args: MutableList<String> -> |
| 35 | + |
| 36 | + val solution = initAndRun(args) |
| 37 | + |
| 38 | + Assertions.assertTrue(solution.individuals.size >= 1) |
| 39 | + assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/overlay", null) |
| 40 | + assertNone(solution, HttpVerb.GET, 200, "/api/overlay", X) |
| 41 | + assertNone(solution, HttpVerb.GET, 200, "/api/overlay", Y) |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + |
| 46 | + @Test |
| 47 | + fun testRunEM_Overlay_X() { |
| 48 | + |
| 49 | + runTestHandlingFlakyAndCompilation( |
| 50 | + "Overlay_X", |
| 51 | + 100 |
| 52 | + ) { args: MutableList<String> -> |
| 53 | + |
| 54 | + setOption(args, "overlay", "src/main/resources/overlay/x.yaml") |
| 55 | + |
| 56 | + val solution = initAndRun(args) |
| 57 | + |
| 58 | + Assertions.assertTrue(solution.individuals.size >= 1) |
| 59 | + assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/overlay", X) |
| 60 | + assertNone(solution, HttpVerb.GET, 200, "/api/overlay", Y) |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + fun testRunEM_Overlay_Y_BB() { |
| 66 | + |
| 67 | + runTestHandlingFlakyAndCompilation( |
| 68 | + "Overlay_Y_BB", |
| 69 | + 100 |
| 70 | + ) { args: MutableList<String> -> |
| 71 | + |
| 72 | + setOption(args, "overlay", "src/main/resources/overlay/subfolder/y.yaml") |
| 73 | + setOption(args, "blackBox", "true") |
| 74 | + setOption(args, "bbTargetUrl", baseUrlOfSut) |
| 75 | + setOption(args, "bbSwaggerUrl", "$baseUrlOfSut/v3/api-docs") |
| 76 | + |
| 77 | + val solution = initAndRun(args) |
| 78 | + |
| 79 | + Assertions.assertTrue(solution.individuals.size >= 1) |
| 80 | + assertNone(solution, HttpVerb.GET, 200, "/api/overlay", X) |
| 81 | + assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/overlay", Y) |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + |
| 86 | + @Test |
| 87 | + fun testRunEM_Overlay_Z_fail() { |
| 88 | + |
| 89 | + runTestHandlingFlaky( |
| 90 | + "Overlay_Z_fail", |
| 91 | + "org.foo.Overlay_Z_fail", |
| 92 | + 100, |
| 93 | + false |
| 94 | + ) { args: MutableList<String> -> |
| 95 | + |
| 96 | + setOption(args, "overlay", "src/main/resources/overlay/z.json") |
| 97 | + //default behavior must be non-lenient |
| 98 | + |
| 99 | + //z does not exist |
| 100 | + JUnitExtra.assertThrowsInnermost(ConfigProblemException::class.java) { |
| 101 | + initAndRun(args) |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + @Test |
| 107 | + fun testRunEM_Overlay_Z_lenient() { |
| 108 | + |
| 109 | + runTestHandlingFlakyAndCompilation( |
| 110 | + "Overlay_Z_lenient", |
| 111 | + 100 |
| 112 | + ) { args: MutableList<String> -> |
| 113 | + |
| 114 | + setOption(args, "overlay", "src/main/resources/overlay/z.json") |
| 115 | + setOption(args, "overlayLenient", "true") |
| 116 | + |
| 117 | + //z does not exist... but, when lenient, shouldn't fail |
| 118 | + val solution = initAndRun(args) |
| 119 | + |
| 120 | + Assertions.assertTrue(solution.individuals.size >= 1) |
| 121 | + assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/overlay", null) |
| 122 | + assertNone(solution, HttpVerb.GET, 200, "/api/overlay", X) |
| 123 | + assertNone(solution, HttpVerb.GET, 200, "/api/overlay", Y) |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + @Test |
| 128 | + fun testRunEM_Overlay_folder() { |
| 129 | + |
| 130 | + runTestHandlingFlaky( |
| 131 | + "Overlay_folder", |
| 132 | + "org.foo.Overlay_folder", |
| 133 | + 100, |
| 134 | + false, |
| 135 | + ) { args: MutableList<String> -> |
| 136 | + |
| 137 | + setOption(args, "overlay", "src/main/resources/overlay") |
| 138 | + //by default, z.json will be picked, and so failed because non-lenient |
| 139 | + |
| 140 | + //z does not exist |
| 141 | + JUnitExtra.assertThrowsInnermost(ConfigProblemException::class.java) { |
| 142 | + initAndRun(args) |
| 143 | + } |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + |
| 148 | + @Test |
| 149 | + fun testRunEM_Overlay_folder_filtered() { |
| 150 | + |
| 151 | + runTestHandlingFlakyAndCompilation( |
| 152 | + "Overlay_folder_filtered", |
| 153 | + 100 |
| 154 | + ) { args: MutableList<String> -> |
| 155 | + |
| 156 | + setOption(args, "overlay", "src/main/resources/overlay") |
| 157 | + //make sure to not pick-up z.json |
| 158 | + setOption(args, "overlayFileSuffixes", ".yaml") |
| 159 | + |
| 160 | + val solution = initAndRun(args) |
| 161 | + |
| 162 | + Assertions.assertTrue(solution.individuals.size >= 1) |
| 163 | + assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/overlay", X) |
| 164 | + assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/overlay", Y) |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | + |
| 169 | +} |
0 commit comments