Skip to content

Commit

Permalink
[FIXUP] Streamlining and remove now unused test-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Aug 25, 2024
1 parent afc83e4 commit 6aabd05
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 292 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.eclipse.core.resources.IFile;
Expand All @@ -41,6 +41,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;

@SuppressWarnings("restriction")
Expand All @@ -50,47 +51,63 @@ public class UnitTestLaunchConfigConfigurationTest extends AbstractMavenProjectT
private static final String REPLACED_SUREFIRE_POM_STRING = "<!-- surefireArgs: replacedByArgsSets -->";
private static final String REPLACED_FAILSAFE_POM_STRING = "<!-- failsafeArgs: replacedByArgsSets -->";
private static final String ROOT_PATH = "/projects/surefireFailsafeToTestLaunchSettings";

private String testType;
private ILaunchManager launchManager;

public UnitTestLaunchConfigConfigurationTest(String testType) {
super();
this.testType = testType;
}
private static ILaunchManager LAUNCH_MANAGER = DebugPlugin.getDefault().getLaunchManager();

private static final String SUREFIRE_ARGS_SET = """
<configuration>
<argLine>
--argLineItem=surefireArgLineValue
</argLine>
<systemPropertyVariables>
<surefireProp1>surefireProp1Value</surefireProp1>
</systemPropertyVariables>
<environmentVariables>
<surefireEnvironmentVariables1>surefireEnvironmentVariables1Value</surefireEnvironmentVariables1>
</environmentVariables>
</configuration>
""";
private static final String FAILSAFE_ARGS_SET = """
<configuration>
<argLine>
--argLineItem=failsafeArgLineValue
</argLine>
<systemPropertyVariables>
<failsafeProp1>failsafeProp1Value</failsafeProp1>
</systemPropertyVariables>
<environmentVariables>
<failsafeEnvironmentVariables1>failsafeEnvironmentVariables1Value</failsafeEnvironmentVariables1>
</environmentVariables>
</configuration>
""";

// Define the parameters to be used in the test
@Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {
{ MavenRuntimeClasspathProvider.JDT_TESTNG_TEST },
{ MavenRuntimeClasspathProvider.JDT_JUNIT_TEST } });
public static Collection<Object> data() {
return List.of(MavenRuntimeClasspathProvider.JDT_TESTNG_TEST, MavenRuntimeClasspathProvider.JDT_JUNIT_TEST);
}

@Parameter(0)
public String testType;

@Override
@Before
public void setUp() throws Exception {
super.setUp();

((MavenConfigurationImpl) MavenPlugin.getMavenConfiguration()).setAutomaticallyUpdateConfiguration(true);
setAutoBuilding(true);

// Get the launch manager
launchManager = DebugPlugin.getDefault().getLaunchManager();

}

@Test
public void test_configuration_must_be_updated_with_surefire_config()
throws CoreException, IOException, InterruptedException {
// Get launch type
ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(testType);
ILaunchConfigurationType type = LAUNCH_MANAGER.getLaunchConfigurationType(testType);

assumeTrue(testType + " support not available", type != null);

File pomFile = getTestFile("argumentsAreSet/pom.xml");
File surefireConf = getTestFile("argumentsAreSet/surefireArgsSet.xml");
File failsafeConf = null;
String surefireConf = SUREFIRE_ARGS_SET;
String failsafeConf = null;

IProject project = importProject(pomFile.getAbsolutePath());

Expand All @@ -100,14 +117,14 @@ public void test_configuration_must_be_updated_with_surefire_config()
updateProject(project);
waitForJobsToComplete();

ILaunchConfiguration[] updatedConfigurations = launchManager.getLaunchConfigurations(type);
ILaunchConfiguration[] updatedConfigurations = LAUNCH_MANAGER.getLaunchConfigurations(type);
assertTrue(updatedConfigurations.length == 1);

mergePomAndPluginConfigIntoProject(project, pomFile, surefireConf, failsafeConf);
updateProject(project);
waitForJobsToComplete();

updatedConfigurations = launchManager.getLaunchConfigurations(type);
updatedConfigurations = LAUNCH_MANAGER.getLaunchConfigurations(type);
assertTrue(updatedConfigurations.length == 1);

ILaunchConfiguration config = updatedConfigurations[0];
Expand All @@ -133,13 +150,13 @@ public void test_configuration_must_be_updated_with_surefire_config()
public void test_configuration_must_be_updated_with_failsafe_config()
throws CoreException, IOException, InterruptedException {
// Get launch type
ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(testType);
ILaunchConfigurationType type = LAUNCH_MANAGER.getLaunchConfigurationType(testType);

assumeTrue(testType + " support not available", type != null);

File pomFile = getTestFile("argumentsAreSet/pom.xml");
File surefireConf = null;
File failsafeConf = getTestFile("argumentsAreSet/failsafeArgsSet.xml");
String surefireConf = null;
String failsafeConf = FAILSAFE_ARGS_SET;

IProject project = importProject(pomFile.getAbsolutePath());
// waitForJobsToComplete();
Expand All @@ -150,13 +167,13 @@ public void test_configuration_must_be_updated_with_failsafe_config()
updateProject(project);
waitForJobsToComplete();

ILaunchConfiguration[] updatedConfigurations = launchManager.getLaunchConfigurations(type);
ILaunchConfiguration[] updatedConfigurations = LAUNCH_MANAGER.getLaunchConfigurations(type);
assertTrue(updatedConfigurations.length == 1);

mergePomAndPluginConfigIntoProject(project, pomFile, surefireConf, failsafeConf);
updateProject(project);

updatedConfigurations = launchManager.getLaunchConfigurations(type);
updatedConfigurations = LAUNCH_MANAGER.getLaunchConfigurations(type);
assertTrue(updatedConfigurations.length == 1);

ILaunchConfiguration config = updatedConfigurations[0];
Expand All @@ -182,13 +199,13 @@ public void test_configuration_must_be_updated_with_failsafe_config()
public void test_configuration_must_be_updated_with_surefire_config_when_created()
throws CoreException, IOException, InterruptedException {
// Get launch type
ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(testType);
ILaunchConfigurationType type = LAUNCH_MANAGER.getLaunchConfigurationType(testType);

assumeTrue(testType + " support not available", type != null);

File pomFile = getTestFile("argumentsAreSet/pom.xml");
File surefireConf = getTestFile("argumentsAreSet/surefireArgsSet.xml");
File failsafeConf = null;
String surefireConf = SUREFIRE_ARGS_SET;
String failsafeConf = null;

IProject project = importProject(pomFile.getAbsolutePath());
mergePomAndPluginConfigIntoProject(project, pomFile, surefireConf, failsafeConf);
Expand All @@ -198,7 +215,7 @@ public void test_configuration_must_be_updated_with_surefire_config_when_created
// create basic unit test
createDefaultTest(project, type, "test.SomeTest");

ILaunchConfiguration[] updatedConfigurations = launchManager.getLaunchConfigurations(type);
ILaunchConfiguration[] updatedConfigurations = LAUNCH_MANAGER.getLaunchConfigurations(type);
assertTrue(updatedConfigurations.length == 1);

ILaunchConfiguration config = updatedConfigurations[0];
Expand All @@ -224,13 +241,13 @@ public void test_configuration_must_be_updated_with_surefire_config_when_created
public void test_configuration_must_be_updated_with_failSafe_config_when_created()
throws CoreException, IOException, InterruptedException {
// Get launch type
ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(testType);
ILaunchConfigurationType type = LAUNCH_MANAGER.getLaunchConfigurationType(testType);

assumeTrue(testType + " support not available", type != null);

File pomFile = getTestFile("argumentsAreSet/pom.xml");
File surefireConf = null;
File failsafeConf = getTestFile("argumentsAreSet/failsafeArgsSet.xml");
String surefireConf = null;
String failsafeConf = FAILSAFE_ARGS_SET;

IProject project = importProject(pomFile.getAbsolutePath());
mergePomAndPluginConfigIntoProject(project, pomFile, surefireConf, failsafeConf);
Expand All @@ -240,7 +257,7 @@ public void test_configuration_must_be_updated_with_failSafe_config_when_created
// create basic unit test
createDefaultTest(project, type, "test.SomeTestIT");

ILaunchConfiguration[] updatedConfigurations = launchManager.getLaunchConfigurations(type);
ILaunchConfiguration[] updatedConfigurations = LAUNCH_MANAGER.getLaunchConfigurations(type);
assertTrue(updatedConfigurations.length == 1);

ILaunchConfiguration config = updatedConfigurations[0];
Expand Down Expand Up @@ -279,20 +296,18 @@ private void createDefaultTest(IProject project, ILaunchConfigurationType type,
}

// Merge the pom and plugins configuration into the project
private void mergePomAndPluginConfigIntoProject(IProject project, File pomTemplate, File surefireConf,
File failsafeConf) throws IOException, CoreException {
private void mergePomAndPluginConfigIntoProject(IProject project, File pomTemplate, String surefireConfiguration,
String failsafeConfiguration) throws IOException, CoreException {
String pom = Utils.read(project, pomTemplate);
IFile pomFileWS = project.getFile(pomTemplate.getName());
String newContent = pom;

if (surefireConf != null) {
String plugin = Utils.read(project, surefireConf);
newContent = newContent.replace(REPLACED_SUREFIRE_POM_STRING, plugin);
if (surefireConfiguration != null) {
newContent = newContent.replace(REPLACED_SUREFIRE_POM_STRING, surefireConfiguration);
}

if (failsafeConf != null) {
String plugin = Utils.read(project, failsafeConf);
newContent = newContent.replace(REPLACED_FAILSAFE_POM_STRING, plugin);
if (failsafeConfiguration != null) {
newContent = newContent.replace(REPLACED_FAILSAFE_POM_STRING, failsafeConfiguration);
}

pomFileWS.setContents(new ByteArrayInputStream(newContent.getBytes()), true, false, null);
Expand Down
Loading

0 comments on commit 6aabd05

Please sign in to comment.