From eb78ee21a1cb7c45657a30f2b8285ed18386e2ff Mon Sep 17 00:00:00 2001 From: Ancuta Morarasu Date: Wed, 11 May 2016 11:56:38 +0000 Subject: [PATCH] Merged HEAD (5.2) to 5.2.N (5.2.1) 126517 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 122952 gjames: RA-211: test for custom caching git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126861 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../tests/api/mocks/CowEntityResource.java | 24 +++++++++++++++++++ .../framework/tests/core/ExecutionTests.java | 12 ++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/source/test-java/org/alfresco/rest/framework/tests/api/mocks/CowEntityResource.java b/source/test-java/org/alfresco/rest/framework/tests/api/mocks/CowEntityResource.java index 634f7b1a9c..d3065679dc 100644 --- a/source/test-java/org/alfresco/rest/framework/tests/api/mocks/CowEntityResource.java +++ b/source/test-java/org/alfresco/rest/framework/tests/api/mocks/CowEntityResource.java @@ -1,6 +1,7 @@ package org.alfresco.rest.framework.tests.api.mocks; import org.alfresco.rest.framework.BinaryProperties; +import org.alfresco.rest.framework.WebApiParam; import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; import org.alfresco.rest.framework.resource.EntityResource; import org.alfresco.rest.framework.resource.actions.interfaces.BinaryResourceAction; @@ -10,6 +11,8 @@ import org.alfresco.rest.framework.resource.content.BinaryResource; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.Parameters; import org.alfresco.rest.framework.webscripts.WithResponse; +import org.springframework.extensions.webscripts.Cache; +import org.springframework.extensions.webscripts.Description; import org.springframework.extensions.webscripts.Status; import java.io.InputStream; @@ -26,10 +29,31 @@ public class CowEntityResource implements EntityResourceAction.ReadByIdWithRespo BinaryResourceAction.DeleteWithResponse, BinaryResourceAction.UpdateWithResponse { + public final static Cache CACHE_COW = new Cache(new Description.RequiredCache() + { + @Override + public boolean getNeverCache() + { + return false; + } + + @Override + public boolean getIsPublic() + { + return true; + } + + @Override + public boolean getMustRevalidate() + { + return false; + } + }); @Override public Goat readById(String id, Parameters parameters, WithResponse withResponse) { + withResponse.setCache(CACHE_COW); return new Goat("Goat"+id); } diff --git a/source/test-java/org/alfresco/rest/framework/tests/core/ExecutionTests.java b/source/test-java/org/alfresco/rest/framework/tests/core/ExecutionTests.java index bbaac349d3..17d5b60427 100644 --- a/source/test-java/org/alfresco/rest/framework/tests/core/ExecutionTests.java +++ b/source/test-java/org/alfresco/rest/framework/tests/core/ExecutionTests.java @@ -3,6 +3,7 @@ package org.alfresco.rest.framework.tests.core; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -17,15 +18,18 @@ import org.alfresco.rest.framework.resource.actions.ActionExecutor; import org.alfresco.rest.framework.resource.content.ContentInfo; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.Params; +import org.alfresco.rest.framework.tests.api.mocks.CowEntityResource; import org.alfresco.rest.framework.tests.api.mocks.Goat; import org.alfresco.rest.framework.tests.api.mocks.Grass; import org.alfresco.rest.framework.tests.api.mocks.Sheep; import org.alfresco.rest.framework.tests.api.mocks3.FlockEntityResource; import org.alfresco.rest.framework.webscripts.AbstractResourceWebScript; +import org.alfresco.rest.framework.webscripts.ApiWebScript; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; +import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.WebScriptRequest; import org.springframework.extensions.webscripts.WebScriptResponse; @@ -54,12 +58,16 @@ public class ExecutionTests extends AbstractContextTest Object result = executor.execute(entityResource, Params.valueOf((String)null, null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), true); assertNotNull(result); + WebScriptResponse response = mock(WebScriptResponse.class); entityResource = locator.locateEntityResource(api,"cow", HttpMethod.GET); - result = executor.execute(entityResource, Params.valueOf((String)null, null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), true); + result = executor.execute(entityResource, Params.valueOf((String)null, null, mock(WebScriptRequest.class)), response, true); assertNotNull(result); + verify(response, times(1)).setCache((Cache) ApiWebScript.CACHE_NEVER); - result = executor.execute(entityResource, Params.valueOf("543", null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), true); + response = mock(WebScriptResponse.class); + result = executor.execute(entityResource, Params.valueOf("543", null, mock(WebScriptRequest.class)), response, true); assertNotNull(result); + verify(response, times(1)).setCache((Cache) CowEntityResource.CACHE_COW); ResourceWithMetadata baa = locator.locateRelationResource(api,"sheep", "baaahh", HttpMethod.GET); result = executor.execute(baa, Params.valueOf("4", null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), true);