Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to JUnit 5 - Jenkins #51 #589

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/*******************************************************************************
* Copyright (c) 2010, 2011 Tasktop Technologies and others.
*
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0
*
*
* SPDX-License-Identifier: EPL-2.0
*
* Tasktop Technologies - initial API and implementation
* See git histpry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

history

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D'oh!

*******************************************************************************/

package org.eclipse.mylyn.internal.jenkins.core.client;
Expand All @@ -18,7 +19,7 @@
public class JenkinsServerInfo {

public enum Type {
HUDSON, JENKINS
JENKINS
}

private final String version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Tasktop Technologies - improvements
* Eike Stepper - improvements for bug 323759
* Benjamin Muskalla - 323920: [build] config retrival fails for jobs with whitespaces
* See git histpry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

history

*******************************************************************************/

package org.eclipse.mylyn.internal.jenkins.core.client;
Expand Down Expand Up @@ -470,18 +471,11 @@ public JenkinsServerInfo execute() throws IOException, JenkinsException, JAXBExc
protected JenkinsServerInfo doProcess(CommonHttpResponse response, IOperationMonitor monitor)
throws IOException, JenkinsException, JAXBException {
Header header = response.getResponse().getFirstHeader("X-Jenkins"); //$NON-NLS-1$
Type type;
if (header == null) {
type = Type.HUDSON;
header = response.getResponse().getFirstHeader("X-Hudson"); //$NON-NLS-1$
if (header == null) {
throw new JenkinsException(NLS.bind("{0} does not appear to be a Hudson or Jenkins instance", //$NON-NLS-1$
baseUrl()));
}
} else {
type = Type.JENKINS;
throw new JenkinsException(NLS.bind("{0} does not appear to be a Jenkins instance", //$NON-NLS-1$
baseUrl()));
}
JenkinsServerInfo info = new JenkinsServerInfo(type, header.getValue());
JenkinsServerInfo info = new JenkinsServerInfo(Type.JENKINS, header.getValue());
return info;
}
}.run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="0.0.0",
org.eclipse.search;bundle-version="0.0.0",
org.eclipse.ui;bundle-version="0.0.0",
org.eclipse.ui.workbench.texteditor;bundle-version="0.0.0",
org.junit;bundle-version="4.8.2"
junit-jupiter-api;bundle-version="5.10.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend to prefer "Import-Package" for 3rd party libs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.
I wasn't sure about that so I just followed what was done with JUnit 4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I tried "importing" and had to add the libraries to the .target file with older versions. So I don't know what is the best solution?

I'm still trying to figure out how all this works.
What are the pros and cons of using the versions made available implicitly vs the ones from the orbit/drop/??? sites

junit-platform-suite-api;bundle-version="1.10.3",
junit-platform-suite-engine;bundle-version="1.10.3",
junit-platform-suite-commons;bundle-version="1.10.3",
org.hamcrest;bundle-version="2.2.0"
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-Vendor: Eclipse Mylyn
Export-Package: org.eclipse.mylyn.jenkins.tests;x-internal:=true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,71 +7,25 @@
*
* Contributors:
* Tasktop Technologies - initial API and implementation
* See git history
*******************************************************************************/

package org.eclipse.mylyn.jenkins.tests;

import java.util.List;

import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil;
import org.eclipse.mylyn.commons.sdk.util.ManagedSuite;
import org.eclipse.mylyn.commons.sdk.util.ManagedTestSuite;
import org.eclipse.mylyn.commons.sdk.util.TestConfiguration;
import org.eclipse.mylyn.jenkins.tests.client.JenkinsClientTest;
import org.eclipse.mylyn.jenkins.tests.client.JenkinsUrlTest;
import org.eclipse.mylyn.jenkins.tests.client.JenkinsValidationTest;
import org.eclipse.mylyn.jenkins.tests.core.JenkinsConnectorTest;
import org.eclipse.mylyn.jenkins.tests.core.JenkinsServerBehaviourTest;
import org.eclipse.mylyn.jenkins.tests.integration.JenkinsIntegrationTest;
import org.eclipse.mylyn.jenkins.tests.support.JenkinsFixture;

import junit.framework.Test;
import junit.framework.TestSuite;

/**
* @author Steffen Pingel
*/
@SuppressWarnings("nls")
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;
import org.junit.platform.suite.api.SuiteDisplayName;

@Suite
@SuiteDisplayName("Jenkins Test Suite")
@SelectClasses({ SuiteSetup.class, JenkinsConnectorTest.class, JenkinsServerBehaviourTest.class, JenkinsUrlTest.class,
JenkinsValidationTest.class, JenkinsClientTest.class, JenkinsIntegrationTest.class })
public class AllJenkinsTests {

public static Test suite() {
if (CommonTestUtil.fixProxyConfiguration()) {
CommonTestUtil.dumpSystemInfo(System.err);
}
TestConfiguration testConfiguration = ManagedSuite.getTestConfigurationOrCreateDefault();
testConfiguration.setLocalOnly(true); // No CI Server
TestSuite suite = new ManagedTestSuite(AllJenkinsTests.class.getName());
addTests(suite, testConfiguration);
return suite;
}

public static Test suite(TestConfiguration configuration) {
TestSuite suite = new TestSuite(AllJenkinsTests.class.getName());
addTests(suite, configuration);
return suite;
}

private static void addTests(TestSuite suite, TestConfiguration configuration) {
suite.addTestSuite(JenkinsConnectorTest.class);
suite.addTestSuite(JenkinsServerBehaviourTest.class);
suite.addTestSuite(JenkinsUrlTest.class);
if (!configuration.isLocalOnly()) {
// network tests
suite.addTestSuite(JenkinsValidationTest.class);
List<JenkinsFixture> fixtures = configuration.discover(JenkinsFixture.class, "jenkins");
for (JenkinsFixture fixture : fixtures) {
if (fixture.isExcluded()
|| fixture.isUseCertificateAuthentication() && CommonTestUtil.isCertificateAuthBroken()) {
continue;
}
fixture.createSuite(suite);
fixture.add(JenkinsClientTest.class);
if (!fixture.isUseCertificateAuthentication()) {
fixture.add(JenkinsIntegrationTest.class);
}
fixture.done();
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*******************************************************************************
* Copyright (c) 2024 George Lindholm
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html.
*
* Contributors:
* See git history
*******************************************************************************/

package org.eclipse.mylyn.jenkins.tests;

import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil;
import org.eclipse.mylyn.commons.sdk.util.ManagedSuite;
import org.eclipse.mylyn.commons.sdk.util.TestConfiguration;
import org.eclipse.mylyn.jenkins.tests.support.JenkinsFixture;
import org.junit.jupiter.api.Test;

public class SuiteSetup {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need instead a JUnit 5 Extensions or some other new feature so that we can support multible fixtures

private static boolean notLocalOnly = false;

private static boolean useCertificateAuthentication = false;

private static boolean fixtureActive = false;

static {
if (CommonTestUtil.fixProxyConfiguration()) {
CommonTestUtil.dumpSystemInfo(System.err);
}
TestConfiguration configuration = ManagedSuite.getTestConfigurationOrCreateDefault();

if (!configuration.isLocalOnly()) {
// network tests
notLocalOnly = true;
for (JenkinsFixture fixture : configuration.discover(JenkinsFixture.class, "jenkins")) { //$NON-NLS-1$
if (fixture.isExcluded()
|| fixture.isUseCertificateAuthentication() && CommonTestUtil.isCertificateAuthBroken()) {
continue;
}
fixtureActive = true;
useCertificateAuthentication = !fixture.isUseCertificateAuthentication();
}
}
}

@Test
public void dummyTest() {
// This is a dummy test to ensure the setup method is run
}

public static boolean isNotLocalOnly() {
return notLocalOnly;
}

public static boolean isUseCertificateAuthentication() {
return useCertificateAuthentication;
}

public static boolean isFixtureActive() {
return fixtureActive;
}

}
Loading