public class QProfilesMediumTest {
@org.junit.Rule
- public ServerTester serverTester = new ServerTester().addExtensions(XooRulesDefinition.class, XooProfileDefinition.class);
+ public ServerTester serverTester = new ServerTester().addComponents(XooRulesDefinition.class, XooProfileDefinition.class);
@Test
public void register_profile_at_startup() throws Exception {
/**
* Entry point to implement medium tests of server components
*
- * @since 4.3
+ * @since 4.4
*/
public class ServerTester extends ExternalResource {
- private File tempDir;
private Platform platform;
+ private File tempDir;
+ private Object[] components;
- private Object[] extensions;
-
+ /**
+ * Called only when JUnit @Rule or @ClassRule is used.
+ */
@Override
protected void before() {
- tempDir = createTempDir();
+ start();
+ }
+ public void start() {
+ if (platform != null) {
+ throw new IllegalStateException("Already started");
+ }
+ tempDir = createTempDir();
Properties properties = new Properties();
properties.setProperty(CoreProperties.SONAR_HOME, tempDir.getAbsolutePath());
properties.setProperty(DatabaseProperties.PROP_URL, "jdbc:h2:" + tempDir.getAbsolutePath() + "/h2");
platform = new Platform();
platform.init(properties);
- platform.addExtensions(extensions);
+ platform.addExtensions(components);
platform.doStart();
}
}
}
+ /**
+ * Called only when JUnit @Rule or @ClassRule is used.
+ */
@Override
protected void after() {
- platform.doStop();
- platform = null;
+ stop();
+ }
+
+ public void stop() {
+ if (platform != null) {
+ platform.doStop();
+ platform = null;
+ }
FileUtils.deleteQuietly(tempDir);
}
- public ServerTester addExtensions(Object... extensions) {
- this.extensions = extensions;
+ public ServerTester addComponents(Object... components) {
+ this.components = components;
return this;
}