Search in sources :

Example 1 with JSONUtils

use of org.springframework.extensions.webscripts.json.JSONUtils in project alfresco-remote-api by Alfresco.

the class FormRestApiGet_Test method testJsonContentParsesCorrectly.

public void testJsonContentParsesCorrectly() throws Exception {
    JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
    String jsonPostString = jsonPostData.toString();
    Response rsp = sendRequest(new PostRequest(FORM_DEF_URL, jsonPostString, APPLICATION_JSON), 200);
    String jsonResponseString = rsp.getContentAsString();
    Object jsonObject = new JSONUtils().toObject(jsonResponseString);
    assertNotNull("JSON object was null.", jsonObject);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) JSONUtils(org.springframework.extensions.webscripts.json.JSONUtils)

Example 2 with JSONUtils

use of org.springframework.extensions.webscripts.json.JSONUtils in project records-management by Alfresco.

the class BaseWebScriptUnitTest method getMockedContainer.

/**
 * Helper method to get mocked container object.
 *
 * @param template              classpath location of webscripts ftl template
 * @return {@link Container}    mocked container
 */
protected Container getMockedContainer(String template) throws Exception {
    FormatRegistry mockedFormatRegistry = mock(FormatRegistry.class);
    doReturn("application/json").when(mockedFormatRegistry).getMimeType(anyString(), anyString());
    ScriptProcessorRegistry mockedScriptProcessorRegistry = mock(ScriptProcessorRegistry.class);
    doReturn(null).when(mockedScriptProcessorRegistry).findValidScriptPath(anyString());
    TemplateProcessorRegistry mockedTemplateProcessorRegistry = mock(TemplateProcessorRegistry.class);
    doReturn(template).when(mockedTemplateProcessorRegistry).findValidTemplatePath(anyString());
    FTLTemplateProcessor ftlTemplateProcessor = new FTLTemplateProcessor() {

        @Override
        protected TemplateLoader getTemplateLoader() {
            return new ClassTemplateLoader(getClass(), "/");
        }
    };
    ftlTemplateProcessor.init();
    doReturn(ftlTemplateProcessor).when(mockedTemplateProcessorRegistry).getTemplateProcessor(anyString());
    Container mockedContainer = mock(Container.class);
    doReturn(mockedFormatRegistry).when(mockedContainer).getFormatRegistry();
    doReturn(mockedScriptProcessorRegistry).when(mockedContainer).getScriptProcessorRegistry();
    doReturn(mockedTemplateProcessorRegistry).when(mockedContainer).getTemplateProcessorRegistry();
    Map<String, Object> containerTemplateParameters = new HashMap<>(5);
    containerTemplateParameters.put("jsonUtils", new JSONUtils());
    containerTemplateParameters.put("people", getMockedPeopleObject());
    doReturn(containerTemplateParameters).when(mockedContainer).getTemplateParameters();
    SearchPath mockedSearchPath = mock(SearchPath.class);
    doReturn(false).when(mockedSearchPath).hasDocument(anyString());
    doReturn(mockedSearchPath).when(mockedContainer).getSearchPath();
    // setup description
    Description mockDescription = mock(Description.class);
    doReturn(mock(RequiredCache.class)).when(mockDescription).getRequiredCache();
    return mockedContainer;
}
Also used : ScriptProcessorRegistry(org.springframework.extensions.webscripts.ScriptProcessorRegistry) FTLTemplateProcessor(org.springframework.extensions.webscripts.processor.FTLTemplateProcessor) RequiredCache(org.springframework.extensions.webscripts.Description.RequiredCache) Description(org.springframework.extensions.webscripts.Description) HashMap(java.util.HashMap) ClassTemplateLoader(freemarker.cache.ClassTemplateLoader) FormatRegistry(org.springframework.extensions.webscripts.FormatRegistry) Matchers.anyString(org.mockito.Matchers.anyString) Container(org.springframework.extensions.webscripts.Container) JSONObject(org.json.JSONObject) SearchPath(org.springframework.extensions.webscripts.SearchPath) TemplateProcessorRegistry(org.springframework.extensions.webscripts.TemplateProcessorRegistry) JSONUtils(org.springframework.extensions.webscripts.json.JSONUtils)

Aggregations

JSONObject (org.json.JSONObject)2 JSONUtils (org.springframework.extensions.webscripts.json.JSONUtils)2 ClassTemplateLoader (freemarker.cache.ClassTemplateLoader)1 HashMap (java.util.HashMap)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Container (org.springframework.extensions.webscripts.Container)1 Description (org.springframework.extensions.webscripts.Description)1 RequiredCache (org.springframework.extensions.webscripts.Description.RequiredCache)1 FormatRegistry (org.springframework.extensions.webscripts.FormatRegistry)1 ScriptProcessorRegistry (org.springframework.extensions.webscripts.ScriptProcessorRegistry)1 SearchPath (org.springframework.extensions.webscripts.SearchPath)1 TemplateProcessorRegistry (org.springframework.extensions.webscripts.TemplateProcessorRegistry)1 PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)1 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)1 FTLTemplateProcessor (org.springframework.extensions.webscripts.processor.FTLTemplateProcessor)1