Search in sources :

Example 1 with ScriptErrorCode

use of org.forgerock.openam.scripting.ScriptConstants.ScriptErrorCode 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...
    }
}
Also used : Context(org.forgerock.services.context.Context) HttpContext(org.forgerock.json.resource.http.HttpContext) ClientContext(org.forgerock.services.context.ClientContext) ScriptException(org.forgerock.openam.scripting.ScriptException) ScriptErrorCode(org.forgerock.openam.scripting.ScriptConstants.ScriptErrorCode) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test)

Example 2 with ScriptErrorCode

use of org.forgerock.openam.scripting.ScriptConstants.ScriptErrorCode in project OpenAM by OpenRock.

the class ScriptExceptionTest method shouldMapScriptErrorCodeToLocalisedMessage.

@Test
public void shouldMapScriptErrorCodeToLocalisedMessage() {
    // given
    ScriptException se;
    Locale locale = new Locale("te");
    for (ScriptErrorCode errorCode : ScriptErrorCode.values()) {
        // when
        se = new ScriptException(errorCode);
        //then
        assertThat(se.getL10NMessage(locale)).isEqualTo(format(errorCode.name() + "-TRANSLATED"));
    }
}
Also used : Locale(java.util.Locale) ScriptErrorCode(org.forgerock.openam.scripting.ScriptConstants.ScriptErrorCode) Test(org.testng.annotations.Test)

Example 3 with ScriptErrorCode

use of org.forgerock.openam.scripting.ScriptConstants.ScriptErrorCode in project OpenAM by OpenRock.

the class ScriptExceptionMappingHandlerTest method shouldHandleAllScriptExceptionCodes.

@Test
public void shouldHandleAllScriptExceptionCodes() throws Exception {
    for (ScriptErrorCode errorCode : ScriptErrorCode.values()) {
        // when
        ResourceException re = mappingHandler.handleError(new ScriptException(errorCode));
        // then
        assertNotNull(re);
        assertNotNull(re.getMessage());
        assertTrue(isClientError(re.getCode()) || re.isServerError());
    }
}
Also used : ScriptException(org.forgerock.openam.scripting.ScriptException) ScriptErrorCode(org.forgerock.openam.scripting.ScriptConstants.ScriptErrorCode) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test)

Aggregations

ScriptErrorCode (org.forgerock.openam.scripting.ScriptConstants.ScriptErrorCode)3 Test (org.testng.annotations.Test)3 ResourceException (org.forgerock.json.resource.ResourceException)2 ScriptException (org.forgerock.openam.scripting.ScriptException)2 Locale (java.util.Locale)1 HttpContext (org.forgerock.json.resource.http.HttpContext)1 ClientContext (org.forgerock.services.context.ClientContext)1 Context (org.forgerock.services.context.Context)1