diff --git a/chutney/action-impl/src/main/java/com/chutneytesting/action/jakarta/JakartaConnectionFactory.java b/chutney/action-impl/src/main/java/com/chutneytesting/action/jakarta/JakartaConnectionFactory.java index cc8f1d582..56dc1cf03 100644 --- a/chutney/action-impl/src/main/java/com/chutneytesting/action/jakarta/JakartaConnectionFactory.java +++ b/chutney/action-impl/src/main/java/com/chutneytesting/action/jakarta/JakartaConnectionFactory.java @@ -93,11 +93,13 @@ private CloseableResource obtainCloseableResource(Target target, String d } }); } catch (InvalidSelectorException e) { - throw new UncheckedJakartaException("Cannot parse selector " + e.getMessage(), e); + throw new UncheckedJakartaException(e); } catch (NameNotFoundException e) { - throw new UncheckedJakartaException("Cannot find destination " + e.getMessage() + " on jms server " + target.name() + " (" + target.uri().toString() + ")", e); - } catch (NamingException | JMSException e) { - throw new UncheckedJakartaException("Cannot connect to jms server " + target.name() + " (" + target.uri().toString() + "): " + e.getMessage(), e); + throw new UncheckedJakartaException(e, target); + } catch (NamingException e) { + throw new UncheckedJakartaException(e, target); + } catch (JMSException e) { + throw new UncheckedJakartaException(e, target); } } diff --git a/chutney/action-impl/src/main/java/com/chutneytesting/action/jakarta/UncheckedJakartaException.java b/chutney/action-impl/src/main/java/com/chutneytesting/action/jakarta/UncheckedJakartaException.java index fbc02cf9b..0aef40f48 100644 --- a/chutney/action-impl/src/main/java/com/chutneytesting/action/jakarta/UncheckedJakartaException.java +++ b/chutney/action-impl/src/main/java/com/chutneytesting/action/jakarta/UncheckedJakartaException.java @@ -7,10 +7,28 @@ package com.chutneytesting.action.jakarta; +import com.chutneytesting.action.spi.injectable.Target; +import jakarta.jms.InvalidSelectorException; +import jakarta.jms.JMSException; +import javax.naming.NameNotFoundException; +import javax.naming.NamingException; + @SuppressWarnings("serial") class UncheckedJakartaException extends RuntimeException { - public UncheckedJakartaException(String message, Exception cause) { - super(message, cause); + public UncheckedJakartaException(InvalidSelectorException e) { + super("Cannot parse selector " + e.getMessage(), e); + } + + public UncheckedJakartaException(NameNotFoundException e, Target target) { + super("Cannot find destination " + e.getMessage() + " on jms server " + target.name() + " (" + target.uri().toString() + ")", e); + } + + public UncheckedJakartaException(JMSException e, Target target) { + super("Cannot connect to jms server " + target.name() + " (" + target.uri().toString() + "): " + e.getMessage(), e); + } + + public UncheckedJakartaException(NamingException e, Target target) { + super("Cannot connect to jms server " + target.name() + " (" + target.uri().toString() + "): " + e.getMessage(), e); } } diff --git a/chutney/action-impl/src/main/java/com/chutneytesting/action/jms/JmsConnectionFactory.java b/chutney/action-impl/src/main/java/com/chutneytesting/action/jms/JmsConnectionFactory.java index e121720e8..aeae9a83e 100644 --- a/chutney/action-impl/src/main/java/com/chutneytesting/action/jms/JmsConnectionFactory.java +++ b/chutney/action-impl/src/main/java/com/chutneytesting/action/jms/JmsConnectionFactory.java @@ -93,11 +93,13 @@ private CloseableResource obtainCloseableResource(Target target, String d } }); } catch (InvalidSelectorException e) { - throw new UncheckedJmsException("Cannot parse selector " + e.getMessage(), e); + throw new UncheckedJmsException(e); } catch (NameNotFoundException e) { - throw new UncheckedJmsException("Cannot find destination " + e.getMessage() + " on jms server " + target.name() + " (" + target.uri().toString() + ")", e); - } catch (NamingException | JMSException e) { - throw new UncheckedJmsException("Cannot connect to jms server " + target.name() + " (" + target.uri().toString() + "): " + e.getMessage(), e); + throw new UncheckedJmsException(e, target); + } catch (NamingException e) { + throw new UncheckedJmsException(e, target); + } catch (JMSException e) { + throw new UncheckedJmsException(e, target); } } diff --git a/chutney/action-impl/src/main/java/com/chutneytesting/action/jms/UncheckedJmsException.java b/chutney/action-impl/src/main/java/com/chutneytesting/action/jms/UncheckedJmsException.java index 35fd1f678..e7b027d1c 100644 --- a/chutney/action-impl/src/main/java/com/chutneytesting/action/jms/UncheckedJmsException.java +++ b/chutney/action-impl/src/main/java/com/chutneytesting/action/jms/UncheckedJmsException.java @@ -7,10 +7,28 @@ package com.chutneytesting.action.jms; +import com.chutneytesting.action.spi.injectable.Target; +import javax.jms.InvalidSelectorException; +import javax.jms.JMSException; +import javax.naming.NameNotFoundException; +import javax.naming.NamingException; + @SuppressWarnings("serial") class UncheckedJmsException extends RuntimeException { - public UncheckedJmsException(String message, Exception cause) { - super(message, cause); + public UncheckedJmsException(InvalidSelectorException e) { + super("Cannot parse selector " + e.getMessage(), e); + } + + public UncheckedJmsException(NameNotFoundException e, Target target) { + super("Cannot find destination " + e.getMessage() + " on jms server " + target.name() + " (" + target.uri().toString() + ")", e); + } + + public UncheckedJmsException(JMSException e, Target target) { + super("Cannot connect to jms server " + target.name() + " (" + target.uri().toString() + "): " + e.getMessage(), e); + } + + public UncheckedJmsException(NamingException e, Target target) { + super("Cannot connect to jms server " + target.name() + " (" + target.uri().toString() + "): " + e.getMessage(), e); } } diff --git a/chutney/engine/src/main/java/com/chutneytesting/engine/domain/delegation/CannotDelegateException.java b/chutney/engine/src/main/java/com/chutneytesting/engine/domain/delegation/CannotDelegateException.java index 09823f316..9aa4744d3 100644 --- a/chutney/engine/src/main/java/com/chutneytesting/engine/domain/delegation/CannotDelegateException.java +++ b/chutney/engine/src/main/java/com/chutneytesting/engine/domain/delegation/CannotDelegateException.java @@ -10,8 +10,8 @@ @SuppressWarnings("serial") public class CannotDelegateException extends RuntimeException { - public CannotDelegateException(String message) { - super(message); + public CannotDelegateException(NamedHostAndPort delegate) { + super("Unable to connect to " + delegate.name() + " at " + delegate.host() + ":" + delegate.port()); } } diff --git a/chutney/engine/src/main/java/com/chutneytesting/engine/domain/execution/engine/evaluation/EvaluationException.java b/chutney/engine/src/main/java/com/chutneytesting/engine/domain/execution/engine/evaluation/EvaluationException.java index e52dd669c..0dab9ea59 100644 --- a/chutney/engine/src/main/java/com/chutneytesting/engine/domain/execution/engine/evaluation/EvaluationException.java +++ b/chutney/engine/src/main/java/com/chutneytesting/engine/domain/execution/engine/evaluation/EvaluationException.java @@ -7,14 +7,20 @@ package com.chutneytesting.engine.domain.execution.engine.evaluation; +import org.springframework.expression.ParseException; + @SuppressWarnings("serial") public class EvaluationException extends RuntimeException { - EvaluationException(String message) { - super(message); + EvaluationException(String expression) { + super("Cannot resolve " + expression + ", Spring evaluation is null"); + } + + EvaluationException(String expression, Exception e) { + super("Cannot resolve " + expression + " , " + e.getMessage(), e); } - EvaluationException(String message, Exception cause) { - super(message, cause); + EvaluationException(String expression, ParseException e) { + super("Cannot parse " + expression + " , " + e.getMessage(), e); } } diff --git a/chutney/engine/src/main/java/com/chutneytesting/engine/domain/execution/engine/evaluation/StepDataEvaluator.java b/chutney/engine/src/main/java/com/chutneytesting/engine/domain/execution/engine/evaluation/StepDataEvaluator.java index 9483cbf2f..c6da65d73 100644 --- a/chutney/engine/src/main/java/com/chutneytesting/engine/domain/execution/engine/evaluation/StepDataEvaluator.java +++ b/chutney/engine/src/main/java/com/chutneytesting/engine/domain/execution/engine/evaluation/StepDataEvaluator.java @@ -148,7 +148,7 @@ private Object evaluate(ExpressionParser parser, final EvaluationContext evaluat try { Object result = expression.getValue(evaluationContext); if (result == null) { - throw new EvaluationException("Cannot resolve " + expressionAsString + ", Spring evaluation is null"); + throw new EvaluationException(expressionAsString); } return result; } catch (org.springframework.expression.EvaluationException e) { @@ -159,7 +159,7 @@ private Object evaluate(ExpressionParser parser, final EvaluationContext evaluat initialException = (Exception) initialException.getCause(); } } - throw new EvaluationException("Cannot resolve " + expressionAsString + " , " + initialException.getMessage(), initialException); + throw new EvaluationException(expressionAsString, initialException); } } @@ -180,7 +180,7 @@ private Expression parseExpression(ExpressionParser parser, String expressionAsS try { expression = parser.parseExpression(expressionAsString); } catch (ParseException e) { - throw new EvaluationException("Cannot parse " + expressionAsString + " , " + e.getMessage(), e); + throw new EvaluationException(expressionAsString, e); } return expression; } diff --git a/chutney/engine/src/main/java/com/chutneytesting/engine/infrastructure/delegation/HttpClient.java b/chutney/engine/src/main/java/com/chutneytesting/engine/infrastructure/delegation/HttpClient.java index 6f9186899..7637d4d05 100644 --- a/chutney/engine/src/main/java/com/chutneytesting/engine/infrastructure/delegation/HttpClient.java +++ b/chutney/engine/src/main/java/com/chutneytesting/engine/infrastructure/delegation/HttpClient.java @@ -71,7 +71,7 @@ public StepExecutionReport handDown(Step step, NamedHostAndPort delegate) throws StepExecutionReportDto reportDto = restTemplate.postForObject("https://" + delegate.host() + ":" + delegate.port() + EXECUTION_URL, request, StepExecutionReportDto.class); return StepExecutionReportMapper.fromDto(reportDto); } else { - throw new CannotDelegateException("Unable to connect to " + delegate.name() + " at " + delegate.host() + ":" + delegate.port()); + throw new CannotDelegateException(delegate); } } diff --git a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/Environment.java b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/Environment.java index b3d7f2a73..324e75878 100644 --- a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/Environment.java +++ b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/Environment.java @@ -41,7 +41,7 @@ public static EnvironmentBuilder builder() { Environment addTarget(Target target) { if (this.containsTarget(target)) { - throw new AlreadyExistingTargetException("Target [" + target.name + "] already exists in [" + this.name + "] environment"); + throw new AlreadyExistingTargetException(target.name, this.name); } return Environment.builder().from(this).addTarget(target).build(); diff --git a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/EnvironmentService.java b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/EnvironmentService.java index bfa3e67dd..ce35c9cae 100644 --- a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/EnvironmentService.java +++ b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/EnvironmentService.java @@ -68,7 +68,7 @@ public Environment createEnvironment(Environment environment) throws InvalidEnvi public Environment createEnvironment(Environment environment, boolean force) throws InvalidEnvironmentNameException, AlreadyExistingEnvironmentException { if (!force && envAlreadyExist(environment)) { - throw new AlreadyExistingEnvironmentException("Environment [" + environment.name + "] already exists"); + throw new AlreadyExistingEnvironmentException(environment.name); } createOrUpdate(environment); return environment; @@ -82,11 +82,11 @@ public void deleteEnvironment(String environmentName) throws EnvironmentNotFound List environmentNames = environmentRepository.listNames(); if (environmentNames.stream().noneMatch(env -> env.equals(environmentName))) { logger.error("Environment not found for name {}", environmentName); - throw new EnvironmentNotFoundException("Environment not found for name " + environmentNames); + throw new EnvironmentNotFoundException(environmentNames); } if (environmentNames.size() == 1) { logger.error("Cannot delete environment with name {} : cannot delete the last env", environmentName); - throw new SingleEnvironmentException("Cannot delete environment with name " + environmentName + " : cannot delete the last env"); + throw new SingleEnvironmentException(environmentName); } environmentRepository.delete(environmentName); updateEnvironmentHandlers.forEach(renameEnvironmentHandler -> renameEnvironmentHandler.deleteEnvironment(environmentName)); @@ -109,10 +109,10 @@ public void updateEnvironment(String environmentName, Environment newVersion) th public String defaultEnvironmentName() throws EnvironmentNotFoundException { List envs = environmentRepository.listNames(); if (envs.size() > 1) { - throw new UnresolvedEnvironmentException("There is more than one environment. Could not resolve the default one"); + throw new UnresolvedEnvironmentException(); } if (envs.isEmpty()) { - throw new NoEnvironmentFoundException("No Environment found"); + throw new NoEnvironmentFoundException(); } return envs.get(0); @@ -209,7 +209,7 @@ public void deleteVariable(String key, List envs) { .filter(env -> env.containsVariable(key)).toList(); if (!envs.isEmpty() && environments.isEmpty()) { - throw new EnvVariableNotFoundException("Variable [" + key + "] not found"); + throw new EnvVariableNotFoundException(key); } environments .forEach(env -> { @@ -228,7 +228,7 @@ private void addVariable(EnvironmentVariable variable, Environment env) throws E private void createOrUpdate(Environment environment) { if (!NAME_VALIDATION_PATTERN.matcher(environment.name).matches()) { - throw new InvalidEnvironmentNameException("Environment name must be of 3 to 20 letters, digits, underscore or hyphen"); + throw new InvalidEnvironmentNameException(); } environmentRepository.save(environment); } diff --git a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/AlreadyExistingEnvironmentException.java b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/AlreadyExistingEnvironmentException.java index 0c2c4fc87..163134136 100644 --- a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/AlreadyExistingEnvironmentException.java +++ b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/AlreadyExistingEnvironmentException.java @@ -9,7 +9,7 @@ @SuppressWarnings("serial") public class AlreadyExistingEnvironmentException extends RuntimeException { - public AlreadyExistingEnvironmentException(String message) { - super(message); + public AlreadyExistingEnvironmentException(String environmentName) { + super("Environment [" + environmentName + "] already exists"); } } diff --git a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/AlreadyExistingTargetException.java b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/AlreadyExistingTargetException.java index 4dcf447ea..32293923c 100644 --- a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/AlreadyExistingTargetException.java +++ b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/AlreadyExistingTargetException.java @@ -10,8 +10,8 @@ @SuppressWarnings("serial") public class AlreadyExistingTargetException extends RuntimeException { - public AlreadyExistingTargetException(String message) { - super(message); + public AlreadyExistingTargetException(String targetName, String environmentName) { + super("Target [" + targetName + "] already exists in [" + environmentName + "] environment"); } } diff --git a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/CannotDeleteEnvironmentException.java b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/CannotDeleteEnvironmentException.java index 6e89bb77d..a21f0610a 100644 --- a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/CannotDeleteEnvironmentException.java +++ b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/CannotDeleteEnvironmentException.java @@ -7,14 +7,13 @@ package com.chutneytesting.environment.domain.exception; +import java.io.IOException; +import java.nio.file.Path; + @SuppressWarnings("serial") public class CannotDeleteEnvironmentException extends RuntimeException { - public CannotDeleteEnvironmentException(String message) { - super(message); - } - - public CannotDeleteEnvironmentException(String message, Exception cause) { - super(message, cause); + public CannotDeleteEnvironmentException(Path environmentPath, IOException e) { + super("Cannot delete configuration file: " + environmentPath, e); } } diff --git a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/EnvVariableNotFoundException.java b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/EnvVariableNotFoundException.java index 3ab27ad14..8cc03b4c5 100644 --- a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/EnvVariableNotFoundException.java +++ b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/EnvVariableNotFoundException.java @@ -9,7 +9,7 @@ @SuppressWarnings("serial") public class EnvVariableNotFoundException extends RuntimeException { - public EnvVariableNotFoundException(String message) { - super(message); + public EnvVariableNotFoundException(String variableKey) { + super("Variable [" + variableKey + "] not found"); } } diff --git a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/EnvironmentNotFoundException.java b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/EnvironmentNotFoundException.java index 0630b9cd2..4250faac3 100644 --- a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/EnvironmentNotFoundException.java +++ b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/EnvironmentNotFoundException.java @@ -7,9 +7,16 @@ package com.chutneytesting.environment.domain.exception; +import java.nio.file.Path; +import java.util.List; + @SuppressWarnings("serial") public class EnvironmentNotFoundException extends RuntimeException { - public EnvironmentNotFoundException(String message) { - super(message); + public EnvironmentNotFoundException(Path environmentPath) { + super("Configuration file not found: " + environmentPath); + } + + public EnvironmentNotFoundException(List environmentNames) { + super("Environment not found for name " + environmentNames); } } diff --git a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/InvalidEnvironmentNameException.java b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/InvalidEnvironmentNameException.java index 28cd00a05..0258b6497 100644 --- a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/InvalidEnvironmentNameException.java +++ b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/InvalidEnvironmentNameException.java @@ -9,7 +9,7 @@ @SuppressWarnings("serial") public class InvalidEnvironmentNameException extends RuntimeException { - public InvalidEnvironmentNameException(String message) { - super(message + ". NOTE: Environment are stored in files, names must be of the form [A-Z0-9_\\-]{3,20}"); + public InvalidEnvironmentNameException() { + super("Environment name must be of 3 to 20 letters, digits, underscore or hyphen. NOTE: Environment are stored in files, names must be of the form [A-Z0-9_\\-]{3,20}"); } } diff --git a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/NoEnvironmentFoundException.java b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/NoEnvironmentFoundException.java index 21cc9d0e3..6d41d9722 100644 --- a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/NoEnvironmentFoundException.java +++ b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/NoEnvironmentFoundException.java @@ -9,7 +9,7 @@ @SuppressWarnings("serial") public class NoEnvironmentFoundException extends RuntimeException { - public NoEnvironmentFoundException(String message) { - super(message); + public NoEnvironmentFoundException() { + super("No Environment found"); } } diff --git a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/SingleEnvironmentException.java b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/SingleEnvironmentException.java index 9910dc466..877a96bec 100644 --- a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/SingleEnvironmentException.java +++ b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/SingleEnvironmentException.java @@ -9,11 +9,7 @@ public class SingleEnvironmentException extends RuntimeException { - public SingleEnvironmentException(String message) { - super(message); + public SingleEnvironmentException(String environmentName) { + super("Cannot delete environment with name " + environmentName + " : cannot delete the last env"); } - - public SingleEnvironmentException(String message, Exception cause) { - super(message, cause); - } } diff --git a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/UnresolvedEnvironmentException.java b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/UnresolvedEnvironmentException.java index e9edc92d0..5c264151a 100644 --- a/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/UnresolvedEnvironmentException.java +++ b/chutney/environment/src/main/java/com/chutneytesting/environment/domain/exception/UnresolvedEnvironmentException.java @@ -9,7 +9,7 @@ @SuppressWarnings("serial") public class UnresolvedEnvironmentException extends RuntimeException { - public UnresolvedEnvironmentException(String message) { - super(message); + public UnresolvedEnvironmentException() { + super("There is more than one environment. Could not resolve the default one"); } } diff --git a/chutney/environment/src/main/java/com/chutneytesting/environment/infra/JsonFilesEnvironmentRepository.java b/chutney/environment/src/main/java/com/chutneytesting/environment/infra/JsonFilesEnvironmentRepository.java index 0dd022c88..5f5f75b25 100644 --- a/chutney/environment/src/main/java/com/chutneytesting/environment/infra/JsonFilesEnvironmentRepository.java +++ b/chutney/environment/src/main/java/com/chutneytesting/environment/infra/JsonFilesEnvironmentRepository.java @@ -58,7 +58,7 @@ public synchronized void save(Environment environment) throws UnsupportedOperati public Environment findByName(String name) throws EnvironmentNotFoundException { Path environmentPath = getEnvironmentPath(name); if (!Files.exists(environmentPath)) { - throw new EnvironmentNotFoundException("Configuration file not found: " + environmentPath); + throw new EnvironmentNotFoundException(environmentPath); } try { byte[] bytes = Files.readAllBytes(environmentPath); @@ -91,13 +91,13 @@ private boolean isJsonFile(Path path) { public void delete(String name) { Path environmentPath = getEnvironmentPath(name); if (!Files.exists(environmentPath)) { - throw new EnvironmentNotFoundException("Configuration file not found: " + environmentPath); + throw new EnvironmentNotFoundException(environmentPath); } try { Path backupPath = Paths.get(environmentPath.toString() + UUID.randomUUID().getMostSignificantBits() + ".backup"); Files.move(environmentPath, backupPath); } catch (IOException e) { - throw new CannotDeleteEnvironmentException("Cannot delete configuration file: " + environmentPath, e); + throw new CannotDeleteEnvironmentException(environmentPath, e); } } diff --git a/chutney/environment/src/test/java/com/chutneytesting/environment/api/environment/HttpEnvironmentApiTest.java b/chutney/environment/src/test/java/com/chutneytesting/environment/api/environment/HttpEnvironmentApiTest.java index 5eb9bcffd..3e5da3c33 100644 --- a/chutney/environment/src/test/java/com/chutneytesting/environment/api/environment/HttpEnvironmentApiTest.java +++ b/chutney/environment/src/test/java/com/chutneytesting/environment/api/environment/HttpEnvironmentApiTest.java @@ -125,7 +125,7 @@ public void createEnvironment_adds_it_to_repository() throws Exception { @Test public void createEnvironment_returns_400_when_name_is_invalid() throws Exception { - doThrow(new InvalidEnvironmentNameException("message")).when(environmentRepository).save(any()); + doThrow(new InvalidEnvironmentNameException()).when(environmentRepository).save(any()); mockMvc.perform( post(environmentBasePath) .content("{\"name\": \"env test\", \"description\": \"test description\"}") @@ -156,7 +156,7 @@ public void deleteEnvironment_does_not_deletes_last_env() throws Exception { @Test public void deleteEnvironment_returns_404_when_not_found() throws Exception { - doThrow(new EnvironmentNotFoundException("message")).when(environmentRepository).delete(any()); + doThrow(new EnvironmentNotFoundException(List.of("message"))).when(environmentRepository).delete(any()); mockMvc.perform(delete(environmentBasePath + "/env test")) .andDo(MockMvcResultHandlers.log()) @@ -176,7 +176,7 @@ public void deleteEnvironment_deletes_it_from_repo() throws Exception { @Test public void updateEnvironment_returns_404_when_not_found() throws Exception { - when(environmentRepository.findByName(any())).thenThrow(new EnvironmentNotFoundException("message")); + when(environmentRepository.findByName(any())).thenThrow(new EnvironmentNotFoundException(List.of("message"))); mockMvc.perform( put(environmentBasePath + "/env test") @@ -275,7 +275,7 @@ private void addAvailableEnvironment(String envName, String... targetNames) { .thenAnswer(iom -> { String envNameParam = iom.getArgument(0); if (!registeredEnvironments.containsKey(envNameParam)) { - throw new EnvironmentNotFoundException("test env not found"); + throw new EnvironmentNotFoundException(List.of("test env not found")); } return registeredEnvironments.get(envNameParam); } diff --git a/chutney/environment/src/test/java/com/chutneytesting/environment/api/target/TargetControllerTest.java b/chutney/environment/src/test/java/com/chutneytesting/environment/api/target/TargetControllerTest.java index 6f9319f75..55020e3c1 100644 --- a/chutney/environment/src/test/java/com/chutneytesting/environment/api/target/TargetControllerTest.java +++ b/chutney/environment/src/test/java/com/chutneytesting/environment/api/target/TargetControllerTest.java @@ -244,7 +244,7 @@ private void addAvailableEnvironment(String envName, String... targetNames) { .thenAnswer(iom -> { String envNameParam = iom.getArgument(0); if (!registeredEnvironments.containsKey(envNameParam)) { - throw new EnvironmentNotFoundException("test env not found"); + throw new EnvironmentNotFoundException(List.of("test env not found")); } return registeredEnvironments.get(envNameParam); } diff --git a/chutney/environment/src/test/java/com/chutneytesting/environment/api/variable/VariableControllerTest.java b/chutney/environment/src/test/java/com/chutneytesting/environment/api/variable/VariableControllerTest.java index b41197b50..7209c932e 100644 --- a/chutney/environment/src/test/java/com/chutneytesting/environment/api/variable/VariableControllerTest.java +++ b/chutney/environment/src/test/java/com/chutneytesting/environment/api/variable/VariableControllerTest.java @@ -231,7 +231,7 @@ private void addAvailableEnvironment(String envName, List targetsNames, .thenAnswer(iom -> { String envNameParam = iom.getArgument(0); if (!registeredEnvironments.containsKey(envNameParam)) { - throw new EnvironmentNotFoundException("test env not found"); + throw new EnvironmentNotFoundException(List.of("test env not found")); } return registeredEnvironments.get(envNameParam); } diff --git a/chutney/server-core/src/main/java/com/chutneytesting/server/core/domain/scenario/AlreadyExistingScenarioException.java b/chutney/server-core/src/main/java/com/chutneytesting/server/core/domain/scenario/AlreadyExistingScenarioException.java index d068d22a1..3de824be5 100644 --- a/chutney/server-core/src/main/java/com/chutneytesting/server/core/domain/scenario/AlreadyExistingScenarioException.java +++ b/chutney/server-core/src/main/java/com/chutneytesting/server/core/domain/scenario/AlreadyExistingScenarioException.java @@ -10,8 +10,8 @@ @SuppressWarnings("serial") public class AlreadyExistingScenarioException extends RuntimeException { - public AlreadyExistingScenarioException(String message) { - super(message); + public AlreadyExistingScenarioException() { + super("Scenario already existing"); } } diff --git a/chutney/server/src/test/java/com/chutneytesting/RestExceptionHandlerTest.java b/chutney/server/src/test/java/com/chutneytesting/RestExceptionHandlerTest.java index 4fe5d6fcc..251767184 100644 --- a/chutney/server/src/test/java/com/chutneytesting/RestExceptionHandlerTest.java +++ b/chutney/server/src/test/java/com/chutneytesting/RestExceptionHandlerTest.java @@ -58,7 +58,7 @@ public static List usernamePrivateKeyTargets() { of(new ScenarioNotFoundException("12345"), NOT_FOUND, status().isNotFound()), of(new HttpMessageConversionException(""), BAD_REQUEST, status().isBadRequest()), of(new IllegalArgumentException(), BAD_REQUEST, status().isBadRequest()), - of(new AlreadyExistingTargetException(""), CONFLICT, status().isConflict()), + of(new AlreadyExistingTargetException("", ""), CONFLICT, status().isConflict()), of(new ScenarioConversionException("", mock(Exception.class)), UNPROCESSABLE_ENTITY, status().isUnprocessableEntity()) ); } diff --git a/kotlin-dsl/src/main/kotlin/com/chutneytesting/kotlin/util/HttpClient.kt b/kotlin-dsl/src/main/kotlin/com/chutneytesting/kotlin/util/HttpClient.kt index bda2cf2c2..94c9b990c 100644 --- a/kotlin-dsl/src/main/kotlin/com/chutneytesting/kotlin/util/HttpClient.kt +++ b/kotlin-dsl/src/main/kotlin/com/chutneytesting/kotlin/util/HttpClient.kt @@ -77,7 +77,7 @@ object HttpClient { httpResponse.use { response -> if (response.code >= 300) { - throw HttpClientException("Call to server returned status ${response.reasonPhrase}") + throw HttpClientException(response.reasonPhrase) } try { @@ -194,6 +194,6 @@ object HttpClient { } class HttpClientException : RuntimeException { - constructor(message: String?) : super(message) + constructor(reasonPhrase: String?) : super("Call to server returned status $reasonPhrase") constructor(cause: Throwable?) : super(cause) }