Search in sources :

Example 1 with SmoothieContainerBootstrap

use of org.hudsonci.inject.internal.SmoothieContainerBootstrap in project hudson-2.x by hudson.

the class SmoothieTestSupport method setUp.

@Before
public void setUp() throws Exception {
    SmoothieUtil.reset();
    new SmoothieContainerBootstrap().bootstrap(getClass().getClassLoader(), Smoothie.class, getClass());
}
Also used : SmoothieContainerBootstrap(org.hudsonci.inject.internal.SmoothieContainerBootstrap) Before(org.junit.Before)

Example 2 with SmoothieContainerBootstrap

use of org.hudsonci.inject.internal.SmoothieContainerBootstrap in project hudson-2.x by hudson.

the class HudsonTestCase method setUp.

@Override
protected void setUp() throws Exception {
    //System.setProperty("hudson.PluginStrategy", "hudson.ClassicPluginStrategy");
    env.pin();
    recipe();
    AbstractProject.WORKSPACE.toString();
    User.clear();
    // Bootstrap the container with details about our testing classes, so it can figure out what to scan/include
    // force-reset, some tests may not properly hit the tear-down to reset so do it again here
    SmoothieUtil.reset();
    new SmoothieContainerBootstrap().bootstrap(getClass().getClassLoader(), Hudson.class, Smoothie.class, HudsonTestCase.class, getClass());
    try {
        hudson = newHudson();
    } catch (Exception e) {
        // if Hudson instance fails to initialize, it leaves the instance field non-empty and break all the rest of the tests, so clean that up.
        Field f = Hudson.class.getDeclaredField("theInstance");
        f.setAccessible(true);
        f.set(null, null);
        throw e;
    }
    // collecting usage stats from tests are pointless.
    hudson.setNoUsageStatistics(true);
    hudson.setCrumbIssuer(new TestCrumbIssuer());
    final WebAppController controller = WebAppController.get();
    try {
        controller.setContext(hudson.servletContext);
    } catch (IllegalStateException e) {
        // handle tests which run several times inside the same JVM
        Field f = WebAppController.class.getDeclaredField("context");
        f.setAccessible(true);
        f.set(controller, hudson.servletContext);
    }
    try {
        controller.setInstallStrategy(new DefaultInstallStrategy());
    } catch (IllegalStateException e) {
    // strategy already set ignore
    }
    controller.install(hudson);
    hudson.servletContext.setAttribute("version", "?");
    WebAppMain.installExpressionFactory(new ServletContextEvent(hudson.servletContext));
    // set a default JDK to be the one that the harness is using.
    hudson.getJDKs().add(new JDK("default", System.getProperty("java.home")));
    configureUpdateCenter();
    // expose the test instance as a part of URL tree.
    // this allows tests to use a part of the URL space for itself.
    hudson.getActions().add(this);
    // cause all the descriptors to reload.
    // ideally we'd like to reset them to properly emulate the behavior, but that's not possible.
    Mailer.descriptor().setHudsonUrl(null);
    for (Descriptor d : hudson.getExtensionList(Descriptor.class)) d.load();
}
Also used : Field(java.lang.reflect.Field) DefaultInstallStrategy(hudson.stapler.WebAppController.DefaultInstallStrategy) ClassDescriptor(org.kohsuke.stapler.ClassDescriptor) PropertyDescriptor(java.beans.PropertyDescriptor) SmoothieContainerBootstrap(org.hudsonci.inject.internal.SmoothieContainerBootstrap) WebAppController(hudson.stapler.WebAppController) FailingHttpStatusCodeException(com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException) BadCredentialsException(org.acegisecurity.BadCredentialsException) UsernameNotFoundException(org.acegisecurity.userdetails.UsernameNotFoundException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) CSSParseException(org.w3c.css.sac.CSSParseException) AbstractArtifactResolutionException(org.apache.maven.artifact.resolver.AbstractArtifactResolutionException) AuthenticationException(org.acegisecurity.AuthenticationException) SAXException(org.xml.sax.SAXException) DataAccessException(org.springframework.dao.DataAccessException) CSSException(org.w3c.css.sac.CSSException) MalformedURLException(java.net.MalformedURLException) ServletContextEvent(javax.servlet.ServletContextEvent)

Aggregations

SmoothieContainerBootstrap (org.hudsonci.inject.internal.SmoothieContainerBootstrap)2 FailingHttpStatusCodeException (com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException)1 WebAppController (hudson.stapler.WebAppController)1 DefaultInstallStrategy (hudson.stapler.WebAppController.DefaultInstallStrategy)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 ServletContextEvent (javax.servlet.ServletContextEvent)1 AuthenticationException (org.acegisecurity.AuthenticationException)1 BadCredentialsException (org.acegisecurity.BadCredentialsException)1 UsernameNotFoundException (org.acegisecurity.userdetails.UsernameNotFoundException)1 AbstractArtifactResolutionException (org.apache.maven.artifact.resolver.AbstractArtifactResolutionException)1 Before (org.junit.Before)1 ClassDescriptor (org.kohsuke.stapler.ClassDescriptor)1 DataAccessException (org.springframework.dao.DataAccessException)1 CSSException (org.w3c.css.sac.CSSException)1 CSSParseException (org.w3c.css.sac.CSSParseException)1 SAXException (org.xml.sax.SAXException)1