Skip to content

Commit

Permalink
Clean up asynchron frontend tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
tabergma committed Aug 7, 2014
1 parent 4410117 commit e2481a0
Show file tree
Hide file tree
Showing 14 changed files with 361 additions and 523 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
import de.uni_potsdam.hpi.metanome.input.csv.CsvFile;
import de.uni_potsdam.hpi.metanome.test_helper.EqualsAndHashCodeTester;

import org.hamcrest.collection.IsIterableContainingInAnyOrder;
import org.junit.Test;

import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

/**
Expand Down Expand Up @@ -125,4 +129,28 @@ public void testEqualsAndHashCode() {
new EqualsAndHashCodeTester<FileInput>()
.performBasicEqualsAndHashCodeChecks(fileInput, equalFileInput, notEqualFileInput);
}


/**
* Test method for {@link de.uni_potsdam.hpi.metanome.results_db.FileInput#retrieveAll()}
*/
@Test
public void testRetrieveAll() throws EntityStorageException {
// Setup
HibernateUtil.clear();

// Expected values
Input expectedInput = new FileInput()
.store();

// Execute functionality
List<Input> actualInputs = FileInput.retrieveAll();

// Check result
assertThat(actualInputs, IsIterableContainingInAnyOrder
.containsInAnyOrder(expectedInput));

// Cleanup
HibernateUtil.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@

import de.uni_potsdam.hpi.metanome.test_helper.EqualsAndHashCodeTester;

import org.hamcrest.collection.IsIterableContainingInAnyOrder;
import org.junit.Test;

import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;

/**
* Tests for {@link de.uni_potsdam.hpi.metanome.results_db.TableInput}
Expand Down Expand Up @@ -80,4 +84,27 @@ public void testEqualsAndHashCode() {
new EqualsAndHashCodeTester<TableInput>()
.performBasicEqualsAndHashCodeChecks(tableInput, equalTableInput, notEqualTableInput);
}

/**
* Test method for {@link de.uni_potsdam.hpi.metanome.results_db.TableInput#retrieveAll()}
*/
@Test
public void testRetrieveAll() throws EntityStorageException {
// Setup
HibernateUtil.clear();

// Expected values
Input expectedInput = new TableInput()
.store();

// Execute functionality
List<Input> actualInputs = TableInput.retrieveAll();

// Check result
assertThat(actualInputs, IsIterableContainingInAnyOrder
.containsInAnyOrder(expectedInput));

// Cleanup
HibernateUtil.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void onSuccess(List<DatabaseConnection> result) {

if (result != null) {
for (DatabaseConnection db : result) {
String identifier = db.getId() + ": " + db.getUrl();
String identifier = db.getUrl();
dbConnectionNames.add(identifier);
dbMap.put(identifier, db);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
public class CsvFileInput extends InputField {

public ListBoxInput listbox;
protected Map<String, FileInput> fileInputs;
public Map<String, FileInput> fileInputs;
private TabWrapper messageReceiver;
/**
* When using the link from Data Sources page, this is where the selected file is stored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
public class SqlIteratorInput extends InputField {

public ListBoxInput listbox;
protected Map<String, DatabaseConnection> databaseConnections;
public Map<String, DatabaseConnection> databaseConnections;
private TabWrapper messageReceiver;
/**
* When using the link from Data Sources page, this is where the selected database connection is stored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ public void run() {
}
};

delayTestFinish(6000);
timer.schedule(1000);

timer.schedule(5000);
delayTestFinish(2000);
}

/**
Expand Down Expand Up @@ -184,7 +184,7 @@ public void onSuccess(List<Algorithm> result) {

((AlgorithmServiceAsync) GWT.create(AlgorithmService.class)).listAllAlgorithms(callback);

delayTestFinish(5000);
delayTestFinish(1000);
}

private RunConfigurationPage getRunConfigurationPage(final BasePage page) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import de.uni_potsdam.hpi.metanome.results_db.FileInput;
import de.uni_potsdam.hpi.metanome.results_db.TableInput;

import java.io.File;
import java.util.List;

/**
Expand All @@ -36,6 +35,11 @@
*/
public class TestHelper {

static boolean[] reset_blocked = {true};
static boolean[] database_connection_blocked = {true};
static boolean[] file_input_blocked = {true};
static boolean[] algorithm_blocked = {true};

protected static TestDatabaseHelperServiceAsync
testDatabaseHelperService =
GWT.create(TestDatabaseHelperService.class);
Expand All @@ -44,22 +48,20 @@ public class TestHelper {
* Resets the database synchronously.
*/
public static void resetDatabaseSync() {
final boolean[] blocked = {true};
testDatabaseHelperService.resetDatabase(new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable throwable) {
}

@Override
public void onSuccess(Void aVoid) {
blocked[0] = false;
reset_blocked[0] = false;
}
});

Timer rpcCheck = new Timer() {
@Override
public void run() {
if (blocked[0]) {
if (reset_blocked[0]) {
this.schedule(100);
}
}
Expand All @@ -73,22 +75,22 @@ public void run() {
* @param algorithm the {@link de.uni_potsdam.hpi.metanome.results_db.Algorithm} to store
*/
public static void storeAlgorithmSync(Algorithm algorithm) {
final boolean[] blocked = {true};
testDatabaseHelperService.storeAlgorithmInDatabase(algorithm, new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable throwable) {
public void onFailure(Throwable caught) {

}

@Override
public void onSuccess(Void aVoid) {
blocked[0] = false;
algorithm_blocked[0] = false;
}
});

Timer rpcCheck = new Timer() {
@Override
public void run() {
if (blocked[0]) {
if (algorithm_blocked[0]) {
this.schedule(100);
}
}
Expand All @@ -100,22 +102,58 @@ public void run() {
* Stores a database connection.
*
* @param connection the {@link de.uni_potsdam.hpi.metanome.results_db.DatabaseConnection} to store
* @param callback the async callback
*/
public static void storeDatabaseConnection(DatabaseConnection connection,
AsyncCallback<Long> callback) {
testDatabaseHelperService.storeDatabaseConnection(connection, callback);
public static void storeDatabaseConnectionSync(DatabaseConnection connection) {
testDatabaseHelperService.storeDatabaseConnection(connection, new AsyncCallback<Long>() {
@Override
public void onFailure(Throwable caught) {

}

@Override
public void onSuccess(Long result) {
database_connection_blocked[0] = false;
}
});

Timer rpcCheck = new Timer() {
@Override
public void run() {
if (database_connection_blocked[0]) {
this.schedule(100);
}
}
};
rpcCheck.schedule(100);
}

/**
* Stores a file input.
*
* @param fileInput the {@link de.uni_potsdam.hpi.metanome.results_db.FileInput} to store
* @param callback the async callback
*/
public static void storeFileInput(FileInput fileInput,
AsyncCallback<Long> callback) {
testDatabaseHelperService.storeFileInput(fileInput, callback);
public static void storeFileInputSync(FileInput fileInput) {
testDatabaseHelperService.storeFileInput(fileInput, new AsyncCallback<Long>() {
@Override
public void onFailure(Throwable caught) {

}

@Override
public void onSuccess(Long result) {
file_input_blocked[0] = false;
}
});

Timer rpcCheck = new Timer() {
@Override
public void run() {
if (file_input_blocked[0]) {
this.schedule(100);
}
}
};
rpcCheck.schedule(100);
}

/**
Expand Down
Loading

0 comments on commit e2481a0

Please sign in to comment.