package com.mysema.query.suites;

import static com.mysema.query.sql.domain.QSurvey.survey;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import com.google.common.base.Throwables;
import com.mysema.query.AbstractBaseTest;
import com.mysema.query.Connections;
import com.mysema.query.QueryException;
import com.mysema.query.sql.H2Templates;

import org.junit.BeforeClass;
import org.junit.Test;

public class H2ExceptionSuiteTest extends AbstractBaseTest {

    @BeforeClass
    public static void setUp() throws Exception {
        Connections.initH2();
        Connections.setTemplates(H2Templates.builder().build());

        Connections.getConnection().createStatement()
                .execute("ALTER TABLE SURVEY ADD CONSTRAINT UNIQUE_ID UNIQUE(ID)");
    }

    public static void tearDown() throws Exception {
        Connections.getConnection().createStatement()
                .execute("ALTER TABLE SURVEY DROP CONSTRAINT UNIQUE_ID");
    }

    @Test
    public void UpdateBatchFailed() {
        execute(insert(survey).columns(survey.name, survey.name2)
                .values("New Survey", "New Survey"));
        Exception result = null;
        try {
            execute(update(survey)
                    .set(survey.id, 1).addBatch()
                    .set(survey.id, 2).addBatch());
        } catch (QueryException e) {
            result = e;
        }
        assertNotNull(result);
        assertTrue(Throwables.getStackTraceAsString(result)
                .contains("Suppressed"));
    }
}

@@ -296,16 +296,57 @@
 ctions;%0A
+import com.mysema.query.JavaSpecVersion;%0A
 import c
@@ -1497,19 +1497,36 @@
     
-assertTrue(
+String stackTraceAsString = 
 Thro
@@ -1561,17 +1561,323 @@
 (result)
+;
 %0A
+        switch (JavaSpecVersion.CURRENT) %7B%0A            case JAVA6:%0A                assertTrue(stackTraceAsString%0A                        .contains(%22Detailed SQLException information:%22));%0A                break;%0A            default://Java%E2%84%A2 7 and higher%0A                assertTrue(stackTraceAsString%0A        
         
@@ -1905,21 +1905,32 @@
 ppressed
+:
 %22));%0A
+        %7D%0A
     %7D%0A%7D%0A

Add specific asserts for Java 6 and 7