Discoverer { public String addOffering(Offering newOffering) { if (newOffering == null) return null; String offeringName = newOffering.getName(); if (offeringManager.getOffering(offeringName) != null) { offeringManager.removeOffering(offeringName); } offeringManager.addOffering(newOffering); this.offeringNodeTemplates.add(newOffering.getNodeTemplate()); totalCrawledOfferings++; return offeringName; } Discoverer(MongoClient mongoClient, ArrayList<String> activeCrawlers);  Discoverer(MongoClient mongoClient); synchronized void setRefreshing(boolean refreshing); synchronized boolean getRefreshing(); Offering fetchOffer(String cloudOfferingId); String addOffering(Offering newOffering); boolean removeOffering(String cloudOfferingId); Collection<String> getAllOfferingIds(); void generateSingleOffering(); void refreshRepository(); public int totalCrawledOfferings; public int crawledTimes; public Date lastCrawl; public OfferingManager offeringManager; }
@Test public void testAddOffering() { Fongo fongo = new Fongo("Mongo DB"); Discoverer d = new Discoverer(fongo.getMongo()); String ofId = "EC2"; d.addOffering(new Offering(ofId)); Offering of = d.fetchOffer(ofId); Assert.assertNotNull(of); Assert.assertEquals(of.getName(), ofId); }
@Test public void testFetch() throws IOException { Fongo fongo = new Fongo("Mongo DB"); Discoverer d = new Discoverer(fongo.getMongo()); ArrayList<String> offerings = new ArrayList<String>(); offerings.add("EC2"); offerings.add("Azure"); offerings.add("Openshift"); for (String name: offerings) { d.addOffering(new Offering(name)); } ArrayList<String> offeringIds = (new DiscovererAPI(d)).getOfferingIds(); Assert.assertEquals(offeringIds.size(), offerings.size()); for (String id: offeringIds) { Assert.assertTrue(offerings.contains(id)); } }
@Test public void testFetchIf() throws IOException { Fongo fongo = new Fongo("Mongo DB"); Discoverer d = new Discoverer(fongo.getMongo()); ArrayList<String> offeringNames = new ArrayList<String>(); offeringNames.add("EC2"); offeringNames.add("Azure"); offeringNames.add("Openshift"); for (String name: offeringNames) { d.addOffering(new Offering(name)); } Offering of = new Offering("Example"); of.addProperty("num_cpus", "8"); d.addOffering(of); ArrayList<DiscovererAPI.OfferingRepresentation> offerings = (new DiscovererAPI(d)).getOfferingsIf("{ \"num_cpus\": \"8\" }"); Assert.assertEquals(offerings.size(), 1); String fetchedOffering = offerings.get(0).getOffering(); Assert.assertEquals(fetchedOffering, of.toTosca()); }