protected String callMetadataService(String nodeString) throws ConnectorServiceException { GetRequest request = new GetRequest("/api/metadata?nodeRef=" + nodeString + "&shortQNames=true"); Response response = null; String jsonResponse = null; try { response = server.submitRequest( request.getMethod(), request.getFullUri(), request.getHeaders(), request.getBody(), request.getEncoding(), request.getType()); if (response != null) { jsonResponse = response.getContentAsString(); } } catch (UnsupportedEncodingException e) { throw new AlfrescoRuntimeException(e.getMessage()); } catch (IOException e) { throw new AlfrescoRuntimeException(e.getMessage()); } assertNotNull("Response /api/metadata is null", jsonResponse); log.info("Response /api/metadata json is: " + jsonResponse); return jsonResponse; }
@Override protected org.springframework.extensions.webscripts.connector.Response retrieveFormDefinition( String itemKind, String itemId, List<String> visibleFields, FormConfigElement formConfig) { org.springframework.extensions.webscripts.connector.Response response = null; try { assertEquals("Parameter 'itemKind' isn't 'node' value", "node", itemKind); assertFalse("itemId is empty", itemId != null && itemId.isEmpty()); assertTrue("Visible fields are empty", visibleFields.size() > 0); assertEquals("Form config 'name' field isn't 'form' value", "form", formConfig.getName()); ByteArrayInputStream bais = generateFormDefPostBody(itemKind, itemId, visibleFields, formConfig); assertTrue("Can't read bytes from ByteArrayInputStream ", bais.available() > 0); String json = getStringFromInputStream(bais); log.info("Request 'formdefinitions' json is: " + json); PostRequest request = new PostRequest("/api/formdefinitions", json, "application/json"); org.springframework.extensions.webscripts.TestWebScriptServer.Response responseTest = server.submitRequest( request.getMethod(), request.getFullUri(), request.getHeaders(), request.getBody(), request.getEncoding(), request.getType()); if (responseTest.getStatus() == 200) { JSONObject jsonParsedObject = new JSONObject(new JSONTokener(responseTest.getContentAsString())); assertNotNull("JSON from responseTest is null", jsonParsedObject); Object dataObj = jsonParsedObject.get("data"); assertEquals(JSONObject.class, dataObj.getClass()); JSONObject rootDataObject = (JSONObject) dataObj; String item = (String) rootDataObject.get("item"); String submissionUrl = (String) rootDataObject.get("submissionUrl"); String type = (String) rootDataObject.get("type"); JSONObject definitionObject = (JSONObject) rootDataObject.get("definition"); JSONObject formDataObject = (JSONObject) rootDataObject.get("formData"); assertNotNull("Item is null ", item); assertNotNull("Submission url is null ", submissionUrl); assertNotNull("Type is null ", type); assertNotNull("Definition is null ", definitionObject); assertNotNull("Form data is null ", formDataObject); log.info("Response form 'formdefinitions' json 'data' is: " + dataObj); ResponseStatus status = new ResponseStatus(); status.setCode(responseTest.getStatus()); assertFalse("Response content is empty", responseTest.getContentAsString().isEmpty()); response = new org.springframework.extensions.webscripts.connector.Response( responseTest.getContentAsString(), status); assertNotNull("Response data is null.", response.getText()); } else { assertEquals( "Response /api/formdefinitions is not 200 status", 200, responseTest.getStatus()); } } catch (Exception e) { log.error("Response form 'formdefinitions' exception : " + e.getMessage()); } return response; }
public void testMNT11660() throws Exception { FormUIGet formUIGet = (FormUIGetExtend) ctx.getBean("webscript.org.alfresco.test.components.form.form.get"); assertNotNull("'FormUIGetExtend' bean for test is null.", formUIGet); ConfigSource configSource = new ClassPathConfigSource("test-config-custom-forms.xml"); XMLConfigService svc = new XMLConfigService(configSource); svc.initConfig(); formUIGet.setConfigService(svc); GetRequest requestWithAspect = new GetRequest( "/test/components/form?htmlid=template_default-formContainer&itemKind=node&itemId=" + folderWithAspect.toString() + "&formId=null&mode=view"); Response rspFormWithAspect = server.submitRequest( requestWithAspect.getMethod(), requestWithAspect.getFullUri(), requestWithAspect.getHeaders(), requestWithAspect.getBody(), requestWithAspect.getEncoding(), requestWithAspect.getType()); assertEquals( "The status of response is " + rspFormWithAspect.getStatus(), 200, rspFormWithAspect.getStatus()); String contentWithAspect = rspFormWithAspect.getContentAsString(); log.info( "Response form for node with dublincore aspect status is " + rspFormWithAspect.getStatus() + " content is " + contentWithAspect); assertNotNull("Response content for 'contentWithAspect' is null", contentWithAspect); assertTrue( "Return the following content: " + contentWithAspect, contentWithAspect.contains("My Set")); GetRequest requestWithoutAspect = new GetRequest( "/test/components/form?htmlid=template_default-formContainer&itemKind=node&itemId=" + folderWithoutAspect.toString() + "&formId=null&mode=view"); Response rspFormWithoutAspect = server.submitRequest( requestWithoutAspect.getMethod(), requestWithoutAspect.getFullUri(), requestWithoutAspect.getHeaders(), requestWithoutAspect.getBody(), requestWithoutAspect.getEncoding(), requestWithoutAspect.getType()); assertEquals( "The status of response is " + rspFormWithoutAspect.getStatus(), 200, rspFormWithoutAspect.getStatus()); String contentWithoutAspect = rspFormWithoutAspect.getContentAsString(); log.info( "Response form for node without aspect status is " + rspFormWithoutAspect.getStatus() + " content is " + contentWithoutAspect); assertNotNull("Response content for 'contentWithoutAspect' is null", contentWithoutAspect); assertFalse( "Return the following content: " + contentWithoutAspect, contentWithoutAspect.contains("My Set")); }