Skip to content

Commit

Permalink
Introduced separate model for the tests - completed (issue #54).
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed Sep 3, 2012
1 parent 511b35c commit ae82eb8
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 124 deletions.
7 changes: 4 additions & 3 deletions src/test/java/com/tightdb/experiment/FailureExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
import java.util.Date;

import com.tightdb.Group;
import com.tightdb.example.EmployeeTable;
import com.tightdb.test.TestEmployeeTable;

public class FailureExample {

public static void main(String[] args) {
Group group = new Group();
EmployeeTable employees = new EmployeeTable(group);
TestEmployeeTable employees = new TestEmployeeTable(group);

employees.add("John", "Doe", 10000, true, new byte[] { 1, 2, 3 }, new Date(), "extra");
employees.add("John", "Doe", 10000, true, new byte[] { 1, 2, 3 },
new Date(), "extra");

employees.at(0).phones.get();

Expand Down
17 changes: 9 additions & 8 deletions src/test/java/com/tightdb/lib/AbstractDataOperationsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
import org.testng.annotations.Test;

import com.tightdb.Mixed;
import com.tightdb.example.Employee;
import com.tightdb.example.EmployeeQuery;
import com.tightdb.example.EmployeeView;
import com.tightdb.test.TestEmployeeQuery;
import com.tightdb.test.TestEmployeeRow;
import com.tightdb.test.TestEmployeeView;

public abstract class AbstractDataOperationsTest {

protected static final String NAME0 = "John";
protected static final String NAME1 = "Nikolche";
protected static final String NAME2 = "Johny";

protected abstract AbstractRowset<Employee, EmployeeView, EmployeeQuery> getEmployees();
protected abstract AbstractRowset<TestEmployeeRow, TestEmployeeView, TestEmployeeQuery> getEmployees();

@AfterMethod
public void clear() {
Expand Down Expand Up @@ -59,7 +59,8 @@ public void shouldAllowMixedValues() throws IllegalAccessException {

getEmployees().at(1).setExtra(Mixed.mixedValue("new_value"));
assertEquals("new_value", getEmployees().at(1).getExtra().getValue());
assertEquals("new_value", getEmployees().at(1).getExtra().getStringValue());
assertEquals("new_value", getEmployees().at(1).getExtra()
.getStringValue());
}

@Test
Expand Down Expand Up @@ -94,12 +95,12 @@ public void shouldPrintData() {
assertNotNull(getEmployees().toString());
TightDB.print(getEmployees());
TightDB.print("Employees", getEmployees());

assertNotNull(getEmployees().first().toString());
TightDB.print("First employee", getEmployees().first());

assertNotNull(getEmployees().first().birthdate.toString());
assertNotNull(getEmployees().first().phones.toString());
}

}
20 changes: 10 additions & 10 deletions src/test/java/com/tightdb/lib/AbstractNavigationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,52 @@

import org.testng.annotations.Test;

import com.tightdb.example.Employee;
import com.tightdb.example.EmployeeQuery;
import com.tightdb.example.EmployeeView;
import com.tightdb.test.TestEmployeeQuery;
import com.tightdb.test.TestEmployeeRow;
import com.tightdb.test.TestEmployeeView;

public abstract class AbstractNavigationTest {

protected abstract AbstractRowset<Employee, EmployeeView, EmployeeQuery> getTableOrView();
protected abstract AbstractRowset<TestEmployeeRow, TestEmployeeView, TestEmployeeQuery> getTableOrView();

@Test
public void shouldNavigateToFirstRecord() {
Employee first = getTableOrView().first();
TestEmployeeRow first = getTableOrView().first();

assertEquals(0, first.getPosition());
}

@Test
public void shouldNavigateToLastRecord() {
Employee last = getTableOrView().last();
TestEmployeeRow last = getTableOrView().last();

assertEquals(getTableOrView().size() - 1, last.getPosition());
}

@Test
public void shouldNavigateToNextRecord() {
Employee e = getTableOrView().at(0).next();
TestEmployeeRow e = getTableOrView().at(0).next();

assertEquals(1, e.getPosition());
}

@Test
public void shouldNavigateToPreviousRecord() {
Employee e = getTableOrView().at(1).previous();
TestEmployeeRow e = getTableOrView().at(1).previous();

assertEquals(0, e.getPosition());
}

@Test
public void shouldNavigateAfterSpecifiedRecords() {
Employee e = getTableOrView().at(0).after(2);
TestEmployeeRow e = getTableOrView().at(0).after(2);

assertEquals(2, e.getPosition());
}

@Test
public void shouldNavigateBeforeSpecifiedRecords() {
Employee e = getTableOrView().at(2).before(2);
TestEmployeeRow e = getTableOrView().at(2).before(2);

assertEquals(0, e.getPosition());
}
Expand Down
79 changes: 42 additions & 37 deletions src/test/java/com/tightdb/lib/GroupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,99 +11,104 @@
import org.testng.annotations.Test;

import com.tightdb.Group;
import com.tightdb.example.EmployeeTable;
import com.tightdb.test.TestEmployeeTable;

public class GroupTest {

protected static final String NAME0 = "John";
protected static final String NAME1 = "Nikolche";
protected static final String NAME2 = "Johny";

@Test (enabled=true)
@Test(enabled = true)
public void groupFileCanClose() throws NullPointerException, IOException {
Group group = new Group();
group.writeToFile("testfile.tdb");
group.close();
group.close();

Group group2 = new Group("testfile.tdb");
group2.close();
}
@Test (enabled=true)

@Test(enabled = true)
public void groupByteBufferCanClose() {
Group group = new Group();
ByteBuffer data = group.writeToByteBuffer();
group.close();
group.close();

Group group2 = new Group(data);
group2.close();
}
@Test (enabled=false)

@Test(enabled = false)
public void groupMemCanClose() {
Group group = new Group();
byte[] data = group.writeToMem();
group.close();

Group group2 = new Group(data);
group2.close();

// data is deleted by group()!
// FIXME:
// FIXME:
System.out.println("Data len:" + data.length);
}


@Test (enabled = false)

@Test(enabled = false)
public void shouldCreateTablesInGroup() {
Group group = new Group();

EmployeeTable employees = new EmployeeTable(group);
employees.add(NAME0, "Doe", 10000, true, new byte[] { 1, 2, 3 }, new Date(), "extra");
employees.add(NAME2, "B. Good", 20000, true, new byte[] { 1, 2, 3 }, new Date(), true);
employees.insert(1, NAME1, "Mihajlovski", 30000, false, new byte[] { 4, 5 }, new Date(), 1234);
TestEmployeeTable employees = new TestEmployeeTable(group);
employees.add(NAME0, "Doe", 10000, true, new byte[] { 1, 2, 3 },
new Date(), "extra");
employees.add(NAME2, "B. Good", 20000, true, new byte[] { 1, 2, 3 },
new Date(), true);
employees.insert(1, NAME1, "Mihajlovski", 30000, false, new byte[] { 4,
5 }, new Date(), 1234);

byte[] data = group.writeToMem();

// check table info retrieval
assertEquals(1, group.getTableCount());
assertEquals(EmployeeTable.class.getCanonicalName(), group.getTableName(0));
assertTrue(group.hasTable(EmployeeTable.class.getCanonicalName()));
assertEquals(TestEmployeeTable.class.getCanonicalName(),
group.getTableName(0));
assertTrue(group.hasTable(TestEmployeeTable.class.getCanonicalName()));
assertFalse(group.hasTable("xxxxxx"));

// check table retrieval
assertEquals(employees.size(), group.getTable(EmployeeTable.class.getCanonicalName()).size());

assertEquals(employees.size(),
group.getTable(TestEmployeeTable.class.getCanonicalName())
.size());

employees.clear();
group.close();

Group group2 = new Group(data);
EmployeeTable employees2 = new EmployeeTable(group2);

TestEmployeeTable employees2 = new TestEmployeeTable(group2);
group2.close();

assertEquals(3, employees2.size());
assertEquals(NAME0, employees2.at(0).getFirstName());
assertEquals(NAME1, employees2.at(1).getFirstName());
assertEquals(NAME2, employees2.at(2).getFirstName());
employees2.clear();

Group group3 = new Group();
EmployeeTable employees3 = new EmployeeTable(group3);
TestEmployeeTable employees3 = new TestEmployeeTable(group3);

assertEquals(0, employees3.size());

employees3.clear();

System.out.println("Closing group 1...");
group.close();

System.out.println("Closing group 2...");
group2.close(); // FIXME: crashes here!

System.out.println("Closing group 3...");
group3.close();

System.out.println("Done");
}
}
14 changes: 7 additions & 7 deletions src/test/java/com/tightdb/lib/MixedSubtableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@

import org.testng.annotations.Test;

import com.tightdb.example.EmployeeTable;
import com.tightdb.example.PhoneTable;
import com.tightdb.test.TestEmployeeRow;
import com.tightdb.test.TestEmployeeTable;
import com.tightdb.test.TestPhoneTable;

public class MixedSubtableTest extends AbstractTest {

@Test
public void shouldStoreSubtableInMixedTypeColumn() {
TestEmployeeRow employee = employees.at(0);
PhoneTable phones = employee.extra.createSubtable(PhoneTable.class);
TestPhoneTable phones = employee.extra.createSubtable(TestPhoneTable.class);

phones.add("mobile", "123");
assertEquals(1, phones.size());

PhoneTable phones2 = employee.extra.getSubtable(PhoneTable.class);
TestPhoneTable phones2 = employee.extra.getSubtable(TestPhoneTable.class);
assertEquals(1, phones2.size());
}

@Test(expectedExceptions = IllegalArgumentException.class)
public void shouldFailOnOnWrongSubtableRetrievalFromMixedTypeColumn() {
TestEmployeeRow employee = employees.at(0);
PhoneTable phones = employee.extra.createSubtable(PhoneTable.class);
TestPhoneTable phones = employee.extra.createSubtable(TestPhoneTable.class);

phones.add("mobile", "123");
assertEquals(1, phones.size());

// should fail - since we try to get the wrong subtable class
employee.extra.getSubtable(EmployeeTable.class);
employee.extra.getSubtable(TestEmployeeTable.class);
}

@Test(expectedExceptions = IllegalArgumentException.class)
Expand All @@ -40,7 +40,7 @@ public void shouldFailOnOnSubtableRetrtievalFromIncorrectType() {
employee.extra.set(123);

// should fail
employee.extra.getSubtable(PhoneTable.class);
employee.extra.getSubtable(TestPhoneTable.class);
}

}
36 changes: 19 additions & 17 deletions src/test/java/com/tightdb/lib/TableDataOperationsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,45 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.tightdb.example.Employee;
import com.tightdb.example.EmployeeQuery;
import com.tightdb.example.EmployeeTable;
import com.tightdb.example.EmployeeView;
import com.tightdb.test.TestEmployeeQuery;
import com.tightdb.test.TestEmployeeRow;
import com.tightdb.test.TestEmployeeTable;
import com.tightdb.test.TestEmployeeView;

@Test
public class TableDataOperationsTest extends AbstractDataOperationsTest {

private EmployeeTable employees;
private TestEmployeeTable employees;

@Override
protected AbstractRowset<Employee, EmployeeView, EmployeeQuery> getEmployees() {
protected AbstractRowset<TestEmployeeRow, TestEmployeeView, TestEmployeeQuery> getEmployees() {
return employees;
}

@BeforeMethod
public void init() {
employees = new EmployeeTable();

employees.add(NAME0, "Doe", 10000, true, new byte[] { 1, 2, 3 }, new Date(), "extra");
employees.add(NAME2, "B. Good", 10000, true, new byte[] { 1, 2, 3 }, new Date(), true);
employees.insert(1, NAME1, "Mihajlovski", 30000, false, new byte[] { 4, 5 }, new Date(), 1234);
employees = new TestEmployeeTable();

employees.add(NAME0, "Doe", 10000, true, new byte[] { 1, 2, 3 },
new Date(), "extra");
employees.add(NAME2, "B. Good", 10000, true, new byte[] { 1, 2, 3 },
new Date(), true);
employees.insert(1, NAME1, "Mihajlovski", 30000, false, new byte[] { 4,
5 }, new Date(), 1234);
}

private void setAndTestValue(long val)
{

private void setAndTestValue(long val) {
employees.at(1).setSalary(val);
assertEquals(val, employees.at(1).getSalary());
}

@Test
public void shouldStoreValues() {
setAndTestValue(Integer.MAX_VALUE);
setAndTestValue(Integer.MIN_VALUE);

setAndTestValue(Long.MAX_VALUE);
setAndTestValue(Long.MIN_VALUE);
}

}
Loading

0 comments on commit ae82eb8

Please sign in to comment.