/*
 * Copyright (C) 2017 Reece H. Dunn
 *
 * 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 uk.co.reecedunn.intellij.plugin.marklogic.tests.query;

import junit.framework.TestCase;
import uk.co.reecedunn.intellij.plugin.marklogic.query.*;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;

@SuppressWarnings("ConstantConditions")
public class QueryBuilderFactoryTest extends TestCase {
    public void testUnsupported() {
        assertThat(QueryBuilderFactory.createQueryBuilderForFile("test.txt"),
                is(nullValue()));
    }

    public void testXQuery() {
        assertThat(QueryBuilderFactory.createQueryBuilderForFile("test.xq"),
                is(instanceOf(XQueryBuilder.class)));
        assertThat(QueryBuilderFactory.createQueryBuilderForFile("test.xqy"),
                is(instanceOf(XQueryBuilder.class)));
        assertThat(QueryBuilderFactory.createQueryBuilderForFile("test.xquery"),
                is(instanceOf(XQueryBuilder.class)));
        assertThat(QueryBuilderFactory.createQueryBuilderForFile("test.xql"),
                is(instanceOf(XQueryBuilder.class)));
        assertThat(QueryBuilderFactory.createQueryBuilderForFile("test.xqu"),
                is(instanceOf(XQueryBuilder.class)));
    }

    public void testJavaScript() {
        assertThat(QueryBuilderFactory.createQueryBuilderForFile("test.js"),
                is(instanceOf(JavaScriptBuilder.class)));
        assertThat(QueryBuilderFactory.createQueryBuilderForFile("test.sjs"),
                is(instanceOf(JavaScriptBuilder.class)));
    }

    public void testSQL() {
        assertThat(QueryBuilderFactory.createQueryBuilderForFile("test.sql"),
                is(instanceOf(SQLBuilder.class)));
    }

    public void testSPARQLQuery() {
        assertThat(QueryBuilderFactory.createQueryBuilderForFile("test.sparql"),
                is(instanceOf(SPARQLQueryBuilder.class)));
        assertThat(QueryBuilderFactory.createQueryBuilderForFile("test.rq"),
                is(instanceOf(SPARQLQueryBuilder.class)));
    }

    public void testSPARQLUpdate() {
        assertThat(QueryBuilderFactory.createQueryBuilderForFile("test.ru"),
                is(instanceOf(SPARQLUpdateBuilder.class)));
    }

    public void testXSLT() {
        assertThat(QueryBuilderFactory.createQueryBuilderForFile("test.xsl"),
                is(instanceOf(XSLTBuilder.class)));
        assertThat(QueryBuilderFactory.createQueryBuilderForFile("test.xslt"),
                is(instanceOf(XSLTBuilder.class)));
    }
}

@@ -654,16 +654,52 @@
 query;%0A%0A
+import com.intellij.util.ArrayUtil;%0A
 import j
@@ -723,16 +723,16 @@
 stCase;%0A
-
 import u
@@ -1153,32 +1153,731 @@
  testXQuery() %7B%0A
+        assertThat(ArrayUtil.indexOf(QueryBuilderFactory.EXTENSIONS, %22xq%22), is(not(-1)));%0A        assertThat(ArrayUtil.indexOf(QueryBuilderFactory.EXTENSIONS, %22xqy%22), is(not(-1)));%0A        assertThat(ArrayUtil.indexOf(QueryBuilderFactory.EXTENSIONS, %22xquery%22), is(not(-1)));%0A        assertThat(ArrayUtil.indexOf(QueryBuilderFactory.EXTENSIONS, %22xql%22), is(not(-1))); // XQuery Language File%0A        assertThat(ArrayUtil.indexOf(QueryBuilderFactory.EXTENSIONS, %22xqm%22), is(-1)); // XQuery Module File%0A        assertThat(ArrayUtil.indexOf(QueryBuilderFactory.EXTENSIONS, %22xqu%22), is(not(-1)));%0A        assertThat(ArrayUtil.indexOf(QueryBuilderFactory.EXTENSIONS, %22xqws%22), is(-1)); // XQuery Web Service%0A%0A
         assertTh
@@ -2560,24 +2560,232 @@
 aScript() %7B%0A
+        assertThat(ArrayUtil.indexOf(QueryBuilderFactory.EXTENSIONS, %22js%22), is(not(-1)));%0A        assertThat(ArrayUtil.indexOf(QueryBuilderFactory.EXTENSIONS, %22sjs%22), is(not(-1))); // Server-side JavaScript%0A%0A
         asse
@@ -3074,24 +3074,116 @@
 testSQL() %7B%0A
+        assertThat(ArrayUtil.indexOf(QueryBuilderFactory.EXTENSIONS, %22sql%22), is(not(-1)));%0A%0A
         asse
@@ -3334,32 +3334,217 @@
 SPARQLQuery() %7B%0A
+        assertThat(ArrayUtil.indexOf(QueryBuilderFactory.EXTENSIONS, %22sparql%22), is(not(-1)));%0A        assertThat(ArrayUtil.indexOf(QueryBuilderFactory.EXTENSIONS, %22rq%22), is(not(-1)));%0A%0A
         assertTh
@@ -3843,24 +3843,115 @@
 LUpdate() %7B%0A
+        assertThat(ArrayUtil.indexOf(QueryBuilderFactory.EXTENSIONS, %22ru%22), is(not(-1)));%0A%0A
         asse
@@ -4074,32 +4074,32 @@
 lass)));%0A    %7D%0A%0A
-
     public void 
@@ -4107,24 +4107,208 @@
 estXSLT() %7B%0A
+        assertThat(ArrayUtil.indexOf(QueryBuilderFactory.EXTENSIONS, %22xsl%22), is(not(-1)));%0A        assertThat(ArrayUtil.indexOf(QueryBuilderFactory.EXTENSIONS, %22xslt%22), is(not(-1)));%0A%0A
         asse

Test the QueryBuilderFactory extensions.