### Question:
DiagnosticsCollectionValidator { public void validate(BaseCmDiagnosticsCollectionRequest request, StackV4Response stackV4Response) { validate(request.getDestination(), stackV4Response, true); }  void validate(BaseCmDiagnosticsCollectionRequest request, StackV4Response stackV4Response); void validate(BaseDiagnosticsCollectionRequest request, StackV4Response stackV4Response); void validate(DiagnosticsDestination destination, StackV4Response stackV4Response, boolean cmBundle);  }### Answer:
@Test void testWithoutTelemetry() { BaseDiagnosticsCollectionRequest request = new BaseDiagnosticsCollectionRequest(); StackV4Response stackV4Response = new StackV4Response(); BadRequestException thrown = assertThrows(BadRequestException.class, () -> underTest.validate(request, stackV4Response)); assertTrue(thrown.getMessage().contains("Telemetry is not enabled for stack")); }
@Test void testWithCloudStorageWithDisabledLogging() { BaseDiagnosticsCollectionRequest request = new BaseDiagnosticsCollectionRequest(); request.setDestination(DiagnosticsDestination.CLOUD_STORAGE); StackV4Response stackV4Response = new StackV4Response(); TelemetryResponse telemetry = new TelemetryResponse(); stackV4Response.setTelemetry(telemetry); BadRequestException thrown = assertThrows(BadRequestException.class, () -> underTest.validate(request, stackV4Response)); assertTrue(thrown.getMessage().contains("Cloud storage logging is disabled for this cluster")); }
@Test void testWithCloudStorageWithEmptyLogging() { BaseDiagnosticsCollectionRequest request = new BaseDiagnosticsCollectionRequest(); request.setDestination(DiagnosticsDestination.CLOUD_STORAGE); StackV4Response stackV4Response = new StackV4Response(); TelemetryResponse telemetry = new TelemetryResponse(); LoggingResponse logging = new LoggingResponse(); telemetry.setLogging(logging); stackV4Response.setTelemetry(telemetry); BadRequestException thrown = assertThrows(BadRequestException.class, () -> underTest.validate(request, stackV4Response)); assertTrue(thrown.getMessage().contains("S3 or ABFS cloud storage logging setting should be enabled for stack")); }
@Test void testWithEngDestinationAndDisabledLogCollection() { BaseDiagnosticsCollectionRequest request = new BaseDiagnosticsCollectionRequest(); request.setDestination(DiagnosticsDestination.ENG); StackV4Response stackV4Response = new StackV4Response(); TelemetryResponse telemetry = new TelemetryResponse(); stackV4Response.setTelemetry(telemetry); BadRequestException thrown = assertThrows(BadRequestException.class, () -> underTest.validate(request, stackV4Response)); assertTrue(thrown.getMessage().contains("Cluster log collection is not enabled for this stack")); }
@Test void testWithValidEngDestination() { BaseDiagnosticsCollectionRequest request = new BaseDiagnosticsCollectionRequest(); request.setDestination(DiagnosticsDestination.ENG); StackV4Response stackV4Response = new StackV4Response(); TelemetryResponse telemetry = new TelemetryResponse(); FeaturesResponse features = new FeaturesResponse(); FeatureSetting featureSetting = new FeatureSetting(); featureSetting.setEnabled(true); features.setClusterLogsCollection(featureSetting); telemetry.setFeatures(features); stackV4Response.setTelemetry(telemetry); underTest.validate(request, stackV4Response); }
@Test void testWithSupportDestination() { BaseDiagnosticsCollectionRequest request = new BaseDiagnosticsCollectionRequest(); request.setDestination(DiagnosticsDestination.SUPPORT); StackV4Response stackV4Response = new StackV4Response(); TelemetryResponse telemetry = new TelemetryResponse(); stackV4Response.setTelemetry(telemetry); BadRequestException thrown = assertThrows(BadRequestException.class, () -> underTest.validate(request, stackV4Response)); assertTrue(thrown.getMessage().contains("Destination SUPPORT is not supported yet.")); }