/*
* Copyright 2009 David Linsin
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.linsin.github.rest.service;
import java.util.List;
import de.linsin.github.rest.domain.Comment;
import de.linsin.github.rest.domain.Issue;
import de.linsin.github.rest.domain.Repository;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.web.client.HttpClientErrorException;
/**
* Testing {@link IssueBrowserIntegration}
*
* @author David Linsin - [email protected]
*/
public class IssueBrowserIntegrationTest {
private IssueBrowser classUnderTest;
private String username;
private String invalidUsername;
private String repoName;
private String noGoodRepoName;
private String noIssuesRepoName;
@Before
public void setUp() {
username = "dlinsin";
invalidUsername = "dlinsin3805";
repoName = "area51";
noGoodRepoName = "blaha232";
noIssuesRepoName = "synoccer";
classUnderTest = new IssueBrowser(username, System.getProperty("apiToken"));
}
@Test
public void browse_open() {
Repository repo = setupTestRepo();
List<Issue> issues = classUnderTest.browseOpen(repo);
assertFalse(issues.isEmpty());
assertEquals(Issue.State.open.name(), issues.get(0).getState());
}
private Repository setupTestRepo() {
Repository repo = new Repository();
repo.setOwner(username);
repo.setName(repoName);
return repo;
}
@Test
public void browse_open_no_issues() {
Repository repo = new Repository();
repo.setOwner(username);
repo.setName(noIssuesRepoName);
List<Issue> issues = classUnderTest.browseOpen(repo);
assertTrue(issues.isEmpty());
}
@Test(expected = HttpClientErrorException.class)
public void browse_open_invalid_user() {
Repository repo = new Repository();
repo.setOwner(invalidUsername);
repo.setName(noIssuesRepoName);
classUnderTest.browseOpen(repo);
}
@Test(expected = HttpClientErrorException.class)
public void browse_open_invalid_repo() {
Repository repo = new Repository();
repo.setOwner(username);
repo.setName(noGoodRepoName);
classUnderTest.browseOpen(repo);
}
@Test
public void browse_closed() {
Repository repo = setupTestRepo();
List<Issue> issues = classUnderTest.browseClosed(repo);
assertFalse(issues.isEmpty());
assertEquals(Issue.State.closed.name(), issues.get(0).getState());
}
@Test
public void browse_closed_no_issues() {
Repository repo = new Repository();
repo.setOwner(username);
repo.setName(noIssuesRepoName);
List<Issue> issues = classUnderTest.browseClosed(repo);
assertTrue(issues.isEmpty());
}
@Test(expected = HttpClientErrorException.class)
public void browse_closed_invalid_user() {
Repository repo = new Repository();
repo.setOwner(invalidUsername);
repo.setName(noIssuesRepoName);
classUnderTest.browseClosed(repo);
}
@Test(expected = HttpClientErrorException.class)
public void browse_closed_invalid_repo() {
Repository repo = new Repository();
repo.setOwner(username);
repo.setName(noGoodRepoName);
classUnderTest.browseClosed(repo);
}
@Test
public void browse_issue() {
Repository repo = setupTestRepo();
Issue issue = classUnderTest.browse(repo, 1);
assertNotNull(issue);
assertTrue(issue.getNumber() == 1);
}
@Test(expected = HttpClientErrorException.class)
public void browse_none_existing_issue() {
Repository repo = setupTestRepo();
classUnderTest.browse(repo, 1024);
}
@Test(expected = HttpClientErrorException.class)
public void browse_invalid_user() {
Repository repo = new Repository();
repo.setOwner(invalidUsername);
repo.setName(repoName);
classUnderTest.browse(repo, 1);
}
@Test(expected = HttpClientErrorException.class)
public void browse_invalid_repo() {
Repository repo = new Repository();
repo.setOwner(username);
repo.setName(noGoodRepoName);
classUnderTest.browse(repo, 1024);
}
@Test
public void open_issue() {
Repository repo = setupTestRepo();
Issue newIssue = new Issue();
String title = "Issue " + System.currentTimeMillis();
newIssue.setTitle(title);
String body = "my test issue";
newIssue.setBody(body);
Issue ret = classUnderTest.open(repo, newIssue);
assertEquals(title, ret.getTitle());
assertEquals(body, ret.getBody());
assertTrue(ret.getNumber() > 0);
}
@Test(expected = HttpClientErrorException.class)
public void open_issue_invalid_user() {
Repository repo = setupTestRepo();
repo.setOwner(invalidUsername);
Issue newIssue = new Issue();
String title = "Issue " + System.currentTimeMillis();
newIssue.setTitle(title);
String body = "my test issue";
newIssue.setBody(body);
classUnderTest.open(repo, newIssue);
}
@Test(expected = HttpClientErrorException.class)
public void open_issue_invalid_repo() {
Repository repo = setupTestRepo();
repo.setName(noGoodRepoName);
Issue newIssue = new Issue();
String title = "Issue " + System.currentTimeMillis();
newIssue.setTitle(title);
String body = "my test issue";
newIssue.setBody(body);
classUnderTest.open(repo, newIssue);
}
@Test(expected = HttpClientErrorException.class)
public void open_issue_not_authorized() {
classUnderTest = new IssueBrowser(username, "123");
Repository repo = setupTestRepo();
Issue newIssue = new Issue();
String title = "Issue " + System.currentTimeMillis();
newIssue.setTitle(title);
String body = "my test issue";
newIssue.setBody(body);
classUnderTest.open(repo, newIssue);
}
@Test
public void close_issue() {
Repository repo = setupTestRepo();
Issue issue = setUpTestIssue(repo);
classUnderTest.close(repo, issue);
assertTrue(classUnderTest.browseClosed(repo).contains(issue));
}
@Test
public void close_issue_invalid_user() {
Repository repo = setupTestRepo();
Issue issue = setUpTestIssue(repo);
repo.setOwner(invalidUsername);
try {
classUnderTest.close(repo, issue);
fail("expected exception");
} catch (HttpClientErrorException e) {
assertTrue(classUnderTest.browseOpen(setupTestRepo()).contains(issue));
}
}
@Test
public void close_issue_invalid_repo() {
Repository repo = setupTestRepo();
Issue issue = setUpTestIssue(repo);
repo.setName(noGoodRepoName);
try {
classUnderTest.close(repo, issue);
fail("expected exception");
} catch (HttpClientErrorException e) {
assertTrue(classUnderTest.browseOpen(setupTestRepo()).contains(issue));
}
}
@Test
public void close_issue_invalid_number() {
Repository repo = setupTestRepo();
Issue issue = setUpTestIssue(repo);
Issue newIssue = new Issue();
没有合适的资源?快使用搜索试试~ 我知道了~
小程序 github-java-api(源码).zip
共21个文件
java:20个
xml:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 12 浏览量
2023-02-03
13:24:36
上传
评论
收藏 28KB ZIP 举报
温馨提示
免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累成果,供大家学习参考与交流。收取的费用仅用于收集和整理资料耗费时间的酬劳。 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,本人不对所涉及的版权问题或内容负法律责任。如有侵权,请举报或通知本人删除。
资源推荐
资源详情
资源评论
收起资源包目录
小程序 github-java-api(源码).zip (21个子文件)
dlinsin-github-java-api-5f7e387
pom.xml 2KB
src
test
java
de
linsin
github
rest
IntegrationTestSuit.java 1KB
UnitTestSuit.java 1KB
service
RepositoryBrowserIntegrationTest.java 2KB
RepositoryBrowserTest.java 4KB
IssueBrowserTest.java 13KB
IssueBrowserIntegrationTest.java 13KB
main
java
de
linsin
github
rest
resource
CommentIssueResponse.java 1KB
IssueResponse.java 1KB
CommentIssueRequest.java 1KB
RepositoriesResponse.java 1KB
IssueRequest.java 1KB
RepositoryResponse.java 1KB
Request.java 1KB
IssuesResponse.java 1KB
service
Browser.java 2KB
IssueBrowser.java 11KB
RepositoryBrowser.java 3KB
domain
Comment.java 2KB
Repository.java 4KB
Issue.java 5KB
共 21 条
- 1
资源评论
大富大贵7
- 粉丝: 317
- 资源: 8869
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功