View Javadoc

1   package org.codehaus.modello.db;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.archiva.redback.components.modello.db.SQLReservedWords;
23  import org.codehaus.plexus.PlexusTestCase;
24  
25  import java.util.List;
26  
27  /**
28   * SQLReservedWordsTest 
29   *
30   * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
31   * @version $Id: SQLReservedWordsTest.java 1414987 2012-11-28 23:12:52Z olamy $
32   */
33  public class SQLReservedWordsTest extends PlexusTestCase
34  {
35      private SQLReservedWords keywords;
36  
37      protected void setUp() throws Exception
38      {
39          super.setUp();
40  
41          keywords = (SQLReservedWords) lookup( SQLReservedWords.class.getName(), "default" );
42      }
43  
44      protected void tearDown() throws Exception
45      {
46          // No real point in doing this, as the object is essentially read-only.
47          release( keywords );
48          super.tearDown();
49      }
50  
51      public void testTrueKeywords()
52      {
53          assertNotNull( keywords );
54  
55          // Normal Usage
56          assertTrue( keywords.isKeyword( "SELECT" ) );
57          assertTrue( keywords.isKeyword( "INSERT" ) );
58          assertTrue( keywords.isKeyword( "TIMEZONE_HOUR" ) );
59          assertTrue( keywords.isKeyword( "IF" ) );
60          assertTrue( keywords.isKeyword( "IN" ) );
61  
62          // Bad formatted, but otherwise good keywords.
63          assertTrue( keywords.isKeyword( "SQLEXCEPTION                 " ) );
64          assertTrue( keywords.isKeyword( "LOOP\t" ) );
65          assertTrue( keywords.isKeyword( "\n\nEXISTS" ) );
66          assertTrue( keywords.isKeyword( " into " ) );
67          assertTrue( keywords.isKeyword( "Match " ) );
68      }
69  
70      public void testNotKeywords()
71      {
72          assertNotNull( keywords );
73  
74          assertFalse( keywords.isKeyword( "MAVEN" ) );
75          assertFalse( keywords.isKeyword( "REPOSITORY" ) );
76          assertFalse( keywords.isKeyword( "Artifact" ) );
77          assertFalse( keywords.isKeyword( null ) );
78          assertFalse( keywords.isKeyword( "" ) );
79          assertFalse( keywords.isKeyword( "    " ) );
80          assertFalse( keywords.isKeyword( "filename" ) );
81          assertFalse( keywords.isKeyword( "pathTo" ) );
82          assertFalse( keywords.isKeyword( "modello" ) );
83          assertFalse( keywords.isKeyword( "versions" ) );
84      }
85  
86      public void testKeywordSourceList()
87      {
88          List sources;
89  
90          sources = keywords.getKeywordSourceList( "MAVEN" );
91          assertNull( "Should be null.", sources );
92  
93          sources = keywords.getKeywordSourceList( "IF" );
94          assertNotNull( "Should not be null.", sources );
95          assertTrue( sources.size() > 5 );
96      }
97  
98      public void testKeywordSourceString()
99      {
100         String actual = keywords.getKeywordSourceString( "MAVEN" );
101         assertNull( "Should be null.", actual );
102 
103         actual = keywords.getKeywordSourceString( "ADD" );
104         assertEquals( "SQL 92, SQL 99, SQL 2003, JDBC, Derby Server, HSQLDB, MySQL, PostgreSQL, Oracle, PL/SQL, " +
105                 "Microsoft SQL Server, Microsoft Access, IBM DB/2, ODBC", actual );
106 
107         actual = keywords.getKeywordSourceString( "MULTISET" );
108         assertEquals( "SQL 2003, HSQLDB", actual );
109     }
110 }