Java Code Examples for org.junit.rules.ExternalResource

The following are top voted examples for showing how to use org.junit.rules.ExternalResource. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: cloudera-framework   File: TestRunner.java   View source code 6 votes vote down vote up
private Statement withLogging(final FrameworkMethod method, Object target, Statement statement) {
  final AtomicLong time = new AtomicLong();
  List<TestRule> rules = new ArrayList<>();
  rules.add(new ExternalResource() {
    @Override
    protected void before() throws Throwable {
      if (LOG.isDebugEnabled()) {
        time.set(System.currentTimeMillis());
        LOG.debug("Beginning [" + method.getDeclaringClass().getCanonicalName() + "." + method.getName() + "]");
      }
    }

    @Override
    protected void after() {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Completed [" + method.getDeclaringClass().getCanonicalName() + "." + method.getName() + "] in ["
          + (System.currentTimeMillis() - time.get()) + "] ms");
      }
    }
  });
  return new RunRules(statement, rules, getDescription());
}
 
Example 2
Project: dropwizard-guicey   File: GuiceyAppExtension.java   View source code 6 votes vote down vote up
@Override
protected GuiceyInterceptor.ExternalRuleAdapter buildResourceFactory(final UseGuiceyApp annotation) {
    return new GuiceyInterceptor.ExternalRuleAdapter() {
        private GuiceyAppRule rule;

        @Override
        @SuppressWarnings("unchecked")
        public ExternalResource newResource() {
            Preconditions.checkState(rule == null, "External resource creation could be called once.");
            rule = new GuiceyAppRule(annotation.value(), annotation.config(),
                    convertOverrides(annotation.configOverride()));
            return rule;
        }

        @Override
        public Injector getInjector() {
            Preconditions.checkState(rule != null, "External resource not created.");
            return rule.getInjector();
        }
    };
}
 
Example 3
Project: vertx-junit-annotations   File: JUnit4ClassRunnerAdapter.java   View source code 6 votes vote down vote up
@Override
protected List<TestRule> classRules() {
  List<TestRule> rules = super.classRules();
  rules.add(new ExternalResource() {
    @Override
    protected void before() throws Throwable {
      beforeClass();
      super.before();
    }

    @Override
    protected void after() {
      beforeAfterClass();
      super.after();
      afterClass();
    }
  });
  return rules;
}
 
Example 4
Project: camunda-bpm-platform   File: JerseySpecifics.java   View source code 6 votes vote down vote up
public TestRule createTestRule() {
  final TemporaryFolder tempFolder = new TemporaryFolder();

  return RuleChain
    .outerRule(tempFolder)
    .around(new ExternalResource() {

      TomcatServerBootstrap bootstrap = new JerseyTomcatServerBootstrap(webXmlResource);

      protected void before() throws Throwable {
        bootstrap.setWorkingDir(tempFolder.getRoot().getAbsolutePath());
        bootstrap.start();
      }

      protected void after() {
        bootstrap.stop();
      }
    });
}
 
Example 5
Project: camunda-bpm-platform   File: WinkSpecifics.java   View source code 6 votes vote down vote up
public TestRule createTestRule() {
  final TemporaryFolder tempFolder = new TemporaryFolder();

  return RuleChain
    .outerRule(tempFolder)
    .around(new ExternalResource() {

      WinkTomcatServerBootstrap bootstrap = new WinkTomcatServerBootstrap(webXmlResource);

      protected void before() throws Throwable {
        bootstrap.setWorkingDir(tempFolder.getRoot().getAbsolutePath());
        bootstrap.start();
      }

      protected void after() {
        bootstrap.stop();
      }
    });
}
 
Example 6
Project: camunda-bpm-platform   File: JerseySpecifics.java   View source code 6 votes vote down vote up
public TestRule createTestRule() {
  final TemporaryFolder tempFolder = new TemporaryFolder();

  return RuleChain
    .outerRule(tempFolder)
    .around(new ExternalResource() {

      TomcatServerBootstrap bootstrap = new JerseyTomcatServerBootstrap(webXmlResource);

      protected void before() throws Throwable {
        bootstrap.setWorkingDir(tempFolder.getRoot().getAbsolutePath());
        bootstrap.start();
      }

      protected void after() {
        bootstrap.stop();
      }
    });
}
 
Example 7
Project: camunda-bpm-platform   File: CXFSpecifics.java   View source code 6 votes vote down vote up
public TestRule createTestRule() {
  final TemporaryFolder tempFolder = new TemporaryFolder();

  return RuleChain
    .outerRule(tempFolder)
    .around(new ExternalResource() {

      TomcatServerBootstrap bootstrap = new CXFTomcatServerBootstrap(webXmlResource);

      protected void before() throws Throwable {
        bootstrap.setWorkingDir(tempFolder.getRoot().getAbsolutePath());
        bootstrap.start();
      }

      protected void after() {
        bootstrap.stop();
      }
    });
}
 
Example 8
Project: camunda-bpm-platform   File: ResteasySpecifics.java   View source code 6 votes vote down vote up
public TestRule createTestRule() {
  final TemporaryFolder tempFolder = new TemporaryFolder();

  return RuleChain
    .outerRule(tempFolder)
    .around(new ExternalResource() {

      ResteasyTomcatServerBootstrap bootstrap = new ResteasyTomcatServerBootstrap(webXmlResource);

      protected void before() throws Throwable {
        bootstrap.setWorkingDir(tempFolder.getRoot().getAbsolutePath());
        bootstrap.start();
      }

      protected void after() {
        bootstrap.stop();
      }
    });
}
 
Example 9
Project: incubator-netbeans   File: TestCatalogModel.java   View source code 5 votes vote down vote up
/**
 * A JUnit {@link TestRule} that stops tests from interfering with one 
 * another. JUnit will automatically set up/clean up the catalog when this
 * rule is used. <br/>
 * Usage:<br/>
 * {@code @Rule public final TestRule catalogMaintainer = TestCatalogModel.maintainer()}
 * @return the TestRule
 */
public static TestRule maintainer() {
    return new ExternalResource() {

        @Override
        protected void after() {
            getDefault().clearDocumentPool();
        }
    
    };
}
 
Example 10
Project: Selenium-Foundation   File: DriverWatcher.java   View source code 5 votes vote down vote up
/**
 * Get class watcher to manage local Grid servers.
 * 
 * @return external resource object
 */
public static ExternalResource getClassWatcher() {
    return new ExternalResource() {
        @Override
        protected void after() {
            DriverManager.onFinish();
        }
        
    };
}
 
Example 11
Project: camunda-bpm-platform   File: JerseySpecifics.java   View source code 5 votes vote down vote up
public TestRule createTestRule() {
  return new ExternalResource() {

    JerseyServerBootstrap bootstrap = new JerseyServerBootstrap(jaxRsApplication);

    protected void before() throws Throwable {
      bootstrap.start();
    }

    protected void after() {
      bootstrap.stop();
    }
  };
}
 
Example 12
Project: camunda-bpm-platform   File: JerseySpecifics.java   View source code 5 votes vote down vote up
public TestRule createTestRule() {
  return new ExternalResource() {

    JerseyServerBootstrap bootstrap = new JerseyServerBootstrap(jaxRsApplication);

    protected void before() throws Throwable {
      bootstrap.start();
    }

    protected void after() {
      bootstrap.stop();
    }
  };
}
 
Example 13
Project: camunda-bpm-platform   File: CXFSpecifics.java   View source code 5 votes vote down vote up
public TestRule createTestRule() {
  return new ExternalResource() {

    CXFServerBootstrap bootstrap = new CXFServerBootstrap(jaxRsApplication);

    protected void before() throws Throwable {
      bootstrap.start();
    }

    protected void after() {
      bootstrap.stop();
    }
  };
}
 
Example 14
Project: camunda-bpm-platform   File: ResteasySpecifics.java   View source code 5 votes vote down vote up
public TestRule createTestRule() {
  return new ExternalResource() {

    ResteasyServerBootstrap bootstrap = new ResteasyServerBootstrap(jaxRsApplication);

    protected void before() throws Throwable {
      bootstrap.start();
    }

    protected void after() {
      bootstrap.stop();
    }
  };
}
 
Example 15
Project: artifactory-resource   File: ArtifactoryServerConnection.java   View source code 4 votes vote down vote up
@Override
public TestRule createRule() {
	return new ExternalResource() {

	};
}
 
Example 16
Project: monarch   File: SerializableExternalResourceTest.java   View source code 4 votes vote down vote up
@Test
public void hasZeroFields() throws Exception {
  Field[] fields = ExternalResource.class.getDeclaredFields();
  assertThat(fields.length).as("Fields: " + Arrays.asList(fields)).isEqualTo(0);
}
 
Example 17
Project: pitest   File: JUnitCustomRunnerTestUnitFinderTest.java   View source code 4 votes vote down vote up
@ClassRule
public static TestRule rule() {
  return new ExternalResource() {
  };
}
 
Example 18
Project: dropwizard-guicey   File: GuiceyInterceptor.java   View source code 2 votes vote down vote up
/**
 * @return new rule instance
 */
ExternalResource newResource();