-
Notifications
You must be signed in to change notification settings - Fork 914
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
150 additions
and
1 deletion.
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
63 changes: 63 additions & 0 deletions
63
...spring/start/site/extension/dependency/observability/WavefrontHelpDocumentCustomizer.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,63 @@ | ||
/* | ||
* Copyright 2012-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.spring.start.site.extension.dependency.observability; | ||
|
||
import io.spring.initializr.generator.buildsystem.Build; | ||
import io.spring.initializr.generator.spring.documentation.HelpDocument; | ||
import io.spring.initializr.generator.spring.documentation.HelpDocumentCustomizer; | ||
|
||
/** | ||
* A {@link HelpDocumentCustomizer} that provides additional references when Wavefront is | ||
* selected. | ||
* | ||
* @author Stephane Nicoll | ||
* @author Brian Clozel | ||
*/ | ||
class WavefrontHelpDocumentCustomizer implements HelpDocumentCustomizer { | ||
|
||
private final Build build; | ||
|
||
private final String referenceLink; | ||
|
||
WavefrontHelpDocumentCustomizer(String referenceLink, Build build) { | ||
this.referenceLink = referenceLink; | ||
this.build = build; | ||
} | ||
|
||
@Override | ||
public void customize(HelpDocument document) { | ||
document.gettingStarted().addReferenceDocLink(this.referenceLink, "Wavefront for Spring Boot documentation"); | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
sb.append(String.format("## Observability with Wavefront%n%n")); | ||
sb.append(String | ||
.format("If you don't have a Wavefront account, the starter will create a freemium account for you.%n")); | ||
sb.append(String.format("The URL to access the Wavefront Service dashboard is logged on startup.%n")); | ||
|
||
if (this.build.dependencies().has("web") || this.build.dependencies().has("webflux")) { | ||
sb.append( | ||
String.format("%nYou can also access your dashboard using the `/actuator/wavefront` endpoint.%n")); | ||
} | ||
|
||
if (!this.build.dependencies().has("distributed-tracing")) { | ||
sb.append(String.format( | ||
"%nFinally, you can opt-in for distributed tracing by adding the 'Distributed Tracing' entry.%n")); | ||
} | ||
document.addSection((writer) -> writer.print(sb)); | ||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
...g/start/site/extension/dependency/observability/WavefrontHelpDocumentCustomizerTests.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,78 @@ | ||
/* | ||
* Copyright 2012-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.spring.start.site.extension.dependency.observability; | ||
|
||
import io.spring.initializr.generator.test.io.TextAssert; | ||
import io.spring.initializr.generator.test.project.ProjectStructure; | ||
import io.spring.initializr.web.project.ProjectRequest; | ||
import io.spring.start.site.extension.AbstractExtensionTests; | ||
import org.assertj.core.api.ListAssert; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Tests for {@link WavefrontHelpDocumentCustomizer}. | ||
* | ||
* @author Stephane Nicoll | ||
* @author Brian Clozel | ||
*/ | ||
class WavefrontHelpDocumentCustomizerTests extends AbstractExtensionTests { | ||
|
||
@Test | ||
void wavefrontAddGeneralSection() { | ||
assertHelpDocument("3.2.0", "wavefront").contains("## Observability with Wavefront", "", | ||
"If you don't have a Wavefront account, the starter will create a freemium account for you.", | ||
"The URL to access the Wavefront Service dashboard is logged on startup."); | ||
} | ||
|
||
@Test | ||
void wavefrontWithoutWebApplicationDoesNotAddActuatorSection() { | ||
assertHelpDocument("3.2.0", "wavefront") | ||
.doesNotContain("You can also access your dashboard using the `/actuator/wavefront` endpoint."); | ||
} | ||
|
||
@Test | ||
void wavefrontWithWebApplicationAddActuatorSection() { | ||
assertHelpDocument("3.2.0", "wavefront", "web") | ||
.contains("You can also access your dashboard using the `/actuator/wavefront` endpoint."); | ||
} | ||
|
||
@Test | ||
void wavefrontWithoutDistributedTracingAddTracingNote() { | ||
assertHelpDocument("3.2.0", "wavefront") | ||
.contains("Finally, you can opt-in for distributed tracing by adding the 'Distributed Tracing' entry."); | ||
} | ||
|
||
@Test | ||
void wavefrontWithDistributedTracingDoesNotAddTracingNote() { | ||
assertHelpDocument("3.2.0", "wavefront", "distributed-tracing").doesNotContain( | ||
"Finally, you can opt-in for distributed tracing by adding the 'Distributed Tracing' entry."); | ||
} | ||
|
||
@Test | ||
void springBoot3xWavefrontReference() { | ||
assertHelpDocument("3.2.0", "wavefront").contains( | ||
"* [Wavefront for Spring Boot documentation](https://docs.wavefront.com/wavefront_springboot3.html)"); | ||
} | ||
|
||
private ListAssert<String> assertHelpDocument(String version, String... dependencies) { | ||
ProjectRequest request = createProjectRequest(dependencies); | ||
request.setBootVersion(version); | ||
ProjectStructure project = generateProject(request); | ||
return new TextAssert(project.getProjectDirectory().resolve("HELP.md")).lines(); | ||
} | ||
|
||
} |