-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DGS testing dependency automatically for DGS apps
Closes gh-1563
- Loading branch information
Showing
4 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...-site/src/main/java/io/spring/start/site/extension/dependency/dgs/DgsBuildCustomizer.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,40 @@ | ||
/* | ||
* 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.dgs; | ||
|
||
import io.spring.initializr.generator.buildsystem.Build; | ||
import io.spring.initializr.generator.buildsystem.Dependency; | ||
import io.spring.initializr.generator.buildsystem.DependencyScope; | ||
import io.spring.initializr.generator.spring.build.BuildCustomizer; | ||
|
||
/** | ||
* A {@link BuildCustomizer} that automatically adds | ||
* "graphql-dgs-spring-graphql-starter-test" when the {@code dgs} dependency is present. | ||
* | ||
* @author Brian Clozel | ||
*/ | ||
class DgsBuildCustomizer implements BuildCustomizer<Build> { | ||
|
||
@Override | ||
public void customize(Build build) { | ||
build.dependencies() | ||
.add("graphql-dgs-spring-graphql-starter-test", | ||
Dependency.withCoordinates("com.netflix.graphql.dgs", "graphql-dgs-spring-graphql-starter-test") | ||
.scope(DependencyScope.TEST_COMPILE)); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...java/io/spring/start/site/extension/dependency/dgs/DgsProjectGenerationConfiguration.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,39 @@ | ||
/* | ||
* Copyright 2012-2023 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.dgs; | ||
|
||
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency; | ||
import io.spring.initializr.generator.project.ProjectGenerationConfiguration; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
|
||
/** | ||
* {@link ProjectGenerationConfiguration} for generation of projects that use the Netflix | ||
* DGS. | ||
* | ||
* @author Brian Clozel | ||
*/ | ||
@ProjectGenerationConfiguration | ||
@ConditionalOnRequestedDependency("netflix-dgs") | ||
class DgsProjectGenerationConfiguration { | ||
|
||
@Bean | ||
DgsBuildCustomizer dgsBuildCustomizer() { | ||
return new DgsBuildCustomizer(); | ||
} | ||
|
||
} |
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
47 changes: 47 additions & 0 deletions
47
.../src/test/java/io/spring/start/site/extension/dependency/dgs/DgsBuildCustomizerTests.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,47 @@ | ||
/* | ||
* 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.dgs; | ||
|
||
import io.spring.initializr.metadata.Dependency; | ||
import io.spring.initializr.web.project.ProjectRequest; | ||
import io.spring.start.site.extension.AbstractExtensionTests; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class DgsBuildCustomizerTests extends AbstractExtensionTests { | ||
|
||
private Dependency dgsTest; | ||
|
||
@BeforeEach | ||
void setup() { | ||
this.dgsTest = Dependency.withId("graphql-dgs-spring-graphql-starter-test", "com.netflix.graphql.dgs", | ||
"graphql-dgs-spring-graphql-starter-test"); | ||
this.dgsTest.setScope(Dependency.SCOPE_TEST); | ||
} | ||
|
||
@Test | ||
void shouldAddTestingDependency() { | ||
ProjectRequest request = createProjectRequest("web", "netflix-dgs"); | ||
assertThat(mavenPom(request)).hasDependency(Dependency.createSpringBootStarter("web")) | ||
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST)) | ||
.hasDependency(this.dgsTest) | ||
.hasDependenciesSize(4); | ||
} | ||
|
||
} |