View Javadoc

1   /**
2    * Copyright 2006-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.codehaus.mojo.sql;
17  
18  import java.util.Vector;
19  
20  import org.apache.maven.plugin.MojoExecutionException;
21  import org.junit.Test;
22  import org.springframework.core.io.DefaultResourceLoader;
23  import org.springframework.core.io.Resource;
24  
25  /**
26   * Unit test for simple SqlExecMojo.
27   */
28  public class SqlExecMojoTest {
29  	private SqlExecMojo mojo = new SqlExecMojo();
30  
31  	@Test
32  	public void test1() throws MojoExecutionException {
33  		try {
34  			mojo.setResourceListingLocation("classpath:locations.listing");
35  			SqlResource[] resources = mojo.getResources(null, mojo.getResourceListingLocation());
36  			System.out.println(resources.length);
37  			for (SqlResource resource : resources) {
38  				System.out.println(resource.getResource().getDescription());
39  			}
40  		} catch (Exception e) {
41  			e.printStackTrace();
42  		}
43  	}
44  
45  	@Test
46  	public void test2() throws MojoExecutionException {
47  		try {
48  			mojo.setResourceListingLocation("classpath:locations.listing");
49  			String[] locations = new String[] { "classpath:a.properties" };
50  			SqlResource[] resources = mojo.getResources(locations, mojo.getResourceListingLocation());
51  			System.out.println(resources.length);
52  			for (SqlResource resource : resources) {
53  				System.out.println(resource.getResource().getDescription());
54  			}
55  		} catch (Exception e) {
56  			e.printStackTrace();
57  		}
58  	}
59  
60  	@Test
61  	public void test3() throws MojoExecutionException {
62  		try {
63  			mojo.setResourceListingLocation("classpath:locations.listing");
64  			mojo.addResourcesToTransactions();
65  			Vector<SqlExecMojo.Transaction> transactions = mojo.transactions;
66  			System.out.println(transactions.size());
67  			for (SqlExecMojo.Transaction transaction : transactions) {
68  				System.out.println("[" + transaction.resource.location + "] [" + transaction.resource.getResource().getURI() + "]");
69  			}
70  			DefaultResourceLoader loader = new DefaultResourceLoader();
71  			Resource resource = loader.getResource(mojo.getResourceListingLocation());
72  			System.out.println(resource.getURI());
73  		} catch (Exception e) {
74  			e.printStackTrace();
75  		}
76  	}
77  }