use of org.forgerock.openam.scripting.ScriptException in project OpenAM by OpenRock.
the class ScriptExceptionMappingHandlerTest method shouldTranslateMessageToAcceptLanguage.
@Test
public void shouldTranslateMessageToAcceptLanguage() throws Exception {
// given
final Context serverContext = getHttpServerContext("te");
for (ScriptErrorCode errorCode : ScriptErrorCode.values()) {
// when
ResourceException re = mappingHandler.handleError(serverContext, null, new ScriptException(errorCode));
// then
assertNotNull(re);
// assertEquals("Test message", re.getMessage()); //TODO dont get this...
}
}
use of org.forgerock.openam.scripting.ScriptException in project OpenAM by OpenRock.
the class ScriptConfigurationServiceTest method shouldFailIfUuidDoesNotExistOnDelete.
@Test
public void shouldFailIfUuidDoesNotExistOnDelete() throws ScriptException {
// given
String uuid = "1234567890";
when(dataStore.containsUuid(anyString())).thenReturn(false);
// when
try {
service.delete(uuid);
fail("shouldFailIfUuidDoesNotExistOnDelete");
} catch (ScriptException e) {
// then
assertEquals(e.getScriptErrorCode(), SCRIPT_UUID_NOT_FOUND);
}
}
use of org.forgerock.openam.scripting.ScriptException in project OpenAM by OpenRock.
the class ScriptResource method queryCollection.
@Override
public Promise<QueryResponse, ResourceException> queryCollection(Context context, QueryRequest request, QueryResourceHandler resultHandler) {
final QueryFilter<JsonPointer> filter = request.getQueryFilter();
try {
final Set<ScriptConfiguration> configs;
if (filter == null) {
configs = serviceFactory.create(getContextSubject(context), getRealm(context)).getAll();
} else {
QueryFilter<String> stringQueryFilter = filter.accept(new QueryByStringFilterConverter(), null);
configs = serviceFactory.create(getContextSubject(context), getRealm(context)).get(stringQueryFilter);
}
List<ResourceResponse> results = new ArrayList<>();
for (ScriptConfiguration configuration : configs) {
String id = configuration.getId();
results.add(newResourceResponse(id, null, asJson(configuration)));
}
QueryResponsePresentation.enableDeprecatedRemainingQueryResponse(request);
return QueryResponsePresentation.perform(resultHandler, request, results);
} catch (ScriptException se) {
return exceptionMappingHandler.handleError(context, request, se).asPromise();
}
}
use of org.forgerock.openam.scripting.ScriptException in project OpenAM by OpenRock.
the class ScriptConfigurationDataStoreTest method shouldFailIfAttemptingToDeleteDefaultScript.
@Test
public void shouldFailIfAttemptingToDeleteDefaultScript() throws Exception {
// given
String uuid = "1234567890";
ServiceConfig defaultScriptSubConfig = mock(ServiceConfig.class);
given(subGlobalConfig.getSubConfig(uuid)).willReturn(defaultScriptSubConfig);
given(defaultScriptSubConfig.exists()).willReturn(true);
// when
try {
dataStore.delete(uuid);
fail("shouldFailIfAttemptingToDeleteDefaultScript");
} catch (ScriptException e) {
// then
assertEquals(e.getScriptErrorCode(), RETRIEVE_FAILED);
}
}
use of org.forgerock.openam.scripting.ScriptException in project OpenAM by OpenRock.
the class ScriptResource method actionCollection.
@Override
public Promise<ActionResponse, ResourceException> actionCollection(Context context, ActionRequest request) {
if ("validate".equals(request.getAction())) {
try {
JsonValue json = request.getContent();
SupportedScriptingLanguage language = getLanguageFromString(json.get(SCRIPT_LANGUAGE).asString());
String script = json.get(SCRIPT_TEXT).asString();
if (script == null) {
throw new ScriptException(MISSING_SCRIPT);
}
List<ScriptError> scriptErrorList = scriptValidator.validateScript(new ScriptObject(EMPTY, decodeScript(script), language, null));
if (scriptErrorList.isEmpty()) {
return newResultPromise(newActionResponse(json(object(field("success", true)))));
}
Set<Object> errors = new HashSet<>();
for (ScriptError error : scriptErrorList) {
errors.add(object(field("line", error.getLineNumber()), field("column", error.getColumnNumber()), field("message", error.getMessage())));
}
return newResultPromise(newActionResponse(json(object(field("success", false), field("errors", errors)))));
} catch (ScriptException se) {
return exceptionMappingHandler.handleError(context, request, se).asPromise();
}
} else {
return new NotSupportedException().asPromise();
}
}
Aggregations