/* Install and start the blog eba */
URL urlToEba = getUrlToEba("org.apache.aries.samples.blog", "org.apache.aries.samples.blog.jpa.eba");
AriesApplicationManager manager = getOsgiService(AriesApplicationManager.class);
AriesApplication app = manager.createApplication(urlToEba);
AriesApplicationContext ctx = manager.install(app);
ctx.start();
/* Find and check all the blog sample bundles */
Bundle bapi = getInstalledBundle("org.apache.aries.samples.blog.api");
assertNotNull(bapi);
assertEquals(bapi.ACTIVE, bapi.getState());
Bundle bweb = getInstalledBundle("org.apache.aries.samples.blog.web");
assertNotNull(bweb);
assertEquals(bweb.ACTIVE, bweb.getState());
Bundle bbiz = getInstalledBundle("org.apache.aries.samples.blog.biz");
assertNotNull(bbiz);
assertEquals(bbiz.ACTIVE, bbiz.getState());
Bundle bper = getInstalledBundle("org.apache.aries.samples.blog.persistence.jpa");
assertNotNull(bper);
assertEquals(bper.ACTIVE, bper.getState());
/* Datasource and transaction manager services are used by the blog sample */
Bundle bds = getInstalledBundle("org.apache.aries.samples.blog.datasource");
Bundle txs = getInstalledBundle("org.apache.aries.transaction.manager");
/*Wait for all the required services to be registered */
waitForServices(bbiz, "org.apache.aries.samples.blog.api.BloggingService");
waitForServices(bper, "org.apache.aries.samples.blog.api.persistence.BlogPersistenceService");
waitForServices(bds, "javax.sql.XADataSource");
waitForServices(txs, "javax.transaction.TransactionManager");
/*Check that they haven't timed out trying to register*/
assertTrue("No services reistered for " + bbiz.getSymbolicName(), isServiceRegistered(bbiz));
assertTrue("No services reistered for " + bper.getSymbolicName(), isServiceRegistered(bper));
assertTrue("No services reistered for " + bds.getSymbolicName(), isServiceRegistered(bds));
assertTrue("No services reistered for " + txs.getSymbolicName(), isServiceRegistered(txs));
/*Check what services are registered - uncomment for additional debug */
/*
listBundleServices(bbiz);
listBundleServices(bper);
listBundleServices(bds);
listBundleServices(txs);
System.out.println("In test and trying to get connection....");
*/
HttpURLConnection conn = makeConnection("http://localhost:8080/org.apache.aries.samples.blog.web/ViewBlog");
String response = getHTTPResponse(conn);
/* Uncomment for additional debug */
/*
System.out.println("ZZZZZ " + response);
System.out.println("ZZZZZ " + conn.getResponseCode());
System.out.println("ZZZZZ " + HttpURLConnection.HTTP_OK);
*/
assertEquals(HttpURLConnection.HTTP_OK,
conn.getResponseCode());
assertTrue("The response did not contain the expected content", response.contains("Blog home"));
ctx.stop();
manager.uninstall(ctx);
}