package org.callimachusproject.webdriver;

import java.io.File;

import junit.framework.TestSuite;

import org.callimachusproject.webdriver.helpers.AssetDownloader;
import org.callimachusproject.webdriver.helpers.BrowserFunctionalTestCase;
import org.callimachusproject.webdriver.pages.FolderView;
import org.openqa.selenium.By;

public class SchoolWardFunctionalTest extends BrowserFunctionalTestCase {
	private static final String DOWNLOAD_URL = "http://callimachus.googlecode.com/files/schools.car";

	public static TestSuite suite() throws Exception {
		return BrowserFunctionalTestCase
				.suite(SchoolWardFunctionalTest.class);
	}

	public SchoolWardFunctionalTest() {
		super();
	}

	public SchoolWardFunctionalTest(BrowserFunctionalTestCase parent) {
		super(parent);
	}

	public void testSchoolWard() throws Exception {
		File car = new AssetDownloader(new File("downloads"))
				.getLocalAsset(DOWNLOAD_URL);
		FolderView folder = page.openCurrentFolder().openImportPage()
				.selectFile(car).importCar().openCurrentFolder();
		String archive = folder.getCurrentUrl().replaceAll("\\?.*", "?archive");
		File ex = new AssetDownloader(getUsername(), getPassword()).downloadAsset(archive, "schools.car");
		folder.openImportPage().selectFile(ex).importCar();
		ex.delete();
		browser.click(By.linkText("Bartley Green"));
		browser.focusInTopWindow();
		browser.click(By
				.linkText("Bartley Green School A Specialist Technology and Sports College"));
		browser.focusInTopWindow();
		browser.click(By.linkText("Edit"));
		browser.focusInTopWindow();
		browser.type(By.id("name"), "Bartley Green School");
		browser.type(By.id("comment"),
				"A Specialist Technology and Sports College");
		browser.click(By.id("save"));
		browser.focusInTopWindow();
		browser.waitUntilTextPresent(By.tagName("p"),
				"A Specialist Technology and Sports College");
	}

}

@@ -233,16 +233,78 @@
 stCase;%0A
+import org.callimachusproject.webdriver.pages.DatasourceView;%0A
 import o
@@ -1539,32 +1539,93 @@
 sInTopWindow();%0A
+%09%09String uri = browser.getCurrentUrl().replace(%22?view%22, %22%22);%0A
 %09%09browser.click(
@@ -1976,14 +1976,146 @@
 lege%22);%0A
+%09%09page.open(%22/sparql%22, DatasourceView.class).query(%22DELETE WHERE %7B %3C%22 + uri + %22%3E ?p ?o %7D%22).execute();%0A%09%09browser.focusInTopWindow();%0A
 %09%7D%0A%0A%7D%0A

Remove modified school in schools app functional test