use of org.eclipse.epp.internal.mpc.core.model.Market in project epp.mpc by eclipse.
the class DefaultMarketplaceServiceTest method testGetMarket.
@Test
@org.junit.experimental.categories.Category(RemoteTests.class)
public void testGetMarket() throws CoreException {
// Failing due to bug 302670: REST API market response inconsistency
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302670
List<Market> markets = marketplaceService.listMarkets(new NullProgressMonitor());
assertNotNull(markets);
assertFalse(markets.isEmpty());
final String marketName = "Tools";
Market market = null;
for (Market m : markets) {
if (marketName.equals(m.getName())) {
market = m;
}
}
assertNotNull("Expected market " + marketName, market);
Market result = marketplaceService.getMarket(market, new NullProgressMonitor());
assertEquals(market.getId(), result.getId());
assertEquals(market.getName(), result.getName());
assertEquals(market.getUrl(), result.getUrl());
}
use of org.eclipse.epp.internal.mpc.core.model.Market 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.model.Market in project epp.mpc by eclipse.
the class DefaultMarketplaceService method getCategory.
public Category getCategory(ICategory category, IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, 200);
if (category.getId() != null && category.getUrl() == null) {
List<Market> markets = listMarkets(progress.newChild(50));
ICategory resolvedCategory = null;
outer: for (Market market : markets) {
List<Category> categories = market.getCategory();
for (Category aCategory : categories) {
if (aCategory.equalsId(category)) {
resolvedCategory = aCategory;
break outer;
}
}
}
if (progress.isCanceled()) {
throw new OperationCanceledException();
} else if (resolvedCategory == null) {
throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_categoryNotFound, category.getId()));
} else {
return getCategory(resolvedCategory, progress.newChild(150));
}
}
Marketplace marketplace = processRequest(category.getUrl(), API_URI_SUFFIX, progress.newChild(200));
if (marketplace.getCategory().isEmpty()) {
throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_categoryNotFound, category.getUrl()));
} else if (marketplace.getCategory().size() > 1) {
throw new CoreException(createErrorStatus(Messages.DefaultMarketplaceService_unexpectedResponse, category.getUrl()));
}
Category resolvedCategory = marketplace.getCategory().get(0);
return resolvedCategory;
}
use of org.eclipse.epp.internal.mpc.core.model.Market in project epp.mpc by eclipse.
the class MarketContentHandler method startElement.
@Override
public void startElement(String uri, String localName, Attributes attributes) {
if (localName.equals("market")) {
// $NON-NLS-1$
model = new Market();
// $NON-NLS-1$
model.setId(attributes.getValue(NS_URI, "id"));
// $NON-NLS-1$
model.setName(attributes.getValue(NS_URI, "name"));
// $NON-NLS-1$
model.setUrl(toUrlString(attributes.getValue(NS_URI, "url")));
} else if (localName.equals("category")) {
// $NON-NLS-1$
org.eclipse.epp.internal.mpc.core.service.xml.CategoryContentHandler childHandler = new org.eclipse.epp.internal.mpc.core.service.xml.CategoryContentHandler();
childHandler.setParentModel(model);
childHandler.setParentHandler(this);
childHandler.setUnmarshaller(getUnmarshaller());
getUnmarshaller().setCurrentHandler(childHandler);
childHandler.startElement(uri, localName, attributes);
}
}
Aggregations