-
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 resource macro and tests. Fix #1525.
- Loading branch information
1 parent
464442c
commit e72201d
Showing
3 changed files
with
112 additions
and
0 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
19 changes: 19 additions & 0 deletions
19
buildSrc/src/main/java/io/micronaut/guides/core/ResourceMacroSubstitution.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.*; | ||
|
||
@Singleton | ||
public class ResourceMacroSubstitution implements MacroSubstitution{ | ||
@Override | ||
public String substitute(String str, String slug, GuidesOption option) { | ||
String resourceDir = "main"; | ||
|
||
List<String> lines = addIncludesResources(str,slug,option,resourceDir,"resource"); | ||
|
||
return String.join("\n", lines); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
buildSrc/src/test/java/io/micronaut/guides/core/ResourceMacroSubstitutionTest.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,46 @@ | ||
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 ResourceMacroSubstitutionTest { | ||
|
||
@Inject | ||
ResourceMacroSubstitution resourceMacroSubstitution; | ||
|
||
@Test | ||
void testSubstitute() { | ||
String str = "resource:../../../ttfr.sh[]"; | ||
String resJava = resourceMacroSubstitution.substitute(str, "executable-jar", new GuidesOption(BuildTool.GRADLE, Language.JAVA, TestFramework.JUNIT)); | ||
String expectedJava = """ | ||
[source,] | ||
.src/main/../../ttfr.sh | ||
---- | ||
include::{sourceDir}/executable-jar/executable-jar-gradle-java/src/main/resources/../../../ttfr.sh[] | ||
---- | ||
"""; | ||
assertEquals(expectedJava, resJava); | ||
} | ||
|
||
@Test | ||
void testSubstituteWithTags() { | ||
String str = "resource:application.yml[tag=endpoints]"; | ||
String resJava = resourceMacroSubstitution.substitute(str, "adding-commit-info", new GuidesOption(BuildTool.GRADLE, Language.JAVA, TestFramework.JUNIT)); | ||
String expectedJava = """ | ||
[source,yaml] | ||
.src/main/resources/application.yml | ||
---- | ||
include::{sourceDir}/adding-commit-info/adding-commit-info-gradle-java/src/main/resources/application.yml[tag=endpoints] | ||
---- | ||
"""; | ||
assertEquals(expectedJava, resJava); | ||
} | ||
} |