diff --git a/fullstack-helm-client/src/test/java/com/hedera/fullstack/helm/client/test/proxy/request/chart/ChartInstallRequestTest.java b/fullstack-helm-client/src/test/java/com/hedera/fullstack/helm/client/test/proxy/request/chart/ChartInstallRequestTest.java index 9b4338d6a..2b176a5f8 100644 --- a/fullstack-helm-client/src/test/java/com/hedera/fullstack/helm/client/test/proxy/request/chart/ChartInstallRequestTest.java +++ b/fullstack-helm-client/src/test/java/com/hedera/fullstack/helm/client/test/proxy/request/chart/ChartInstallRequestTest.java @@ -17,15 +17,32 @@ package com.hedera.fullstack.helm.client.test.proxy.request.chart; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import com.hedera.fullstack.helm.client.execution.HelmExecutionBuilder; import com.hedera.fullstack.helm.client.model.Chart; import com.hedera.fullstack.helm.client.model.install.InstallChartOptions; import com.hedera.fullstack.helm.client.proxy.request.chart.ChartInstallRequest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +@ExtendWith(MockitoExtension.class) class ChartInstallRequestTest { + @Mock + InstallChartOptions installChartOptionsMock; + + @Mock + Chart chartMock; + + @Mock + HelmExecutionBuilder helmExecutionBuilderMock; + @Test @DisplayName("Test ChartInstallRequest Chart constructor") void testChartInstallRequestChartConstructor() { @@ -45,5 +62,47 @@ void testChartInstallRequestChartConstructor() { .isNotEqualTo(InstallChartOptions.defaults()); } - // TODO: test ChartInstallRequest apply method using mock of builder to verify calls + @Test + @DisplayName("Test ChartInstallRequest apply with unqualified chart") + void testChartInstallRequestApplyUnqualifiedChart() { + final ChartInstallRequest chartInstallRequest = + new ChartInstallRequest("mocked", chartMock, installChartOptionsMock); + assertThat(chartInstallRequest).isNotNull(); + assertThat(chartInstallRequest.chart()).isNotNull().isEqualTo(chartMock); + assertThat(chartInstallRequest.releaseName()).isEqualTo("mocked"); + assertThat(chartInstallRequest.options()).isNotNull().isEqualTo(installChartOptionsMock); + + when(installChartOptionsMock.repo()).thenReturn("mockedRepo"); + when(chartMock.unqualified()).thenReturn("mockedUnqualified"); + when(helmExecutionBuilderMock.positional("mocked")).thenReturn(helmExecutionBuilderMock); + when(helmExecutionBuilderMock.positional("mockedUnqualified")).thenReturn(helmExecutionBuilderMock); + chartInstallRequest.apply(helmExecutionBuilderMock); + verify(helmExecutionBuilderMock, times(1)).subcommands("install"); + verify(installChartOptionsMock, times(1)).apply(helmExecutionBuilderMock); + verify(installChartOptionsMock, times(2)).repo(); + verify(chartMock, times(1)).unqualified(); + verify(helmExecutionBuilderMock, times(2)).positional(anyString()); + } + + @Test + @DisplayName("Test ChartInstallRequest apply with qualified chart") + void testChartInstallRequestApplyQualifiedChart() { + final ChartInstallRequest chartInstallRequest = + new ChartInstallRequest("mocked", chartMock, installChartOptionsMock); + assertThat(chartInstallRequest).isNotNull(); + assertThat(chartInstallRequest.chart()).isNotNull().isEqualTo(chartMock); + assertThat(chartInstallRequest.releaseName()).isEqualTo("mocked"); + assertThat(chartInstallRequest.options()).isNotNull().isEqualTo(installChartOptionsMock); + + when(installChartOptionsMock.repo()).thenReturn(null); + when(chartMock.qualified()).thenReturn("mockedQualified"); + when(helmExecutionBuilderMock.positional("mocked")).thenReturn(helmExecutionBuilderMock); + when(helmExecutionBuilderMock.positional("mockedQualified")).thenReturn(helmExecutionBuilderMock); + chartInstallRequest.apply(helmExecutionBuilderMock); + verify(helmExecutionBuilderMock, times(1)).subcommands("install"); + verify(installChartOptionsMock, times(1)).apply(helmExecutionBuilderMock); + verify(installChartOptionsMock, times(1)).repo(); + verify(chartMock, times(1)).qualified(); + verify(helmExecutionBuilderMock, times(2)).positional(anyString()); + } }