Skip to content

Commit

Permalink
User can browse wants
Browse files Browse the repository at this point in the history
  • Loading branch information
he9lin committed Mar 29, 2012
1 parent b4552f5 commit 761b19b
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 136 deletions.
31 changes: 31 additions & 0 deletions src/jieqoo/android/KASS/integration/test/IntegrationBaseTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package jieqoo.android.KASS.integration.test;

import jieqoo.android.KASS.Main;
import android.test.ActivityInstrumentationTestCase2;

import com.jayway.android.robotium.solo.Solo;

public abstract class IntegrationBaseTests extends ActivityInstrumentationTestCase2<Main> {

protected Solo solo;

public IntegrationBaseTests(String name) {
super(Main.class);
setName(name);
}

protected void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
}

protected void tearDown() throws Exception {
super.tearDown();
try {
solo.finishOpenedActivities();
} catch (Throwable e) {
e.printStackTrace();
}
}

}
49 changes: 0 additions & 49 deletions src/jieqoo/android/KASS/integration/test/SignUpTests.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package jieqoo.android.KASS.integration.test;

import static jieqoo.android.KASS.test.Factory.*;

import org.json.JSONException;
import org.json.JSONObject;

public class UserBrowsesOffersTests extends IntegrationBaseTests {

public UserBrowsesOffersTests(String name) {
super(name);
}

public UserBrowsesOffersTests() {
this("UserBrowsesOffersTests");
}

public final void testBrowsesOffers() throws JSONException {
createUser();
JSONObject listing = createListing();
signoutUser();
createUser();
createOffer(listing.getString("id"));
solo.clickOnButton("我的活动");
solo.clickOnText("我要卖");
assertTrue(solo.searchText(listing.getString("title")));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package jieqoo.android.KASS.integration.test;

import static jieqoo.android.KASS.test.Factory.createListing;
import static jieqoo.android.KASS.test.Factory.createUser;

import org.json.JSONException;
import org.json.JSONObject;

public class UserBrowsesWantsTests extends IntegrationBaseTests {

public UserBrowsesWantsTests(String name) {
super(name);
}

public UserBrowsesWantsTests() {
this("UserBrowsesWantsTests");
}

public final void testBrowsesListings() throws JSONException {
createUser();
JSONObject listing = createListing();

solo.clickOnButton("浏览");
solo.clickOnButton("我的活动");
assertTrue(solo.searchText(listing.getString("title")));
}
}
25 changes: 2 additions & 23 deletions src/jieqoo/android/KASS/integration/test/UserMakesOfferTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static jieqoo.android.KASS.test.Factory.createListing;
import static jieqoo.android.KASS.test.Factory.createUser;
import static jieqoo.android.KASS.test.Factory.signoutUser;
import jieqoo.android.KASS.Main;
import jieqoo.android.KASS.MyOfferIdleActivity;
import jieqoo.android.KASS.widgets.SlideButton.FinishingTouchListener;

Expand All @@ -12,38 +11,18 @@

import android.app.Activity;
import android.app.Instrumentation.ActivityMonitor;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;

import com.jayway.android.robotium.solo.Solo;

public class UserMakesOfferTests extends ActivityInstrumentationTestCase2<Main> {
public class UserMakesOfferTests extends IntegrationBaseTests {

private Solo solo;

public UserMakesOfferTests(String name) {
super(Main.class);
setName(name);
super(name);
}

public UserMakesOfferTests() {
this("UserEditsOfferTests");
}

protected void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
}

protected void tearDown() throws Exception {
super.tearDown();
try {
solo.finishOpenedActivities();
} catch (Throwable e) {
e.printStackTrace();
}
}

public final void testUserMakesOffer() throws JSONException {
createUser();
JSONObject listing = createListing();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package jieqoo.android.KASS.integration.test;

public class UserPostsListingTests {

}
Original file line number Diff line number Diff line change
@@ -1,51 +1,30 @@
package jieqoo.android.KASS.integration.test;

import jieqoo.android.KASS.SignIn;
import jieqoo.android.KASS.models.Account;

import org.json.JSONException;
import org.json.JSONObject;

import android.test.ActivityInstrumentationTestCase2;

import com.jayway.android.robotium.solo.Solo;

import static jieqoo.android.KASS.test.Factory.*;

public class SignInTests extends ActivityInstrumentationTestCase2<SignIn> {

private Solo solo;
public class UserSignsInTests extends IntegrationBaseTests {

public SignInTests(String name) {
super(SignIn.class);
setName(name);
public UserSignsInTests(String name) {
super(name);
}

public SignInTests() {
public UserSignsInTests() {
this("SignInTests");
}

protected void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
}

protected void tearDown() throws Exception {
super.tearDown();
try {
solo.finalize();
} catch (Throwable e) {
e.printStackTrace();
}
}

public final void testSignin() throws JSONException {
JSONObject userJSON = createUser();
signoutUser();

String email = userJSON.getString("email");
String password = userJSON.getString("password");


solo.clickOnButton("登录");
solo.enterText(0, email);
solo.enterText(1, password);
solo.clickOnButton("登录");
Expand Down
36 changes: 36 additions & 0 deletions src/jieqoo/android/KASS/integration/test/UserSignsUpTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
*
*/
package jieqoo.android.KASS.integration.test;

import jieqoo.android.KASS.models.Account;
import static jieqoo.android.KASS.test.Factory.*;

/**
* @author linhe
*
*/
public class UserSignsUpTests extends IntegrationBaseTests {

public UserSignsUpTests() {
this("SignUpTests");
}

public UserSignsUpTests(String name) {
super(name);
}

public final void testSignup() {
signoutUser();

solo.clickOnButton("登录");
solo.clickOnButton("注册");
solo.enterText(0, "kass" + System.currentTimeMillis());
solo.enterText(1, "secret");
solo.enterText(2, "kass" + System.currentTimeMillis() + "@example.com");
solo.enterText(3, "12345678910");
solo.clickOnButton("注册");
solo.waitForText("发布");
assertTrue(Account.getInstance().isAuthenticated());
}
}
73 changes: 38 additions & 35 deletions src/jieqoo/android/KASS/models/test/OfferTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,44 +85,47 @@ public final void testSet() throws JSONException, ParseException {
}

public final void testSaveNewRecord() throws JSONException, Throwable {
createUser();
createUser();

JSONObject listingJSON = createListing();
final String listingId = listingJSON.getString("id");

// Now we need a different user to make the offer.
signoutUser();
createUser();

// create a signal to let us know when our task is done.
final CountDownLatch signal = new CountDownLatch(1);
JSONObject listingJSON = createListing();
final String listingId = listingJSON.getString("id");

// Execute the Async task on the UI thread! THIS IS KEY!
runTestOnUiThread(new Runnable() {
@Override
public void run() {
Offer offer = new Offer();
offer.setListingId(listingId);
offer.setMessage("This is an offer!");
offer.save(new RESTListener() {
public void onSuccess(Object response) {
Log.d(TAG, "RESTListener: success response: " + response);
called = true;
signal.countDown();
}
public void onError(Object response) {
Log.d(TAG, "RESTListener: error response: " + response);
signal.countDown();
}
});
}
});
// Now we need a different user to make the offer.
signoutUser();
createUser();

/* The testing thread will wait here until the UI thread releases it
* above with the countDown() or 10 seconds passes and it times out.
*/
signal.await(10, TimeUnit.SECONDS);
assertTrue(called);
// create a signal to let us know when our task is done.
final CountDownLatch signal = new CountDownLatch(1);

// Execute the Async task on the UI thread! THIS IS KEY!
runTestOnUiThread(new Runnable() {
@Override
public void run() {
Offer offer = new Offer();
offer.setListingId(listingId);
offer.setMessage("This is an offer!");
offer.save(new RESTListener() {
public void onSuccess(Object response) {
Log.d(TAG, "RESTListener: success response: "
+ response);
called = true;
signal.countDown();
}

public void onError(Object response) {
Log.d(TAG, "RESTListener: error response: " + response);
signal.countDown();
}
});
}
});

/*
* The testing thread will wait here until the UI thread releases it
* above with the countDown() or 10 seconds passes and it times out.
*/
signal.await(10, TimeUnit.SECONDS);
assertTrue(called);
}

public final void testSaveExistingRecord() {
Expand Down
Loading

0 comments on commit 761b19b

Please sign in to comment.