use of com.redhat.devtools.intellij.common.utils.UIHelper in project intellij-tekton by redhat-developer.
the class DeployHelperTest method SaveOnCluster_ResourceExists_UpdateExisting.
@Test
public void SaveOnCluster_ResourceExists_UpdateExisting() throws IOException {
String yaml = load(RESOURCE_PATH + "pipeline.yaml");
GenericKubernetesResource genericKubernetesResource = mock(GenericKubernetesResource.class);
when(tkn.getCustomResource(anyString(), anyString(), any())).thenReturn(genericKubernetesResource);
try (MockedStatic<TreeHelper> treeHelperMockedStatic = mockStatic(TreeHelper.class)) {
try (MockedStatic<UIHelper> uiHelperMockedStatic = mockStatic(UIHelper.class)) {
treeHelperMockedStatic.when(() -> TreeHelper.getTkn(any())).thenReturn(tkn);
treeHelperMockedStatic.when(() -> TreeHelper.getPluralKind(anyString())).thenReturn(KIND_PIPELINERUNS);
uiHelperMockedStatic.when(() -> UIHelper.executeInUI(any(Supplier.class))).thenReturn(Messages.OK);
boolean result = DeployHelper.saveOnCluster(project, "namespace", yaml, "message", false, false);
verify(tkn, times(0)).createCustomResource(anyString(), any(), anyString());
verify(tkn, times(1)).editCustomResource(anyString(), anyString(), any(), anyString());
assertTrue(result);
}
}
}
use of com.redhat.devtools.intellij.common.utils.UIHelper in project intellij-tekton by redhat-developer.
the class DeployHelperTest method SaveOnCluster_ResourceNotExists_CreateNew.
@Test
public void SaveOnCluster_ResourceNotExists_CreateNew() throws IOException {
String yaml = load(RESOURCE_PATH + "pipeline.yaml");
when(tkn.getCustomResource(anyString(), anyString(), any())).thenReturn(null);
try (MockedStatic<TreeHelper> treeHelperMockedStatic = mockStatic(TreeHelper.class)) {
try (MockedStatic<UIHelper> uiHelperMockedStatic = mockStatic(UIHelper.class)) {
treeHelperMockedStatic.when(() -> TreeHelper.getTkn(any())).thenReturn(tkn);
treeHelperMockedStatic.when(() -> TreeHelper.getPluralKind(anyString())).thenReturn(KIND_PIPELINERUNS);
uiHelperMockedStatic.when(() -> UIHelper.executeInUI(any(Supplier.class))).thenReturn(Messages.OK);
boolean result = DeployHelper.saveOnCluster(project, "namespace", yaml, "message", false, false);
verify(tkn, times(1)).createCustomResource(anyString(), any(), anyString());
assertTrue(result);
}
}
}
use of com.redhat.devtools.intellij.common.utils.UIHelper in project intellij-tekton by redhat-developer.
the class DeployHelperTest method SaveOnCluster_ResourceIsRun_CreateNew.
@Test
public void SaveOnCluster_ResourceIsRun_CreateNew() throws IOException {
String yaml = load(RESOURCE_PATH + "run.yaml");
try (MockedStatic<TreeHelper> treeHelperMockedStatic = mockStatic(TreeHelper.class)) {
try (MockedStatic<UIHelper> uiHelperMockedStatic = mockStatic(UIHelper.class)) {
treeHelperMockedStatic.when(() -> TreeHelper.getTkn(any())).thenReturn(tkn);
treeHelperMockedStatic.when(() -> TreeHelper.getPluralKind(anyString())).thenReturn(KIND_PIPELINERUNS);
uiHelperMockedStatic.when(() -> UIHelper.executeInUI(any(Supplier.class))).thenReturn(Messages.OK);
boolean result = DeployHelper.saveOnCluster(project, "namespace", yaml, "message", false, false);
verify(tkn, times(1)).createCustomResource(anyString(), any(), anyString());
assertTrue(result);
}
}
}
use of com.redhat.devtools.intellij.common.utils.UIHelper in project intellij-tekton by redhat-developer.
the class DeployHelperTest method SaveOnCluster_ResourceHasAnInvalidApiVersion_Throws.
@Test
public void SaveOnCluster_ResourceHasAnInvalidApiVersion_Throws() throws IOException {
String yaml = load(RESOURCE_PATH + "pipeline_invalid_apiversion.yaml");
try (MockedStatic<TreeHelper> treeHelperMockedStatic = mockStatic(TreeHelper.class)) {
try (MockedStatic<UIHelper> uiHelperMockedStatic = mockStatic(UIHelper.class)) {
treeHelperMockedStatic.when(() -> TreeHelper.getTkn(any())).thenReturn(tkn);
uiHelperMockedStatic.when(() -> UIHelper.executeInUI(any(Supplier.class))).thenReturn(Messages.OK);
try {
DeployHelper.saveOnCluster(project, "namespace", yaml, "message", false, false);
} catch (IOException e) {
assertEquals("Tekton file has not a valid format. ApiVersion field contains an invalid value.", e.getLocalizedMessage());
}
}
}
}
use of com.redhat.devtools.intellij.common.utils.UIHelper in project intellij-tekton by redhat-developer.
the class DeployHelperTest method SaveOnCluster_NamespaceIsEmptyAndResourceIsNotClusterScoped_ActiveNamespaceIsUsed.
@Test
public void SaveOnCluster_NamespaceIsEmptyAndResourceIsNotClusterScoped_ActiveNamespaceIsUsed() throws IOException {
String yaml = load(RESOURCE_PATH + "pipeline.yaml");
when(tkn.getNamespace()).thenReturn("namespace");
try (MockedStatic<TreeHelper> treeHelperMockedStatic = mockStatic(TreeHelper.class)) {
try (MockedStatic<UIHelper> uiHelperMockedStatic = mockStatic(UIHelper.class)) {
uiHelperMockedStatic.when(() -> UIHelper.executeInUI(any(Supplier.class))).thenReturn(Messages.NO);
treeHelperMockedStatic.when(() -> TreeHelper.getTkn(any())).thenReturn(tkn);
boolean result = DeployHelper.saveOnCluster(project, "", yaml, "message", false, false);
verify(tkn, times(1)).getNamespace();
assertFalse(result);
}
}
}
Aggregations