/*! ******************************************************************************
 *
 * Pentaho Data Integration
 *
 * Copyright (C) 2002-2014 by Pentaho : http://www.pentaho.com
 *
 *******************************************************************************
 *
 * 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 org.pentaho.di.core.jdbc;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import org.junit.Test;
import org.pentaho.di.core.exception.KettleSQLException;

public class ThinUtilTest {
  @Test
  public void testFindClauseNullOrEmptyString() throws KettleSQLException {
    assertNull( ThinUtil.findClause( null, null ) );
    assertNull( ThinUtil.findClause( "", null ) );
  }

  @Test
  public void testFindSelectFromNotFound() throws KettleSQLException {
    assertNull( ThinUtil.findClause( "Select * From Test", "WHERE" ) );
  }

  @Test
  public void testFindSelectFromFound() throws KettleSQLException {
    assertEquals( "*", ThinUtil.findClause( "Select * From Test", "SELECT", "FROM" ) );
  }

  @Test
  public void testFindClauseSkipsChars() throws KettleSQLException {
    assertNull( ThinUtil.findClause( "'Select' * From Test", "SELECT", "FROM" ) );
  }
}

@@ -1016,19 +1016,189 @@
 t.assert
-Nul
+False;%0Aimport static org.junit.Assert.assertNotNull;%0Aimport static org.junit.Assert.assertNull;%0Aimport static org.junit.Assert.assertTrue;%0Aimport static org.junit.Assert.fai
 l;%0A%0Aimpo
@@ -1983,11 +1983,604 @@
 ) );%0A  %7D
+%0A%0A  @Test%0A  public void testLikePatternMatching() %7B%0A    try %7B%0A      ThinUtil.like( %22foo%22, null );%0A      fail( %22Null pattern should not be allowed%22 );%0A    %7D catch ( IllegalArgumentException e ) %7B%0A      assertNotNull( e );%0A    %7D%0A%0A    assertTrue( %22Exact Matching%22, ThinUtil.like( %22foobar%22, %22foobar%22 ) );%0A%0A    assertTrue( %22_ Matching%22, ThinUtil.like( %22foobar%22, %22f__b_r%22 ) );%0A    assertTrue( %22* Matching%22, ThinUtil.like( %22foobar%22, %22foo%25%22 ) );%0A%0A    assertTrue( %22Regex Escaping%22, ThinUtil.like( %22foo%5C%5C*?%5B%5D()bar%22, %22%25%5C%5C*?%5B%5D()%25%22 ) );%0A%0A    assertFalse( %22False Match%22, ThinUtil.like( %22foo%22, %22bar%22 ) );%0A  %7D
 %0A%7D%0A

Test like Pattern Match