Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jcabi/jcabi-github
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed Jan 28, 2015
2 parents 061aa28 + c81d8f4 commit 588d31a
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 13 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,21 @@ $ mvn clean install -Pqulice

There are many integration tests that check our classes against
live Github accounts. In order to run them, you should create
a new Github OAuth access token
a new Github OAuth access tokens
([how?](https://help.github.com/articles/creating-an-access-token-for-command-line-use)),
and provide it in command line, like this:
and provide them in command line, like this:

```
$ mvn clean install -Dit.test=RtGistITCase -Dfailsafe.github.key=<token> -Dfailsafe.github.repo=<repo>
$ mvn clean install -Dit.test=RtGistITCase -Dfailsafe.github.key=<token> -Dfailsafe.github.key.second=<second-token> -Dfailsafe.github.repo=<repo>
```

Replace `<token>` with the OAuth access token, and `<repo>` with the name of
repository you create in your account (for test purposes only), for example `yegor256/test`.
The `failsafe.github.key` should have permissions in `failsafe.github.repo` to all scopes needed
by the integration test suite you want to run (including `delete_repo`, which is not set by default!).
Replace `<token>` and `<second-token>` with the OAuth access tokens of two different Github
accounts. This test case will try to fork a gist from first account into second. Replace
`<repo>` with the name of repository you create in your first account (for test purposes
only), for example `yegor256/test`. OAuth access tokens should have permissions in their
respective repos to all scopes needed by the integration test suite you want to run
(including `delete_repo`, which is not set by default!).
Incorrect documentation - example integration test run script #976
Please note that different integration tests may need keys with permissions to different
[scopes](https://developer.github.com/v3/oauth/#scopes);
the `RtGistITCase` test requires permissions to gist scope.
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/com/jcabi/github/mock/MkRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@
import com.jcabi.github.Releases;
import com.jcabi.github.Repo;
import com.jcabi.github.RepoCommits;
import com.jcabi.github.RtLanguage;
import com.jcabi.github.Stars;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.json.JsonObject;
import javax.validation.constraints.NotNull;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.lang3.NotImplementedException;

/**
* Mock Github repo.
Expand All @@ -65,14 +67,12 @@
* @since 0.5
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
* @checkstyle ClassFanOutComplexity (500 lines)
* @todo #923 Implement languages() method.
* Don't forget about unit tests.
*/
@Immutable
@Loggable(Loggable.DEBUG)
@ToString
@EqualsAndHashCode(of = {"storage", "self", "coords" })
@SuppressWarnings("PMD.TooManyMethods")
@SuppressWarnings({"PMD.TooManyMethods", "PMD.ExcessiveImports" })
final class MkRepo implements Repo {

/**
Expand Down Expand Up @@ -281,7 +281,14 @@ public Notifications notifications() {

@Override
public Iterable<Language> languages() {
throw new NotImplementedException("MkRepo#languages");
final List<Language> languages = new ArrayList<Language>(0);
final int java = 999;
languages.add(new RtLanguage("Java", java));
final int php = 888;
languages.add(new RtLanguage("PHP", php));
final int ruby = 777;
languages.add(new RtLanguage("Ruby", ruby));
return languages;
}

@Override
Expand Down
65 changes: 64 additions & 1 deletion src/test/java/com/jcabi/github/RtContentsITCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assume;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;

Expand All @@ -45,7 +46,7 @@
* @author Andres Candal ([email protected])
* @version $Id$
* @since 0.8
* @checkstyle MultipleStringLiterals (300 lines)
* @checkstyle MultipleStringLiterals (500 lines)
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public final class RtContentsITCase {
Expand Down Expand Up @@ -256,6 +257,68 @@ public void getContent() throws Exception {
}
}

/**
* RtContents can iterate content.
* @throws Exception If some problem inside
* @todo #863 unignore after Contents#get is implemented for
* directories (#968 and #903)
*/
@Test
@Ignore
public void iteratesContent() throws Exception {
final Repos repos = github().repos();
final Repo repo = this.rule.repo(repos);
try {
final String afile = RandomStringUtils.randomAlphanumeric(Tv.TEN);
final String dir = RandomStringUtils.randomAlphanumeric(Tv.TEN);
final String bfile = String.format(
"%s/%s",
dir,
RandomStringUtils.randomAlphanumeric(Tv.TEN)
);
final String message = String.format("testMessage");
final Contents contents = repos.get(repo.coordinates()).contents();
contents.create(
this.jsonObject(
afile,
new String(
Base64.encodeBase64(
String.format(
"content a:%d",
System.currentTimeMillis()
).getBytes()
)
),
message
)
);
contents.create(
this.jsonObject(
bfile,
new String(
Base64.encodeBase64(
String.format(
"content b:%d",
System.currentTimeMillis()
).getBytes()
)
),
message
)
);
final Iterable<Content> iterated = contents.iterate("", "master");
MatcherAssert.assertThat(
iterated,
Matchers.allOf(
Matchers.hasItems(contents.get(afile), contents.get(dir)),
Matchers.<Content>iterableWithSize(Tv.THREE)
)
);
} finally {
repos.remove(repo.coordinates());
}
}

/**
* RtContents can check whether content exists or not.
* @throws Exception if any problem inside.
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/com/jcabi/github/mock/MkRepoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
*/
package com.jcabi.github.mock;

import com.google.common.collect.Lists;
import com.jcabi.aspects.Tv;
import com.jcabi.github.Coordinates;
import com.jcabi.github.Language;
import com.jcabi.github.Milestones;
import com.jcabi.github.Repo;
import com.jcabi.github.Repos;
Expand Down Expand Up @@ -139,4 +142,24 @@ public void fetchNotifications() throws IOException {
);
MatcherAssert.assertThat(repo.notifications(), Matchers.notNullValue());
}

/**
* Repo can return Languages iterable.
* @throws IOException if some problem inside
*/
@Test
public void fetchLanguages() throws IOException {
final String user = "testuser4";
final Repo repo = new MkRepo(
new MkStorage.InFile(),
user,
new Coordinates.Simple(user, "testrepo4")
);
final Iterable<Language> languages = repo.languages();
MatcherAssert.assertThat(languages, Matchers.notNullValue());
MatcherAssert.assertThat(
Lists.newArrayList(languages),
Matchers.hasSize(Tv.THREE)
);
}
}

0 comments on commit 588d31a

Please sign in to comment.