package com.github.persapiens.jsfboot.jetty;

import java.net.MalformedURLException;
import static org.assertj.core.api.Assertions.assertThat;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainer;
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.context.web.WebAppConfiguration;
import org.testng.annotations.Test;

/**
 * Taken from https://github.com/ghillert/spring-boot-jsp-demo/blob/jetty/src/main/java/com/hillert/JspDemoApplication.java#L78
 * and from https://github.com/eclipse/jetty.project/issues/420
 * and from https://github.com/spring-projects/spring-boot/pull/5290
 */
@SpringApplicationConfiguration(classes = JettySpringBootAutoConfiguration.class)
@WebAppConfiguration
@Test
public class JsfJettyServerCustomizerIT extends AbstractTestNGSpringContextTests {

    @Autowired
    private JettyProperties jettyProperties;
    
	public void customize() throws MalformedURLException {
		JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory();
        
        JsfJettyServerCustomizer customizer = new JsfJettyServerCustomizer(jettyProperties);
        
        Server server = ((JettyEmbeddedServletContainer) factory.getEmbeddedServletContainer()).getServer();
        
        customizer.customize(server);
        
        Handler[] childHandlersByClass = server.getChildHandlersByClass(WebAppContext.class);
        WebAppContext webAppContext = (WebAppContext) childHandlersByClass[0];
        
        assertThat(webAppContext.getBaseResource().getResource("test.txt").exists()).isTrue();
	}
}

@@ -1990,10 +1990,894 @@
 e();%0A%09%7D%0A
+    %0A    @Test(expectedExceptions = RuntimeException.class)%0A%09public void invalidClassPathResource() throws MalformedURLException %7B%0A%09%09JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory();%0A%0A        JettyProperties jp = new JettyProperties();%0A        jp.setClassPathResource(%22/~%C3%A3%60%60'%5B%C2%AA%C2%BA*-+.@#$%25%7B&*%C3%A7%7C%C2%B0;.%3C%3E%22);%0A        %0A        JsfJettyServerCustomizer customizer = new JsfJettyServerCustomizer(jp);%0A        %0A        Server server = ((JettyEmbeddedServletContainer) factory.getEmbeddedServletContainer()).getServer();%0A        %0A        customizer.customize(server);%0A        %0A        Handler%5B%5D childHandlersByClass = server.getChildHandlersByClass(WebAppContext.class);%0A        WebAppContext webAppContext = (WebAppContext) childHandlersByClass%5B0%5D;%0A        %0A        assertThat(webAppContext.getBaseResource().getResource(%22test.txt%22).exists()).isTrue();%0A%09%7D%0A
 %7D%0A

fix #109 Minor test for JsfJettyServerCustomizerIT added