@Test public void testNameIncludeFooExcludeBar() throws Exception { _regexContextMapper.setIncludes(".*foo.*"); _regexContextMapper.setExcludes(".*bar.*"); assertTrue(_regexContextMapper.matches("abc_foo_def")); assertFalse(_regexContextMapper.matches("abc_bar_def")); }
@Test public void testQNameIncludeEverythingExcludeEverything() throws Exception { _regexContextMapper.setIncludeNamespaces(".*"); _regexContextMapper.setExcludeNamespaces(".*"); assertFalse(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:1.0", "banana"))); assertFalse(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:2.0", "banana"))); }
@Test public void testQNameInclude2Exclude1() throws Exception { _regexContextMapper.setIncludeNamespaces("urn:.*:2.0"); _regexContextMapper.setExcludeNamespaces("urn:.*:1.0"); assertTrue(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:2.0", "foo"))); assertFalse(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:1.0", "foo"))); }
@Test public void testQNameFooExcludeTxt() throws Exception { _regexContextMapper.setIncludeNamespaces("urn:foo:.*"); _regexContextMapper.setExcludes(".*.txt"); assertTrue(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:1.0", "bar.xml"))); assertTrue(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:2.0", "bar.pdf"))); assertFalse(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:1.0", "bar.txt"))); }
@Test public void testQNameIncludeFooIncludeBar() throws Exception { _regexContextMapper.setIncludeNamespaces("urn:foo:1.0"); _regexContextMapper.setIncludes("bar"); assertTrue(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:1.0", "bar"))); assertFalse(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:1.0", "banana"))); assertFalse(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:2.0", "bar"))); }
/** * Will create a new ContextMapper based on the specifications of the passed in * ContextMapperModel, or if a class it not specified, will apply the rest of the model properties * on the default/fallback implementation. * * @param model contains the config details * @return the new ContextMapper instance */ @SuppressWarnings("unchecked") public final ContextMapper<D> newContextMapper(ContextMapperModel model) { ContextMapper<D> contextMapper = null; ContextMapperFactory<D> contextMapperFactory = ContextMapperFactory.getContextMapperFactory(getBindingDataClass()); if (model != null) { contextMapper = contextMapperFactory.newContextMapper( (Class<ContextMapper<D>>) Classes.forName(model.getClazz())); contextMapper.setModel(model); if (contextMapper instanceof RegexContextMapper) { RegexContextMapper<D> regexContextMapper = (RegexContextMapper<D>) contextMapper; regexContextMapper.setIncludes(model.getIncludes()); regexContextMapper.setExcludes(model.getExcludes()); regexContextMapper.setIncludeNamespaces(model.getIncludeNamespaces()); regexContextMapper.setExcludeNamespaces(model.getExcludeNamespaces()); } } else { contextMapper = contextMapperFactory.newContextMapperDefault(); } return contextMapper; }
@Test public void testMixedIncludesExcludes() throws Exception { _regexContextMapper.setIncludes("david, tom.*"); _regexContextMapper.setExcludes("keith"); _regexContextMapper.setIncludeNamespaces("urn:.*:2.0,urn:.*:3.0"); _regexContextMapper.setExcludeNamespaces("urn:.*:3.0"); assertTrue(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:2.0", "tomc"))); assertTrue(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:2.0", "tomf"))); assertFalse(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:1.0", "tomc"))); assertFalse(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:3.0", "david"))); assertFalse(_regexContextMapper.matches(XMLHelper.createQName("urn:foo:2.0", "keith"))); }
@Test public void testNameIncludeEverythingExcludeEverything() throws Exception { _regexContextMapper.setIncludes(".*"); _regexContextMapper.setExcludes(".*"); assertFalse(_regexContextMapper.matches("foo")); }
@Test public void testName() throws Exception { assertTrue(_regexContextMapper.matches("foo")); }