// ------------------------------------------------- Individual Test Methods public void testPatternMatch() { String patternStr = "t.*"; RegexValidator validator = new RegexValidator(); validator.setPattern(patternStr); UIInput component = new UIInput(); String checkme = "test"; try { validator.validate(facesContext, component, checkme); assertTrue(true); } catch (ValidatorException ve) { fail("Exception thrown " + ve.getMessage()); } }
public void testPatterMismatch() { String patternStr = "t.*"; facesContext.getViewRoot().setLocale(Locale.US); RegexValidator validator = new RegexValidator(); validator.setPattern(patternStr); UIInput component = new UIInput(); String checkme = "jest"; try { validator.validate(facesContext, component, checkme); fail("Exception not thrown when tested " + checkme + " against " + patternStr); } catch (ValidatorException ve) { String detail = ve.getFacesMessage().getDetail(); System.out.println("Detail in test: " + detail); assertTrue(detail.equalsIgnoreCase("Regex pattern of 't.*' not matched")); } }
public void testExpired() throws Exception { System.out.println("validate - Expired"); KeyPair pair = KeyManager.createKeyPair(); License license = LicenseFactory.createLicense(); license.setStartDate(new Date(100)); LicenseSigner signer = LicenseSigner.createLicenseSigner((DSAPrivateKey) pair.getPrivate()); signer.sign(license); String key = new String(Hex.encodeHex(pair.getPublic().getEncoded())); Validator validator = new Validator(license, key); boolean ex = false; try { validator.validate(); } catch (ValidatorException e) { System.out.println("\t" + e.getMessage()); ex = true; } assertTrue(ex); }
public void testBlacklist() throws Exception { System.out.println("validate - Blacklist"); KeyPair pair = KeyManager.createKeyPair(); License license = LicenseFactory.createLicense(); license.addProperty("Name", "Jason Nichols"); license.addProperty("Email", "*****@*****.**"); license.addProperty("Gibberish", "qwertyasdfg"); LicenseSigner signer = LicenseSigner.createLicenseSigner((DSAPrivateKey) pair.getPrivate()); signer.sign(license); String key = new String(Hex.encodeHex(pair.getPublic().getEncoded())); Validator validator = new Validator(license, key); validator.addBlacklistedLicense(license.getLicenseSignatureString()); boolean ex = false; try { validator.validate(); } catch (ValidatorException e) { System.out.println("\t" + e.getMessage()); ex = true; } assertTrue(ex); }