코틀린 테스트코드 환경 설정
This commit is contained in:
23
build.gradle
23
build.gradle
@@ -1,6 +1,7 @@
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.5.6'
|
||||
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
|
||||
id "org.jetbrains.kotlin.jvm" version "1.5.0-RC"
|
||||
// id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
|
||||
id "com.github.node-gradle.node" version "3.1.0"
|
||||
id 'java'
|
||||
@@ -26,6 +27,11 @@ repositories {
|
||||
gradlePluginPortal()
|
||||
}
|
||||
|
||||
ext {
|
||||
kotlin_version = '1.5.0-RC'
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||
@@ -54,9 +60,15 @@ dependencies {
|
||||
runtimeOnly 'mysql:mysql-connector-java'
|
||||
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
testImplementation 'org.springframework.security:spring-security-test'
|
||||
testImplementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter-test:2.2.0'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
testImplementation 'io.projectreactor:reactor-test'
|
||||
testImplementation 'org.springframework.security:spring-security-test'
|
||||
|
||||
testImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
|
||||
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
|
||||
testImplementation "com.nhaarman:mockito-kotlin-kt1.1:1.5.0"
|
||||
}
|
||||
|
||||
test {
|
||||
@@ -81,6 +93,13 @@ test {
|
||||
//}
|
||||
|
||||
|
||||
compileTestKotlin {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// NPM 설정
|
||||
|
||||
node {
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
//package myblog.blog.article.controller;
|
||||
//
|
||||
//import myblog.blog.article.service.ArticleService;
|
||||
//import org.junit.jupiter.api.Test;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.boot.test.context.SpringBootTest;
|
||||
//
|
||||
//@SpringBootTest
|
||||
//class ArticleControllerTest {
|
||||
//
|
||||
// @Autowired
|
||||
// ArticleService articleService;
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void 게시물글쓰기() throws Exception {
|
||||
// // given
|
||||
//
|
||||
// // when
|
||||
//
|
||||
// // then
|
||||
// }
|
||||
//}
|
||||
@@ -1,65 +0,0 @@
|
||||
package myblog.blog.rss;
|
||||
|
||||
import myblog.blog.article.domain.Article;
|
||||
import myblog.blog.article.service.ArticleService;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.*;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class RssServiceTest {
|
||||
|
||||
@InjectMocks
|
||||
RssService rssService;
|
||||
|
||||
@Mock
|
||||
ArticleService articleService;
|
||||
|
||||
@Test
|
||||
public void rss요청성공테스트() throws Exception {
|
||||
// given
|
||||
Mockito.when(articleService.getTotalArticle())
|
||||
.thenReturn(Arrays.asList(buildArticle("테스트용","1호",1L),buildArticle("테스트용이에용","2호",2L)));
|
||||
// when
|
||||
String rssFeed = rssService.getRssFeed();
|
||||
// then
|
||||
assertThat(rssFeed).contains("<title><![CDATA[테스트용]]></title>")
|
||||
.contains("<link>https://www.jiniaslog.co.kr/article/view?articleId=1</link>")
|
||||
.contains("<description><![CDATA[<p>1호</p>]]></description>")
|
||||
.contains("<guid>https://www.jiniaslog.co.kr/article/view?articleId=1</guid>");
|
||||
assertThat(rssFeed).contains("<title><![CDATA[테스트용이에용]]></title>")
|
||||
.contains("<link>https://www.jiniaslog.co.kr/article/view?articleId=2</link>")
|
||||
.contains("<description><![CDATA[<p>2호</p>]]></description>")
|
||||
.contains("<guid>https://www.jiniaslog.co.kr/article/view?articleId=2</guid>");
|
||||
}
|
||||
|
||||
private Article buildArticle(String title, String content, Long id) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
|
||||
Article article = Article.builder().title(title).content(content).build();
|
||||
setArticlePrivateFieldId(id, article);
|
||||
setArticleCreatedTimeStamp(article);
|
||||
return article;
|
||||
}
|
||||
|
||||
private void setArticleCreatedTimeStamp(Article article) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
|
||||
Class<?> clazz = Class.forName("myblog.blog.article.domain.Article").getSuperclass();
|
||||
Field field = clazz.getDeclaredField("createdDate");
|
||||
field.setAccessible(true);
|
||||
field.set(article, LocalDateTime.now());
|
||||
}
|
||||
|
||||
private void setArticlePrivateFieldId(Long id, Article article) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
|
||||
Class<?> clazz = Class.forName("myblog.blog.article.domain.Article");
|
||||
Field field = clazz.getDeclaredField("id");
|
||||
field.setAccessible(true);
|
||||
field.set(article, id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package myblog.blog.sitemap;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class SiteMapServiceTest {
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user