Skip to content

Commit

Permalink
Add DGS testing dependency automatically for DGS apps
Browse files Browse the repository at this point in the history
Closes gh-1563
  • Loading branch information
bclozel committed Aug 28, 2024
1 parent d986d1c commit a7c1d9c
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
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));
}

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

}
1 change: 1 addition & 0 deletions start-site/src/main/resources/META-INF/spring.factories
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ io.spring.start.site.extension.dependency.activemq.ActiveMQProjectGenerationConf
io.spring.start.site.extension.dependency.activemq.ArtemisProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.cassandra.CassandraProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.derby.DerbyProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.dgs.DgsProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.dgs.DgsCodegenProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.dockercompose.DockerComposeProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.elasticsearch.ElasticsearchProjectGenerationConfiguration,\
Expand Down
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);
}

}

0 comments on commit a7c1d9c

Please sign in to comment.