Search in sources :

Example 6 with Farmer

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

the class SerializeTests method testIncludeSource.

@Test
public void testIncludeSource() throws IOException {
    ExecutionResult exec1 = new ExecutionResult(new Farmer("180"), null);
    ExecutionResult exec2 = new ExecutionResult(new Farmer("456"), null);
    CollectionWithPagingInfo<ExecutionResult> coll = CollectionWithPagingInfo.asPaged(null, Arrays.asList(exec1, exec2));
    Object resultCollection = helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, "sheep", ParamsExtender.valueOf(true, "1"), coll);
    assertNotNull(resultCollection);
    String out = writeResponse(resultCollection);
    assertTrue("There must 'source' json output", StringUtils.contains(out, "\"source\":{\"name\":\"Dolly\",\"age\":3,\"sheepGuid\":\"1\"}"));
    resultCollection = helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, "sheep", ParamsExtender.valueOf(false, "1"), coll);
    assertNotNull(resultCollection);
    out = writeResponse(resultCollection);
    assertFalse("There must not 'source' json output", StringUtils.contains(out, "\"source\":{\"name\":\"Dolly\",\"age\":3,\"sheepGuid\":\"1\"}"));
    coll = CollectionWithPagingInfo.asPaged(null, Arrays.asList(exec1, exec2), false, 2, new Sheep("barbie"));
    resultCollection = helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, "sheep", ParamsExtender.valueOf(true, "1"), coll);
    assertNotNull(resultCollection);
    out = writeResponse(resultCollection);
    assertTrue("There must 'source' json output", StringUtils.contains(out, "\"source\":{\"name\":\"Dolly\",\"age\":3,\"sheepGuid\":\"barbie\""));
}
Also used : WebScriptResponse(org.springframework.extensions.webscripts.WebScriptResponse) Sheep(org.alfresco.rest.framework.tests.api.mocks.Sheep) ExecutionResult(org.alfresco.rest.framework.jacksonextensions.ExecutionResult) JSONObject(org.json.JSONObject) Farmer(org.alfresco.rest.framework.tests.api.mocks.Farmer) Test(org.junit.Test)

Example 7 with Farmer

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

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

the class SearchQuerySerializerTests method testSerializeContext.

@Test
public void testSerializeContext() throws IOException {
    ExecutionResult exec1 = new ExecutionResult(new Farmer("180"), null);
    FacetFieldContext ffc = new FacetFieldContext("theLabel", Arrays.asList(new Bucket("b1", "name:b1", 23, "displayText1"), new Bucket("b2", null, 34, "displayText2")));
    SearchContext searchContext = new SearchContext(23l, null, Arrays.asList(new FacetQueryContext("f1", "creator:bob", 15), new FacetQueryContext("f2", null, 20)), Arrays.asList(ffc), new SpellCheckContext("aFlag", Arrays.asList("bish", "bash")), null);
    CollectionWithPagingInfo<ExecutionResult> coll = CollectionWithPagingInfo.asPaged(null, Arrays.asList(exec1), false, 2, null, searchContext);
    String out = helper.writeResponse(coll);
    assertTrue("There must 'context' json output", out.contains("\"context\":{\"consistency\":{\"lastTxId\":23}"));
    assertTrue("There must 'facetQueries' json output", out.contains("\"facetQueries\":"));
    assertTrue("There must 'facetQueries f1' json output", out.contains("{\"label\":\"f1\",\"filterQuery\":\"creator:bob\",\"count\":15}"));
    assertTrue("There must 'facetQueries f2' json output", out.contains("{\"label\":\"f2\",\"count\":20}"));
    assertTrue("There must 'spellCheck' json output", out.contains("\"spellCheck\":{\"type\":\"aFlag\",\"suggestions\":[\"bish\",\"bash\"]}"));
    assertTrue("There must 'facetsFields' json output", out.contains("\"facetsFields\":[{\"label\":\"theLabel\",\"buckets\""));
    assertTrue("There must 'bucket1' json output", out.contains("{\"label\":\"b1\",\"filterQuery\":\"name:b1\",\"count\":23,\"display\":\"displayText1\"}"));
    assertTrue("There must 'bucket2' json output", out.contains("{\"label\":\"b2\",\"count\":34,\"display\":\"displayText2\"}"));
    searchContext = new SearchContext(-1, null, null, null, null, null);
    coll = CollectionWithPagingInfo.asPaged(null, Arrays.asList(exec1), false, 2, null, searchContext);
    out = helper.writeResponse(coll);
    assertTrue("There must NOT BE a 'context' json output", out.contains("\"context\":{}"));
    assertFalse("There must NOT BE a 'facetsFields' json output", out.contains("\"facetsFields\":{}"));
}
Also used : FacetFieldContext(org.alfresco.rest.api.search.context.FacetFieldContext) FacetQueryContext(org.alfresco.rest.api.search.context.FacetQueryContext) Bucket(org.alfresco.rest.api.search.context.FacetFieldContext.Bucket) SearchContext(org.alfresco.rest.api.search.context.SearchContext) ExecutionResult(org.alfresco.rest.framework.jacksonextensions.ExecutionResult) Farmer(org.alfresco.rest.framework.tests.api.mocks.Farmer) SpellCheckContext(org.alfresco.rest.api.search.context.SpellCheckContext) Test(org.junit.Test)

Example 9 with Farmer

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

the class JsonJacksonTests method testDeserializeFarmersAsList.

@Test
public void testDeserializeFarmersAsList() throws IOException {
    List<Farmer> aFarmer = jsonHelper.constructList(new StringReader(COLLECTION_START + FARMER_JSON + COLLECTION_END), Farmer.class);
    assertTrue(Collection.class.isAssignableFrom(aFarmer.getClass()));
    assertEquals(1, aFarmer.size());
    aFarmer = jsonHelper.constructList(new StringReader(FARMERS_COLLECTION_JSON), Farmer.class);
    assertTrue(Collection.class.isAssignableFrom(aFarmer.getClass()));
    assertEquals(3, aFarmer.size());
    aFarmer = jsonHelper.constructList(new StringReader(FARMER_JSON), Farmer.class);
    assertTrue(Collection.class.isAssignableFrom(aFarmer.getClass()));
    assertEquals(1, aFarmer.size());
    try {
        aFarmer = jsonHelper.constructList(new StringReader(""), Farmer.class);
        fail("Should not get here.");
    } catch (InvalidArgumentException iae) {
        // Must throw this exception
        assertNotNull(iae);
    }
    try {
        aFarmer = jsonHelper.constructList(new StringReader("rubbish"), Farmer.class);
        fail("Should not get here.");
    } catch (InvalidArgumentException iae) {
        // Must throw this exception
        assertNotNull(iae);
    }
    try {
        aFarmer = jsonHelper.constructList(new StringReader("[]"), Farmer.class);
        fail("Should not get here.");
    } catch (InvalidArgumentException iae) {
        // Must throw this exception
        assertNotNull(iae);
    }
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) StringReader(java.io.StringReader) Collection(java.util.Collection) Farmer(org.alfresco.rest.framework.tests.api.mocks.Farmer) Test(org.junit.Test)

Example 10 with Farmer

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

the class JsonJacksonTests method testDeserializeFarmer.

@Test
public void testDeserializeFarmer() throws IOException {
    Farmer aFarmer = jsonHelper.construct(new StringReader(FARMER_JSON), Farmer.class);
    assertEquals(Farmer.class, aFarmer.getClass());
    assertEquals("Giles", aFarmer.getName());
    assertEquals(54, aFarmer.getAge());
    assertEquals(Farmer.size.LARGE, aFarmer.getFarm());
    try {
        aFarmer = jsonHelper.construct(new StringReader(""), Farmer.class);
        fail("Should not get here.");
    } catch (InvalidArgumentException iae) {
        // Must throw this exception
        assertNotNull(iae);
    }
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) StringReader(java.io.StringReader) Farmer(org.alfresco.rest.framework.tests.api.mocks.Farmer) Test(org.junit.Test)

Aggregations

Farmer (org.alfresco.rest.framework.tests.api.mocks.Farmer)12 Test (org.junit.Test)12 StringReader (java.io.StringReader)5 ExecutionResult (org.alfresco.rest.framework.jacksonextensions.ExecutionResult)5 JSONObject (org.json.JSONObject)5 HashMap (java.util.HashMap)4 Params (org.alfresco.rest.framework.resource.parameters.Params)3 Sheep (org.alfresco.rest.framework.tests.api.mocks.Sheep)3 Content (org.springframework.extensions.surf.util.Content)3 Match (org.springframework.extensions.webscripts.Match)3 WebScriptRequest (org.springframework.extensions.webscripts.WebScriptRequest)3 WebScriptResponse (org.springframework.extensions.webscripts.WebScriptResponse)3 List (java.util.List)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 UnsupportedResourceOperationException (org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException)2 Grass (org.alfresco.rest.framework.tests.api.mocks.Grass)2 ResourceWebScriptPost (org.alfresco.rest.framework.webscripts.ResourceWebScriptPost)2 Method (java.lang.reflect.Method)1 Collection (java.util.Collection)1 FacetFieldContext (org.alfresco.rest.api.search.context.FacetFieldContext)1