Skip to content

Commit

Permalink
Restore Wavefront HELP.md entries
Browse files Browse the repository at this point in the history
  • Loading branch information
mhalbritter committed Feb 9, 2024
1 parent 453c853 commit f7f0995
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* 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.
Expand All @@ -18,6 +18,7 @@

import io.spring.initializr.generator.buildsystem.Build;
import io.spring.initializr.generator.condition.ConditionalOnPlatformVersion;
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency;
import io.spring.initializr.generator.project.ProjectDescription;
import io.spring.initializr.generator.project.ProjectGenerationConfiguration;

Expand Down Expand Up @@ -52,6 +53,13 @@ ObservabilityHelpDocumentCustomizer observabilityHelpDocumentCustomizer(ProjectD
return new ObservabilityHelpDocumentCustomizer(description, build);
}

@Bean
@ConditionalOnRequestedDependency("wavefront")
@ConditionalOnPlatformVersion("[3.2.0, 3.3.0-M1)")
WavefrontHelpDocumentCustomizer wavefrontHelpDocumentCustomizer(Build build) {
return new WavefrontHelpDocumentCustomizer("https://docs.wavefront.com/wavefront_springboot3.html", build);
}

}

@Configuration(proxyBeanMethods = false)
Expand Down
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));
}

}
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();
}

}

0 comments on commit f7f0995

Please sign in to comment.