### Question:
ClouderaManagerConfigService { public void disableKnoxAutorestartIfCmVersionAtLeast(Versioned versionAtLeast, ApiClient client, String clusterName) { try { ClouderaManagerResourceApi resourceApiInstance = clouderaManagerApiFactory.getClouderaManagerResourceApi(client); if (isVersionAtLeast(versionAtLeast, resourceApiInstance)) { modifyKnoxAutorestart(client, clusterName, false); } } catch (ApiException e) { LOGGER.debug("Failed to initialize CM client.", e); } }  void disableKnoxAutorestartIfCmVersionAtLeast(Versioned versionAtLeast, ApiClient client, String clusterName); void enableKnoxAutorestartIfCmVersionAtLeast(Versioned versionAtLeast, ApiClient client, String clusterName);  }### Answer:
@Test public void testDisableKnoxAutorestartIfCmVersionAtLeast() throws ApiException { setUpCMVersion(VERSION_7_1_0); ServicesResourceApi serviceResourceApi = mock(ServicesResourceApi.class); when(clouderaManagerApiFactory.getServicesResourceApi(any())).thenReturn(serviceResourceApi); String knoxName = "knox-e07"; ApiServiceList apiServiceList = new ApiServiceList() .addItemsItem(new ApiService().name("hbase-a63").type("HBASE")) .addItemsItem(new ApiService().name(knoxName).type("KNOX")); when(serviceResourceApi.readServices(TEST_CLUSTER_NAME, DataView.SUMMARY.name())).thenReturn(apiServiceList); underTest.disableKnoxAutorestartIfCmVersionAtLeast(CLOUDERAMANAGER_VERSION_7_1_0, new ApiClient(), TEST_CLUSTER_NAME); ArgumentCaptor<ApiServiceConfig> apiServiceConfigArgumentCaptor = ArgumentCaptor.forClass(ApiServiceConfig.class); verify(serviceResourceApi, times(1)) .updateServiceConfig(eq(TEST_CLUSTER_NAME), eq(knoxName), eq(""), apiServiceConfigArgumentCaptor.capture()); ApiServiceConfig actualBody = apiServiceConfigArgumentCaptor.getValue(); assertFalse(actualBody.getItems().isEmpty()); ApiConfig actualApiConfig = actualBody.getItems().get(0); assertEquals(ClouderaManagerConfigService.KNOX_AUTORESTART_ON_STOP, actualApiConfig.getName()); assertEquals(Boolean.FALSE.toString(), actualApiConfig.getValue()); }
@Test public void testDisableKnoxAutorestartIfCmVersionAtLeastWhenKnoxIsMissing() throws ApiException { setUpCMVersion(VERSION_7_1_0); ServicesResourceApi serviceResourceApi = mock(ServicesResourceApi.class); when(clouderaManagerApiFactory.getServicesResourceApi(any())).thenReturn(serviceResourceApi); ApiServiceList apiServiceList = new ApiServiceList().addItemsItem(new ApiService().name("hbase-a63").type("HBASE")); when(serviceResourceApi.readServices(TEST_CLUSTER_NAME, DataView.SUMMARY.name())).thenReturn(apiServiceList); underTest.disableKnoxAutorestartIfCmVersionAtLeast(CLOUDERAMANAGER_VERSION_7_1_0, new ApiClient(), TEST_CLUSTER_NAME); verify(serviceResourceApi, never()).updateServiceConfig(any(), any(), any(), any()); }
@Test public void testDisableKnoxAutorestartIfCmVersionAtLeastWithLowerVersion() throws ApiException { setUpCMVersion(VERSION_7_0_1); underTest.disableKnoxAutorestartIfCmVersionAtLeast(CLOUDERAMANAGER_VERSION_7_1_0, new ApiClient(), TEST_CLUSTER_NAME); verify(clouderaManagerApiFactory, never()).getServicesResourceApi(any()); }