1 package com.inigoserrano.isdirvalidator;
2
3 import junit.framework.Test;
4 import junit.framework.TestSuite;
5
6 /***
7 * This class actualy is only designed to test in my PC, not for general usage
8 * @task Document to fit the sun code conventions
9 * @task Change to create the directory structure and doesnīt depend on my
10 * personal computer
11 * <br>
12 * <i>This program is license under the terms of the GNU GPL v 2.0 License</i>
13 * @author Iņigo Serrano
14 * @version 2.0.1
15 */
16 public class DirectoryTest extends junit.framework.TestCase {
17 private Directory dir = null;
18 private static String directoryPath = "g://usuarios//inigo//isdircheck";
19
20 /***
21 * Method main.
22 * @param arg the arguments
23 */
24 public static void main(String[] arg) {
25 junit.textui.TestRunner.run(suite());
26 }
27
28 public DirectoryTest(String testName) {
29 super(testName);
30 }
31
32 protected void setUp() {
33 this.dir = new Directory();
34 this.dir.setDirectory(DirectoryTest.directoryPath);
35 }
36
37 public static Test suite() {
38 TestSuite theSuite = new TestSuite();
39 //test the EmailConstraint with all the defaults values
40 theSuite.addTest(new DirectoryTest("testOkFileNoPatterm"));
41 theSuite.addTest(new DirectoryTest("testOkFileOkPatterm"));
42 theSuite.addTest(new DirectoryTest("testNoFileOkPatterm"));
43 theSuite.addTest(new DirectoryTest("testNoFileNoPatterm"));
44 theSuite.addTest(new DirectoryTest("testErrFileNoPatterm"));
45 theSuite.addTest(new DirectoryTest("testNoFileErrPatterm"));
46 theSuite.addTest(new DirectoryTest("testErrFileErrPatterm"));
47 theSuite.addTest(new DirectoryTest("testErrObligFileNoPatterm"));
48 theSuite.addTest(new DirectoryTest("testOkObligFileNoPatterm"));
49 theSuite.addTest(new DirectoryTest("testOkObligFileOkPatterm"));
50 theSuite.addTest(new DirectoryTest("testErrObligFileNoPattermSayFile"));
51 theSuite.addTest(new DirectoryTest("testErrObligFileOkPattermSayFile"));
52 theSuite.addTest(new DirectoryTest("testSubDirectoryOk"));
53 theSuite.addTest(new DirectoryTest("testSubDirectoryErr"));
54 theSuite.addTest(new DirectoryTest("testNoDirectory"));
55 theSuite.addTest(new DirectoryTest("testNoSubDirectory"));
56 return theSuite;
57 }
58
59 public void testErrObligFileOkPattermSayFile() {
60 try {
61 dir.addFile("hola.pepe", true);
62 dir.addFilePatterm(".+");
63 dir.isValid();
64 assertTrue(
65 dir.isObligatoryFileError()
66 && (dir
67 .getInvalidFile()
68 .equals(DirectoryTest.directoryPath + "//hola.pepe")));
69 } catch (Exception e) {
70 e.printStackTrace();
71 fail("Por exception: " + e);
72 }
73 }
74
75 public void testErrObligFileNoPattermSayFile() {
76 try {
77 dir.addFile("build.xml", true);
78 dir.isValid();
79 assertTrue(
80 dir.isExtraFileError()
81 && (dir
82 .getInvalidFile()
83 .equals(
84 DirectoryTest.directoryPath + "//definicion.txt")));
85 } catch (Exception e) {
86 e.printStackTrace();
87 fail("Por exception: " + e);
88 }
89 }
90
91 public void testOkObligFileOkPatterm() {
92 try {
93 dir.addFile("build.xml", true);
94 dir.addFile("definicion.txt", false);
95 dir.addFilePatterm(".+");
96 assertTrue(dir.isValid());
97 } catch (Exception e) {
98 e.printStackTrace();
99 fail("Por exception: " + e);
100 }
101 }
102
103 public void testOkObligFileNoPatterm() {
104 try {
105 dir.addFile("build.xml", true);
106 dir.addFile("definicion.txt", false);
107 assertTrue(dir.isValid());
108 } catch (Exception e) {
109 e.printStackTrace();
110 fail("Por exception: " + e);
111 }
112 }
113
114 public void testErrObligFileNoPatterm() {
115 try {
116 dir.addFile("hola.pepe", true);
117 dir.addFilePatterm(".+");
118 assertTrue((!dir.isValid()) && dir.isObligatoryFileError());
119 } catch (Exception e) {
120 e.printStackTrace();
121 fail("Por exception: " + e);
122 }
123 }
124
125 public void testErrFileErrPatterm() {
126 try {
127 dir.addFile("hola.pepe");
128 dir.addFilePatterm(".+//.xhml");
129 assertTrue(
130 (!dir.isValid())
131 && (dir.isObligatoryFileError() || dir.isExtraFileError()));
132 } catch (Exception e) {
133 e.printStackTrace();
134 fail("Por exception: " + e);
135 }
136 }
137
138 public void testNoFileErrPatterm() {
139 try {
140 dir.addFilePatterm(".+//.txt");
141 assertTrue((!dir.isValid()) && dir.isExtraFileError());
142 } catch (Exception e) {
143 e.printStackTrace();
144 fail("Por exception: " + e);
145 }
146 }
147
148 public void testNoFileOkPatterm() {
149 try {
150 dir.addFilePatterm(".+//.txt");
151 dir.addFilePatterm(".+//.xml");
152 assertTrue(dir.isValid());
153 } catch (Exception e) {
154 e.printStackTrace();
155 fail("Por exception: " + e);
156 }
157 }
158
159 public void testNoFileNoPatterm() {
160 try {
161 assertTrue(dir.isValid());
162 } catch (Exception e) {
163 fail();
164 }
165 }
166
167 public void testOkFileNoPatterm() {
168 try {
169 dir.addFile("build.xml");
170 dir.addFile("definicion.txt");
171 assertTrue(dir.isValid());
172 } catch (Exception e) {
173 fail();
174 }
175 }
176
177 public void testErrFileNoPatterm() {
178 try {
179 dir.addFile("build.xml");
180 assertTrue((!dir.isValid()) && dir.isExtraFileError());
181 } catch (Exception e) {
182 fail("Por la excepcion");
183 }
184 }
185
186 public void testOkFileOkPatterm() {
187 try {
188 dir.addFile("build.xml");
189 dir.addFilePatterm(".+//.txt");
190 assertTrue(dir.isValid());
191 } catch (Exception e) {
192 fail();
193 }
194 }
195
196 public void testNoDirectory() {
197 try {
198 dir.setDirectory("g://usuarios//inigo//pepe");
199 assertTrue((!dir.isValid()) && dir.isDirectoryError());
200 } catch (Exception e) {
201 fail();
202 }
203 }
204
205 public void testSubDirectoryOk() {
206 try {
207 dir.addSubDirectoryPatterm(".+");
208 dir.addSubDirectoryPatterm("[a-zA-Z]+");
209 assertTrue(dir.isValid());
210 } catch (Exception e) {
211 fail();
212 }
213 }
214
215 public void testSubDirectoryErr() {
216 try {
217 dir.addSubDirectoryPatterm("^[a-z]+$");
218 assertTrue((!dir.isValid()) && dir.isExtraSubDirectoryError());
219 } catch (Exception e) {
220 fail();
221 }
222 }
223
224 public void testNoSubDirectory() {
225 try {
226 dir.setDirectory("g://usuarios//inigo//isdircheck//Documentos");
227 dir.addSubDirectoryPatterm(".*");
228 assertTrue(dir.isValid());
229 } catch (Exception e) {
230 fail();
231 }
232 }
233
234 }
This page was automatically generated by Maven