@Test public void testSinglePatternMatch() throws ParameterValidatorException { validator.setPattern("[a-m]+"); mockReq.addParameterValue("test", "amma"); validator.validate(mockReq, "test"); Assert.assertEquals("amma", requestObject.getStringMember()); }
@Test public void testSinglePatternInsensitive2() throws ParameterValidatorException { validator.setCaseInsensitive(true); validator.setPattern("[a-m]+"); mockReq.addParameterValue("test", "AMMA"); validator.validate(mockReq, "test"); Assert.assertEquals("AMMA", requestObject.getStringMember()); }
@Test public void testMultiplePatternMatch() throws ParameterValidatorException { ArrayList<String> patterns = new ArrayList<String>(); patterns.add("one"); patterns.add("two"); patterns.add("three"); validator.setPatterns(patterns); mockReq.addParameterValue("test", "two"); validator.validate(mockReq, "test"); Assert.assertEquals("two", requestObject.getStringMember()); }
@Test public void testEmptySuccess() throws ParameterValidatorException { mockReq.addParameterValue("test", ""); validator.validate(mockReq, "test"); Assert.assertEquals("", requestObject.getStringMember()); }
@Test public void testAllowNullParam() throws ParameterValidatorException { validator.setRequired(false); validator.validate(mockReq, "test"); Assert.assertEquals(null, requestObject.getStringMember()); }