package com.tightdb;

import org.testng.annotations.Test;

import com.tightdb.test.TestHelper;

public class JNICloseTest {

    @Test (enabled=true, expectedExceptions = IllegalStateException.class)
    public void shouldCloseTable() {
        // util.setDebugLevel(1);
        Table table = new Table();
        table.close();

        @SuppressWarnings("unused")
        long s = table.size();
        // TODO: a more specific Exception must be thrown from JNI..
    }

    // TODO: Much more testing needed.
    // Verify that methods make exceptions when Tables are invalidated.
    // Verify subtables are invalidated when table is changed/updated in any way.
    // Check that Group.close works

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

        //  EmployeeTable employees = new EmployeeTable(group);
    }
    
    /**
     * Make sure, that an illegavlStateException is thrown when trying to do queries on a closed table
     */
    @Test(expectedExceptions = IllegalStateException.class)
    public void closeTableShouldThrowExceptionWhenQuery(){
        
        Table table = TestHelper.getTableWithAllColumnTypes();
        
        TableQuery query = table.where();
        
        table.close(); //Table is being closed
        
        query.findAll(); //Should throw exception, as table has been closed
    }



}

@@ -15,16 +15,42 @@
 ghtdb;%0A%0A
+import org.testng.Assert;%0A
 import o
@@ -77,16 +77,16 @@
 s.Test;%0A
-
 %0Aimport 
@@ -159,22 +159,8 @@
 st (
-enabled=true, 
 expe
@@ -924,17 +924,16 @@
 n illega
-v
 lStateEx
@@ -1391,13 +1391,531 @@
 d%0A    %7D%0A
+    %0A    %0A    @Test()%0A    public void closeTableShouldThrowExceptionWhenAccessingView()%7B%0A        %0A        Table table = TestHelper.getTableWithAllColumnTypes();%0A        %0A        TableQuery query = table.where();%0A        %0A        TableView view = query.findAll();%0A        %0A        table.close(); //Closes the table, should not be allowed to access the view%0A        %0A        try%7B view.size(); assert(false); %7D catch (IllegalStateException e)%7B%7D //size() should throw exception, as table is invalid%0A        %0A        %0A    %7D
 %0A%0A%0A%7D%0A

Test cases added for accessing queries and views on closed table