/*
 * Copyright 2011, Mysema Ltd
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mysema.query.sql;

import static org.junit.Assert.assertEquals;

import java.sql.Connection;

import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;

import com.mysema.query.JoinFlag;
import com.mysema.query.sql.domain.QSurvey;

public class JoinFlagsTest {
    
    private Connection connection = EasyMock.createMock(Connection.class);

    private QSurvey s1, s2, s3, s4, s5, s6;
    
    private SQLQuery query;
    
    @Before
    public void setUp() {
        s1 = new QSurvey("s");
        s2 = new QSurvey("s2");    
        s3 = new QSurvey("s3");    
        s4 = new QSurvey("s4");    
        s5 = new QSurvey("s5");
        s6 = new QSurvey("s6");        
        query = new SQLQuery(connection,SQLTemplates.DEFAULT);
        query.from(s1);    
    }

    @Test
    public void JoinFlag_BeforeCondition() {
        query.innerJoin(s2).on(s1.eq(s2));
        query.addJoinFlag(" a ", JoinFlag.Position.BEFORE_CONDITION);
        
        assertEquals("from SURVEY s\n" +
                "inner join SURVEY s2 a \n" +
                "on s = ?", query.toString());
    }
    
    @Test
    public void JoinFlags_BeforeTarget() {
        query.innerJoin(s3).on(s1.eq(s3));
        query.addJoinFlag(" b ", JoinFlag.Position.BEFORE_TARGET);
        
        assertEquals("from SURVEY s\n" +
                "inner join  b SURVEY s3\n" +
                "on s = ?", query.toString());
    }
    
    @Test
    public void JoinFlags_End() {
        query.innerJoin(s4).on(s1.eq(s4));
        query.addJoinFlag(" c ", JoinFlag.Position.END);
        
        assertEquals("from SURVEY s\n" +
                "inner join SURVEY s4\n" +
                "on s = ? c", query.toString());
    }
    
    @Test
    public void JoinFlags_Override() {
        query.innerJoin(s5).on(s1.eq(s5));
        query.addJoinFlag(" d ", JoinFlag.Position.OVERRIDE);
        
        assertEquals("from SURVEY s d SURVEY s5\n" +
                "on s = ?", query.toString());
    }
    
    @Test
    public void JoinFlags_Start() {
        query.innerJoin(s6).on(s1.eq(s6));
        query.addJoinFlag(" e ", JoinFlag.Position.START);
        
        assertEquals("from SURVEY s e \n" +
                "inner join SURVEY s6\n" +
                "on s = ?", query.toString());
    }
    

}

@@ -621,75 +621,107 @@
 ort 
-static org.junit.Assert.assertEquals;%0A%0Aimport java.sql.Connection;%0A
+java.sql.Connection;%0A%0Aimport com.mysema.query.JoinFlag;%0Aimport com.mysema.query.sql.domain.QSurvey;
 %0Aimp
@@ -799,85 +799,51 @@
 st;%0A
-%0A
 import 
-com.mysema.query.JoinFlag;%0Aimport com.mysema.query.sql.domain.QSurvey
+static org.junit.Assert.assertEquals
 ;%0A%0Ap
@@ -1414,16 +1414,17 @@
 JoinFlag
+s
 _BeforeC
@@ -1658,36 +1658,43 @@
            %22on s
- = ?
+.ID = s2.ID
 %22, query.toStrin
@@ -1982,36 +1982,43 @@
            %22on s
- = ?
+.ID = s3.ID
 %22, query.toStrin
@@ -2292,20 +2292,27 @@
    %22on s
- = ?
+.ID = s4.ID
  c%22, que
@@ -2567,36 +2567,43 @@
            %22on s
- = ?
+.ID = s5.ID
 %22, query.toStrin
@@ -2888,12 +2888,19 @@
 on s
- = ?
+.ID = s6.ID
 %22, q

Fix tests