use of org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService in project epp.mpc by eclipse.
the class DefaultMarketplaceServiceTest method computeRelativeSearchUrl.
/**
* bug 302825 - Make sure that search URLs have the following form:<br/>
* <code>http://marketplace.eclipse.org/api/p/search/apachesolr_search/WikiText?filters=tid:38%20tid:31</code>
* <p>
* bug 397004 - If both market and category are provided, make sure market is listed first
*/
@Test
public void computeRelativeSearchUrl() {
DefaultMarketplaceService service = new DefaultMarketplaceService();
String marketId = "31";
String categoryId = "38";
String query = "some query";
Market market = new Market();
market.setId(marketId);
Category category = new Category();
category.setId(categoryId);
String apiSearchPrefix = DefaultMarketplaceService.API_SEARCH_URI_FULL;
String searchUrl = service.computeRelativeSearchUrl(null, null, query, true);
assertEquals(apiSearchPrefix + "some+query", searchUrl);
searchUrl = service.computeRelativeSearchUrl(market, null, query, true);
assertEquals(apiSearchPrefix + "some+query?filters=tid:" + marketId, searchUrl);
searchUrl = service.computeRelativeSearchUrl(null, category, query, true);
assertEquals(apiSearchPrefix + "some+query?filters=tid:" + categoryId, searchUrl);
// bug 397004 - make sure market comes first for api
searchUrl = service.computeRelativeSearchUrl(market, category, query, true);
assertEquals(apiSearchPrefix + "some+query?filters=tid:" + marketId + "%20tid:" + categoryId, searchUrl);
// bug 397004 - make sure category comes first for browser
searchUrl = service.computeRelativeSearchUrl(market, category, query, false);
assertEquals(DefaultMarketplaceService.API_SEARCH_URI + "some+query?filters=tid:" + categoryId + "%20tid:" + marketId, searchUrl);
searchUrl = service.computeRelativeSearchUrl(market, null, null, true);
assertEquals(DefaultMarketplaceService.API_TAXONOMY_URI + marketId + "/" + RemoteMarketplaceService.API_URI_SUFFIX, searchUrl);
searchUrl = service.computeRelativeSearchUrl(null, category, null, false);
assertEquals(DefaultMarketplaceService.API_TAXONOMY_URI + categoryId, searchUrl);
// taxonomy uri is category-first for both API and browser
searchUrl = service.computeRelativeSearchUrl(market, category, null, true);
assertEquals(DefaultMarketplaceService.API_TAXONOMY_URI + categoryId + "," + marketId + "/" + RemoteMarketplaceService.API_URI_SUFFIX, searchUrl);
searchUrl = service.computeRelativeSearchUrl(market, category, null, false);
assertEquals(DefaultMarketplaceService.API_TAXONOMY_URI + categoryId + "," + marketId, searchUrl);
}
use of org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService in project epp.mpc by eclipse.
the class BrowseCatalogItem method getMarketplaceUrl.
private static String getMarketplaceUrl(CatalogDescriptor catalogDescriptor, MarketplaceViewer viewer) throws URISyntaxException {
URL url = catalogDescriptor.getUrl();
try {
ContentType contentType = viewer.getQueryContentType();
if (contentType == ContentType.SEARCH) {
String queryText = viewer.getQueryText();
ICategory queryCategory = viewer.getQueryCategory();
IMarket queryMarket = viewer.getQueryMarket();
String path = new DefaultMarketplaceService(url).computeRelativeSearchUrl(queryMarket, queryCategory, queryText, false);
if (path != null) {
url = new URL(url, path);
}
}
} catch (IllegalArgumentException e) {
// should never happen
MarketplaceClientUi.error(e);
} catch (MalformedURLException e) {
// should never happen
MarketplaceClientUi.error(e);
}
URI uri = url.toURI();
return uri.toString();
}
Aggregations