Skip to content

Instantly share code, notes, and snippets.

@gregw
Created August 3, 2016 04:03
Show Gist options
  • Save gregw/7078b84515b18d45d6682617ea531a99 to your computer and use it in GitHub Desktop.
Save gregw/7078b84515b18d45d6682617ea531a99 to your computer and use it in GitHub Desktop.
Test of IssueRegex
package org.eclipse.jetty.embedded;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.junit.Assert;
import org.junit.Test;
public class IssueRegexTest
{
final static String[] IDs = new String[] {"gid","eid0","eid1","eid2","eid3","cid"};
@Test
public void test()
{
String codehausId = "(?<cid>JETTY-[0-9]{2,})";
String eclipseId = "((^(?<eid0>[0-9]{2,}))|(\\[([a-z]+ )?(?<eid1>[0-9]{2,})\\])|(\\((?<eid2>[0-9]{2,})\\))|((?<eid3>[0-9]{2,}) -))";
String githubId = "(?<gid>#[0-9]{2,})";
Pattern pat = Pattern.compile("^[^-]*?("+codehausId+"|"+eclipseId+"|"+githubId+").*$", Pattern.CASE_INSENSITIVE);
test(pat, "1234", "1234 - Hello");
test(pat, "388073", "[Bug 388073] null session id from cookie causes NPE fixed");
test(pat, "387953", "387953 jstl does not work with jetty-7 in osgi");
test(pat, "JETTY-1515", "JETTY-1515 Include cookies on 304 responses from DefaultServlet.");
test(pat, "388502", "388502 handle earlyEOF with 500");
test(pat, "391483", "[391483] fix bad javadoc example in shutdown handler");
test(pat, null, "RFC 6265 restricts duplicate cookie names in same response");
test(pat, "390108", "(390108) Servlet 3.0 API for programmatic login doesn't appear to work");
test(pat, "#666", "Fixing link and grammatical changes for JMX Dump; added updated diagram for configuration. (#666)");
test(pat, "#658", " Issue #658");
test(pat, "#669", "Support UNC paths in PathResource #669");
test(pat, "#658", "Issue #658");
test(pat, "#699", "Merge pull request #699 from WalkerWatch/jetty-9.3.x");
test(pat, "#679", "Chapter 6 fixes, removal of Quickstart pieces for #679.");
test(pat, "#723", "Fixes #723 - improves MimeType resource loading and error reporting (#724)");
test(pat, "#592", "fix #592");
test(pat, "#81", "Issue #81 Exception not always thrown in Jetty to application when upload part is too big Issue #82 Request.getPart() that results in Exception still allows other parts to be fetched");
test(pat, "486497", "486497 NPE in MappedLoginService");
test(pat, "486394", "Revert \"486394 - Restore MultiPartFilter behavior with regards to temp file access\"");
test(pat, "#80", "Issue #80 (Spin loop in case of HTTP/2 prefaces without H2C).");
}
private void test(Pattern pat, String expected, String raw)
{
Matcher mat = pat.matcher(raw);
if (mat.find())
{
String issue=null;
for (String id:IDs)
{
issue=mat.group(id);
if (issue!=null)
break;
}
System.out.printf("MATCH [%s] - %s%n", issue, raw);
Assert.assertThat(issue,is(expected));
}
else
{
System.out.println("NO MATCH - " + raw);
Assert.assertThat(expected,nullValue());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment