forked from GDSC-PKNU-Official/GDSC_PKNU_Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: GDSC-PKNU-Official#3 Notion 테이블 plainText 추출
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,11 @@ | |
import org.jraf.klibnotion.model.pagination.ResultPage; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
public class NotionApiTest { | ||
|
@@ -65,4 +70,39 @@ public void getRowByEmail() { | |
assertThat(simpleQueryResultPage.results.get(0).getPropertyValues().toString().contains(name)).isEqualTo(true); | ||
} | ||
|
||
@Test | ||
void getPlainTexts(){ | ||
|
||
//given | ||
String name = "가나다"; | ||
String role = "Core"; | ||
String email = "[email protected]"; | ||
|
||
ResultPage<Page> simpleQueryResultPage = client.getDatabases().queryDatabase( | ||
notionTable.getDATABASE_ID(), | ||
null, | ||
null, | ||
new Pagination() | ||
); | ||
|
||
//when | ||
/** | ||
* KlibNotion 라이브러리에서 개별 plainText를 받아올 수 없어 정규식으로 추출하였음 | ||
*/ | ||
String resultInString = simpleQueryResultPage.results.toString(); | ||
List<String> plainTextList = new ArrayList<>(); | ||
// 문자열 중 "(plainText=" ~ "," 범위(이름, 이메일) OR " "name=" ~ "," 범위(역할) 문자열을 추출 | ||
Pattern pattern = Pattern.compile("(?<=\\(plainText=)(.*?)(?=,)|(?<=\\(name=)(.*?)(?=,)"); | ||
Matcher matcher = pattern.matcher(resultInString); | ||
while (matcher.find()) { | ||
plainTextList.add(matcher.group()); | ||
} | ||
|
||
//then | ||
assertThat(plainTextList.size()).isEqualTo(notionTable.getMemberNum() * 3); | ||
assertThat(plainTextList.get(0)).isEqualTo(email); | ||
assertThat(plainTextList.get(1)).isEqualTo(role); | ||
assertThat(plainTextList.get(2)).isEqualTo(name); | ||
} | ||
|
||
} |