Skip to content

Commit

Permalink
Update repo viewing from an external context; update test cases (issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sahan committed Sep 22, 2013
1 parent d5dba1f commit 73c7306
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,28 @@
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;

import android.app.Activity;
import android.content.Intent;

import com.lonepulse.travisjr.BuildsActivity;
import com.lonepulse.travisjr.R;
import com.lonepulse.travisjr.ReposActivity;
import com.lonepulse.travisjr.model.GitHubUser;
import com.lonepulse.travisjr.model.Repo;
import com.lonepulse.travisjr.service.AccountService;
import com.lonepulse.travisjr.service.BasicAccountService;
import com.lonepulse.travisjr.service.BasicRepoService;
import com.lonepulse.travisjr.service.RepoService;
import com.lonepulse.travisjr.util.Resources;

/**
* <p>Unit test for {@link BasicRepoService}.
*
* @category test
* <br><br>
* @version 1.1.0
* @version 1.2.0
* <br><br>
* @since 1.1.0
* <br><br>
* @author <a href="mailto:lahiru@lonepulse.com">Lahiru Sahan Jayasinghe</a>
*/
Expand All @@ -58,8 +68,7 @@ public class RepoServiceTest {


/**
* <p>The instance of {@link BasicRepoService} on which the
* unit tests are exercised.
* <p>The instance of {@link BasicRepoService} on which the unit tests are exercised.</p>
*/
private RepoService repoService;

Expand All @@ -83,7 +92,7 @@ public final void setUp() throws Exception {
}

/**
* <p>Test for {@link RepoService#getReposByMember()}.
* <p>Test for {@link RepoService#getReposByMember()}.</p>
*
* @throws Exception
* if test terminated with an error
Expand Down Expand Up @@ -115,7 +124,7 @@ public List<Repo> call() throws Exception {
}

/**
* <p>Test for {@link RepoService#getReposByOwner()}.
* <p>Test for {@link RepoService#getReposByOwner()}.</p>
*
* @throws Exception
* if test terminated with an error
Expand Down Expand Up @@ -147,7 +156,7 @@ public List<Repo> call() throws Exception {
}

/**
* <p>Test for {@link RepoService#filterCreatedRepos(List)}.
* <p>Test for {@link RepoService#filterCreatedRepos(List)}.</p>
*
* @throws Exception
* if test terminated with an error
Expand Down Expand Up @@ -186,7 +195,7 @@ public List<Repo> call() throws Exception {
}

/**
* <p>Test for {@link RepoService#filterContributedRepos(List)}.
* <p>Test for {@link RepoService#filterContributedRepos(List)}.</p>
*
* @throws Exception
* if test terminated with an error
Expand Down Expand Up @@ -225,7 +234,7 @@ public List<Repo> call() throws Exception {
}

/**
* <p>Test for {@link RepoService#findRepoByName(String, List)}.
* <p>Test for {@link RepoService#findRepoByName(String, List)}.</p>
*
* @throws Exception
* if test terminated with an error
Expand Down Expand Up @@ -255,7 +264,7 @@ public List<Repo> call() throws Exception {
}

/**
* <p>Test for {@link RepoService#getReposByMember(String)}.
* <p>Test for {@link RepoService#getReposByMember(String)}.</p>
*
* @throws Exception
* if test terminated with an error
Expand Down Expand Up @@ -284,7 +293,7 @@ public List<Repo> call() throws Exception {
}

/**
* <p>Test for {@link RepoService#getReposByOwner(String)}.
* <p>Test for {@link RepoService#getReposByOwner(String)}.</p>
*
* @throws Exception
* if test terminated with an error
Expand Down Expand Up @@ -313,7 +322,46 @@ public List<Repo> call() throws Exception {
}

/**
* <p>Tears down the test case by shutting down the {@link #executorService}.
* <p>Test for {@link RepoService#getRepos(android.app.Activity)}.</p>
*
* @throws Exception
* if test terminated with an error
*
* @since 1.1.0
*/
@Test
public final void testTransientRepoSync() throws Exception {

Robolectric.getFakeHttpLayer().interceptHttpRequests(false);

final Activity activity = Robolectric.buildActivity(ReposActivity.class).get();

GitHubUser user = new GitHubUser();
user.setId("1111");
user.setLogin("mozilla");
user.setType("Organization");

Intent intent = new Intent(activity, BuildsActivity.class);
intent.putExtra(Resources.key(R.string.key_transient_user), user);

activity.setIntent(intent);

Future<List<Repo>> future = executorService.submit(new Callable<List<Repo>>() {

public List<Repo> call() throws Exception {

return repoService.getRepos(activity);
}
});

List<Repo> repos = future.get();

assertNotNull(repos);
assertTrue(repos.size() > 0);
}

/**
* <p>Tears down the test case by shutting down the {@link #executorService}.</p>
*
* @throws java.lang.Exception
* if the tear-down failed
Expand Down
Binary file modified travisjr/res/drawable/ic_actionbar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions travisjr/res/values/errors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
<string name="err_fetching_build_info">Failed to fetch info...</string>
<string name="err_github_not_found">Not Found</string>
<string name="err_settings_unavailable_transient">Transient users cannot configure settings</string>
<string name="err_uri_resolution_failure">I can\'t seem to get any information from travis-ci.org</string>

</resources>
2 changes: 2 additions & 0 deletions travisjr/res/values/labels.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<string name="lbl_no_cc">No</string>
<string name="lbl_yes_uc">YES</string>
<string name="lbl_no_uc">NO</string>
<string name="lbl_oops">Oops!</string>
<string name="lbl_return_uc">RETURN</string>
<string name="lbl_sign_in">Sign in with GitHub.</string>
<string name="lbl_seconds">&#160;sec</string>
<string name="lbl_tap_to_configure">(Tap To Configure)</string>
Expand Down
4 changes: 2 additions & 2 deletions travisjr/res/values/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
<resources>

<string name="app_name">Travis Jr.</string>
<string name="version">0.1.1 (beta)</string>
<string name="version">0.2.0 (beta)</string>
<string name="app_url">https://github.com/sahan/Travis-Jr</string>
<string name="license_apache_v2">Apache License, Version 2.0</string>
<string name="license_mit">The MIT License</string>
<string name="license_cpl_v1">Common Public License, Version 1.0</string>
<string name="author">github.com/sahan</string>
<string name="author_url">https://github.com/sahan</string>
<string name="not_available">N/A</string>
<string name="not_available">N.A.</string>
<string name="conf_clear_account">are you sure you want to purge your account?</string>
<string name="sum_pref_sign_out">Clear all credentials, delete any saved data and sign out from your account.</string>
<string name="sum_pref_oss_licenses">Licenses for all open source libraries used in development and testing.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public class BuildInfoActivity extends TravisJrActivity {
private BuildInfo buildInfo;

@Stateful
NavigableMap<String, StringBuilder> logs;
private NavigableMap<String, StringBuilder> logs;

@InjectView(R.id.root)
private View root;
Expand Down Expand Up @@ -201,6 +201,8 @@ protected void onCreate(Bundle savedInstanceState) {

runUITask(UI_SYNC);

logs = new TreeMap<String, StringBuilder>();

ownerName = getIntent().getStringExtra(EXTRA_OWNER_NAME);
repoName = getIntent().getStringExtra(EXTRA_REPO_NAME);
buildId = getIntent().getLongExtra(EXTRA_BUILD_ID, 0);
Expand Down Expand Up @@ -250,8 +252,6 @@ private void fetchBuildInfo() {
buildInfo = buildService.getBuildInfo(ownerName, repoName, buildId);
Set<Entry<BuildJob, StringBuilder>> logEntries = buildService.getJobLogs(buildInfo).entrySet();

logs = new TreeMap<String, StringBuilder>();

for (Entry<BuildJob, StringBuilder> entry : logEntries) {

logs.put(String.valueOf(entry.getKey().getNumber()), entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import com.lonepulse.travisjr.app.TravisJrActivity;
import com.lonepulse.travisjr.model.Repo;
import com.lonepulse.travisjr.service.AccountService;
import com.lonepulse.travisjr.service.IntentFilterService;
import com.lonepulse.travisjr.service.RepoAccessException;
import com.lonepulse.travisjr.service.RepoService;
import com.lonepulse.travisjr.service.UserMode;
Expand Down Expand Up @@ -99,9 +98,6 @@ public class ReposActivity extends TravisJrActivity {
@InjectPojo
private AccountService accountService;

@InjectPojo
private IntentFilterService intentFilterService;

@Stateful
private List<Repo> repos;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@

import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand Down Expand Up @@ -127,25 +128,6 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

accountService = new BasicAccountService();

if(this instanceof ReposActivity) {

Uri uri = getIntent().getData();

if(uri != null) {

try {

GitHubUser user = new BasicIntentFilterService().resolveUser(uri);
getIntent().putExtra(Resources.key(R.string.key_transient_user), user);
}
catch(Exception e) {

Log.e(getClass().getName(), "Failed to resolve a user from the given Uri", e);
}
}
}

network = new NetworkService(this);

actionViewSync = getLayoutInflater().inflate(R.layout.action_view_sync, null);
Expand Down Expand Up @@ -174,6 +156,45 @@ public void onAnimationEnd(Animation animation) {
onInitActionBar(getActionBar());
}

@Override
protected void onPostCreate(Bundle savedInstanceState) {

super.onPostCreate(savedInstanceState);

if(this instanceof ReposActivity) {

Uri uri = getIntent().getData();

if(uri != null) {

try {

GitHubUser user = new BasicIntentFilterService().resolveUser(uri);
((TextView)getActionBar().getCustomView().findViewById(R.id.subtitle)).setText(user.getLogin());

getIntent().putExtra(Resources.key(R.string.key_transient_user), user);
}
catch(Exception e) {

new AlertDialog.Builder(this)
.setTitle(getResources().getString(R.string.lbl_oops))
.setMessage(new StringBuilder(getResources().getString(
R.string.err_uri_resolution_failure)).append(uri.getPath()))
.setPositiveButton(getResources().getString(R.string.lbl_return_uc),
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {

finish();
}
})
.create().show();
}
}
}
}

/**
* <p>Override this callback to initialize the {@link ActionBar} associated
* with this {@link Activity}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,25 @@
import android.content.Context;

import com.lonepulse.icklebot.annotation.inject.Pojo;
import com.lonepulse.travisjr.AuthenticationActivity;
import com.lonepulse.travisjr.model.GitHubUser;
import com.lonepulse.travisjr.view.MissingViewException;

/**
* <p>This contract specifies the services offered for managing the
* user's account.
* user's account.</p>
*
* @since 1.1.0
* <br><br>
* @version 1.1.1
* <br><br>
* @since 1.1.0
* <br><br>
* @author <a href="mailto:sahan@lonepulse.com">Lahiru Sahan Jayasinghe</a>
*/
@Pojo(BasicAccountService.class)
public interface AccountService {

/**
* <p>Retrieves the saved GitHub username from the user credentials.
* <p>Retrieves the saved GitHub username from the user credentials.</p>
*
* @return the saved GitHub username
*
Expand All @@ -54,7 +55,7 @@ public interface AccountService {
String getGitHubUsername() throws MissingCredentialsException;

/**
* <p>Saves the given GitHub username in the user credentials.
* <p>Saves the given GitHub username in the user credentials.</p>
*
* @param username
* the username to save in credentials
Expand All @@ -65,7 +66,7 @@ public interface AccountService {

/**
* <p>If there is a transient {@link GitHubUser} in the given context, the associated
* username is retrieved; else retrieves the username from the user credentials.
* username is retrieved; else retrieves the username from the user credentials.</p>
*
* @param activity
* the {@link Activity} {@link Context} to look for a transient {@link GitHubUser}
Expand All @@ -81,7 +82,7 @@ public interface AccountService {
String getGitHubUsername(Activity activity) throws MissingCredentialsException;

/**
* <p>Indicates whether the user is to be treated as a member or an organization.
* <p>Indicates whether the user is to be treated as a member or an organization.</p>
*
* @return the {@link UserMode} associated with the current user; else
* {@link UserMode#ORGANIZATION} if the user mode failed to be determined
Expand All @@ -102,7 +103,7 @@ public interface AccountService {

/**
* <p>If there is a {@link GitHubUser} in the given context, the associated {@link UserMode}
* is retrieved; else retrieves the {@link UserMode} in the saved credentials.
* is retrieved; else retrieves the {@link UserMode} in the saved credentials.</p>
*
* @param activity
* the {@link Activity} {@link Context} to look for a transient {@link GitHubUser}
Expand All @@ -116,7 +117,7 @@ public interface AccountService {
UserMode getUserMode(Activity activity);

/**
* <p>Retrieves the GitHub username which was saved in the account created by the official GitHub app.
* <p>Retrieves the GitHub username which was saved in the account created by the official GitHub app.</p>
*
* @return the username linked to the official GitHub application
*
Expand All @@ -130,7 +131,7 @@ public interface AccountService {

/**
* <p>Indicates whether the user had already setup account credentials. This can be used before
* {@link #getGitHubUsername()} to circumvent a {@link MissingViewException}.
* {@link #getGitHubUsername()} to circumvent a {@link MissingViewException}.</p>
*
* @return {@code true} if credentials are already saved
*
Expand Down

0 comments on commit 73c7306

Please sign in to comment.