MachineConfigsValidator { public void validate(Map<String, InternalMachineConfig> machines) throws ValidationException { for (Entry<String, InternalMachineConfig> machineConfigEntry : machines.entrySet()) { validateMachine(machineConfigEntry.getKey(), machineConfigEntry.getValue()); } }  void validate(Map<String, InternalMachineConfig> machines);  }
@Test( expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Name of machine '.*' in environment is invalid", dataProvider = "invalidMachineNames") public void shouldFailIfMachinesNameAreInvalid(String machineName) throws Exception { machinesValidator.validate(singletonMap(machineName, machineConfig)); }
@Test(dataProvider = "validMachineNames") public void shouldNotFailIfMachinesNameAreValid(String machineName) throws Exception { machinesValidator.validate(singletonMap(machineName, machineConfig)); }
@Test( expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Machine '.*' in environment contains server conf '.*' with invalid port '.*'", dataProvider = "invalidServerPorts") public void shouldFailIfServerPortIsInvalid(String servicePort) throws Exception { ServerConfigImpl server = new ServerConfigImpl(servicePort, "https", "/some/path", singletonMap("key", "value")); when(machineConfig.getServers()) .thenReturn(singletonMap(Constants.SERVER_WS_AGENT_HTTP_REFERENCE, server)); machinesValidator.validate(singletonMap(MACHINE_NAME, machineConfig)); }
@Test(dataProvider = "validServerPorts") public void shouldNotFailIfServerPortIsValid(String servicePort) throws Exception { ServerConfigImpl server = new ServerConfigImpl(servicePort, "https", "/some/path", singletonMap("key", "value")); when(machineConfig.getServers()) .thenReturn(singletonMap(Constants.SERVER_WS_AGENT_HTTP_REFERENCE, server)); machinesValidator.validate(singletonMap(MACHINE_NAME, machineConfig)); }
@Test( expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Machine '.*' in environment contains server conf '.*' with invalid protocol '.*'", dataProvider = "invalidServerProtocols") public void shouldFailIfServerProtocolIsInvalid(String serviceProtocol) throws Exception { ServerConfigImpl server = new ServerConfigImpl("8080", serviceProtocol, "/some/path", singletonMap("key", "value")); when(machineConfig.getServers()) .thenReturn(singletonMap(Constants.SERVER_WS_AGENT_HTTP_REFERENCE, server)); machinesValidator.validate(singletonMap(MACHINE_NAME, machineConfig)); }
@Test( expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Machine '.*' in environment contains inconsistent memory attributes: Memory limit: '.*', Memory request: '.*'") public void shouldFailIfMemoryAttributesAreInconsistent() throws Exception { when(machineConfig.getAttributes()) .thenReturn( ImmutableMap.of( MEMORY_LIMIT_ATTRIBUTE, String.valueOf(1024L * 1024L * 1024L), MEMORY_REQUEST_ATTRIBUTE, String.valueOf(2048L * 1024L * 1024L))); machinesValidator.validate(singletonMap(MACHINE_NAME, machineConfig)); }
@Test(dataProvider = "validMemoryAttributes") public void shouldSucceedIfMemoryAttributesAreConsistentOrNotPresent( String memoryLimit, String memoryRequest) throws Exception { Map<String, String> attributes = new HashMap<>(); if (memoryLimit != null) { attributes.put(MEMORY_LIMIT_ATTRIBUTE, memoryLimit); } if (memoryRequest != null) { attributes.put(MEMORY_LIMIT_ATTRIBUTE, memoryRequest); } when(machineConfig.getAttributes()).thenReturn(attributes); machinesValidator.validate(singletonMap(MACHINE_NAME, machineConfig)); }
@Test(dataProvider = "validServerProtocols") public void shouldNotFailIfServerProtocolIsValid(String serviceProtocol) throws Exception { ServerConfigImpl server = new ServerConfigImpl("8080", serviceProtocol, "/some/path", singletonMap("key", "value")); when(machineConfig.getServers()) .thenReturn(singletonMap(Constants.SERVER_WS_AGENT_HTTP_REFERENCE, server)); machinesValidator.validate(singletonMap(MACHINE_NAME, machineConfig)); }