### Question:
NetworkCreationValidator { public ValidationResultBuilder validateNetworkCreation(Environment environment, NetworkDto network) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); resultBuilder.prefix("Cannot create environment"); validateNetwork(environment, network, resultBuilder); validateNetworkIdAndCidr(environment, network, resultBuilder); return resultBuilder; } NetworkCreationValidator(Map<CloudPlatform, EnvironmentNetworkValidator> envNetworkValidators, EnvironmentDtoConverter environmentDtoConverter); ValidationResultBuilder validateNetworkCreation(Environment environment, NetworkDto network); ValidationResultBuilder validateNetworkEdit(Environment environment, NetworkDto network);  }### Answer:
@Test void testValidateWhenAzureSpecificValidationIsCalled() { AzureParams azureParams = NetworkTestUtils.getAzureParams(true, true, true); NetworkDto networkDto = NetworkTestUtils.getNetworkDto(azureParams, null, null, azureParams.getNetworkId(), null, 1); environment.setCloudPlatform("aZuRe"); environment.setCidr(null); ValidationResultBuilder resultBuilder = underTest.validateNetworkCreation(environment, networkDto); ValidationResult validationResult = resultBuilder.build(); assertFalse(validationResult.hasError()); verify(environmentNetworkValidatorMock).validateDuringRequest(networkDto, resultBuilder); }
@Test void testValidateWhenNetworkCidrAndNetworkIdOnAzure() { AzureParams azureParams = NetworkTestUtils.getAzureParams(true, true, true); NetworkDto networkDto = NetworkTestUtils.getNetworkDto(azureParams, null, null, azureParams.getNetworkId(), "0.0.0.0/0", 1); environment.setCloudPlatform(CloudPlatform.AZURE.name()); environment.setCidr(null); ValidationResultBuilder resultBuilder = underTest.validateNetworkCreation(environment, networkDto); ValidationResult validationResult = resultBuilder.build(); assertTrue(validationResult.hasError()); assertEquals(1, validationResult.getErrors().size()); String actual = validationResult.getErrors().get(0); assertEquals("The AZURE network id ('aNetworkId') must not be defined if cidr ('0.0.0.0/0') is defined!", actual); }
@Test void testValidateWhenNoNetworkCidrAndNetworkIdOnAzure() { AzureParams azureParams = NetworkTestUtils.getAzureParams(true, true, true); NetworkDto networkDto = NetworkTestUtils.getNetworkDto(azureParams, null, null, azureParams.getNetworkId(), null, 1); environment.setCloudPlatform(CloudPlatform.AZURE.name()); environment.setCidr(null); ValidationResultBuilder resultBuilder = underTest.validateNetworkCreation(environment, networkDto); ValidationResult validationResult = resultBuilder.build(); assertFalse(validationResult.hasError()); }
@Test void testValidateWhenNetworkCidrAndNoNetworkIdOnAzure() { AzureParams azureParams = NetworkTestUtils.getAzureParams(true, false, false); NetworkDto networkDto = NetworkTestUtils.getNetworkDto(azureParams, null, null, null, "0.0.0.0/0", 1); environment.setCloudPlatform(CloudPlatform.AZURE.name()); environment.setCidr(null); ValidationResultBuilder resultBuilder = underTest.validateNetworkCreation(environment, networkDto); ValidationResult validationResult = resultBuilder.build(); assertFalse(validationResult.hasError()); }
@Test void testValidateWhenNoNetworkCidrAndNoNetworkIdOnYarn() { NetworkDto networkDto = NetworkTestUtils.getNetworkDto(null, null, new YarnParams(), null, null, 1); environment.setCloudPlatform(CloudPlatform.YARN.name()); environment.setCidr(null); ValidationResultBuilder resultBuilder = underTest.validateNetworkCreation(environment, networkDto); ValidationResult validationResult = resultBuilder.build(); assertFalse(validationResult.hasError()); }