diff --git a/src/main/java/io/codeka/gaia/modules/controller/ModuleRestController.java b/src/main/java/io/codeka/gaia/modules/controller/ModuleRestController.java index efe3e7022..6ca4062b8 100644 --- a/src/main/java/io/codeka/gaia/modules/controller/ModuleRestController.java +++ b/src/main/java/io/codeka/gaia/modules/controller/ModuleRestController.java @@ -83,5 +83,13 @@ public Optional readme(@PathVariable String id) { return moduleGitRepository.getReadme(module); } +} + +@ResponseStatus(HttpStatus.NOT_FOUND) +class ModuleNotFoundException extends RuntimeException{ +} +@ResponseStatus(HttpStatus.FORBIDDEN) +class ModuleForbiddenException extends RuntimeException{ } + diff --git a/src/main/java/io/codeka/gaia/modules/controller/ModulesMVCController.java b/src/main/java/io/codeka/gaia/modules/controller/ModulesMVCController.java deleted file mode 100644 index f2ba4c846..000000000 --- a/src/main/java/io/codeka/gaia/modules/controller/ModulesMVCController.java +++ /dev/null @@ -1,53 +0,0 @@ -package io.codeka.gaia.modules.controller; - -import io.codeka.gaia.modules.repository.TerraformModuleGitRepository; -import io.codeka.gaia.modules.repository.TerraformModuleRepository; -import io.codeka.gaia.teams.User; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.ResponseStatus; - -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import java.util.Optional; - -@Controller -public class ModulesMVCController { - - private TerraformModuleRepository terraformModuleRepository; - private TerraformModuleGitRepository terraformModuleGitRepository; - - @Autowired - public ModulesMVCController( - TerraformModuleRepository terraformModuleRepository, - TerraformModuleGitRepository terraformModuleGitRepository) { - this.terraformModuleRepository = terraformModuleRepository; - this.terraformModuleGitRepository = terraformModuleGitRepository; - } - -// @GetMapping("/modules/import") - public String importModule() { - return "modules_import"; - } - -// @GetMapping("/modules/{id}/description") - public String description(@PathVariable String id, Model model) { - model.addAttribute("module", terraformModuleRepository.findById(id).orElseThrow()); - return "module_description"; - } - - -} - -@ResponseStatus(HttpStatus.NOT_FOUND) -class ModuleNotFoundException extends RuntimeException{ -} - -@ResponseStatus(HttpStatus.FORBIDDEN) -class ModuleForbiddenException extends RuntimeException{ -} diff --git a/src/test/java/io/codeka/gaia/modules/controller/ModulesMVCControllerTest.java b/src/test/java/io/codeka/gaia/modules/controller/ModulesMVCControllerTest.java deleted file mode 100644 index a373f2ec9..000000000 --- a/src/test/java/io/codeka/gaia/modules/controller/ModulesMVCControllerTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package io.codeka.gaia.modules.controller; - -import io.codeka.gaia.modules.bo.TerraformModule; -import io.codeka.gaia.modules.repository.TerraformModuleGitRepository; -import io.codeka.gaia.modules.repository.TerraformModuleRepository; -import io.codeka.gaia.teams.Team; -import io.codeka.gaia.teams.User; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.ui.Model; - -import java.util.NoSuchElementException; -import java.util.Optional; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.*; - -@ExtendWith(MockitoExtension.class) -class ModulesMVCControllerTest { - - private ModulesMVCController controller; - - @Mock - private TerraformModuleRepository moduleRepository; - - @Mock - private TerraformModuleGitRepository moduleGitRepository; - - private User admin = new User("admin", null); - - private Team userTeam = new Team("Red Is Dead"); - - private User standardUser = new User("Odile Deray", userTeam); - - @BeforeEach - void setup() { - controller = new ModulesMVCController(moduleRepository, moduleGitRepository); - } - - @Test - void description_shouldReturnRightView() { - // given - var module = new TerraformModule(); - var model = mock(Model.class); - - // when - when(moduleRepository.findById(anyString())).thenReturn(Optional.of(module)); - var result = controller.description("TEST", model); - - // then - assertThat(result).isEqualTo("module_description"); - verify(moduleRepository).findById("TEST"); - verify(model).addAttribute("module", module); - } - - @Test - void description_shouldThrowExceptionIfModuleNotFound() { - // given - var model = mock(Model.class); - - // when - when(moduleRepository.findById(anyString())).thenReturn(Optional.empty()); - assertThrows(NoSuchElementException.class, () -> controller.description("TEST", model)); - - // then - verify(moduleRepository).findById("TEST"); - verify(model, never()).addAttribute(eq("module"), any()); - } - - @Test - void importModule_shouldShowImportModuleView(){ - // when - var res = controller.importModule(); - - // then - assertEquals("modules_import", res); - } - -}