-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds testResource macro to core. Fix #1526.
- Loading branch information
1 parent
0a6b4c1
commit 58fe4fb
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
buildSrc/src/main/java/io/micronaut/guides/core/TestResourceMacroSubstitution.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,19 @@ | ||
package io.micronaut.guides.core; | ||
|
||
import jakarta.inject.Singleton; | ||
|
||
import java.util.List; | ||
|
||
import static io.micronaut.guides.core.MacroUtils.addIncludesResources; | ||
|
||
@Singleton | ||
public class TestResourceMacroSubstitution implements MacroSubstitution{ | ||
@Override | ||
public String substitute(String str, String slug, GuidesOption option) { | ||
String resourceDir = "test"; | ||
|
||
List<String> lines = addIncludesResources(str,slug,option,resourceDir,"testResource"); | ||
|
||
return String.join("\n", lines); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
buildSrc/src/test/java/io/micronaut/guides/core/TestResourceMacroSubstitutionTest.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,32 @@ | ||
package io.micronaut.guides.core; | ||
|
||
import io.micronaut.starter.api.TestFramework; | ||
import io.micronaut.starter.options.BuildTool; | ||
import io.micronaut.starter.options.Language; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import jakarta.inject.Inject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@MicronautTest(startApplication = false) | ||
public class TestResourceMacroSubstitutionTest { | ||
|
||
@Inject | ||
TestResourceMacroSubstitution testResourceMacroSubstitution; | ||
|
||
@Test | ||
void testSubstitute() { | ||
String str = "testResource:app/application-test.yml[tag=testcontainers]"; | ||
String resJava = testResourceMacroSubstitution.substitute(str, "micronaut-metrics-oci", new GuidesOption(BuildTool.GRADLE, Language.JAVA, TestFramework.JUNIT)); | ||
String expectedJava = """ | ||
[source,yaml] | ||
.src/test/resources/application-test.yml | ||
---- | ||
include::{sourceDir}/micronaut-metrics-oci/micronaut-metrics-oci-gradle-java/src/test/resources/application-test.yml[tag=testcontainers] | ||
---- | ||
"""; | ||
assertEquals(expectedJava, resJava); | ||
} | ||
} |