StackAdvisorHelper { StackAdvisorCommand<ValidationResponse> createValidationCommand( StackAdvisorRequestType requestType) throws StackAdvisorException { StackAdvisorCommand<ValidationResponse> command; if (requestType == StackAdvisorRequestType.HOST_GROUPS) { command = new ComponentLayoutValidationCommand(recommendationsDir, recommendationsArtifactsLifetime, stackAdvisorScript, requestId, saRunner, metaInfo); } else if (requestType == StackAdvisorRequestType.CONFIGURATIONS) { command = new ConfigurationValidationCommand(recommendationsDir, recommendationsArtifactsLifetime, stackAdvisorScript, requestId, saRunner, metaInfo); } else { throw new StackAdvisorRequestException(String.format("Unsupported request type, type=%s", requestType)); } return command; } @Inject  StackAdvisorHelper(Configuration conf, StackAdvisorRunner saRunner,
                            AmbariMetaInfo metaInfo); synchronized ValidationResponse validate(StackAdvisorRequest request); synchronized RecommendationResponse recommend(StackAdvisorRequest request);  }
@Test public void testCreateValidationCommand_returnsComponentLayoutValidationCommand() throws IOException, StackAdvisorException { Configuration configuration = mock(Configuration.class); when(configuration.getRecommendationsArtifactsRolloverMax()).thenReturn(100); StackAdvisorRunner saRunner = mock(StackAdvisorRunner.class); AmbariMetaInfo metaInfo = mock(AmbariMetaInfo.class); StackAdvisorHelper helper = new StackAdvisorHelper(configuration, saRunner, metaInfo); StackAdvisorRequestType requestType = StackAdvisorRequestType.HOST_GROUPS; StackAdvisorCommand<ValidationResponse> command = helper.createValidationCommand(requestType); assertEquals(ComponentLayoutValidationCommand.class, command.getClass()); }
@Test public void testCreateValidationCommand_returnsConfigurationValidationCommand() throws IOException, StackAdvisorException { Configuration configuration = mock(Configuration.class); when(configuration.getRecommendationsArtifactsRolloverMax()).thenReturn(100); StackAdvisorRunner saRunner = mock(StackAdvisorRunner.class); AmbariMetaInfo metaInfo = mock(AmbariMetaInfo.class); StackAdvisorHelper helper = new StackAdvisorHelper(configuration, saRunner, metaInfo); StackAdvisorRequestType requestType = StackAdvisorRequestType.CONFIGURATIONS; StackAdvisorCommand<ValidationResponse> command = helper.createValidationCommand(requestType); assertEquals(ConfigurationValidationCommand.class, command.getClass()); }