001package org.xbib.elasticsearch.river.plugin;
002
003import java.io.IOException;
004
005import org.testng.Assert;
006import org.testng.annotations.Test;
007
008import org.xbib.elasticsearch.plugin.jdbc.util.SQLCommand;
009
010public class SQLCommandTests extends Assert {
011                @Test
012                public void simpleQuery() throws IOException {
013                        SQLCommand sc = new SQLCommand().setSQL("select * from table");
014                        assertTrue(sc.isQuery());
015                }
016
017                @Test
018                public void updateQueryType() throws IOException {
019                        SQLCommand sc = new SQLCommand().setSQL("update foo");
020                        assertFalse(sc.isQuery());
021                }
022
023                @Test
024                public void updateWithSubselect() throws IOException {
025                        SQLCommand sc = new SQLCommand().setSQL("update foo set thingie = select");
026                        assertFalse(sc.isQuery());
027                }
028
029                @Test
030                public void updateWithSubselectAndLeadingWhitespace() throws IOException {
031                        SQLCommand sc = new SQLCommand().setSQL("   update foo set thingie = select");
032                        assertFalse(sc.isQuery());
033                }
034
035                @Test
036                public void updateUpperCaseWithSelect() throws IOException {
037                        SQLCommand sc = new SQLCommand().setSQL("UPDATE foo set thingie = SELECT");
038                        assertFalse(sc.isQuery());
039                }
040
041                @Test
042                public void insertWithSelect() throws IOException {
043                        SQLCommand sc = new SQLCommand().setSQL("insert into foo values select * from bar");
044                        assertFalse(sc.isQuery());
045                }
046}