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

Add initial testing support #44

Merged
merged 3 commits into from
Jun 9, 2018
Merged
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
86 changes: 86 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,92 @@
</exclusion>
</exclusions>
</dependency>

<!-- Test Scope -->

<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.3</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<version>2.3</version>
<scope>test</scope>
</dependency>

<!-- Test Scope deps required to defeat Maven Enforcer's requireUpperBoundDeps -->

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>1.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>2.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci</groupId>
<artifactId>annotation-indexer</artifactId>
<version>1.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.5.v20170502</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>9.4.5.v20170502</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>5.0.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>2.7.1</version>
<scope>test</scope>
</dependency>

</dependencies>

<developers>
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/hockeyapp/HockeyappApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ public OldVersionHolder(String numberOldVersions, String sortOldVersions, String
this.sortOldVersions = Util.fixEmptyAndTrim(sortOldVersions);
this.strategyOldVersions = Util.fixEmptyAndTrim(strategyOldVersions);
}

public String getNumberOldVersions() {
return numberOldVersions;
}

public String getSortOldVersions() {
return sortOldVersions;
}

public String getStrategyOldVersions() {
return strategyOldVersions;
}
}

@Extension
Expand Down Expand Up @@ -195,4 +207,6 @@ public FormValidation doCheckFilePath(@QueryParameter String value) {
}
}
}


}
22 changes: 10 additions & 12 deletions src/main/java/hockeyapp/HockeyappBuildAction.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package hockeyapp;

import hudson.model.Action;
import hudson.model.ProminentProjectAction;

public class HockeyappBuildAction implements ProminentProjectAction
{
public class HockeyappBuildAction implements ProminentProjectAction {
public String iconFileName;
public String displayName;
public String urlName;

public HockeyappBuildAction()
{
public HockeyappBuildAction() {
}

public HockeyappBuildAction(Action action)
{
public HockeyappBuildAction(Action action) {
iconFileName = action.getIconFileName();
displayName = action.getDisplayName();
urlName = action.getUrlName();
Expand All @@ -23,11 +21,11 @@ public String getIconFileName() {
return iconFileName;
}

public String getDisplayName() {
return displayName;
}
public String getDisplayName() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Extra leading spaces?

Copy link
Author

Choose a reason for hiding this comment

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

All other files are indented with 4 spaces per tab, this brings this file into line with that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, kk. Thought it was tab, plus space.
👍

return displayName;
}

public String getUrlName() {
return urlName;
}
public String getUrlName() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Leading spaces

Copy link
Author

Choose a reason for hiding this comment

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

Ditto above.

return urlName;
}
}
26 changes: 10 additions & 16 deletions src/main/java/hockeyapp/HockeyappRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public class HockeyappRecorder extends Recorder implements SimpleBuildStep {
public static final String DEFAULT_HOCKEY_URL = "https://rink.hockeyapp.net";
public static final int DEFAULT_TIMEOUT = 60000;


@Exported
public List<HockeyappApplication> applications;

Expand Down Expand Up @@ -351,17 +350,14 @@ private boolean performForApplication(Run<?, ?> build, FilePath workspace, EnvVa
EnvAction envData = new EnvAction();
build.addAction(envData);

if (envData != null) {

if (appIndex == 0) {
envData.add("HOCKEYAPP_INSTALL_URL", installUrl);
envData.add("HOCKEYAPP_CONFIG_URL", configUrl);
}

envData.add("HOCKEYAPP_INSTALL_URL_" + appIndex, installUrl);
envData.add("HOCKEYAPP_CONFIG_URL_" + appIndex, configUrl);
if (appIndex == 0) {
envData.add("HOCKEYAPP_INSTALL_URL", installUrl);
envData.add("HOCKEYAPP_CONFIG_URL", configUrl);
}

envData.add("HOCKEYAPP_INSTALL_URL_" + appIndex, installUrl);
envData.add("HOCKEYAPP_CONFIG_URL_" + appIndex, configUrl);

String appId;
if (application.getNumberOldVersions() != null) {
if (application.uploadMethod instanceof VersionCreation) {
Expand Down Expand Up @@ -474,7 +470,6 @@ private void createReleaseNotes(Run<?, ?> build, FilePath workspace, MultipartEn

private ChangeLogSet<? extends Entry> getChangeLogSetFromRun(Run<?, ?> build) {
ItemGroup<?> ig = build.getParent().getParent();
nextItem:
for (Item item : ig.getItems()) {
if (!item.getFullDisplayName().equals(build.getFullDisplayName())
&& !item.getFullDisplayName().equals(build.getParent().getFullDisplayName())) {
Expand Down Expand Up @@ -639,6 +634,9 @@ public BaseUrlHolder(String baseUrl) {
this.baseUrl = baseUrl;
}

public String getBaseUrl() {
return baseUrl;
}
}

@Extension
Expand Down Expand Up @@ -745,11 +743,8 @@ public FormValidation doCheckDebugMode(@QueryParameter String value) {
}

private String readReleaseNotesFile(File file) throws IOException {
FileInputStream inputStream = new FileInputStream(file);
try {
try (FileInputStream inputStream = new FileInputStream(file)) {
return IOUtils.toString(inputStream, "UTF-8");
} finally {
inputStream.close();
}
}

Expand Down Expand Up @@ -778,5 +773,4 @@ public String getUrlName() {
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public String getDisplayName() {

@SuppressWarnings("unused")
public FormValidation doCheckFileName(@QueryParameter String value) throws IOException, ServletException {
if(value.isEmpty()) {
if (value.isEmpty()) {
return FormValidation.error("You must enter a File Name.");
} else {
return FormValidation.ok();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public String getDisplayName() {

@SuppressWarnings("unused")
public FormValidation doCheckReleaseNotes(@QueryParameter String value) throws IOException, ServletException {
if(value.isEmpty()) {
if (value.isEmpty()) {
return FormValidation.error("You must enter Release Notes.");
} else {
return FormValidation.ok();
Expand Down
63 changes: 63 additions & 0 deletions src/test/java/hockeyapp/ConfigurationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package hockeyapp;

import hockeyapp.builder.HockeyappApplicationBuilder;
import hockeyapp.builder.HockeyappRecorderBuilder;
import hudson.model.FreeStyleProject;
import net.hockeyapp.jenkins.releaseNotes.ChangelogReleaseNotes;
import net.hockeyapp.jenkins.uploadMethod.AppCreation;
import org.junit.ClassRule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import java.util.Arrays;
import java.util.Collections;

public class ConfigurationTest {
@ClassRule public static JenkinsRule jenkinsRule = new JenkinsRule();

@Test
public void roundTripPublisherConfiguration() throws Exception {
roundtripTest(new HockeyappRecorderBuilder()
.setApplications(Collections.singletonList(new HockeyappApplicationBuilder().create()))
.create());
}

@Test
public void roundTripPublisherConfigurationWithOldVersionHolder() throws Exception {
roundtripTest(new HockeyappRecorderBuilder()
.setApplications(Collections.singletonList(
new HockeyappApplicationBuilder()
.setOldVersionHolder(new HockeyappApplication.OldVersionHolder(
"5",
"version",
"purge"
))
.create()))
.create());
}

@Test
public void roundTripPublisherConfigurationWithMultipleApps() throws Exception {
roundtripTest(new HockeyappRecorderBuilder()
.setApplications(Arrays.asList(
new HockeyappApplicationBuilder()
.setReleaseNotesMethod(new ChangelogReleaseNotes())
.create(),
new HockeyappApplicationBuilder()
.setUploadMethod(new AppCreation(false))
.create()))
.create());
}

private void roundtripTest(HockeyappRecorder original) throws Exception {
FreeStyleProject project = jenkinsRule.createFreeStyleProject();
project.getPublishersList().add(original);
jenkinsRule.submit(jenkinsRule
.createWebClient()
.getPage(project, "configure")
.getFormByName("config"));
jenkinsRule.assertEqualDataBoundBeans(
original,
project.getPublishersList().get(HockeyappRecorder.class));
}
}
Loading