Skip to content

Commit

Permalink
Migrate to JUnit 5 - Jenkins #51
Browse files Browse the repository at this point in the history
  • Loading branch information
gnl42 committed Aug 7, 2024
1 parent 693ab1c commit 1a4e301
Show file tree
Hide file tree
Showing 21 changed files with 380 additions and 294 deletions.
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
*******************************************************************************/

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
*******************************************************************************/

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",
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 {
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

0 comments on commit 1a4e301

Please sign in to comment.