01: /*******************************************************************************
02: * Portions created by Sebastian Thomschke are copyright (c) 2005-2007
03: * Sebastian Thomschke.
04: *
05: * All Rights Reserved. This program and the accompanying materials
06: * are made available under the terms of the Eclipse Public License v1.0
07: * which accompanies this distribution, and is available at
08: * http://www.eclipse.org/legal/epl-v10.html
09: *
10: * Contributors:
11: * Makkari - initial implementation.
12: *******************************************************************************/package net.sf.oval.test.constraints;
13:
14: import junit.framework.Assert;
15: import net.sf.oval.constraint.AssertURLCheck;
16: import net.sf.oval.constraint.AssertURLCheck.URIScheme;
17:
18: /**
19: * @author Makkari
20: *
21: */
22: public class AssertURLTest extends AbstractContraintsTest {
23: private static final URIScheme[] permittedSchemes = {
24: URIScheme.FTP, URIScheme.HTTP, URIScheme.HTTPS };
25:
26: public void testAssertURL() {
27: URIScheme[] actualPermittedSchemes = null;
28:
29: final AssertURLCheck check = new AssertURLCheck();
30: super .testCheck(check);
31: Assert.assertNull(check.getPermittedURISchemes());
32:
33: check.setPermittedURISchemes(AssertURLTest.permittedSchemes);
34: actualPermittedSchemes = check.getPermittedURISchemes();
35: Assert.assertNotNull(actualPermittedSchemes);
36: Assert.assertEquals(AssertURLTest.permittedSchemes.length,
37: actualPermittedSchemes.length);
38: for (int n = 0; n < AssertURLTest.permittedSchemes.length; n++) {
39: Assert.assertEquals(AssertURLTest.permittedSchemes[n],
40: actualPermittedSchemes[n]);
41: Assert.assertEquals(AssertURLTest.permittedSchemes[n]
42: .toString(), actualPermittedSchemes[n].getScheme());
43: }
44:
45: Assert.assertFalse(check.isConnect());
46: check.setConnect(true);
47: Assert.assertTrue(check.isConnect());
48:
49: check.setConnect(false);
50: Assert.assertTrue(check
51: .isSatisfied(this , null, null, validator));
52: Assert.assertFalse(check.isSatisfied(this , "http", null,
53: validator));
54: Assert.assertFalse(check.isSatisfied(this , "https", null,
55: validator));
56: Assert.assertFalse(check.isSatisfied(this , "ftp", null,
57: validator));
58: Assert.assertTrue(check.isSatisfied(this ,
59: "http://www.google.com", null, validator));
60: Assert.assertTrue(check.isSatisfied(this ,
61: "https://www.google.com", null, validator));
62: Assert.assertTrue(check.isSatisfied(this ,
63: "httPs://www.google.com", null, validator));
64: Assert.assertTrue(check.isSatisfied(this ,
65: "ftp://ftp.is.co.za/rfc/rfc1808.txt", null, validator));
66: Assert.assertFalse(check.isSatisfied(this ,
67: "ptth://www.google.com", null, validator));
68: Assert.assertFalse(check.isSatisfied(this ,
69: "http://www.g[oogle.com", null, validator));
70:
71: check.setConnect(true);
72: Assert.assertTrue(check
73: .isSatisfied(this , null, null, validator));
74: Assert.assertFalse(check.isSatisfied(this , "http", null,
75: validator));
76: Assert.assertFalse(check.isSatisfied(this , "https", null,
77: validator));
78: Assert.assertFalse(check.isSatisfied(this , "ftp", null,
79: validator));
80: Assert.assertTrue(check.isSatisfied(this ,
81: "http://www.google.com", null, validator));
82: Assert.assertTrue(check.isSatisfied(this ,
83: "https://www.365online.com/banking.htm", null,
84: validator));
85: Assert.assertFalse(check.isSatisfied(this ,
86: "http://www.cfhsdagfhas6sa.com", null, validator));
87: Assert.assertFalse(check.isSatisfied(this ,
88: "http://www.checkupdown.com/accounts/grpb/B1394343/",
89: null, validator));
90: Assert.assertTrue(check.isSatisfied(this ,
91: "ftp://ftp.is.co.za/rfc/rfc1808.txt", null, validator));
92: Assert.assertFalse(check.isSatisfied(this ,
93: "ftp://ftp.is.co.za/rff/rfc1808.txt", null, validator));
94:
95: check.setPermittedURISchemes(null);
96: }
97: }
|