Search in sources :

Example 1 with Grass

use of org.alfresco.rest.framework.tests.api.mocks.Grass 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 Grass

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

the class InspectorTests method testUniqueIdAnnotation.

@Test
public void testUniqueIdAnnotation() {
    String uniqueId = ResourceInspector.findUniqueId(new Grass("34"));
    assertNull(uniqueId);
    uniqueId = ResourceInspector.findUniqueId(new Farmer("345"));
    assertNotNull(uniqueId);
    assertTrue("345".equals(uniqueId));
    // inherited classes are ok (with overidden unique id method)
    uniqueId = ResourceInspector.findUniqueId(new FarmersSon("567"));
    assertNotNull(uniqueId);
    assertTrue("567".equals(uniqueId));
    // inherited classes are ok (with overidden unique id method but @UniqueId annotation not specified)
    uniqueId = ResourceInspector.findUniqueId(new FarmersGrandson("12"));
    assertNotNull(uniqueId);
    assertTrue("12".equals(uniqueId));
    // More than 1 annotation should throw IllegalArgumentException
    try {
        uniqueId = ResourceInspector.findUniqueId(new FarmersDaughter("21"));
        fail("Should throw an InvalidArgumentException");
    } catch (IllegalArgumentException error) {
    // this is correct
    }
}
Also used : FarmersSon(org.alfresco.rest.framework.tests.api.mocks2.FarmersSon) FarmersGrandson(org.alfresco.rest.framework.tests.api.mocks2.FarmersGrandson) FarmersDaughter(org.alfresco.rest.framework.tests.api.mocks2.FarmersDaughter) Grass(org.alfresco.rest.framework.tests.api.mocks.Grass) Farmer(org.alfresco.rest.framework.tests.api.mocks.Farmer) Test(org.junit.Test)

Example 3 with Grass

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

the class ExecutionTests method testInvokePost.

@Test
public void testInvokePost() throws IOException {
    AbstractResourceWebScript executor = getExecutor("executorOfPost");
    ResourceWithMetadata resource = locator.locateRelationResource(api, "sheep", "blacksheep", HttpMethod.POST);
    final Sheep aSheep = new Sheep("xyz");
    Object result = executor.execute(resource, Params.valueOf("654", null, NULL_PARAMS, Arrays.asList(aSheep), mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
    assertNotNull(result);
    assertEquals(aSheep, ((ExecutionResult) result).getRoot());
    ResourceWithMetadata grassResource = locator.locateEntityResource(api, "grass", HttpMethod.POST);
    final Grass grr = new Grass("grr");
    result = executor.execute(grassResource, Params.valueOf("654", null, NULL_PARAMS, Arrays.asList(grr), mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
    assertEquals(grr, ((ExecutionResult) result).getRoot());
    final Goat goat = new Goat("xyz");
    ResourceWithMetadata cowresource = locator.locateEntityResource(api, "cow", HttpMethod.POST);
    WebScriptResponse response = mock(WebScriptResponse.class);
    result = executor.execute(cowresource, Params.valueOf("654", null, NULL_PARAMS, Arrays.asList(goat), mock(WebScriptRequest.class)), response, false);
    assertEquals(goat, ((ExecutionResult) result).getRoot());
    verify(response, times(1)).setStatus(Status.STATUS_ACCEPTED);
    ResourceWithMetadata entityResource = locator.locateRelationResource(api, "grass", "grow", HttpMethod.POST);
    result = executor.execute(entityResource, Params.valueOf("654", null, NULL_PARAMS, grr, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
    assertEquals("Growing well", result);
    ResourceWithMetadata calfResource = locator.locateRelationResource(api, "cow", "calf", HttpMethod.POST);
    result = executor.execute(calfResource, Params.valueOf("654", null, NULL_PARAMS, Arrays.asList(goat), mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
    assertEquals(goat, ((ExecutionResult) result).getRoot());
    Map<String, String> templateVars = new HashMap();
    templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "sheep");
    templateVars.put(ResourceLocator.ENTITY_ID, "sheepId");
    templateVars.put(ResourceLocator.RELATIONSHIP_RESOURCE, "baaahh");
    templateVars.put(ResourceLocator.PROPERTY, "chew");
    ResourceWithMetadata collResource = locator.locateResource(api, templateVars, HttpMethod.POST);
    result = executor.execute(collResource, Params.valueOf("654", "345", NULL_PARAMS, null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
    assertEquals("All done", result);
}
Also used : WebScriptRequest(org.springframework.extensions.webscripts.WebScriptRequest) HashMap(java.util.HashMap) 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) Grass(org.alfresco.rest.framework.tests.api.mocks.Grass) Matchers.anyString(org.mockito.Matchers.anyString) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) Test(org.junit.Test)

Aggregations

Grass (org.alfresco.rest.framework.tests.api.mocks.Grass)3 Test (org.junit.Test)3 Farmer (org.alfresco.rest.framework.tests.api.mocks.Farmer)2 Goat (org.alfresco.rest.framework.tests.api.mocks.Goat)2 Sheep (org.alfresco.rest.framework.tests.api.mocks.Sheep)2 HashMap (java.util.HashMap)1 ResourceWithMetadata (org.alfresco.rest.framework.core.ResourceWithMetadata)1 ExecutionResult (org.alfresco.rest.framework.jacksonextensions.ExecutionResult)1 FarmersDaughter (org.alfresco.rest.framework.tests.api.mocks2.FarmersDaughter)1 FarmersGrandson (org.alfresco.rest.framework.tests.api.mocks2.FarmersGrandson)1 FarmersSon (org.alfresco.rest.framework.tests.api.mocks2.FarmersSon)1 SlimGoat (org.alfresco.rest.framework.tests.api.mocks3.SlimGoat)1 AbstractResourceWebScript (org.alfresco.rest.framework.webscripts.AbstractResourceWebScript)1 JSONObject (org.json.JSONObject)1 Matchers.anyString (org.mockito.Matchers.anyString)1 WebScriptRequest (org.springframework.extensions.webscripts.WebScriptRequest)1 WebScriptResponse (org.springframework.extensions.webscripts.WebScriptResponse)1