001    /**
002     * Copyright 2004-2012 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.apache.torque.mojo;
017    
018    import java.util.Collections;
019    import java.util.Comparator;
020    import java.util.Vector;
021    
022    import org.apache.torque.util.TransactionComparator;
023    import org.junit.Test;
024    import org.kuali.db.Transaction;
025    
026    public class TransactionComparatorTest {
027    
028            @Test
029            public void testComparator() {
030                    Comparator<Transaction> comparator = new TransactionComparator<Transaction>("ks-embedded-db");
031                    Vector<Transaction> transactions = new Vector<Transaction>();
032                    transactions.add(getTransaction("003.sql"));
033                    transactions.add(getTransaction("004.sql"));
034                    transactions.add(getTransaction("001.sql"));
035                    transactions.add(getTransaction("sql/oracle/ks-embedded-db.sql"));
036                    transactions.add(getTransaction("002.sql"));
037                    transactions.add(getTransaction("sql/oracle/ks-embedded-db-constraints.sql"));
038                    transactions.add(getTransaction("001.sql"));
039                    transactions.add(getTransaction("000.sql"));
040                    transactions.add(getTransaction("zzz000.sql"));
041                    Collections.sort(transactions, comparator);
042                    showTransactions(transactions);
043            }
044    
045            protected void showTransactions(Vector<Transaction> transactions) {
046                    for (Transaction t : transactions) {
047                            System.out.println(t.getResourceLocation());
048                    }
049            }
050    
051            protected Transaction getTransaction(String location) {
052                    Transaction t = new Transaction();
053                    t.setResourceLocation(location);
054                    return t;
055            }
056    }