Skip to content

Commit

Permalink
Refactoring: Github -> GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalgrimaud committed Mar 10, 2022
1 parent ecafebf commit 41c771e
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package tech.jhipster.lite.generator.ci.github.actions.application;

import org.springframework.stereotype.Service;
import tech.jhipster.lite.generator.ci.github.actions.domain.GitHubActionsService;
import tech.jhipster.lite.generator.project.domain.Project;

@Service
public class GitHubActionsApplicationService {

private final GitHubActionsService gitHubActionsService;

public GitHubActionsApplicationService(GitHubActionsService gitHubActionsService) {
this.gitHubActionsService = gitHubActionsService;
}

public void addGitHubActionsForMaven(Project project) {
gitHubActionsService.addGitHubActionsForMaven(project);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import tech.jhipster.lite.generator.project.domain.Project;
import tech.jhipster.lite.generator.project.domain.ProjectRepository;

public class GithubActionsDomainService implements GithubActionsService {
public class GitHubActionsDomainService implements GitHubActionsService {

public static final String GITHUB_ACTIONS_CI_SOURCE_FOLDER = "ci/github/actions/.github/workflows/";
public static final String GITHUB_ACTIONS_CI_YML = "github-actions.yml.mustache";
Expand All @@ -15,7 +15,7 @@ public class GithubActionsDomainService implements GithubActionsService {

private final ProjectRepository projectRepository;

public GithubActionsDomainService(ProjectRepository projectRepository) {
public GitHubActionsDomainService(ProjectRepository projectRepository) {
this.projectRepository = projectRepository;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

import tech.jhipster.lite.generator.project.domain.Project;

public interface GithubActionsService {
public interface GitHubActionsService {
void addGitHubActionsForMaven(Project project);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tech.jhipster.lite.generator.ci.github.actions.domain.GithubActionsDomainService;
import tech.jhipster.lite.generator.ci.github.actions.domain.GithubActionsService;
import tech.jhipster.lite.generator.ci.github.actions.domain.GitHubActionsDomainService;
import tech.jhipster.lite.generator.ci.github.actions.domain.GitHubActionsService;
import tech.jhipster.lite.generator.project.domain.ProjectRepository;

@Configuration
public class GithubActionsBeanConfiguration {
public class GitHubActionsBeanConfiguration {

private final ProjectRepository projectRepository;

public GithubActionsBeanConfiguration(ProjectRepository projectRepository) {
public GitHubActionsBeanConfiguration(ProjectRepository projectRepository) {
this.projectRepository = projectRepository;
}

@Bean
public GithubActionsService githubActionsService() {
return new GithubActionsDomainService(projectRepository);
public GitHubActionsService gitHubActionsService() {
return new GitHubActionsDomainService(projectRepository);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.jhipster.lite.generator.ci.github.actions.application.GithubActionsApplicationService;
import tech.jhipster.lite.generator.ci.github.actions.application.GitHubActionsApplicationService;
import tech.jhipster.lite.generator.project.domain.Project;
import tech.jhipster.lite.generator.project.infrastructure.primary.dto.ProjectDTO;
import tech.jhipster.lite.technical.infrastructure.primary.annotation.GeneratorStep;

@RestController
@RequestMapping("/api/github-actions/")
@Tag(name = "GitHub Actions")
class GithubActionsResource {
@Tag(name = "Continuous Integration")
class GitHubActionsResource {

private final GithubActionsApplicationService githubActionsApplicationService;
private final GitHubActionsApplicationService gitHubActionsApplicationService;

GithubActionsResource(GithubActionsApplicationService githubActionsApplicationService) {
this.githubActionsApplicationService = githubActionsApplicationService;
GitHubActionsResource(GitHubActionsApplicationService gitHubActionsApplicationService) {
this.gitHubActionsApplicationService = gitHubActionsApplicationService;
}

@Operation(summary = "Init Github Actions YML files")
@Operation(summary = "Add GitHub Actions")
@ApiResponse(responseCode = "500", description = "An error occurred while adding GitHub Actions")
@PostMapping("/maven")
@GeneratorStep(id = "github-actions")
public void addGitHubActionsForMaven(@RequestBody ProjectDTO projectDTO) {
Project project = ProjectDTO.toProject(projectDTO);
githubActionsApplicationService.init(project);
gitHubActionsApplicationService.addGitHubActionsForMaven(project);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
import tech.jhipster.lite.generator.project.domain.Project;

@IntegrationTest
class GithubActionsApplicationServiceIT {
class GitHubActionsApplicationServiceIT {

@Autowired
GithubActionsApplicationService githubActionsApplicationService;
GitHubActionsApplicationService gitHubActionsApplicationService;

@Test
void shouldInit() {
void shouldAddGitHubActionsForMaven() {
Project project = tmpProject();

githubActionsApplicationService.init(project);
gitHubActionsApplicationService.addGitHubActionsForMaven(project);

GithubActionsAssertFiles.assertFilesYml(project);
GitHubActionsAssertFiles.assertFilesYml(project);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

import tech.jhipster.lite.generator.project.domain.Project;

public class GithubActionsAssertFiles {
public class GitHubActionsAssertFiles {

public static void assertFilesYml(Project project) {
assertFileExist(project, ".github/workflows/github-actions.yml");
assertFileExist(project, ".github/actions/setup/action.yml");
}

public static void assertFilesGithubActions(Project project) {
public static void assertFilesGitHubActions(Project project) {
assertFilesYml(project);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@

@UnitTest
@ExtendWith(MockitoExtension.class)
class GithubActionsDomainServiceTest {
class GitHubActionsDomainServiceTest {

@Mock
private ProjectRepository projectRepository;

@InjectMocks
private GithubActionsDomainService githubActionsDomainService;
private GitHubActionsDomainService gitHubActionsDomainService;

@Test
void shouldInit() {
void shouldAddGitHubActionsForMaven() {
Project project = tmpProject();

assertThatCode(() -> githubActionsDomainService.addGitHubActionsForMaven(project)).doesNotThrowAnyException();
assertThatCode(() -> gitHubActionsDomainService.addGitHubActionsForMaven(project)).doesNotThrowAnyException();

verify(projectRepository)
.template(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import tech.jhipster.lite.IntegrationTest;
import tech.jhipster.lite.generator.ci.github.actions.domain.GithubActionsDomainService;
import tech.jhipster.lite.generator.ci.github.actions.domain.GitHubActionsDomainService;

@IntegrationTest
class GithubActionsBeanConfigurationIT {
class GitHubActionsBeanConfigurationIT {

@Autowired
ApplicationContext applicationContext;

@Test
void shouldGetBean() {
assertThat(applicationContext.getBean("githubActionsService")).isNotNull().isInstanceOf(GithubActionsDomainService.class);
assertThat(applicationContext.getBean("gitHubActionsService")).isNotNull().isInstanceOf(GitHubActionsDomainService.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static tech.jhipster.lite.TestUtils.convertObjectToJsonBytes;
import static tech.jhipster.lite.TestUtils.readFileToObject;
import static tech.jhipster.lite.generator.ci.github.actions.application.GithubActionsAssertFiles.assertFilesGithubActions;
import static tech.jhipster.lite.generator.ci.github.actions.application.GitHubActionsAssertFiles.assertFilesGitHubActions;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -13,29 +13,29 @@
import org.springframework.test.web.servlet.MockMvc;
import tech.jhipster.lite.IntegrationTest;
import tech.jhipster.lite.common.domain.FileUtils;
import tech.jhipster.lite.generator.ci.github.actions.application.GithubActionsApplicationService;
import tech.jhipster.lite.generator.ci.github.actions.application.GitHubActionsApplicationService;
import tech.jhipster.lite.generator.project.domain.Project;
import tech.jhipster.lite.generator.project.infrastructure.primary.dto.ProjectDTO;

@IntegrationTest
@AutoConfigureMockMvc
class GithubActionsResourceIT {
class GitHubActionsResourceIT {

@Autowired
MockMvc mockMvc;

@Autowired
GithubActionsApplicationService githubActionsApplicationService;
GitHubActionsApplicationService gitHubActionsApplicationService;

@Test
void shouldInit() throws Exception {
void shouldAddGitHubActionsForMaven() throws Exception {
ProjectDTO projectDTO = readFileToObject("json/chips.json", ProjectDTO.class).folder(FileUtils.tmpDirForTest());

mockMvc
.perform(post("/api/github-actions/maven").contentType(MediaType.APPLICATION_JSON).content(convertObjectToJsonBytes(projectDTO)))
.andExpect(status().isOk());

Project project = ProjectDTO.toProject(projectDTO);
assertFilesGithubActions(project);
assertFilesGitHubActions(project);
}
}

0 comments on commit 41c771e

Please sign in to comment.