-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/#3 노션 API 테스트 #4
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
476a930
Issue #3 feat: .gitignore 추가
dmswjdchl 3c44b20
Issue #3 feat: .gitignore 수정
dmswjdchl 6aa2305
Issue #3 feat: dependency klibnotion 추가
dmswjdchl 6f3aea3
Issue #3 test: notion 테이블 가져오기
dmswjdchl ade9c12
Revert "Issue #3 test: notion 테이블 가져오기"
dmswjdchl 0c1d761
Issue #3 test: notion 테이블 가져오기
dmswjdchl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
68 changes: 68 additions & 0 deletions
68
src/test/java/com/gdscpknu/gdscpknu/notion/NotionApiTest.java
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.gdscpknu.gdscpknu.notion; | ||
|
||
import org.jraf.klibnotion.client.blocking.BlockingNotionClient; | ||
import org.jraf.klibnotion.model.database.Database; | ||
import org.jraf.klibnotion.model.database.query.DatabaseQuery; | ||
import org.jraf.klibnotion.model.database.query.filter.DatabaseQueryPredicate; | ||
import org.jraf.klibnotion.model.database.query.filter.DatabaseQueryPropertyFilter; | ||
import org.jraf.klibnotion.model.page.Page; | ||
import org.jraf.klibnotion.model.pagination.Pagination; | ||
import org.jraf.klibnotion.model.pagination.ResultPage; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
public class NotionApiTest { | ||
|
||
private final NotionTable notionTable = new NotionTable(); | ||
private final BlockingNotionClient client = notionTable.initClient(); | ||
|
||
@Test | ||
public void getTable() { | ||
//given | ||
|
||
//when | ||
Database database = client.getDatabases().getDatabase(notionTable.getDATABASE_ID()); | ||
ResultPage<Page> simpleQueryResultPage = client.getDatabases().queryDatabase( | ||
notionTable.getDATABASE_ID(), | ||
null, | ||
null, | ||
new Pagination() | ||
); | ||
|
||
//then | ||
// System.out.println("simpleQueryResultPage = " + simpleQueryResultPage.results); | ||
assertThat(database.getTitle().getPlainText()).isEqualTo(notionTable.getTableName()); | ||
assertThat(simpleQueryResultPage.results.size()).isEqualTo(notionTable.getMemberNum()); | ||
} | ||
|
||
@Test | ||
public void getRowByEmail() { | ||
//given | ||
String name = "가나다"; | ||
String role = "Core"; | ||
String email = "[email protected]"; | ||
|
||
//when | ||
ResultPage<Page> simpleQueryResultPage = client.getDatabases().queryDatabase( | ||
notionTable.getDATABASE_ID(), | ||
new DatabaseQuery() | ||
.any( | ||
new DatabaseQueryPropertyFilter.Text( | ||
"이메일", | ||
new DatabaseQueryPredicate.Text.Equals(email) | ||
) | ||
), | ||
null, | ||
new Pagination() | ||
); | ||
|
||
//then | ||
assertThat(simpleQueryResultPage.results.size()).isEqualTo(1); | ||
// System.out.println("simpleQueryResultPage = " + simpleQueryResultPage.results.get(0).getPropertyValues()); | ||
assertThat(simpleQueryResultPage.results.get(0).getPropertyValues().toString().contains(email)).isEqualTo(true); | ||
assertThat(simpleQueryResultPage.results.get(0).getPropertyValues().toString().contains(role)).isEqualTo(true); | ||
assertThat(simpleQueryResultPage.results.get(0).getPropertyValues().toString().contains(name)).isEqualTo(true); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/test/java/com/gdscpknu/gdscpknu/notion/NotionTable.java
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.gdscpknu.gdscpknu.notion; | ||
|
||
import org.jraf.klibnotion.client.*; | ||
import org.jraf.klibnotion.client.blocking.BlockingNotionClient; | ||
import org.jraf.klibnotion.client.blocking.BlockingNotionClientUtils; | ||
|
||
public class NotionTable { | ||
|
||
private final String TOKEN = ""; | ||
private final String DATABASE_ID = ""; | ||
private final String tableName = "MEMBER PROFILE"; | ||
private final int memberNum = 3; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. memberNum은 회원 수를 말하는 거죠?? 테스트 용으로 임의로 3명으로 지정해 놓은 변수로 이해하면 될까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네넵 맞습니다! |
||
|
||
public BlockingNotionClient initClient() { | ||
NotionClient notionClient = NotionClient.newInstance( | ||
new ClientConfiguration( | ||
new Authentication(TOKEN) | ||
) | ||
); | ||
return BlockingNotionClientUtils.asBlockingNotionClient(notionClient); | ||
} | ||
|
||
public String getDATABASE_ID() { | ||
return DATABASE_ID; | ||
} | ||
|
||
public String getTableName() { | ||
return tableName; | ||
} | ||
|
||
public int getMemberNum() { | ||
return memberNum; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
equals 써서 바로 string 비교할 수도 있지 않나요? 호옥시 contains.equals(true)로 한 이유가 있을까요?? 저도 잘 몰라서 질문 드려용
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
simpleQueryResultPage.results.get(0).getPropertyValues()
-> 이렇게 하면 사용자 이름, 이메일, 역할에 관한 정보가 들어가 있긴 한데
bold=false, italic=false, strikethrough=false, underline=false 이런 정보들도 같이 나와서 contains 사용했습니다.
simpleQueryResultPage.results.get(0).getPropertyValues().get(0).getValue()
-> 하면 이메일 정보만 따로 나오긴 하는데 여기에도 다른 정보들도 같이 나와서 일단 저렇게 작성해뒀습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
실제 사용하는 과정에서는 파싱해서 email, name, role만 따로 가져올 필요가 있겠네요.
답변 감사합니다!