Skip to content

Commit

Permalink
Finish SprintAWS till chap 02
Browse files Browse the repository at this point in the history
gimquokka committed Feb 8, 2021
1 parent 29dea48 commit 07a65d8
Showing 8 changed files with 111 additions and 2 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -26,5 +26,6 @@ repositories{

dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.projectlombok:lombok')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rootProject.name = 'freelec-springboot2-webservice'
rootProject.name = ' -springboot2-webservice'

11 changes: 11 additions & 0 deletions src/main/java/com/spring/book/springboot/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.spring.book.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
public static void main(String[] args){
SpringApplication.run(Application.class, args);
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/spring/book/springboot/web/HelloController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.spring.book.springboot.web;

import com.spring.book.springboot.web.dto.HelloResponseDto;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
@GetMapping("/hello")
public String hello() {
return "hello";
}

@GetMapping("/hello/dto")
public HelloResponseDto helloDto(@RequestParam("name") String name,
@RequestParam("age") int age) {
return new HelloResponseDto(name, age);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.spring.book.springboot.web.dto;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public class HelloResponseDto {
private final String name;
private final int age;
}
44 changes: 44 additions & 0 deletions src/test/java/com/spring/book/springboot/HelloControllerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.spring.book.springboot;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;

import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

//@WebMvcTest(controllers = HelloController.class)
@RunWith(SpringRunner.class)
@WebMvcTest
public class HelloControllerTest {

@Autowired
private MockMvc mvc;

@Test
public void hello가_리턴된다() throws Exception {
String hello = "hello";

mvc.perform(get("/hello"))
.andExpect(status().isOk())
.andExpect(content().string(hello));
}

@Test
public void helloDto가_리턴된다() throws Exception {
String name = "Gimquokka";
int age = 26;

mvc.perform(
get("/hello/dto") // 아... /hello 구나...ㅜㅜ
.param("name", name)
.param("age", String.valueOf(age)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.name", is(name)))
.andExpect(jsonPath("$.age", is(age)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.spring.book.springboot.dto;

import com.spring.book.springboot.web.dto.HelloResponseDto;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class HelloResponseDtoTest {

@Test
public void 롬북_기능_테스트(){
String name = "Gimquokka";
int age = 26;

HelloResponseDto dto = new HelloResponseDto(name, age);

assertThat(dto.getName()).isEqualTo(name);
assertThat(dto.getAge()).isEqualTo(age);
}

}

0 comments on commit 07a65d8

Please sign in to comment.