-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix mapping entry point generator properties to client properties (#1459
- Loading branch information
Showing
26 changed files
with
473 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...ite-java-client-generator/src/test/groovy/io/micronaut/openapi/test/api/ClientSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.micronaut.openapi.test.api | ||
|
||
import spock.lang.Specification | ||
|
||
import static io.micronaut.openapi.test.util.TestUtils.assertFileContains | ||
|
||
class ClientSpec extends Specification { | ||
|
||
String outputPath = "build/generated/openapi" | ||
|
||
void "test client id"() { | ||
expect: | ||
assertFileContains(outputPath + "/src/main/java/io/micronaut/openapi/test/api/PetApi.java", | ||
'@Client(id = "myClient", path = "${openapi-micronaut-client-base-path}")'); | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
test-suite-java-client-generator/src/test/java/io/micronaut/openapi/test/util/TestUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package io.micronaut.openapi.test.util; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Arrays; | ||
import java.util.regex.Pattern; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
/** | ||
* An abstract class with methods useful for testing | ||
*/ | ||
public final class TestUtils { | ||
|
||
private TestUtils() { | ||
} | ||
|
||
public static void assertFileContainsRegex(String path, String... regex) { | ||
assertFileExists(path); | ||
String file = readFile(path); | ||
for (String line : regex) { | ||
assertTrue(Pattern.compile(line.replace(" ", "\\s+")).matcher(file).find()); | ||
} | ||
} | ||
|
||
public static void assertFileNotContainsRegex(String path, String... regex) { | ||
assertFileExists(path); | ||
String file = readFile(path); | ||
for (String line : regex) { | ||
assertFalse(Pattern.compile(line.replace(" ", "\\s+")).matcher(file).find()); | ||
} | ||
} | ||
|
||
public static void assertFileContains(String path, String... lines) { | ||
assertFileExists(path); | ||
String file = linearize(readFile(path)); | ||
for (String line : lines) { | ||
assertTrue(file.contains(linearize(line)), "File does not contain line [" + line + "]"); | ||
} | ||
} | ||
|
||
public static void assertFileNotContains(String path, String... lines) { | ||
assertFileExists(path); | ||
String file = linearize(readFile(path)); | ||
for (String line : lines) { | ||
assertFalse(file.contains(linearize(line)), "File contains line [" + line + "]"); | ||
} | ||
} | ||
|
||
public static void assertFileExists(String file) { | ||
Path path = Paths.get(file); | ||
if (!path.toFile().exists()) { | ||
while (path.getParent() != null && !path.getParent().toFile().exists()) { | ||
path = path.getParent(); | ||
} | ||
String message = "File \"" + file + "\" should exist, however \"" + path + "\" could not be found."; | ||
if (path.getParent() != null) { | ||
Path parent = path.getParent(); | ||
File[] contents = parent.toFile().listFiles(); | ||
message += "\nContents of folder \"" + path.getParent() + "\": "; | ||
if (contents == null) { | ||
message += null; | ||
} else { | ||
message += Arrays.stream(contents) | ||
.map(f -> f.toString().substring(parent.toString().length() + 1)) | ||
.toList(); | ||
} | ||
message += "."; | ||
} | ||
fail(message); | ||
} | ||
} | ||
|
||
public static void assertFileNotExists(String path) { | ||
assertFalse(Paths.get(path).toFile().exists(), "File \"" + path + "\" should not exist"); | ||
} | ||
|
||
public static String readFile(String path) { | ||
String file = null; | ||
try { | ||
file = Files.readString(Paths.get(path)); | ||
assertNotNull(file, "File \"" + path + "\" does not exist"); | ||
} catch (IOException e) { | ||
fail("Unable to evaluate file " + path); | ||
} | ||
|
||
return file; | ||
} | ||
|
||
public static String linearize(String target) { | ||
return target.replaceAll("\r?\n", "").replaceAll("\\s+", "s"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
test-suite-java-server-generator/src/test/resources/application-test.properties
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
test-suite-java-server-generator/src/test/resources/application-test.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
micronaut: | ||
server: | ||
context-path: /api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...lin-kapt-client-generator/src/test/groovy/io/micronaut/openapi/test/api/ClientSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.micronaut.openapi.test.api | ||
|
||
import spock.lang.Specification | ||
|
||
import static io.micronaut.openapi.test.util.TestUtils.assertFileContains | ||
|
||
class ClientSpec extends Specification { | ||
|
||
String outputPath = "build/generated/openapi" | ||
|
||
void "test client id"() { | ||
expect: | ||
assertFileContains(outputPath + "/src/main/java/io/micronaut/openapi/test/api/PetApi.java", | ||
'@Client(id = "myClient", path = "${openapi-micronaut-client-base-path}")'); | ||
} | ||
} |
Oops, something went wrong.