Source:
<code>public void vanityRedirectURLMAP() throws IOException, DotDataException { Contentlet vanityURLContentlet = null; try { List<ContentType> listContentType = APILocator.getContentTypeAPI(user).findUrlMapped(); ContentType newsContentType = null; <START> for(ContentType ct : listContentType){ <END> if(("news").equalsIgnoreCase(ct.variable())){ newsContentType = ct; break; } } final Contentlet urlmapContentlet = contentletAPI.findByStructure(new StructureTransformer(newsContentType).asStructure(), user, true, -1, 0).get(0); String forwardTo = "/news/" + urlmapContentlet.getStringProperty("urlTitle"); vanityURLContentlet = filtersUtil .createVanityUrl("urlmap", defaultHost.getIdentifier(), "/urlnews", forwardTo, 200, 1, defaultLanguageId); filtersUtil.publishVanityUrl(vanityURLContentlet); VanityURLFilter filter = new VanityURLFilter(); FilterChain chain = Mockito.mock(FilterChain.class); Logger.info(this.getClass(), "/urlnews should forward to " + forwardTo); HttpServletRequest request = getMockRequest("demo.dotcms.com", "/urlnews"); MockResponseWrapper response = new MockResponseWrapper( Mockito.mock(HttpServletResponse.class)); filter.doFilter(request, response, chain); Logger.info(this.getClass(), "looking for 200, got:" + response.getStatus()); Assert.assertEquals(200, response.getStatus()); Logger.info(this.getClass(), "looking for " + forwardTo + ", got:" + request .getAttribute(Constants.CMS_FILTER_URI_OVERRIDE)); Assert.assertEquals(forwardTo, request.getAttribute(Constants.CMS_FILTER_URI_OVERRIDE)); } catch (Exception e) { e.printStackTrace(); Assert.fail(); } finally { try { if(vanityURLContentlet != null) { contentletAPI.delete(vanityURLContentlet, user, false); } } catch (Exception e) { Logger.error(this.getClass(), "Error deleting Vanity URL"); } } }</code><technical_language>a name contentType</technical_language>

Target:
public void vanityRedirectURLMAP() throws IOException, DotDataException { Contentlet vanityURLContentlet = null; try { final List<ContentType> listContentType = APILocator.getContentTypeAPI(user).findUrlMapped(); ContentType newsContentType = null; for(final ContentType contentType : listContentType){ if(("news").equalsIgnoreCase(contentType.variable())){ newsContentType = contentType; break; } } final Contentlet urlmapContentlet = contentletAPI.findByStructure(new StructureTransformer(newsContentType).asStructure(), user, true, -1, 0).get(0); final String forwardTo = "/news/" + urlmapContentlet.getStringProperty("urlTitle"); vanityURLContentlet = filtersUtil .createVanityUrl("urlmap", defaultHost.getIdentifier(), "/urlnews", forwardTo, 200, 1, defaultLanguageId); filtersUtil.publishVanityUrl(vanityURLContentlet); VanityURLFilter filter = new VanityURLFilter(); FilterChain chain = Mockito.mock(FilterChain.class); Logger.info(this.getClass(), "/urlnews should forward to " + forwardTo); final HttpServletRequest request = getMockRequest("demo.dotcms.com", "/urlnews"); final MockResponseWrapper response = new MockResponseWrapper( Mockito.mock(HttpServletResponse.class)); filter.doFilter(request, response, chain); Logger.info(this.getClass(), "looking for 200, got:" + response.getStatus()); Assert.assertEquals(200, response.getStatus()); Logger.info(this.getClass(), "looking for " + forwardTo + ", got:" + request .getAttribute(Constants.CMS_FILTER_URI_OVERRIDE)); Assert.assertEquals(forwardTo, request.getAttribute(Constants.CMS_FILTER_URI_OVERRIDE)); } catch (Exception e) { e.printStackTrace(); Assert.fail(); } finally { try { if(vanityURLContentlet != null) { contentletAPI.delete(vanityURLContentlet, user, false); } } catch (Exception e) { Logger.error(this.getClass(), "Error deleting Vanity URL"); } } }