애플리케이션 테스트 수행

< NcsTest17 – src/main/resources – application.properties >

< NcsTest17 – src/test/java – ncstest – NcsTest17ApplicationTests >

< NcsTest17 – src/main/java – ncstest.domain.entity – (Class) BoardEntity >

#datasource 설정
spring.datasource.url=jdbc:mariadb://ncstest13.cxo8jbfuiro9.ap-northeast-2.rds.amazonaws.com:3306/the
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=12345678
#server.port=80

spring.jpa.open-in-view=false
#jpa-common
spring.jpa.show-sql=true

#개발단계에서만 테스트하고 실제 적용할때는 사용하지 마세요
spring.jpa.generate-ddl=false
spring.jpa.hibernate.use-new-id-generator-mappings=true

#spring.jpa.database=mysql
#spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.database-platform=org.hibernate.dialect.MariaDB103Dialect

##logging####
logging.level.ncstest.config=info
logging.level.ncstest.security=info
logging.level.ncstest.controller=debug
logging.level.ncstest.service=debug
logging.file.name=mylog.log
package ncstest;

import java.util.List;
import java.util.stream.IntStream;

import javax.transaction.Transactional;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.test.annotation.Commit;

import lombok.extern.log4j.Log4j2;
import ncstest.domain.entity.BoardEntity;
import ncstest.domain.entity.BoardEntityRepository;
import ncstest.domain.entity.MemberEntity;
import ncstest.domain.entity.MemberEntityRepository;
import ncstest.security.MemberRole;

@Log4j2
@SpringBootTest
class NcsTest17ApplicationTests {

	
	@Autowired
	MemberEntityRepository memberEntityRepository;
	
	@Autowired
	PasswordEncoder passwordEncoder;
	
	@Autowired
	BoardEntityRepository boardEntityRepository;
	
	
	
//	@Test
//	void 더미데이터입력테스트() {
//		
//		IntStream.rangeClosed(1, 10).forEach( i -> {
//			
//			MemberEntity memberEntity = MemberEntity.builder()
//																			  			.email("test"+i+"@test.com")
//																		  				.password( passwordEncoder.encode("1111") )
//																		  				.name( "test"+i )
//																		  				.build();
//			
//			memberEntity.addRole(MemberRole.USER);
//			
//			memberEntityRepository.save(memberEntity);
//			
//			
//			
//			BoardEntity entity = BoardEntity.builder()
//																			.subject("제목 테스트 "+i)
//																			.content("내용 테스트 "+i)
//																			.writer( memberEntity.getName() )
//																			.build();
//			
//			boardEntityRepository.save(entity);
//			
//		});
//		
//	}
	
	
//	@Test
//	void board입력테스트() {
//		
//		BoardEntity entity = BoardEntity.builder()
//																    .subject("test") 
//																    .content("test")
//																    .writer("test")
//																    .build();
//
//		boardEntityRepository.save(entity);
//		
//		
//		log.info("입력 결과 : "+entity);
//		
//	}
	
	
//	@Test
//	void board모두읽어오기테스트() {
//		
//		List<BoardEntity> result = boardEntityRepository.findAll(); 
//		
//		for(BoardEntity entity : result) {
//			
//			System.out.println(entity);
//			
//			log.info("조회 결과 : "+entity);
//			
//		}
//		
//	}
	

//	@Commit // [ @Test ] 할 때, [ @Transactional ]을 사용하면 자동으로 rollback이 발생하므로, [ @Commit ]을 별도로 꼭 넣어줘야 함
//	@Transactional
//	@Test
//	void board수정테스트() {
//		
//		BoardEntity result = boardEntityRepository.findById(12L)
//																						  .map( e -> e.update("제목 수정","내용 수정") ) // Create method 'update(String, String)' in type 'BoardEntity'
//																						  .orElseThrow();
//		
//		log.info("수정 결과 "+result);
//		
//	}
	
	
	@Test
	void board삭제() { 
		
		boardEntityRepository.deleteById(12L);
		
		log.info("(12L) 삭제 성공");
		
	}
	
	
}