Skip to content

Commit 9f8b58c

Browse files
committed
fix: Address test failures
1 parent bdd6815 commit 9f8b58c

8 files changed

Lines changed: 16 additions & 52 deletions

File tree

plugin/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
<dependency>
105105
<groupId>org.jenkins-ci.plugins</groupId>
106106
<artifactId>config-file-provider</artifactId>
107+
<version>3.7.1</version>
107108
</dependency>
108109
<dependency>
109110
<groupId>org.jenkins-ci.plugins</groupId>

plugin/src/main/resources/jenkins/plugins/openstack/pipeline/OpenStackMachineStep/help.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<dd>The booted machine will be kept alive whilst the current run is kicking. This is the default mode if no scope is defined.
77
</dd>
88
<dt><code>unlimited</code></dt>
9-
<dd>The booted machine will be kept alive forever. Mind the possible resources extarvation at the Openstack provider!
9+
<dd>The booted machine will be kept alive forever. Mind the possible resources starvation at the OpenStack provider!
1010
</dd>
1111
</dl>
1212
</div>

plugin/src/test/java/jenkins/plugins/openstack/compute/JCloudsSlaveTemplateTest.java

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.util.Map;
99
import java.util.Properties;
1010
import java.util.stream.Stream;
11-
import java.lang.reflect.Field;
1211

1312
import org.htmlunit.html.HtmlForm;
1413
import hudson.util.FormValidation;
@@ -21,6 +20,7 @@
2120
import org.junit.Rule;
2221
import org.junit.Test;
2322
import org.mockito.ArgumentCaptor;
23+
import org.mockito.internal.util.reflection.Whitebox;
2424
import org.openstack4j.model.compute.BDMDestType;
2525
import org.openstack4j.model.compute.BDMSourceType;
2626
import org.openstack4j.model.compute.BlockDeviceMappingCreate;
@@ -36,13 +36,12 @@
3636

3737
import static jenkins.plugins.openstack.compute.JCloudsSlaveTemplate.parseSecurityGroups;
3838
import static jenkins.plugins.openstack.compute.JCloudsSlaveTemplate.selectNetworkIds;
39-
import static org.hamcrest.Matchers.containsString;
40-
import static org.hamcrest.Matchers.equalTo;
41-
import static org.hamcrest.Matchers.hasSize;
39+
import static org.hamcrest.Matchers.*;
4240
import static org.junit.Assert.*;
4341
import static org.junit.Assert.assertEquals;
4442
import static org.junit.Assert.assertNotNull;
4543
import static org.hamcrest.MatcherAssert.assertThat;
44+
import static org.mockito.Matchers.any;
4645
import static org.mockito.Mockito.*;
4746

4847
public class JCloudsSlaveTemplateTest {
@@ -276,7 +275,9 @@ private void testBootFromVolumeSnapshot(final String volumeSnapshotName, final S
276275
@SuppressWarnings("unchecked")
277276
private NovaBlockDeviceMappingCreate getBlockDeviceMapping(ServerCreateBuilder scbActual) {
278277
assertNotNull(scbActual);
279-
List<BlockDeviceMappingCreate> blockDeviceMapping = (List<BlockDeviceMappingCreate>) getInternalState(scbActual.build(), "blockDeviceMapping");
278+
List<BlockDeviceMappingCreate> blockDeviceMapping = (List<BlockDeviceMappingCreate>) Whitebox.getInternalState(
279+
scbActual.build(), "blockDeviceMapping"
280+
);
280281
assertThat(blockDeviceMapping, hasSize(1));
281282
return (NovaBlockDeviceMappingCreate) blockDeviceMapping.get(0);
282283
}
@@ -341,43 +342,10 @@ public void allowToUseVolumeSnapshotNameAsWellAsId() throws Exception {
341342
assertEquals("vs-id", getVolumeSnapshotId(builders.get(0)));
342343
assertEquals("something-else", getVolumeSnapshotId(builders.get(1)));
343344
}
344-
private static Object getInternalState(Object target, String field) {
345-
Class<?> c = target.getClass();
346-
try {
347-
Field f = getFieldFromHierarchy(c, field);
348-
f.setAccessible(true);
349-
return f.get(target);
350-
} catch (Exception e) {
351-
throw new RuntimeException("Unable to set internal state on a private field. Please report to mockito mailing list.", e);
352-
}
353-
}
354-
355-
private static Field getFieldFromHierarchy(Class<?> clazz, String field) {
356-
Field f = getField(clazz, field);
357-
while (f == null && clazz != Object.class) {
358-
clazz = clazz.getSuperclass();
359-
f = getField(clazz, field);
360-
}
361-
if (f == null) {
362-
throw new RuntimeException(
363-
"You want me to set value to this field: '" + field +
364-
"' on this class: '" + clazz.getSimpleName() +
365-
"' but this field is not declared withing hierarchy of this class!");
366-
}
367-
return f;
368-
}
369-
370-
private static Field getField(Class<?> clazz, String field) {
371-
try {
372-
return clazz.getDeclaredField(field);
373-
} catch (NoSuchFieldException e) {
374-
return null;
375-
}
376-
}
377345

378346
@SuppressWarnings("unchecked")
379347
private String getVolumeSnapshotId(ServerCreateBuilder builder) {
380-
List<BlockDeviceMappingCreate> mapping = (List<BlockDeviceMappingCreate>) getInternalState(
348+
List<BlockDeviceMappingCreate> mapping = (List<BlockDeviceMappingCreate>) Whitebox.getInternalState(
381349
builder.build(),
382350
"blockDeviceMapping"
383351
);

plugin/src/test/java/jenkins/plugins/openstack/compute/ProvisioningTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void verifyOptionsPropagatedToLauncher() throws Exception {
151151
assertEquals(slave.getPublicAddress(), launcher.getHost());
152152
assertEquals("credid", launcher.getCredentialsId());
153153
//noinspection deprecation
154-
assertEquals("java", launcher.getHost()); // https://github.com/jenkinsci/ssh-slaves-plugin/commit/9d25b12b1340e00d63a069f54c1b2361f745b6fc#commitcomment-49501649
154+
assertEquals("java", launcher.getJavaPath()); // https://github.com/jenkinsci/ssh-slaves-plugin/commit/9d25b12b1340e00d63a069f54c1b2361f745b6fc#commitcomment-49501649
155155
assertEquals(expected.getJvmOptions(), launcher.getJvmOptions());
156156
assertEquals(10, (int) slave.getSlaveOptions().getRetentionTime());
157157

plugin/src/test/java/jenkins/plugins/openstack/compute/slaveopts/BootSourceTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@
4848
import static org.junit.Assert.assertEquals;
4949
import static org.junit.Assert.fail;
5050
import static org.mockito.Mockito.*;
51-
//import static org.mockito.Mockito.doReturn;
52-
//import static org.mockito.Mockito.mock;
53-
//import static org.mockito.Mockito.verify;
54-
//import static org.mockito.Mockito.verifyNoMoreInteractions;
55-
//import static org.mockito.Mockito.when;
5651

5752
public class BootSourceTest {
5853
private static final FormValidation VALIDATION_REQUIRED = FormValidation.error(hudson.util.Messages._FormValidation_ValidateRequired().toString(US));

plugin/src/test/resources/jenkins/plugins/openstack/compute/JCloudsCloudTest/globalConfigMigrationFromV1/config.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version='1.0' encoding='UTF-8'?>
22
<hudson>
33
<disabledAdministrativeMonitors/>
4-
<version>2.387.1</version>
4+
<version>1.642.1</version>
55
<numExecutors>2</numExecutors>
66
<mode>NORMAL</mode>
77
<useSecurity>true</useSecurity>
@@ -15,7 +15,7 @@
1515
<viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
1616
<myViewsTabBar class="hudson.views.DefaultMyViewsTabBar"/>
1717
<clouds>
18-
<jenkins.plugins.openstack.compute.JCloudsCloud plugin="openstack-cloud">
18+
<jenkins.plugins.openstack.compute.JCloudsCloud plugin="openstack-cloud@1.8">
1919
<name>OSCloud</name>
2020
<identity>tenant:user</identity>
2121
<credential>w52oEIGWBalT2GPsVd0pMODVwEohhbQ+fI8wOt0eVHo=</credential>

plugin/src/test/resources/jenkins/plugins/openstack/compute/JCloudsCloudTest/globalConfigMigrationFromV1/credentials.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version='1.0' encoding='UTF-8'?>
2-
<com.cloudbees.plugins.credentials.SystemCredentialsProvider plugin="credentials">
2+
<com.cloudbees.plugins.credentials.SystemCredentialsProvider plugin="credentials@1.24">
33
<domainCredentialsMap class="hudson.util.CopyOnWriteMap$Hash">
44
<entry>
55
<com.cloudbees.plugins.credentials.domains.Domain>
66
<specifications/>
77
</com.cloudbees.plugins.credentials.domains.Domain>
88
<java.util.concurrent.CopyOnWriteArrayList>
9-
<com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey plugin="ssh-credentials">
9+
<com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey plugin="ssh-credentials@1.11">
1010
<scope>GLOBAL</scope>
1111
<id>2d07660b-c5c7-4e8b-82fd-a6ffe3429b39</id>
1212
<description></description>

plugin/src/test/resources/jenkins/plugins/openstack/compute/JCloudsCloudTest/globalConfigMigrationFromV1/jenkins.plugins.openstack.compute.UserDataConfig.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version='1.0' encoding='UTF-8'?>
2-
<jenkins.plugins.openstack.compute.UserDataConfig_-UserDataConfigProvider plugin="openstack-cloud">
2+
<jenkins.plugins.openstack.compute.UserDataConfig_-UserDataConfigProvider plugin="openstack-cloud@1.8">
33
<configs>
44
<entry>
55
<string>jenkins.plugins.openstack.compute.UserDataConfig.1455188317989</string>
6-
<org.jenkinsci.lib.configprovider.model.Config plugin="config-file-provider">
6+
<org.jenkinsci.lib.configprovider.model.Config plugin="config-file-provider@2.10.0">
77
<id>jenkins.plugins.openstack.compute.UserDataConfig.1455188317989</id>
88
<name>cloudInit</name>
99
<comment></comment>

0 commit comments

Comments
 (0)