Search in sources :

Example 1 with UIHelper

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);
        }
    }
}
Also used : Supplier(java.util.function.Supplier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UIHelper(com.redhat.devtools.intellij.common.utils.UIHelper) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource) FixtureBaseTest(com.redhat.devtools.intellij.tektoncd.FixtureBaseTest) Test(org.junit.Test)

Example 2 with UIHelper

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);
        }
    }
}
Also used : Supplier(java.util.function.Supplier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UIHelper(com.redhat.devtools.intellij.common.utils.UIHelper) FixtureBaseTest(com.redhat.devtools.intellij.tektoncd.FixtureBaseTest) Test(org.junit.Test)

Example 3 with UIHelper

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);
        }
    }
}
Also used : Supplier(java.util.function.Supplier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UIHelper(com.redhat.devtools.intellij.common.utils.UIHelper) FixtureBaseTest(com.redhat.devtools.intellij.tektoncd.FixtureBaseTest) Test(org.junit.Test)

Example 4 with UIHelper

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());
            }
        }
    }
}
Also used : Supplier(java.util.function.Supplier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UIHelper(com.redhat.devtools.intellij.common.utils.UIHelper) IOException(java.io.IOException) FixtureBaseTest(com.redhat.devtools.intellij.tektoncd.FixtureBaseTest) Test(org.junit.Test)

Example 5 with UIHelper

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);
        }
    }
}
Also used : Supplier(java.util.function.Supplier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UIHelper(com.redhat.devtools.intellij.common.utils.UIHelper) FixtureBaseTest(com.redhat.devtools.intellij.tektoncd.FixtureBaseTest) Test(org.junit.Test)

Aggregations

UIHelper (com.redhat.devtools.intellij.common.utils.UIHelper)5 FixtureBaseTest (com.redhat.devtools.intellij.tektoncd.FixtureBaseTest)5 Supplier (java.util.function.Supplier)5 Test (org.junit.Test)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 GenericKubernetesResource (io.fabric8.kubernetes.api.model.GenericKubernetesResource)1 IOException (java.io.IOException)1