use of org.alfresco.rest.framework.webscripts.WithResponse in project alfresco-remote-api by Alfresco.
the class WithResponseTest method testSetHeader.
@Test
public void testSetHeader() throws Exception {
WithResponse callBack = new WithResponse(Status.STATUS_OK, ResponseWriter.DEFAULT_JSON_CONTENT, ResponseWriter.CACHE_NEVER);
callBack.setHeader("king", "can");
callBack.setHeader("king", "kong");
assertTrue(callBack.getHeaders().size() == 1);
List<String> vals = callBack.getHeaders().get("king");
assertTrue(vals.size() == 1);
assertEquals("kong", vals.get(0));
}
use of org.alfresco.rest.framework.webscripts.WithResponse in project alfresco-remote-api by Alfresco.
the class WithResponseTest method testAddHeader.
@Test
public void testAddHeader() throws Exception {
WithResponse callBack = new WithResponse(Status.STATUS_OK, ResponseWriter.DEFAULT_JSON_CONTENT, ResponseWriter.CACHE_NEVER);
callBack.addHeader("king", "can");
callBack.addHeader("king", "kong");
assertTrue(callBack.getHeaders().size() == 1);
List<String> vals = callBack.getHeaders().get("king");
assertTrue(vals.size() == 2);
assertEquals(vals, Arrays.asList("can", "kong"));
}
use of org.alfresco.rest.framework.webscripts.WithResponse in project alfresco-remote-api by Alfresco.
the class InspectorTests method testInspectOperations.
@Test
public void testInspectOperations() throws IllegalAccessException, InstantiationException, Throwable {
Api api = Api.valueOf("alfrescomock", "private", "1");
List<ResourceMetadata> metainfo = new ArrayList<ResourceMetadata>();
GrassEntityResource grassEntityResource = new GrassEntityResource();
ResourceInspector.inspectOperations(api, GrassEntityResource.class, "-root-", metainfo);
assertEquals(3, metainfo.size());
for (ResourceMetadata resourceMetadata : metainfo) {
assertEquals(ResourceMetadata.RESOURCE_TYPE.OPERATION, resourceMetadata.getType());
OperationResourceMetaData operationResourceMetaData = (OperationResourceMetaData) resourceMetadata;
Method actionMethod = operationResourceMetaData.getOperationMethod();
String result = null;
final WithResponse wr = new WithResponse(Status.STATUS_OK, ResponseWriter.DEFAULT_JSON_CONTENT, ResponseWriter.CACHE_NEVER);
switch(resourceMetadata.getUniqueId()) {
case "/-root-/{id}/grow":
assertNotNull("GrassEntityResource supports POST", resourceMetadata.getOperation(HttpMethod.POST));
assertNull("GrassEntityResource does not support DELETE", resourceMetadata.getOperation(HttpMethod.DELETE));
ResourceOperation op = resourceMetadata.getOperation(HttpMethod.POST);
assertEquals("grow should return ACCEPTED", Status.STATUS_ACCEPTED, op.getSuccessStatus());
Class paramType = resourceMetadata.getObjectType(op);
Object paramObj = paramType.newInstance();
result = (String) ResourceInspectorUtil.invokeMethod(actionMethod, grassEntityResource, "xyz", paramObj, Params.valueOf("notUsed", null, mock(WebScriptRequest.class)), wr);
assertEquals("Growing well", result);
assertFalse(operationResourceMetaData.isNoAuth(null));
break;
case "/-root-/{id}/cut":
assertNotNull("GrassEntityResource supports POST", resourceMetadata.getOperation(HttpMethod.POST));
assertNull("GrassEntityResource does not support GET", resourceMetadata.getOperation(HttpMethod.GET));
op = resourceMetadata.getOperation(HttpMethod.POST);
assertNull(resourceMetadata.getObjectType(op));
assertEquals("cut should return ACCEPTED", Status.STATUS_NOT_IMPLEMENTED, op.getSuccessStatus());
result = (String) ResourceInspectorUtil.invokeMethod(actionMethod, grassEntityResource, "xyz", null, Params.valueOf("notUsed", null, mock(WebScriptRequest.class)), wr);
assertEquals("All done", result);
assertFalse(operationResourceMetaData.isNoAuth(null));
break;
case "/-root-/{id}/cut-noAuth":
assertNotNull("GrassEntityResource supports POST", resourceMetadata.getOperation(HttpMethod.POST));
op = resourceMetadata.getOperation(HttpMethod.POST);
assertNull(resourceMetadata.getObjectType(op));
assertEquals("cut should return ACCEPTED", Status.STATUS_NOT_IMPLEMENTED, op.getSuccessStatus());
result = (String) ResourceInspectorUtil.invokeMethod(actionMethod, grassEntityResource, "xyz", null, Params.valueOf("notUsed", null, mock(WebScriptRequest.class)), wr);
assertEquals("All done without Auth", result);
assertTrue(operationResourceMetaData.isNoAuth(null));
break;
default:
fail("Invalid action information.");
}
}
}
use of org.alfresco.rest.framework.webscripts.WithResponse in project alfresco-remote-api by Alfresco.
the class WithResponseTest method testDefaults.
@Test
public void testDefaults() throws Exception {
WithResponse callBack = new WithResponse(Status.STATUS_OK, ResponseWriter.DEFAULT_JSON_CONTENT, ResponseWriter.CACHE_NEVER);
assertEquals(Status.STATUS_OK, callBack.getStatus());
assertEquals(ResponseWriter.DEFAULT_JSON_CONTENT, callBack.getContentInfo());
assertEquals(ResponseWriter.CACHE_NEVER, callBack.getCache());
assertTrue(callBack.getHeaders().isEmpty());
}
use of org.alfresco.rest.framework.webscripts.WithResponse in project alfresco-remote-api by Alfresco.
the class WithResponseTest method testSetters.
@Test
public void testSetters() throws Exception {
WithResponse callBack = new WithResponse(Status.STATUS_OK, ResponseWriter.DEFAULT_JSON_CONTENT, ResponseWriter.CACHE_NEVER);
callBack.setStatus(Status.STATUS_GONE);
Cache myCache = new Cache(new Description.RequiredCache() {
@Override
public boolean getNeverCache() {
return false;
}
@Override
public boolean getIsPublic() {
return true;
}
@Override
public boolean getMustRevalidate() {
return true;
}
});
callBack.setCache(myCache);
ContentInfo myContent = new ContentInfoImpl(Format.HTML.mimetype(), "UTF-16", 12, Locale.FRENCH);
callBack.setContentInfo(myContent);
assertEquals(Status.STATUS_GONE, callBack.getStatus());
assertEquals(myCache, callBack.getCache());
assertEquals(myContent, callBack.getContentInfo());
}
Aggregations