001    /**
002     * Copyright 2006-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.codehaus.mojo.sql;
017    
018    import java.util.Vector;
019    
020    import org.apache.maven.plugin.MojoExecutionException;
021    import org.junit.Test;
022    import org.springframework.core.io.DefaultResourceLoader;
023    import org.springframework.core.io.Resource;
024    
025    /**
026     * Unit test for simple SqlExecMojo.
027     */
028    public class SqlExecMojoTest {
029            private SqlExecMojo mojo = new SqlExecMojo();
030    
031            @Test
032            public void test1() throws MojoExecutionException {
033                    try {
034                            mojo.setResourceListingLocation("classpath:locations.listing");
035                            SqlResource[] resources = mojo.getResources(null, mojo.getResourceListingLocation());
036                            System.out.println(resources.length);
037                            for (SqlResource resource : resources) {
038                                    System.out.println(resource.getResource().getDescription());
039                            }
040                    } catch (Exception e) {
041                            e.printStackTrace();
042                    }
043            }
044    
045            @Test
046            public void test2() throws MojoExecutionException {
047                    try {
048                            mojo.setResourceListingLocation("classpath:locations.listing");
049                            String[] locations = new String[] { "classpath:a.properties" };
050                            SqlResource[] resources = mojo.getResources(locations, mojo.getResourceListingLocation());
051                            System.out.println(resources.length);
052                            for (SqlResource resource : resources) {
053                                    System.out.println(resource.getResource().getDescription());
054                            }
055                    } catch (Exception e) {
056                            e.printStackTrace();
057                    }
058            }
059    
060            @Test
061            public void test3() throws MojoExecutionException {
062                    try {
063                            mojo.setResourceListingLocation("classpath:locations.listing");
064                            mojo.addResourcesToTransactions();
065                            Vector<SqlExecMojo.Transaction> transactions = mojo.transactions;
066                            System.out.println(transactions.size());
067                            for (SqlExecMojo.Transaction transaction : transactions) {
068                                    System.out.println("[" + transaction.resource.location + "] [" + transaction.resource.getResource().getURI() + "]");
069                            }
070                            DefaultResourceLoader loader = new DefaultResourceLoader();
071                            Resource resource = loader.getResource(mojo.getResourceListingLocation());
072                            System.out.println(resource.getURI());
073                    } catch (Exception e) {
074                            e.printStackTrace();
075                    }
076            }
077    }