use of elemental.json.JsonException in project flow by vaadin.
the class BundleConfigurationReader method getFragments.
/**
* Get the fragments data from the bundle configuration specified: fragment
* name and a set of file paths as strings to the resources that are to be
* included in the final produced fragment file.
*
* @return the fragments defined in the configuration file
*
* @throws IllegalStateException
* if parsed json file does not contain valid fragment data
*/
public Map<String, Set<String>> getFragments() {
Map<String, Set<String>> fragments = new HashMap<>();
if (bundleConfigurationJson == null || !bundleConfigurationJson.hasKey("fragments")) {
return fragments;
}
JsonArray fragmentsArray;
try {
fragmentsArray = bundleConfigurationJson.getArray("fragments");
} catch (JsonException | ClassCastException e) {
throw new IllegalStateException("The 'fragments' property of a given bundle configuration should be an array.", e);
}
for (int i = 0; i < fragmentsArray.length(); ++i) {
JsonObject fragment;
try {
fragment = fragmentsArray.getObject(i);
} catch (JsonException | ClassCastException e) {
throw new IllegalStateException("The 'fragments' array of a given bundle configuration should contain fragment objects only.", e);
}
String fragmentName = extractFragmentName(fragment);
fragments.put(fragmentName, extractFragmentFiles(fragment, fragmentName));
}
return fragments;
}
use of elemental.json.JsonException in project flow by vaadin.
the class NodeUpdaterTest method getJsonFileContent_incorrectPackageJsonContent_throwsExceptionWithFileName.
@Test
public void getJsonFileContent_incorrectPackageJsonContent_throwsExceptionWithFileName() throws IOException {
File brokenPackageJsonFile = temporaryFolder.newFile("broken-package.json");
FileUtils.writeStringToFile(brokenPackageJsonFile, "{ some broken json ", UTF_8);
JsonException exception = Assert.assertThrows(JsonException.class, () -> NodeUpdater.getJsonFileContent(brokenPackageJsonFile));
MatcherAssert.assertThat(exception.getMessage(), StringContains.containsString("Cannot parse package file "));
MatcherAssert.assertThat(exception.getMessage(), StringContains.containsString("broken-package.json"));
}
use of elemental.json.JsonException in project che by eclipse.
the class JsonRpcEntityValidatorTest method shouldThrowJsonRpcExceptionWhenParsingFails.
@Test(expected = JsonRpcException.class)
public void shouldThrowJsonRpcExceptionWhenParsingFails() throws Exception {
when(jsonFactory.parse(anyString())).thenThrow(new JsonException(""));
validator.validate("message");
verify(jsonFactory).parse("message");
}
use of elemental.json.JsonException in project che by eclipse.
the class AppStateManager method restoreState.
private void restoreState(JsonObject settings) {
try {
if (settings.hasKey(WORKSPACE)) {
JsonObject workspace = settings.getObject(WORKSPACE);
for (String key : workspace.keys()) {
if (persistenceComponents.containsKey(key)) {
StateComponent component = persistenceComponents.get(key);
component.loadState(workspace.getObject(key));
}
}
}
} catch (JsonException e) {
Log.error(getClass(), e);
}
}
use of elemental.json.JsonException in project flow by vaadin.
the class BundleConfigurationReader method extractFragmentFiles.
private Set<String> extractFragmentFiles(JsonObject fragment, String fragmentName) {
JsonArray fragmentFiles;
try {
fragmentFiles = fragment.getArray("files");
if (fragmentFiles == null) {
throw new IllegalStateException(String.format("Fragment with name '%s' has no `files` array field specified.", fragmentName));
}
} catch (JsonException | ClassCastException e) {
throw new IllegalStateException(String.format("Fragment with name '%s' has no `files` array field specified.", fragmentName), e);
}
Set<String> files = Sets.newHashSetWithExpectedSize(fragmentFiles.length());
for (int j = 0; j < fragmentFiles.length(); ++j) {
try {
files.add(fragmentFiles.getString(j));
} catch (JsonException | ClassCastException e) {
throw new IllegalStateException(String.format("The 'files' array of a fragment with name '%s' should only contain string file paths", fragmentName), e);
}
}
if (files.isEmpty()) {
throw new IllegalStateException(String.format("Fragment with name '%s' has no files specified, each fragment should have at least one file specified", fragmentName));
}
return files;
}
Aggregations