use of uk.gov.justice.subscription.SubscriptionDescriptorException in project microservice_framework by CJSCommonPlatform.
the class SubscriptionDescriptorParser method read.
public SubscriptionDescriptor read(final Path absolutePath) {
try {
subscriptionDescriptorFileValidator.validate(absolutePath);
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()).registerModule(new Jdk8Module()).registerModule(new ParameterNamesModule(PROPERTIES));
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
return mapper.readValue(absolutePath.toFile(), SubscriptionDescriptorDef.class).getSubscriptionDescriptor();
} catch (final NoSuchFileException e) {
throw new SubscriptionDescriptorException(format("No such subscriptions YAML file %s ", absolutePath), e);
} catch (final ValidationException e) {
throw new SubscriptionDescriptorException(format("Failed to validate subscriptions yaml file %s ", absolutePath), e);
} catch (final IOException e) {
throw new SubscriptionDescriptorException(format("Failed to read subscriptions yaml file %s ", absolutePath), e);
}
}
use of uk.gov.justice.subscription.SubscriptionDescriptorException in project microservice_framework by CJSCommonPlatform.
the class SubscriptionDescriptorParserTest method shouldThrowFileNotFoundException.
@Test
public void shouldThrowFileNotFoundException() {
final Path path = get("this-subscription-does-not-exist.yaml").toAbsolutePath();
try {
subscriptionDescriptorParser.read(path);
fail();
} catch (SubscriptionDescriptorException re) {
assertThat(re, is(instanceOf(SubscriptionDescriptorException.class)));
assertThat(re.getCause(), is(instanceOf(NoSuchFileException.class)));
}
}
use of uk.gov.justice.subscription.SubscriptionDescriptorException in project microservice_framework by CJSCommonPlatform.
the class SubscriptionDescriptorParserTest method shouldFailOnIncorrectSubscriptionYaml.
@Test
public void shouldFailOnIncorrectSubscriptionYaml() {
final Path path = getFromClasspath("incorrect-subscription.yaml");
try {
subscriptionDescriptorParser.read(path);
fail();
} catch (final SubscriptionDescriptorException re) {
assertThat(re, is(instanceOf(SubscriptionDescriptorException.class)));
assertThat(re.getCause(), is(instanceOf(ValidationException.class)));
assertThat(re.getCause().getMessage(), is("#/subscription_descriptor: required key [spec_version] not found"));
}
}
use of uk.gov.justice.subscription.SubscriptionDescriptorException in project microservice_framework by CJSCommonPlatform.
the class SubscriptionDescriptorFileValidator method validate.
public void validate(final Path filePath) {
try {
final JSONObject convert = yamlFileToJsonObjectConverter.convert(filePath);
schema().validate(convert);
} catch (IOException ex) {
throw new SubscriptionDescriptorException(format("Unable to convert to JSON file %s ", filePath.toString()), ex);
}
}
Aggregations