Skip to content
Open
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
Expand Up @@ -58,7 +58,7 @@ public static void init() {

@Test
public void testDoFillClusterItemsEmptyWithEmptyCredentialsId() throws IOException {
DescriptorImpl descriptor = setUpClusterDescriptor(ImmutableList.of(), null, null);
DescriptorImpl descriptor = setUpClusterDescriptor3(ImmutableList.of(), null, null);
ListBoxModel expected =
initExpected(ImmutableList.of(EMPTY_NAME), ImmutableList.of(EMPTY_VALUE));
ListBoxModel result = descriptor.doFillClusterItems(jenkins, null, null, TEST_PROJECT_ID);
Expand All @@ -68,7 +68,7 @@ public void testDoFillClusterItemsEmptyWithEmptyCredentialsId() throws IOExcepti

@Test
public void testDoFillClusterItemsEmptyWithEmptyProjectId() throws IOException {
DescriptorImpl descriptor = setUpClusterDescriptor(ImmutableList.of(), null, null);
DescriptorImpl descriptor = setUpClusterDescriptor3(ImmutableList.of(), null, null);
ListBoxModel expected =
initExpected(ImmutableList.of(EMPTY_NAME), ImmutableList.of(EMPTY_VALUE));
ListBoxModel result = descriptor.doFillClusterItems(jenkins, null, TEST_CREDENTIALS_ID, null);
Expand Down Expand Up @@ -184,7 +184,7 @@ public void testDoCheckClusterMessageWithEmptyCluster() throws IOException {

@Test
public void testDoCheckClusterMessageWithEmptyCredentialsId() throws IOException {
DescriptorImpl descriptor = setUpClusterDescriptor(ImmutableList.of(), null, null);
DescriptorImpl descriptor = setUpClusterDescriptor3(ImmutableList.of(), null, null);
FormValidation result = descriptor.doCheckCluster(jenkins, TEST_CLUSTER, null, TEST_PROJECT_ID);
assertNotNull(result);
assertEquals(
Expand All @@ -193,7 +193,7 @@ public void testDoCheckClusterMessageWithEmptyCredentialsId() throws IOException

@Test
public void testDoCheckClusterMessageWithEmptyProjectId() throws IOException {
DescriptorImpl descriptor = setUpClusterDescriptor(ImmutableList.of(), null, null);
DescriptorImpl descriptor = setUpClusterDescriptor2(ImmutableList.of(), null, null);
FormValidation result =
descriptor.doCheckCluster(jenkins, TEST_CLUSTER, TEST_CREDENTIALS_ID, null);
assertNotNull(result);
Expand Down Expand Up @@ -289,4 +289,49 @@ private DescriptorImpl setUpClusterDescriptor(
.thenReturn(ImmutableList.copyOf(clusters));
return descriptor;
}

private DescriptorImpl setUpClusterDescriptor2(
List<String> initialClusters, AbortException abortException, IOException ioException)
throws IOException {
DescriptorImpl descriptor = Mockito.spy(DescriptorImpl.class);
if (abortException != null) {
Mockito.doThrow(abortException)
.when(descriptor)
.getClientFactory(any(Jenkins.class), anyString());
return descriptor;
}
ClientFactory clientFactory = Mockito.mock(ClientFactory.class);
Mockito.doReturn(clientFactory)
.when(descriptor)
.getClientFactory(any(Jenkins.class), anyString());
ContainerClient containerClient = Mockito.mock(ContainerClient.class);
if (ioException != null) {
Mockito.when(containerClient.listAllClusters(anyString())).thenThrow(ioException);
return descriptor;
}
List<Cluster> clusters = new ArrayList<>();
initialClusters.forEach(c -> clusters.add(ClusterUtil.fromNameAndLocation(c)));
return descriptor;
}

private DescriptorImpl setUpClusterDescriptor3(
List<String> initialClusters, AbortException abortException, IOException ioException)
throws IOException {
DescriptorImpl descriptor = Mockito.spy(DescriptorImpl.class);
if (abortException != null) {
Mockito.doThrow(abortException)
.when(descriptor)
.getClientFactory(any(Jenkins.class), anyString());
return descriptor;
}
ClientFactory clientFactory = Mockito.mock(ClientFactory.class);
ContainerClient containerClient = Mockito.mock(ContainerClient.class);
if (ioException != null) {
Mockito.when(containerClient.listAllClusters(anyString())).thenThrow(ioException);
return descriptor;
}
List<Cluster> clusters = new ArrayList<>();
initialClusters.forEach(c -> clusters.add(ClusterUtil.fromNameAndLocation(c)));
return descriptor;
}
}