-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add endpoint that throws test exception (#493)
- Loading branch information
Showing
4 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/main/java/edu/hawaii/its/api/controller/GroupingsRestControllerv2_1ForTesting.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,26 @@ | ||
package edu.hawaii.its.api.controller; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
import edu.hawaii.its.api.exception.ExceptionForTesting; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/groupings/v2.1/testing") | ||
public class GroupingsRestControllerv2_1ForTesting { | ||
|
||
private static final Log logger = LogFactory.getLog(GroupingsRestControllerv2_1ForTesting.class); | ||
|
||
@GetMapping(value = "/exception") | ||
@ResponseBody | ||
public ResponseEntity throwException() { | ||
logger.debug("Entered REST throwException"); | ||
throw new ExceptionForTesting("Test exception"); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/edu/hawaii/its/api/exception/ExceptionForTesting.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,7 @@ | ||
package edu.hawaii.its.api.exception; | ||
|
||
public class ExceptionForTesting extends RuntimeException { | ||
public ExceptionForTesting(String message) { | ||
super(message); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/test/java/edu/hawaii/its/api/controller/GroupingsRestControllerv2_1ForTestingTest.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,36 @@ | ||
package edu.hawaii.its.api.controller; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import edu.hawaii.its.api.configuration.SpringBootWebApplication; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.web.context.WebApplicationContext; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup; | ||
|
||
@SpringBootTest(classes = { SpringBootWebApplication.class }) | ||
public class GroupingsRestControllerv2_1ForTestingTest { | ||
|
||
private static final String API_BASE = "/api/groupings/v2.1/testing"; | ||
@Autowired | ||
private WebApplicationContext context; | ||
private MockMvc mockMvc; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
mockMvc = webAppContextSetup(context).build(); | ||
} | ||
|
||
@Test | ||
public void throwExceptionTest() throws Exception { | ||
assertNotNull(mockMvc.perform(get(API_BASE + "/exception")) | ||
.andExpect(status().isInternalServerError())); | ||
|
||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/test/java/edu/hawaii/its/api/exception/ExceptionForTestingTest.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,17 @@ | ||
package edu.hawaii.its.api.exception; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class ExceptionForTestingTest { | ||
|
||
@Test | ||
public void construction() { | ||
ExceptionForTesting ex = new ExceptionForTesting("Test Exception"); | ||
assertNotNull(ex); | ||
assertThat(ex.getMessage(), equalTo("Test Exception")); | ||
} | ||
} |