1 37 package net.sourceforge.cruisecontrol.sourcecontrols; 38 39 import java.io.File ; 40 import java.net.URL ; 41 import java.net.URLDecoder ; 42 43 import junit.framework.TestCase; 44 import net.sourceforge.cruisecontrol.CruiseControlException; 45 46 54 public class Maven2SnapshotDependencyTest extends TestCase { 55 56 private static final String BAD_REPOSITORY = "folder"; 57 58 private static final String PROJECT_XML_RELATIVE_PATH = 59 "net/sourceforge/cruisecontrol/sourcecontrols/maven2-pom.xml"; 60 61 private static final String TEST_PROJECT_XML; 62 private static final String TEST_REPOSITORY; 63 64 static { 65 URL projectUrl = ClassLoader.getSystemResource(PROJECT_XML_RELATIVE_PATH); 66 TEST_PROJECT_XML = URLDecoder.decode(projectUrl.getPath()); 67 TEST_REPOSITORY = new File (TEST_PROJECT_XML).getParentFile().getAbsolutePath() + "/maven2repo"; 69 } 70 71 private Maven2SnapshotDependency dep; 72 73 public Maven2SnapshotDependencyTest(String name) { 74 super(name); 75 } 76 77 protected void setUp() { 78 dep = new Maven2SnapshotDependency(); 79 } 80 81 82 public void testValidateNoProject() { 83 84 try { 85 dep.validate(); 86 fail("Maven2SnapshotDependency should throw exceptions when required attributes are not set."); 87 } catch (CruiseControlException e) { 88 assertEquals("'pomFile' is required for Maven2SnapshotDependency", e.getMessage()); 89 } 90 } 91 92 public void testValidateProjectDoesNotExist() { 93 94 String fileName = BAD_REPOSITORY; 95 dep.setPomFile(fileName); 96 File f = new File (fileName); 97 try { 98 dep.validate(); 99 fail("Maven2SnapshotDependency should throw exceptions when required attributes have bad values."); 100 } catch (CruiseControlException e) { 101 assertEquals("Pom file '" + f.getAbsolutePath() 102 + "' does not exist.", e.getMessage()); 103 } 104 } 105 106 public void testValidateProjectIsDirectory() { 107 108 String fileName = TEST_REPOSITORY; 109 dep.setPomFile(fileName); 110 File f = new File (fileName); 111 try { 112 dep.validate(); 113 fail("Maven2SnapshotDependency should throw exceptions when required attributes have bad values."); 114 } catch (CruiseControlException e) { 115 assertEquals( 116 "The directory '" 117 + f.getAbsolutePath() 118 + "' cannot be used as the pomFile for Maven2SnapshotDependency.", 119 e.getMessage()); 120 } 121 } 122 123 public void testValidateRepositoryNotSet() throws Exception { 124 dep.setPomFile(TEST_PROJECT_XML); 125 dep.validate(); 126 } 127 128 public void testValidateRepositoryDoesNotExist() throws Exception { 129 130 String fileName = BAD_REPOSITORY; 131 dep.setPomFile(TEST_PROJECT_XML); 132 dep.setLocalRepository(fileName); 133 File f = new File (fileName); 134 try { 135 dep.validate(); 136 fail("Maven2SnapshotDependency should throw exceptions when repository has bad value."); 137 } catch (CruiseControlException e) { 138 assertEquals("Local Maven repository '" + f.getAbsolutePath() 139 + "' does not exist.", e.getMessage()); 140 } 141 } 142 143 public void testValidateRepositoryIsNotDirectory() throws Exception { 144 145 String fileName = TEST_PROJECT_XML; 146 dep.setPomFile(fileName); 147 dep.setLocalRepository(fileName); 148 File f = new File (fileName); 149 try { 150 dep.validate(); 151 fail("Maven2SnapshotDependency should throw exceptions when repository has bad value."); 152 } catch (CruiseControlException e) { 153 assertEquals("Local Maven repository '" + f.getAbsolutePath() 154 + "' must be a directory.", e.getMessage()); 155 } 156 } 157 158 public void testValidateOkWithRepo() throws Exception { 159 dep.setPomFile(TEST_PROJECT_XML); 160 dep.setLocalRepository(TEST_REPOSITORY); 161 dep.validate(); 162 } 163 164 public void testValidateOk() throws Exception { 165 dep.setPomFile(TEST_PROJECT_XML); 166 dep.validate(); 167 } 168 169 218 219 245 246 } 248 | Popular Tags |