Search in sources :

Example 1 with Goat

use of org.alfresco.rest.framework.tests.api.mocks.Goat in project alfresco-remote-api by Alfresco.

the class SerializeTests method testExpandEmbedded.

@Test
public void testExpandEmbedded() throws IOException {
    assertNotNull(helper);
    Farmer aFarmer = new Farmer("180");
    aFarmer.setGoatId("1111");
    aFarmer.setSheepId("2222");
    ExecutionResult res = (ExecutionResult) helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, null, Params.valueOf("notUsed", null, null), aFarmer);
    assertNotNull(res);
    assertTrue(Farmer.class.equals(res.getRoot().getClass()));
    Map<String, Object> embeds = res.getEmbedded();
    assertNotNull(embeds);
    assertTrue(embeds.size() > 0);
    ExecutionResult goat = (ExecutionResult) embeds.get("goat");
    assertTrue(Goat.class.equals(goat.getRoot().getClass()));
    ExecutionResult grassEmbed = (ExecutionResult) goat.getEmbedded().get("grass");
    Grass grass = (Grass) grassEmbed.getRoot();
    assertNotNull(grass);
    assertTrue("Goat1111".equals(grass.getId()));
    ExecutionResult sheep = (ExecutionResult) embeds.get("sheep");
    assertTrue(Sheep.class.equals(sheep.getRoot().getClass()));
    Sheep aSheep = (Sheep) sheep.getRoot();
    assertTrue("2222".equals(aSheep.getId()));
    String out = writeResponse(res);
    assertTrue("There must be json output", StringUtils.isNotBlank(out));
}
Also used : Sheep(org.alfresco.rest.framework.tests.api.mocks.Sheep) ExecutionResult(org.alfresco.rest.framework.jacksonextensions.ExecutionResult) JSONObject(org.json.JSONObject) Goat(org.alfresco.rest.framework.tests.api.mocks.Goat) SlimGoat(org.alfresco.rest.framework.tests.api.mocks3.SlimGoat) Grass(org.alfresco.rest.framework.tests.api.mocks.Grass) Farmer(org.alfresco.rest.framework.tests.api.mocks.Farmer) Test(org.junit.Test)

Example 2 with Goat

use of org.alfresco.rest.framework.tests.api.mocks.Goat in project alfresco-remote-api by Alfresco.

the class SerializeTests method testSerializeList.

@Test
public void testSerializeList() throws IOException {
    assertNotNull(helper);
    Object res = helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, null, Params.valueOf("notUsed", null, null), Arrays.asList(new Goat(), new Sheep("ABCD"), new Sheep("XYZ")));
    String out = writeResponse(res);
    assertTrue("There must be json output", StringUtils.isNotBlank(out));
}
Also used : WebScriptResponse(org.springframework.extensions.webscripts.WebScriptResponse) Sheep(org.alfresco.rest.framework.tests.api.mocks.Sheep) JSONObject(org.json.JSONObject) Goat(org.alfresco.rest.framework.tests.api.mocks.Goat) SlimGoat(org.alfresco.rest.framework.tests.api.mocks3.SlimGoat) Test(org.junit.Test)

Example 3 with Goat

use of org.alfresco.rest.framework.tests.api.mocks.Goat in project alfresco-remote-api by Alfresco.

the class SerializeTests method testInvokeVersions.

@Test
public void testInvokeVersions() throws IOException {
    final Map<String, Object> respons = new HashMap<String, Object>();
    ResourceWithMetadata entityResource = locator.locateEntityResource(api, "goat", HttpMethod.GET);
    assertNotNull(entityResource);
    EntityResourceAction.ReadById<?> getter = (ReadById<?>) entityResource.getResource();
    Object readById = getter.readById("1234A3", NOT_USED);
    assertTrue("Version 1 must be a goat.", Goat.class.equals(readById.getClass()));
    String out = writeResponse(readById);
    assertNotNull(out);
    Api v3 = Api.valueOf(api.getName(), api.getScope().toString(), "3");
    entityResource = locator.locateEntityResource(v3, "goat", HttpMethod.GET);
    assertNotNull(entityResource);
    getter = (ReadById<?>) entityResource.getResource();
    Object readByIdForNewVersion = getter.readById("1234A3", NOT_USED);
    assertTrue("Version 3 must be a slim goat.", SlimGoat.class.equals(readByIdForNewVersion.getClass()));
    respons.put("v3Goat", readByIdForNewVersion);
    out = writeResponse(readByIdForNewVersion);
    entityResource = locator.locateEntityResource(api, "grass", HttpMethod.GET);
    // ok for version 1
    assertNotNull(entityResource);
    try {
        entityResource = locator.locateEntityResource(v3, "grass", HttpMethod.GET);
        fail("Should throw an UnsupportedResourceOperationException");
    } catch (UnsupportedResourceOperationException error) {
    // this is correct
    }
}
Also used : EntityResourceAction(org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction) ReadById(org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction.ReadById) HashMap(java.util.HashMap) UnsupportedResourceOperationException(org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException) SlimGoat(org.alfresco.rest.framework.tests.api.mocks3.SlimGoat) JSONObject(org.json.JSONObject) Goat(org.alfresco.rest.framework.tests.api.mocks.Goat) SlimGoat(org.alfresco.rest.framework.tests.api.mocks3.SlimGoat) Api(org.alfresco.rest.framework.Api) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) Test(org.junit.Test)

Example 4 with Goat

use of org.alfresco.rest.framework.tests.api.mocks.Goat in project alfresco-remote-api by Alfresco.

the class SerializeTests method testSerializeMap.

@Test
public void testSerializeMap() throws IOException {
    assertNotNull(helper);
    Map<String, Object> aMap = new HashMap<String, Object>();
    aMap.put("goatie", new Goat());
    aMap.put("sheepie", new Sheep("ABCD"));
    aMap.put("sheepy", new Sheep("XYZ"));
    Object res = helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, null, Params.valueOf("notUsed", null, null), aMap);
    String out = writeResponse(res);
    assertTrue("There must be json output", StringUtils.isNotBlank(out));
}
Also used : HashMap(java.util.HashMap) WebScriptResponse(org.springframework.extensions.webscripts.WebScriptResponse) Sheep(org.alfresco.rest.framework.tests.api.mocks.Sheep) JSONObject(org.json.JSONObject) Goat(org.alfresco.rest.framework.tests.api.mocks.Goat) SlimGoat(org.alfresco.rest.framework.tests.api.mocks3.SlimGoat) Test(org.junit.Test)

Example 5 with Goat

use of org.alfresco.rest.framework.tests.api.mocks.Goat in project alfresco-remote-api by Alfresco.

the class ExecutionTests method testInvokePut.

@Test
public void testInvokePut() throws IOException {
    ResourceWithMetadata entityResource = locator.locateEntityResource(api, "sheep", HttpMethod.PUT);
    AbstractResourceWebScript executor = getExecutor("executorOfPut");
    final Sheep aSheep = new Sheep("xyz");
    Object result = executor.execute(entityResource, Params.valueOf("654", null, NULL_PARAMS, aSheep, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
    assertNotNull(result);
    assertEquals(aSheep, ((ExecutionResult) result).getRoot());
    final Goat goat = new Goat("xyz");
    ResourceWithMetadata cowResource = locator.locateEntityResource(api, "cow", HttpMethod.PUT);
    result = executor.execute(cowResource, Params.valueOf("654", null, NULL_PARAMS, goat, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
    assertNotNull(result);
    assertEquals(goat, ((ExecutionResult) result).getRoot());
    ResourceWithMetadata resource = locator.locateRelationResource(api, "sheep", "blacksheep", HttpMethod.PUT);
    result = executor.execute(resource, Params.valueOf("654", null, NULL_PARAMS, aSheep, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
    assertNotNull(result);
    assertEquals(aSheep, ((ExecutionResult) result).getRoot());
    ResourceWithMetadata baaPhoto = locator.locateRelationResource(api, "sheep/{entityId}/baaahh", "photo", HttpMethod.PUT);
    result = executor.execute(baaPhoto, Params.valueOf("4", "56", mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
    assertNull(result);
    ResourceWithMetadata flockEntityResource = locator.locateRelationResource(api3, "flock", "photo", HttpMethod.PUT);
    result = executor.execute(flockEntityResource, Params.valueOf("654", null, NULL_PARAMS, goat, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
    assertNull(result);
    ResourceWithMetadata calf = locator.locateRelationResource(api, "cow", "calf", HttpMethod.PUT);
    result = executor.execute(calf, Params.valueOf("654", null, NULL_PARAMS, goat, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
    assertNotNull(result);
    assertEquals(goat, ((ExecutionResult) result).getRoot());
    cowResource = locator.locateRelationResource(api, "cow", "photo", HttpMethod.PUT);
    result = executor.execute(cowResource, Params.valueOf("654", null, NULL_PARAMS, goat, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
    assertNull(result);
    calf = locator.locateRelationResource(api, "cow/{entityId}/calf", "photo", HttpMethod.PUT);
    result = executor.execute(calf, Params.valueOf("4", "56", mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
    assertNull(result);
}
Also used : WebScriptRequest(org.springframework.extensions.webscripts.WebScriptRequest) AbstractResourceWebScript(org.alfresco.rest.framework.webscripts.AbstractResourceWebScript) WebScriptResponse(org.springframework.extensions.webscripts.WebScriptResponse) Sheep(org.alfresco.rest.framework.tests.api.mocks.Sheep) Goat(org.alfresco.rest.framework.tests.api.mocks.Goat) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) Test(org.junit.Test)

Aggregations

Goat (org.alfresco.rest.framework.tests.api.mocks.Goat)8 Test (org.junit.Test)8 Sheep (org.alfresco.rest.framework.tests.api.mocks.Sheep)7 SlimGoat (org.alfresco.rest.framework.tests.api.mocks3.SlimGoat)6 WebScriptResponse (org.springframework.extensions.webscripts.WebScriptResponse)6 JSONObject (org.json.JSONObject)5 HashMap (java.util.HashMap)3 ResourceWithMetadata (org.alfresco.rest.framework.core.ResourceWithMetadata)3 Grass (org.alfresco.rest.framework.tests.api.mocks.Grass)2 AbstractResourceWebScript (org.alfresco.rest.framework.webscripts.AbstractResourceWebScript)2 WebScriptRequest (org.springframework.extensions.webscripts.WebScriptRequest)2 HashSet (java.util.HashSet)1 Api (org.alfresco.rest.framework.Api)1 UnsupportedResourceOperationException (org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException)1 ExecutionResult (org.alfresco.rest.framework.jacksonextensions.ExecutionResult)1 EntityResourceAction (org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction)1 ReadById (org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction.ReadById)1 CollectionWithPagingInfo (org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo)1 Paging (org.alfresco.rest.framework.resource.parameters.Paging)1 Farmer (org.alfresco.rest.framework.tests.api.mocks.Farmer)1