From 2e299a7ebd88d14b1dcc329f881a329bc1c1d248 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Tue, 9 May 2017 12:03:50 +0200 Subject: [PATCH] fixed test --- jetty-annotations/src/test/jar/test-sci.jar | Bin 7570 -> 7570 bytes .../TestAnnotationConfiguration.java | 125 ++++++++++-------- 2 files changed, 68 insertions(+), 57 deletions(-) diff --git a/jetty-annotations/src/test/jar/test-sci.jar b/jetty-annotations/src/test/jar/test-sci.jar index b067e15c96883f0588d1cd27e9a6e5f3c2747cb8..bb9b90654bbc2aeb9f2e711a158a958597e6a50c 100644 GIT binary patch delta 2221 zcmZXW3p|tiAIBdynroKX#+F=0VJ`nt=2DWwn2|FbVH_!)RE(H%u;wmOE>C6uj?|d` zmP6%Ml5jdM6DpCSEw>U5(s7wl&bI&Q_0Ru2&+GSk|1RI(@B4k8*Z1>%o;=$;Ta2e0 z1gZ$YU@*Xi$|Zp~89|LK034PB00iiOMln+l1cVP*AQ;3EdmlS;c`pn1xriGBq*Z%A zWA{XFjALa*DbSLyy;e>AEDC6|gq9DaByCy|3ZkCY^?Mn%Y|2t8bilBK_vvZXQXf-p zT0^flN0=&7!<5^L{0#hEpQIqR>t}U3gh$@dZcuP+tHpBWs)9F-e2xj{O{e-r-8%oxq`EGs*im3B-8?_AOp^*uWK%>G+3b@IpE zQJHqHzSA}JcDfevh-!{VV;nl!nJE;lD*4nGU%bKn0vUaxAdK6cn8UhLG4b+{0c@{> z$UFZTjbDBq>rZSh&se^H;DXuc)i3nf?>CF?EWjE`Y~9V_iTP%0KC~3?o;la{-Gdgr=0y#nCKnA` z(@Kq*m$%1KuICYy;~cQg{lT}Y4IFD76D*I;{Hnj>Kn6K=?{8mgthU&!xh4fIVjY|vRS<=3C8pS!$dYkxR4l^@|y{G$6c zJZ-y?M$ezS;^T|>15+AVcitlPP)NR~p*o@#sZiADW~o5$nJvJUFO`|+E7hyN7|R?s zcG6G1d-XVHbne-?kH@z_L;_~U3-F9z2#-7JHMzl7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=bRXEl~!ibCdiBacEz8x+79l__Me)-z+X4Nqs7 zaj7AoBE3^9RiWuXPMl19vOr<)0Z2f(!El=3VWDa_d^QYnlH%fQ z^8!ntRT{XD#rSL*;#_ap85yc*%s1UZ4#3^ExoGq zn;NyRa_qz)Xej!>A4yOLqc183@>nbwg~5s1nHUohhcPf)y3I3%-SEz4*=-@8z5v! zw3QTyQriBXn>znlTJ=U)aB%RS7kEkw7i<72vM9Nqlz@YH9OSmFa9RaiqpBd%ovea` zAmoKZ>%mqPg|$D_GT|;$e$X sciNames = new HashSet<>(Arrays.asList("org.eclipse.jetty.annotations.ServerServletContainerInitializer", "com.acme.initializer.FooInitializer")); - + //prepare an sci that will be on the webapp's classpath File jarDir = new File(MavenTestingUtils.getTestResourcesDir().getParentFile(), "jar"); File testSciJar = new File(jarDir, "test-sci.jar"); - assertTrue(testSciJar.exists()); - URLClassLoader webAppLoader = new URLClassLoader(new URL[] {testSciJar.toURI().toURL()}, Thread.currentThread().getContextClassLoader()); + assertTrue(testSciJar.exists()); + URLClassLoader webAppLoader = new URLClassLoader(new URL[]{testSciJar.toURI().toURL()}, Thread.currentThread().getContextClassLoader()); - //test 3.1 webapp loads both server and app scis - AnnotationConfiguration config = new AnnotationConfiguration(); - WebAppContext context = new WebAppContext(); - context.setClassLoader(webAppLoader); - context.getMetaData().setWebXml(Resource.newResource(web31true)); - context.getServletContext().setEffectiveMajorVersion(3); - context.getServletContext().setEffectiveMinorVersion(1); - List scis = config.getNonExcludedInitializers(context); - assertNotNull(scis); - assertEquals(2, scis.size()); - assertTrue (sciNames.contains(scis.get(0).getClass().getName())); - assertTrue (sciNames.contains(scis.get(1).getClass().getName())); - - //test a 3.1 webapp with metadata-complete=false loads both server and webapp scis - config = new AnnotationConfiguration(); - context = new WebAppContext(); - context.setClassLoader(webAppLoader); - context.getMetaData().setWebXml(Resource.newResource(web31false)); - context.getServletContext().setEffectiveMajorVersion(3); - context.getServletContext().setEffectiveMinorVersion(1); - scis = config.getNonExcludedInitializers(context); - assertNotNull(scis); - assertEquals(2, scis.size()); - assertTrue (sciNames.contains(scis.get(0).getClass().getName())); - assertTrue (sciNames.contains(scis.get(1).getClass().getName())); - - - //test 2.5 webapp with configurationDiscovered=false loads only server scis - config = new AnnotationConfiguration(); - context = new WebAppContext(); - context.setClassLoader(webAppLoader); - context.getMetaData().setWebXml(Resource.newResource(web25)); - context.getServletContext().setEffectiveMajorVersion(2); - context.getServletContext().setEffectiveMinorVersion(5); - scis = config.getNonExcludedInitializers(context); - assertNotNull(scis); - assertEquals(1, scis.size()); - assertTrue ("org.eclipse.jetty.annotations.ServerServletContainerInitializer".equals(scis.get(0).getClass().getName())); - - //test 2.5 webapp with configurationDiscovered=true loads both server and webapp scis - config = new AnnotationConfiguration(); - context = new WebAppContext(); - context.setConfigurationDiscovered(true); - context.setClassLoader(webAppLoader); - context.getMetaData().setWebXml(Resource.newResource(web25)); - context.getServletContext().setEffectiveMajorVersion(2); - context.getServletContext().setEffectiveMinorVersion(5); - scis = config.getNonExcludedInitializers(context); - assertNotNull(scis); - assertEquals(2, scis.size()); - assertTrue (sciNames.contains(scis.get(0).getClass().getName())); - assertTrue (sciNames.contains(scis.get(1).getClass().getName())); + ClassLoader orig = Thread.currentThread().getContextClassLoader(); + try + { + + //test 3.1 webapp loads both server and app scis + AnnotationConfiguration config = new AnnotationConfiguration(); + WebAppContext context = new WebAppContext(); + context.setClassLoader(webAppLoader); + context.getMetaData().setWebXml(Resource.newResource(web31true)); + context.getServletContext().setEffectiveMajorVersion(3); + context.getServletContext().setEffectiveMinorVersion(1); + Thread.currentThread().setContextClassLoader(webAppLoader); + List scis = config.getNonExcludedInitializers(context); + + assertNotNull(scis); + assertEquals(2, scis.size()); + assertTrue(sciNames.contains(scis.get(0).getClass().getName())); + assertTrue(sciNames.contains(scis.get(1).getClass().getName())); + + //test a 3.1 webapp with metadata-complete=false loads both server and webapp scis + config = new AnnotationConfiguration(); + context = new WebAppContext(); + context.setClassLoader(webAppLoader); + context.getMetaData().setWebXml(Resource.newResource(web31false)); + context.getServletContext().setEffectiveMajorVersion(3); + context.getServletContext().setEffectiveMinorVersion(1); + scis = config.getNonExcludedInitializers(context); + assertNotNull(scis); + assertEquals(2, scis.size()); + assertTrue(sciNames.contains(scis.get(0).getClass().getName())); + assertTrue(sciNames.contains(scis.get(1).getClass().getName())); + + + //test 2.5 webapp with configurationDiscovered=false loads only server scis + config = new AnnotationConfiguration(); + context = new WebAppContext(); + context.setClassLoader(webAppLoader); + context.getMetaData().setWebXml(Resource.newResource(web25)); + context.getServletContext().setEffectiveMajorVersion(2); + context.getServletContext().setEffectiveMinorVersion(5); + scis = config.getNonExcludedInitializers(context); + assertNotNull(scis); + assertEquals(1, scis.size()); + assertTrue("org.eclipse.jetty.annotations.ServerServletContainerInitializer".equals(scis.get(0).getClass().getName())); + + //test 2.5 webapp with configurationDiscovered=true loads both server and webapp scis + config = new AnnotationConfiguration(); + context = new WebAppContext(); + context.setConfigurationDiscovered(true); + context.setClassLoader(webAppLoader); + context.getMetaData().setWebXml(Resource.newResource(web25)); + context.getServletContext().setEffectiveMajorVersion(2); + context.getServletContext().setEffectiveMinorVersion(5); + scis = config.getNonExcludedInitializers(context); + assertNotNull(scis); + assertEquals(2, scis.size()); + assertTrue(sciNames.contains(scis.get(0).getClass().getName())); + assertTrue(sciNames.contains(scis.get(1).getClass().getName())); + } + finally + { + Thread.currentThread().setContextClassLoader(orig); + } } - + @Test public void testGetFragmentFromJar() throws Exception