-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add dateUpdated field to Post model and create InfoController
- Loading branch information
1 parent
2be3407
commit 95fc3a7
Showing
6 changed files
with
140 additions
and
3 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/main/java/com/liatrio/dojo/devopsknowledgeshareapi/InfoController.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,20 @@ | ||
package com.liatrio.dojo.devopsknowledgeshareapi; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@CrossOrigin(origins = "*", maxAge = 3600) | ||
@RestController | ||
@Slf4j | ||
public class InfoController { | ||
|
||
private String deploymentType = System.getenv("DEPLOYMENT_TYPE") != null ? System.getenv("DEPLOYMENT_TYPE") : "blue"; | ||
|
||
@GetMapping("/info") | ||
public String getInfo() { | ||
log.info("{}: received a GET request for /info", deploymentType); | ||
return "Welcome to the API version 1.0"; | ||
} | ||
} |
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
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
4 changes: 4 additions & 0 deletions
4
src/main/java/com/liatrio/dojo/devopsknowledgeshareapi/PostRepository.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 |
---|---|---|
@@ -1,10 +1,14 @@ | ||
package com.liatrio.dojo.devopsknowledgeshareapi; | ||
|
||
import java.util.Collection; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.rest.core.annotation.RepositoryRestResource; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@RepositoryRestResource | ||
@Repository | ||
interface PostRepository extends JpaRepository<Post, Long> { | ||
|
||
Collection<Post> findByTitle(String title); | ||
} |
46 changes: 46 additions & 0 deletions
46
src/test/java/com/liatrio/dojo/devopsknowledgeshareapi/InfoControllerTest.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,46 @@ | ||
package com.liatrio.dojo.devopsknowledgeshareapi; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers; | ||
|
||
public class InfoControllerTest { | ||
// User visits the /info URL of the service | ||
// Given the user is not logged in | ||
// When the user visits the /info page | ||
// Then the user should see the phrase "Welcome to the API version 1.0"" | ||
// And they should not see an error message | ||
|
||
@WebMvcTest(InfoController.class) | ||
public class InfoControllerTest { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@Test | ||
public void testInfoPageNotLoggedIn() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.get("/info")) | ||
.andExpect(MockMvcResultMatchers.status().isOk()) | ||
.andExpect(MockMvcResultMatchers.content().string("Welcome to the API version 1.0")) | ||
.andExpect(MockMvcResultMatchers.content().string(Matchers.not(Matchers.containsString("error")))); | ||
} | ||
|
||
@Test | ||
public void testInfoPageLoggedIn() throws Exception { | ||
// Additional test case for when the user is logged in | ||
// Implement the test logic here | ||
} | ||
|
||
@Test | ||
public void testInfoPageError() throws Exception { | ||
// Additional test case for when an error occurs on the /info page | ||
// Implement the test logic here | ||
} | ||
|
||
// Add more test cases as needed | ||
|
||
} | ||
} |
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