Browse Source

test 추가

sungwoobaek@idatabank.com 5 years ago
parent
commit
999448b9db

+ 3 - 1
.gitignore

@@ -1,3 +1,5 @@
 .class
 *.class
-.vscode/
+.vscode/
+consentApi/bin/test/com/dbs/consentServer/*.class
+consentApi/bin/main/com/dbs/consentServer/controller/*.class

BIN
consentApi/bin/main/com/dbs/consentServer/controller/ConsentSvc.class


BIN
consentApi/bin/test/com/dbs/consentServer/ConsentApiApplicationTests.class


+ 1 - 0
consentApi/build.gradle

@@ -32,6 +32,7 @@ dependencies {
 	implementation 'io.springfox:springfox-swagger-ui:2.6.1'
 	implementation 'io.springfox:springfox-swagger-ui:2.6.1'
 
+	testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
 }
 
 // jar 생성 추가

+ 1 - 1
consentApi/src/main/java/com/dbs/consentServer/controller/ConsentSvc.java

@@ -223,7 +223,7 @@ public class ConsentSvc {
     return result;
   }
 
-  @RequestMapping(value = "getOcrTag", method = RequestMethod.POST)
+  @RequestMapping(value = "getOcrTag", method = RequestMethod.GET)
   public String getOcrTag() {
     String ocrTag = consentService.getOcrTag();
     return ocrTag;

+ 39 - 3
consentApi/src/test/java/com/dbs/consentServer/ConsentApiApplicationTests.java

@@ -1,13 +1,49 @@
 package com.dbs.consentServer;
 
+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;
+
+import java.util.Optional;
+
+import com.dbs.consentServer.service.ConsentService;
+
 import org.junit.jupiter.api.Test;
+// import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.MvcResult;
+import org.springframework.test.web.servlet.ResultMatcher;
+
+// import static org.junit.Assert.assertThat;
 
 @SpringBootTest
+@AutoConfigureMockMvc
 class ConsentApiApplicationTests {
+  @Autowired
+  private ConsentService consentService;
 
-	@Test
-	void contextLoads() {
+  /**
+   * getOcrTag 요청 테스트
+   * 해당 API 를 호출 하여 OCRTAG 가 유효한지 검사한다
+   * @param mvc
+   * @throws Exception
+   */
+  @Test
+  void getOcrTagTest(@Autowired MockMvc mvc) throws Exception {
+    mvc.perform(get("/ConsentSvc/getOcrTag"))
+			.andExpect(status().isOk())
+      .andExpect(content().contentType("text/plain;charset=UTF-8"))
+      .andExpect(new ResultMatcher(){
+        @Override
+        public void match(MvcResult result) throws Exception {
+          Optional.ofNullable(result.getResponse().getContentAsString())
+            .filter((body) -> body.length() == 13)
+            .orElseThrow(() -> new Exception("OCRTAG length is not same with pre-defined(length: 13)"));          
+        }
+      }
+    );
 	}
-
 }