Skip to content

Commit

Permalink
Issue photo#459 (Card 7) (Multi-site login)
Browse files Browse the repository at this point in the history
app:
- Credentials: renamed mServer field to mHost. Added getHost method and
changed internals of getServer method.
- Credentials: removed setters for fields
- LoginUtils.SelectAccountDialogFragment: replaced emails with host in
the select account dialog
test:
- CredentialsTest: added checkCredentialsV2 method
- AccountTroveboxResponseTest: added testMultiResponseV2 test
- res/raw/json_login_multiple_v2.txt: added
  • Loading branch information
httpdispatch committed Oct 10, 2013
1 parent 69066ea commit c35fa49
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 33 deletions.
36 changes: 8 additions & 28 deletions app/src/com/trovebox/android/app/model/Credentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @author Eugene Popovich
*/
public class Credentials implements Parcelable {
private String mServer;
private String mHost;
private String mOAuthConsumerKey;
private String mOAuthConsumerSecret;
private String mOAuthToken;
Expand All @@ -27,62 +27,42 @@ private Credentials() {
}

public Credentials(JSONObject json) throws JSONException {
mServer = "http://" + json.getString("host");
mHost = json.getString("host");
mOAuthConsumerKey = json.getString("id");
mOAuthConsumerSecret = json.getString("clientSecret");
mOAuthToken = json.getString("userToken");
mOAuthTokenSecret = json.getString("userSecret");
mEmail = json.getString("owner");
}

public String getServer() {
return mServer;
public String getHost() {
return mHost;
}

public void setServer(String server) {
this.mServer = server;
public String getServer() {
return "http://" + mHost;
}

public String getoAuthConsumerKey() {
return mOAuthConsumerKey;
}

public void setoAuthConsumerKey(String oAuthConsumerKey) {
this.mOAuthConsumerKey = oAuthConsumerKey;
}

public String getoAuthConsumerSecret() {
return mOAuthConsumerSecret;
}

public void setoAuthConsumerSecret(String oAuthConsumerSecret) {
this.mOAuthConsumerSecret = oAuthConsumerSecret;
}

public String getoAuthToken() {
return mOAuthToken;
}

public void setoAuthToken(String oAuthToken) {
this.mOAuthToken = oAuthToken;
}

public String getoAuthTokenSecret() {
return mOAuthTokenSecret;
}

public void setoAuthTokenSecret(String oAuthTokenSecret) {
this.mOAuthTokenSecret = oAuthTokenSecret;
}

public String getEmail() {
return mEmail;
}

public void setEmail(String email) {
this.mEmail = email;
}

public void saveCredentials(Context context) {
Preferences.setServer(context, this.getServer());

Expand Down Expand Up @@ -113,7 +93,7 @@ public int describeContents() {

@Override
public void writeToParcel(Parcel out, int flags) {
out.writeString(mServer);
out.writeString(mHost);
out.writeString(mEmail);
out.writeString(mOAuthConsumerKey);
out.writeString(mOAuthConsumerSecret);
Expand All @@ -135,7 +115,7 @@ public Credentials[] newArray(int size) {

private Credentials(Parcel in) {
this();
mServer = in.readString();
mHost = in.readString();
mEmail = in.readString();
mOAuthConsumerKey = in.readString();
mOAuthConsumerSecret = in.readString();
Expand Down
2 changes: 1 addition & 1 deletion app/src/com/trovebox/android/app/util/LoginUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {

final String[] items = new String[handler.getItems().length];
for (int i = 0; i < items.length; i++) {
items[i] = handler.getItems()[i].getEmail();
items[i] = handler.getItems()[i].getHost();
}

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
Expand Down
126 changes: 126 additions & 0 deletions test/res/raw/json_login_multiple_v2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{
"message":"User logged in successfully.",
"code":200,
"result":[
{
"_owner":"[email protected]",
"_type":"owner",
"host":"test.trovebox.com",
"id":"102230629a6802fbca9825a4617bfe",
"owner":"[email protected]",
"actor":"[email protected]",
"name":"Jaisen's Phone",
"clientSecret":"0f5d654bca",
"userToken":"b662440d621f2f71352f8865888fe2",
"userSecret":"6d1e8fc274",
"type":"access",
"status":"1",
"dateCreated":1381190570,
"profile":{
"id":"test.trovebox.com",
"photoUrl":"http:\/\/d1odebs29o9vbg.cloudfront.net\/custom\/196912\/27005_original-526fb8_100x100xCR.jpg",
"counts":{
"photos":397,
"albums":27,
"tags":141,
"storage":316116992,
"storage_str":"316116992"
},
"name":"Trovebox Test Name",
"limit":{
"allowed":100,
"remaining":2147483647,
"resetsOn":1383289200,
"resetsInDays":25
},
"paid":true,
"email":"[email protected]",
"isOwner":true,
"permission":{
"C":true,
"R":true,
"U":true,
"D":true
}
}
},
{
"_owner":"[email protected]",
"_type":"admin",
"host":"test2.trovebox.com",
"id":"102230629a6802fbca9825a4617bfe",
"owner":"[email protected]",
"actor":"[email protected]",
"name":"Jaisen's Phone",
"clientSecret":"0f5d654bca",
"userToken":"b662440d621f2f71352f8865888fe2",
"userSecret":"6d1e8fc274",
"type":"access",
"status":"1",
"dateCreated":1381190570,
"profile":{
"id":"test2.trovebox.com",
"photoUrl":"http:\/\/www.gravatar.com\/avatar\/98d3a0767a868b52f7e320340d35bc45?s=100&d=http%2F%2Fdm5ing2l7y91e.cloudfront.net%2Fassets%2Fthemes%2Ffabrizio1.0%2Fimages%2Fprofile-default.png",
"counts":{
"photos":55,
"albums":5,
"tags":20,
"storage":121390080,
"storage_str":"121390080"
},
"name":"Trovebox User",
"limit":{
"allowed":100,
"remaining":2147483647,
"resetsOn":1383289200,
"resetsInDays":25
},
"paid":true,
"email":"[email protected]",
"isOwner":true,
"permission":{
"C":true,
"R":true,
"U":true,
"D":true
}
}
},
{
"_owner":"[email protected]",
"_type":"group",
"host":"test3.trovebox.com",
"id":"102230629a6802fbca9825a4617bfe",
"owner":"[email protected]",
"actor":"[email protected]",
"name":"Jaisen's Phone",
"clientSecret":"0f5d654bca",
"userToken":"b662440d621f2f71352f8865888fe2",
"userSecret":"6d1e8fc274",
"type":"access",
"status":"1",
"dateCreated":1381190570,
"profile":{
"id":"test3.trovebox.com",
"photoUrl":"http:\/\/awesomeness.openphoto.me\/custom\/201203\/62f010-Boracay-Philippines-033_100x100xCR.jpg",
"counts":{
"photos":363,
"albums":5,
"tags":37
},
"name":" Demo User",
"isOwner":false,
"permission":{
"C":[
4
],
"R":[
4
],
"U":false,
"D":false
}
}
}
]
}
17 changes: 13 additions & 4 deletions test/src/com/trovebox/android/test/model/CredentialsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public class CredentialsTest extends InstrumentationTestCase {
public void testFromJson() {
Credentials c;
try {
JSONObject json = JSONUtils
.getJson(getInstrumentation().getContext(),
JSONObject json = JSONUtils.getJson(getInstrumentation().getContext(),
R.raw.json_credentials);
c = new Credentials(json);
} catch (JSONException e) {
Expand All @@ -29,8 +28,7 @@ public void testFromJson() {
public void testCredentialsParcelable() {
Credentials c;
try {
JSONObject json = JSONUtils
.getJson(getInstrumentation().getContext(),
JSONObject json = JSONUtils.getJson(getInstrumentation().getContext(),
R.raw.json_credentials);
c = new Credentials(json);
} catch (JSONException e) {
Expand Down Expand Up @@ -59,4 +57,15 @@ public static void checkCredentials(Credentials c, String email) {
assertEquals(c.getoAuthTokenSecret(), "6d1e8fc274");

}

public static void checkCredentialsV2(Credentials c, String email, String server) {
assertNotNull(c);
assertEquals(c.getEmail(), email);
assertEquals(c.getServer(), server);
assertEquals(c.getoAuthConsumerKey(), "102230629a6802fbca9825a4617bfe");
assertEquals(c.getoAuthConsumerSecret(), "0f5d654bca");
assertEquals(c.getoAuthToken(), "b662440d621f2f71352f8865888fe2");
assertEquals(c.getoAuthTokenSecret(), "6d1e8fc274");

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,21 @@ public void testMultiResponse() throws JSONException {
CredentialsTest.checkCredentials(credentials[0], "[email protected]");
CredentialsTest.checkCredentials(credentials[1], "[email protected]");
}

public void testMultiResponseV2() throws JSONException {
JSONObject json = JSONUtils.getJson(getInstrumentation().getContext(),
R.raw.json_login_multiple_v2);
AccountTroveboxResponse response = new AccountTroveboxResponse(RequestType.UNKNOWN, json);
assertNotNull(response);
assertEquals(200, response.getCode());
Credentials[] credentials = response.getCredentials();
assertNotNull(credentials);
assertTrue(credentials.length == 3);
CredentialsTest.checkCredentialsV2(credentials[0], "[email protected]",
"http://test.trovebox.com");
CredentialsTest.checkCredentialsV2(credentials[1], "[email protected]",
"http://test2.trovebox.com");
CredentialsTest.checkCredentialsV2(credentials[2], "[email protected]",
"http://test3.trovebox.com");
}
}

0 comments on commit c35fa49

Please sign in to comment.