mirror of
https://github.com/jlengrand/github-api.git
synced 2026-04-05 08:21:21 +00:00
Add offline support to the API to make parsing events easier
- When we receive events from a webhook, it is non-trivial to determine which GitHub instance the event came from or for that matter even if the event actually came from GitHub or GitHub Enterprise. - In order to ensure that the logic for parsing events does not get replicated in clients, we need to be able to call GitHub.parseEventPayload(Reader,Class) without knowing which GitHub the event originates from and without the resulting objects triggering API calls back to a GitHub - Thus we add GitHub.offline() to provide an off-line connection - Thus we modify some of the object classes to return best-effort objects when off-line - Add support for more of the event types into GHEventPayload - Add tests of the event payload and accessing critical fields when using GitHub.offline()
This commit is contained in:
@@ -13,6 +13,7 @@ import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -20,6 +21,19 @@ import static org.mockito.Mockito.when;
|
||||
* Unit test for {@link GitHub}.
|
||||
*/
|
||||
public class GitHubTest {
|
||||
@Test
|
||||
public void testOffline() throws Exception {
|
||||
GitHub hub = GitHub.offline();
|
||||
assertEquals("https://api.github.invalid/test", hub.getApiURL("/test").toString());
|
||||
assertTrue(hub.isAnonymous());
|
||||
try {
|
||||
hub.getRateLimit();
|
||||
fail("Offline instance should always fail");
|
||||
} catch (IOException e) {
|
||||
assertEquals("Offline", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGitHubServerWithHttp() throws Exception {
|
||||
GitHub hub = GitHub.connectToEnterprise("http://enterprise.kohsuke.org/api/v3", "bogus","bogus");
|
||||
|
||||
Reference in New Issue
Block a user