use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.
the class SearchMapperTests method fromTimezone.
@Test
public void fromTimezone() throws Exception {
SearchParameters searchParameters = new SearchParameters();
// Doesn't error
searchMapper.fromLocalization(searchParameters, null);
searchMapper.fromLocalization(searchParameters, new Localization("", null));
try {
searchMapper.fromLocalization(searchParameters, new Localization("nonsense", null));
fail();
} catch (IllegalArgumentException iae) {
assertTrue(iae.getLocalizedMessage().contains("Invalid timezone"));
}
try {
searchMapper.fromLocalization(searchParameters, new Localization("GMT+25", null));
fail();
} catch (IllegalArgumentException iae) {
assertTrue(iae.getLocalizedMessage().contains("Invalid timezone"));
}
searchMapper.fromLocalization(searchParameters, new Localization("America/New_York", null));
assertEquals("America/New_York", searchParameters.getTimezone());
searchMapper.fromLocalization(searchParameters, new Localization("America/Denver", null));
assertEquals("America/Denver", searchParameters.getTimezone());
searchMapper.fromLocalization(searchParameters, new Localization("America/Los_Angeles", null));
assertEquals("America/Los_Angeles", searchParameters.getTimezone());
searchMapper.fromLocalization(searchParameters, new Localization("Europe/Madrid", null));
assertEquals("Europe/Madrid", searchParameters.getTimezone());
searchMapper.fromLocalization(searchParameters, new Localization("GMT+1", null));
assertEquals("GMT+01:00", searchParameters.getTimezone());
searchMapper.fromLocalization(searchParameters, new Localization("GMT+01:00", null));
assertEquals("GMT+01:00", searchParameters.getTimezone());
searchMapper.fromLocalization(searchParameters, new Localization("GMT-9", null));
assertEquals("GMT-09:00", searchParameters.getTimezone());
searchMapper.fromLocalization(searchParameters, new Localization("GMT+08:00", null));
assertEquals("GMT+08:00", searchParameters.getTimezone());
searchMapper.fromLocalization(searchParameters, new Localization("GMT-12:00", null));
assertEquals("GMT-12:00", searchParameters.getTimezone());
try {
searchMapper.fromLocalization(searchParameters, new Localization("UTC+5", null));
fail();
} catch (IllegalArgumentException iae) {
assertTrue("UTC is not support by java.util.timezone", iae.getLocalizedMessage().contains("Incompatible timezoneId"));
}
try {
searchMapper.fromLocalization(searchParameters, new Localization("UTC+06:00", null));
fail();
} catch (IllegalArgumentException iae) {
assertTrue(iae.getLocalizedMessage().contains("Incompatible timezoneId"));
}
}
use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.
the class SearchMapperTests method fromFilterQuery.
@Test
public void fromFilterQuery() throws Exception {
SearchParameters searchParameters = new SearchParameters();
// Doesn't error
searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("hedgehog", null, null), new FilterQuery("king", null, null)));
assertEquals(2, searchParameters.getFilterQueries().size());
assertEquals("hedgehog", searchParameters.getFilterQueries().get(0));
assertEquals("king", searchParameters.getFilterQueries().get(1));
searchParameters = new SearchParameters();
searchParameters.setLanguage(SearchService.LANGUAGE_CMIS_ALFRESCO);
try {
searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("hedgehog", null, null)));
fail();
} catch (InvalidArgumentException iae) {
// You can't specify FilterQuery when using the CMIS language
assertNotNull(iae);
}
try {
searchParameters.setLanguage(SearchService.LANGUAGE_SOLR_ALFRESCO);
searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery(null, null, null)));
fail();
} catch (IllegalArgumentException iae) {
// You can't specify FilterQuery when using the CMIS language
assertNotNull(iae);
}
searchParameters = new SearchParameters();
searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("{!afts}description:xyz", Arrays.asList("desc1", "desc2"), null)));
assertEquals("{!afts tag=desc1,desc2 }description:xyz", searchParameters.getFilterQueries().get(0));
searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("{!afts}description:xyz", Arrays.asList("desc1"), null)));
assertEquals("{!afts tag=desc1 }description:xyz", searchParameters.getFilterQueries().get(1));
searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("description:xyz", Arrays.asList("desc1"), null)));
assertEquals("{!afts tag=desc1 }description:xyz", searchParameters.getFilterQueries().get(2));
searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("{!afts} description:xyz", Arrays.asList("desc1"), null)));
assertEquals("{!afts tag=desc1 } description:xyz", searchParameters.getFilterQueries().get(3));
searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery(" {!afts cake} description:xyz", Arrays.asList("desc1"), null)));
assertEquals("{!afts tag=desc1 cake} description:xyz", searchParameters.getFilterQueries().get(4));
searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("{!afts tag=desc1}description:xyz", Arrays.asList("desc1"), null)));
assertEquals("{!afts tag=desc1}description:xyz", searchParameters.getFilterQueries().get(5));
searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("created:2011", Arrays.asList("desc1"), null)));
assertEquals("{!afts tag=desc1 }created:2011", searchParameters.getFilterQueries().get(6));
searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("=cm:name:cabbage", Arrays.asList("desc1"), null)));
assertEquals("{!afts tag=desc1 }=cm:name:cabbage", searchParameters.getFilterQueries().get(7));
searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("{http://www.alfresco.org/model/content/1.0}title:workflow", null, null)));
assertEquals("{http://www.alfresco.org/model/content/1.0}title:workflow", searchParameters.getFilterQueries().get(8));
searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("{http://www.alfresco.org/model/content/1.0}title:workflow", Arrays.asList("desc1"), null)));
assertEquals("{!afts tag=desc1 }{http://www.alfresco.org/model/content/1.0}title:workflow", searchParameters.getFilterQueries().get(9));
searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("{!afts} description:xyz", Arrays.asList("desc1", "desc2"), null)));
assertEquals("{!afts tag=desc1,desc2 }description:xyz", searchParameters.getFilterQueries().get(0));
searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("{ !afts } description:xyz", Arrays.asList("desc1", "desc2"), null)));
assertEquals("{!afts tag=desc1,desc2 }description:xyz", searchParameters.getFilterQueries().get(0));
searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery(null, Arrays.asList("desc1"), Arrays.asList("cm:name:cabbage", "cm:creator:bob"))));
assertEquals("{!afts tag=desc1 }cm:name:cabbage OR cm:creator:bob", searchParameters.getFilterQueries().get(12));
searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery(null, null, Arrays.asList("cm:name:cabbage", "cm:creator:bob"))));
assertEquals("cm:name:cabbage OR cm:creator:bob", searchParameters.getFilterQueries().get(13));
searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery(null, null, Arrays.asList("cm:name:cabbage"))));
assertEquals("cm:name:cabbage", searchParameters.getFilterQueries().get(14));
searchMapper.fromFilterQuery(searchParameters, Arrays.asList(new FilterQuery("created:2011", null, Arrays.asList("cm:name:cabbage"))));
assertEquals("Single query should take precident over multiple queries ORed together.", "created:2011", searchParameters.getFilterQueries().get(15));
}
use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.
the class SearchMapperTests method fromHighlight.
@Test
public void fromHighlight() throws Exception {
SearchParameters searchParameters = new SearchParameters();
List<FieldHighlightParameters> fields = Arrays.asList(new FieldHighlightParameters("desc", 50, 100, false, "@", "#"), new FieldHighlightParameters("title", 55, 105, true, "*", "¿"));
GeneralHighlightParameters highlightParameters = new GeneralHighlightParameters(5, 10, false, "{", "}", 20, true, fields);
searchMapper.fromHighlight(searchParameters, highlightParameters);
assertEquals(searchParameters.getHighlight(), highlightParameters);
}
use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.
the class SearchMapperTests method fromFacetQuery.
@Test
public void fromFacetQuery() throws Exception {
SearchParameters searchParameters = new SearchParameters();
// Doesn't error
searchMapper.fromFacetQuery(searchParameters, null);
searchMapper.fromFacetQuery(searchParameters, Arrays.asList(new FacetQuery("ping", null, null), new FacetQuery("pong", "table", null)));
assertEquals(2, searchParameters.getFacetQueries().size());
assertEquals("{!afts key='ping'}ping", searchParameters.getFacetQueries().get(0));
assertEquals("{!afts key='table'}pong", searchParameters.getFacetQueries().get(1));
try {
searchMapper.fromFacetQuery(searchParameters, Arrays.asList(new FacetQuery("ping", null, null), new FacetQuery("{!afts}pang", "tennis", null)));
fail();
} catch (InvalidArgumentException iae) {
// Cannot start with afts
assertNotNull(iae);
}
}
use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.
the class SearchMapperTests method testMandatory.
@Test(expected = IllegalArgumentException.class)
public void testMandatory() throws Exception {
SearchRequestContext searchRequest = SearchRequestContext.from(SearchQuery.EMPTY);
SearchParameters searchParameters = searchMapper.toSearchParameters(ResultMapperTests.EMPTY_PARAMS, SearchQuery.EMPTY, searchRequest);
}
Aggregations