Skip to content

add alert dialog #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import static edu.grinnell.appdev.grinnelldirectory.EncryptionUtils.decrypt;
import static edu.grinnell.appdev.grinnelldirectory.EncryptionUtils.encrypt;
import static junit.framework.Assert.assertEquals;

@RunWith(AndroidJUnit4.class)
Expand All @@ -16,9 +18,11 @@ public class EncryptionTest {
public void testEncryption() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
String encrypted = EncryptionUtils.encrypt(appContext, "String to Encrypt");
String decrypted = EncryptionUtils.decrypt(appContext, encrypted);
String encrypted = encrypt(appContext, "String to Encrypt");
String decrypted = decrypt(appContext, encrypted);
assertEquals("String to Encrypt", decrypted);


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@
import java.util.List;
import java.util.concurrent.CountDownLatch;

import edu.grinnell.appdev.grinnelldirectory.interfaces.APICallerInterface;
import edu.grinnell.appdev.grinnelldirectory.models.Person;
import edu.grinnell.appdev.grinnelldirectory.interfaces.DbSearchCallback;
import edu.grinnell.appdev.grinnelldirectory.interfaces.SearchCaller;
import edu.grinnell.appdev.grinnelldirectory.models.User;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;


@RunWith(AndroidJUnit4.class)
public class NetworkingTest {
Expand All @@ -36,32 +31,33 @@ public void successfulSearchTests() throws Exception {
final CountDownLatch latch = new CountDownLatch(2);

User user = new User("test1stu", "selfserv1");
DBAPICaller apiCaller = new DBAPICaller(user, new APICallerInterface() {
@Override
public void onSearchSuccess(List<Person> people) {
assertNotNull(people);
assertFalse(people.size() == 0);
latch.countDown();
}

@Override
public void authenticateUserCallSuccess(boolean success, Person person) {
fail("Test Failed: Not testing authentication.");
latch.countDown();
}

@Override
public void onServerFailure(String fail_message) {
fail("Test Failed: " + fail_message);
latch.countDown();
}

@Override
public void onNetworkingError(String fail_message) {
fail("Test Failed: " + fail_message);
latch.countDown();
}
});
SearchCaller apiCaller = new DBAPICaller((DbSearchCallback) this);
// DBAPICaller apiCaller = new DBAPICaller(user, new APICallerInterface() {
// @Override
// public void onSearchSuccess(List<Person> people) {
// assertNotNull(people);
// assertFalse(people.size() == 0);
// latch.countDown();
// }
//
// @Override
// public void authenticateUserCallSuccess(boolean success, Person person) {
// fail("Test Failed: Not testing authentication.");
// latch.countDown();
// }
//
// @Override
// public void onServerFailure(String fail_message) {
// fail("Test Failed: " + fail_message);
// latch.countDown();
// }
//
// @Override
// public void onNetworkingError(String fail_message) {
// fail("Test Failed: " + fail_message);
// latch.countDown();
// }
// });

List<String> test_list_1 = new ArrayList();
test_list_1.add(0, "Nicholas");
Expand All @@ -82,14 +78,13 @@ public void onNetworkingError(String fail_message) {
test_list_3.add(9, "");
test_list_3.add(10, "");
test_list_3.add(11, "");
test_list_3.add(12, "");
test_list_3.add(13, "");
test_list_3.add(14, "");

// Works
apiCaller.simpleSearch(test_list_1);
apiCaller.simpleSearch(test_list_1.get(0), test_list_1.get(1), test_list_1.get(2), test_list_1.get(3));
// Works
apiCaller.advancedSearch(test_list_3);
apiCaller.advancedSearch(test_list_3.get(0), test_list_3.get(1), test_list_3.get(2), test_list_3.get(3),
test_list_3.get(4), test_list_3.get(5), test_list_3.get(6), test_list_3.get(7),
test_list_3.get(8), test_list_3.get(9), test_list_3.get(10), test_list_3.get(11));

latch.await();
}
Expand All @@ -100,31 +95,32 @@ public void failingTest() throws Exception {
final CountDownLatch latch = new CountDownLatch(2);

User user = new User("test1stu", "selfserv1");
DBAPICaller apiCaller = new DBAPICaller(user, new APICallerInterface() {
@Override
public void onSearchSuccess(List<Person> people) {
fail("Test Failed: search should not return successful results");
latch.countDown();
}

@Override
public void authenticateUserCallSuccess(boolean success, Person person) {
fail("Test Failed: search should not return successful results");
latch.countDown();
}

@Override
public void onServerFailure(String fail_message) {
assertEquals("\"No records returned\"", fail_message);
latch.countDown();
}

@Override
public void onNetworkingError(String fail_message) {
fail("Test Failed: " + fail_message);
latch.countDown();
}
});
SearchCaller apiCaller = new DBAPICaller((DbSearchCallback) this);
// DBAPICaller apiCaller = new DBAPICaller(user, new APICallerInterface() {
// @Override
// public void onSearchSuccess(List<Person> people) {
// fail("Test Failed: search should not return successful results");
// latch.countDown();
// }
//
// @Override
// public void authenticateUserCallSuccess(boolean success, Person person) {
// fail("Test Failed: search should not return successful results");
// latch.countDown();
// }
//
// @Override
// public void onServerFailure(String fail_message) {
// assertEquals("\"No records returned\"", fail_message);
// latch.countDown();
// }
//
// @Override
// public void onNetworkingError(String fail_message) {
// fail("Test Failed: " + fail_message);
// latch.countDown();
// }
// });

// Not real major
List<String> test_list_1 = new ArrayList();
Expand All @@ -151,14 +147,14 @@ public void onNetworkingError(String fail_message) {
test_list_3.add(9, "");
test_list_3.add(10, "2117");
test_list_3.add(11, "1aaaadsfhsfd");
test_list_3.add(12, "");
test_list_3.add(13, "");

// "Bad request"
apiCaller.simpleSearch(test_list_1);

// "No "
apiCaller.advancedSearch(test_list_3);

apiCaller.simpleSearch(test_list_1.get(0), test_list_1.get(1), test_list_1.get(2), test_list_1.get(3));

apiCaller.advancedSearch(test_list_3.get(0), test_list_3.get(1), test_list_3.get(2), test_list_3.get(3),
test_list_3.get(4), test_list_3.get(5), test_list_3.get(6), test_list_3.get(7),
test_list_3.get(8), test_list_3.get(9), test_list_3.get(10), test_list_3.get(11));

latch.await();

Expand All @@ -170,31 +166,32 @@ public void tooManyResultsTest() throws Exception {
final CountDownLatch latch = new CountDownLatch(2);

User user = new User("test1stu", "selfserv1");
DBAPICaller apiCaller = new DBAPICaller(user, new APICallerInterface() {
@Override
public void onSearchSuccess(List<Person> people) {
fail("Test Failed: search should not return successful results");
latch.countDown();
}

@Override
public void authenticateUserCallSuccess(boolean success, Person person) {
fail("Test Failed: authenticate not called");
latch.countDown();
}

@Override
public void onServerFailure(String fail_message) {
assertEquals("\"Search returned too many records. Please narrow your search and try again.\"", fail_message);
latch.countDown();
}

@Override
public void onNetworkingError(String fail_message) {
fail("Test Failed: " + fail_message);
latch.countDown();
}
});
SearchCaller apiCaller = new DBAPICaller((DbSearchCallback) user);
// DBAPICaller apiCaller = new DBAPICaller(user, new APICallerInterface() {
// @Override
// public void onSearchSuccess(List<Person> people) {
// fail("Test Failed: search should not return successful results");
// latch.countDown();
// }
//
// @Override
// public void authenticateUserCallSuccess(boolean success, Person person) {
// fail("Test Failed: authenticate not called");
// latch.countDown();
// }
//
// @Override
// public void onServerFailure(String fail_message) {
// assertEquals("\"Search returned too many records. Please narrow your search and try again.\"", fail_message);
// latch.countDown();
// }
//
// @Override
// public void onNetworkingError(String fail_message) {
// fail("Test Failed: " + fail_message);
// latch.countDown();
// }
// });

// will return too many results
List<String> test_list_4 = new ArrayList();
Expand All @@ -214,8 +211,11 @@ public void onNetworkingError(String fail_message) {
test_list_4.add(13, "");

// "Search returned too many records. Please narrow your search and try again."
apiCaller.simpleSearch(test_list_4);
apiCaller.advancedSearch(test_list_4);
apiCaller.simpleSearch(test_list_4.get(0), test_list_4.get(1), test_list_4.get(2), test_list_4.get(3));

apiCaller.advancedSearch(test_list_4.get(0), test_list_4.get(1), test_list_4.get(2), test_list_4.get(3),
test_list_4.get(4), test_list_4.get(5), test_list_4.get(6), test_list_4.get(7),
test_list_4.get(8), test_list_4.get(9), test_list_4.get(10), test_list_4.get(11));

latch.await();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

@RunWith(AndroidJUnit4.class)
public class ScraperTest {

@Test
public void testAuthentication() throws Exception {
// TODO: 2/25/17 Implement!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package edu.grinnell.appdev.grinnelldirectory;

import java.util.List;

import edu.grinnell.appdev.grinnelldirectory.interfaces.DbSearchAPI;
import edu.grinnell.appdev.grinnelldirectory.interfaces.DbSearchCallback;
import edu.grinnell.appdev.grinnelldirectory.interfaces.SearchCaller;
import edu.grinnell.appdev.grinnelldirectory.models.Person;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
Expand Down Expand Up @@ -49,6 +50,7 @@ public void simpleSearch(String lastName, String firstName, String major, String
);
}


@Override public void advancedSearch(String lastName, String firstName, String userName,
String campusPhone, String campusAddress, String homeAddress, String classYear,
String facStaffOffice, String major, String concentration, String sgaPosition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import com.crashlytics.android.Crashlytics;
import io.fabric.sdk.android.Fabric;

import static edu.grinnell.appdev.grinnelldirectory.EncryptionUtils.isEncryptionKeySet;
import static edu.grinnell.appdev.grinnelldirectory.EncryptionUtils.setAppEncryptionKey;

public class DBApplication extends Application {

@Override
public void onCreate() {
super.onCreate();
Fabric.with(this, new Crashlytics());

if (!EncryptionUtils.isEncryptionKeySet(this)) {
EncryptionUtils.setAppEncryptionKey(this, "" + System.currentTimeMillis());
if (!isEncryptionKeySet(this)) {
setAppEncryptionKey(this, "" + System.currentTimeMillis());
}
}
}
Loading