From 6e101cb9fdb3681f5bf52a24e976bc955827892b Mon Sep 17 00:00:00 2001 From: SeoJin Kim Date: Sun, 13 Jun 2021 18:58:16 +0900 Subject: [PATCH] =?UTF-8?q?[Spring][=EC=87=BC=ED=95=91=EB=AA=B0=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=EC=A0=9D=ED=8A=B8][27]=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=20-=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://kimvampa.tistory.com/230?category=771727 --- .../com/vam/service/AdminServiceImpl.java | 13 ++++ .../com/vam/service/AdminServiceTests.java | 68 +++++++++++++++++++ .../maven/com.vam/controller/pom.properties | 2 +- .../com/vam/service/AdminServiceImpl.java | 12 ++++ .../com/vam/service/AdminServiceTests.java | 68 +++++++++++++++++++ .../maven/com.vam/controller/pom.properties | 2 +- 6 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 VamPa/src/test/java/com/vam/service/AdminServiceTests.java create mode 100644 VamPa_MySQL/src/test/java/com/vam/service/AdminServiceTests.java diff --git a/VamPa/src/main/java/com/vam/service/AdminServiceImpl.java b/VamPa/src/main/java/com/vam/service/AdminServiceImpl.java index 20a4efc..e8813e5 100644 --- a/VamPa/src/main/java/com/vam/service/AdminServiceImpl.java +++ b/VamPa/src/main/java/com/vam/service/AdminServiceImpl.java @@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.vam.mapper.AdminMapper; +import com.vam.model.AttachImageVO; import com.vam.model.BookVO; import com.vam.model.CateVO; import com.vam.model.Criteria; @@ -27,6 +28,18 @@ public class AdminServiceImpl implements AdminService { adminMapper.bookEnroll(book); + if(book.getImageList() == null || book.getImageList().size() <= 0) { + return; + } + + book.getImageList().forEach(attach ->{ + + attach.setBookId(book.getBookId()); + adminMapper.imageEnroll(attach); + + }); + + } /* 카테고리 리스트 */ diff --git a/VamPa/src/test/java/com/vam/service/AdminServiceTests.java b/VamPa/src/test/java/com/vam/service/AdminServiceTests.java new file mode 100644 index 0000000..c3e994b --- /dev/null +++ b/VamPa/src/test/java/com/vam/service/AdminServiceTests.java @@ -0,0 +1,68 @@ +package com.vam.service; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.vam.model.AttachImageVO; +import com.vam.model.BookVO; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml") +public class AdminServiceTests { + + @Autowired + private AdminService service; + + + /* 상품 등록 & 상품 이미지 등록 테스트 */ + @Test + public void bookEnrollTEsts() { + + BookVO book = new BookVO(); + // 상품 정보 + book.setBookName("service 테스트"); + book.setAuthorId(27); + book.setPubleYear("2021-03-18"); + book.setPublisher("출판사"); + book.setCateCode("202001"); + book.setBookPrice(20000); + book.setBookStock(300); + book.setBookDiscount(0.23); + book.setBookIntro("책 소개 "); + book.setBookContents("책 목차 "); + + // 이미지 정보 + List imageList = new ArrayList(); + + AttachImageVO image1 = new AttachImageVO(); + AttachImageVO image2 = new AttachImageVO(); + + image1.setFileName("test Image 1"); + image1.setUploadPath("test image 1"); + image1.setUuid("test1111"); + + image2.setFileName("test Image 2"); + image2.setUploadPath("test image 2"); + image2.setUuid("test2222"); + + imageList.add(image1); + imageList.add(image2); + + + book.setImageList(imageList); + + // bookEnroll() 메서드 호출 + service.bookEnroll(book); + + System.out.println("등록된 VO : " + book); + + + } + +} diff --git a/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties b/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties index a81d780..30ee2b8 100644 --- a/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties +++ b/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven Integration for Eclipse -#Mon Jun 07 20:30:56 KST 2021 +#Sun Jun 13 17:29:35 KST 2021 m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa m2e.projectName=VamPa groupId=com.vam diff --git a/VamPa_MySQL/src/main/java/com/vam/service/AdminServiceImpl.java b/VamPa_MySQL/src/main/java/com/vam/service/AdminServiceImpl.java index 0c6c694..fe64da7 100644 --- a/VamPa_MySQL/src/main/java/com/vam/service/AdminServiceImpl.java +++ b/VamPa_MySQL/src/main/java/com/vam/service/AdminServiceImpl.java @@ -27,6 +27,18 @@ public class AdminServiceImpl implements AdminService { adminMapper.bookEnroll(book); + if(book.getImageList() == null || book.getImageList().size() <= 0) { + return; + } + + book.getImageList().forEach(attach ->{ + + attach.setBookId(book.getBookId()); + adminMapper.imageEnroll(attach); + + }); + + } /* 카테고리 리스트 */ diff --git a/VamPa_MySQL/src/test/java/com/vam/service/AdminServiceTests.java b/VamPa_MySQL/src/test/java/com/vam/service/AdminServiceTests.java new file mode 100644 index 0000000..b128665 --- /dev/null +++ b/VamPa_MySQL/src/test/java/com/vam/service/AdminServiceTests.java @@ -0,0 +1,68 @@ +package com.vam.service; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.vam.model.AttachImageVO; +import com.vam.model.BookVO; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml") +public class AdminServiceTests { + + @Autowired + private AdminService service; + + + /* 상품 등록 & 상품 이미지 등록 테스트 */ + @Test + public void bookEnrollTEsts() { + + BookVO book = new BookVO(); + // 상품 정보 + book.setBookName("mapper 테스트"); + book.setAuthorId(8); + book.setPubleYear("2021-03-18"); + book.setPublisher("출판사"); + book.setCateCode("202001"); + book.setBookPrice(20000); + book.setBookStock(300); + book.setBookDiscount(0.23); + book.setBookIntro("책 소개 "); + book.setBookContents("책 목차 "); + + // 이미지 정보 + List imageList = new ArrayList(); + + AttachImageVO image1 = new AttachImageVO(); + AttachImageVO image2 = new AttachImageVO(); + + image1.setFileName("test Image 1"); + image1.setUploadPath("test image 1"); + image1.setUuid("test1111"); + + image2.setFileName("test Image 2"); + image2.setUploadPath("test image 2"); + image2.setUuid("test2222"); + + imageList.add(image1); + imageList.add(image2); + + + book.setImageList(imageList); + + // bookEnroll() 메서드 호출 + service.bookEnroll(book); + + System.out.println("등록된 VO : " + book); + + + } + +} diff --git a/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties b/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties index 5d84855..61003b6 100644 --- a/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties +++ b/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven Integration for Eclipse -#Mon Jun 07 20:30:56 KST 2021 +#Sun Jun 13 18:53:10 KST 2021 m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa_MySQL m2e.projectName=VamPa_MySQL groupId=com.vam