feat: 创建 Spring Boot 4 项目及 Gitea/GitLab CI/CD 流水线
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package com.lightjob.demo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringbootCiciDemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringbootCiciDemoApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.lightjob.demo.controller;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class HelloController {
|
||||
|
||||
@GetMapping(value = "/api/hello", produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
public String hello() {
|
||||
return "Hello from Spring Boot 4 CI/CD Demo!";
|
||||
}
|
||||
}
|
||||
2
src/main/resources/application.properties
Normal file
2
src/main/resources/application.properties
Normal file
@@ -0,0 +1,2 @@
|
||||
spring.application.name=springboot-cici-demo
|
||||
server.port=8080
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.lightjob.demo;
|
||||
|
||||
import com.lightjob.demo.controller.HelloController;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
@SpringBootTest
|
||||
class SpringbootCiciDemoApplicationTests {
|
||||
|
||||
@Autowired
|
||||
private HelloController helloController;
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
assertNotNull(helloController);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.lightjob.demo.controller;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
class HelloControllerTest {
|
||||
|
||||
private final MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new HelloController()).build();
|
||||
|
||||
@Test
|
||||
void helloReturnsPlainText() throws Exception {
|
||||
mockMvc.perform(get("/api/hello"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string("Hello from Spring Boot 4 CI/CD Demo!"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user