|
From: <tre...@us...> - 2007-08-04 00:19:54
|
Revision: 234
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=234&view=rev
Author: trevorolio
Date: 2007-08-03 17:19:57 -0700 (Fri, 03 Aug 2007)
Log Message:
-----------
Refactored the WebAPI classes like so:
WebAPIDescriptor: handles all of the URL creation mojo for a given Ogoglio service
WebAPIAuthenticator: contains login information and fetches account and auth documents
WebAPIClientWire: handles all HTTP communication
WebAPIClient: wraps the descriptor, wire, and authenticator to provide easy functions for manipulating the remote ogoglio service
NOTE: WebAPIClient instances are no longer bound to a single space
These changes make it easier for us to test because the individual objects can be mocked more easily, and in general removes a lot of the intertwined nastiness that had grown up in WebAPIClient.
NOTE: spaceui.js has changed to reflect that the viewer applet now takes a spaceID parameter instead of a spaceURI. If you have custom HTML wrapping the viewer jar you'll need to change it after this update.
NOTE 2: There are two tests in templatesync which don't pass, mostly because I'm still getting my feet under me with RMock and I'm going to bother Ian until he helps me. Also, the Persist tests are hard coded for a specific db setup, which Ian is going to fix Real Soon Now.
Modified Paths:
--------------
spaces/trunk/src/com/ogoglio/client/ClientTests.java
spaces/trunk/src/com/ogoglio/client/MultiuserTests.java
spaces/trunk/src/com/ogoglio/client/SpaceClient.java
spaces/trunk/src/com/ogoglio/client/SpaceDuplicator.java
spaces/trunk/src/com/ogoglio/client/SpaceDuplicatorTests.java
spaces/trunk/src/com/ogoglio/client/WebAPIAuthenticator.java
spaces/trunk/src/com/ogoglio/client/WebAPIClient.java
spaces/trunk/src/com/ogoglio/client/WebAPIClientWire.java
spaces/trunk/src/com/ogoglio/client/WebAPIUtil.java
spaces/trunk/src/com/ogoglio/media/WebStore.java
spaces/trunk/src/com/ogoglio/site/AccountServlet.java
spaces/trunk/src/com/ogoglio/site/MessageProxy.java
spaces/trunk/src/com/ogoglio/site/SpaceServlet.java
spaces/trunk/src/com/ogoglio/site/TemplateResource.java
spaces/trunk/src/com/ogoglio/templatesync/GeomComparator.java
spaces/trunk/src/com/ogoglio/templatesync/MaterialsComparator.java
spaces/trunk/src/com/ogoglio/templatesync/ScriptComparator.java
spaces/trunk/src/com/ogoglio/templatesync/SyncTool.java
spaces/trunk/src/com/ogoglio/templatesync/SyncToolSpec.java
spaces/trunk/src/com/ogoglio/templatesync/SyncToolTest.java
spaces/trunk/src/com/ogoglio/templatesync/TypedFileComparator.java
spaces/trunk/src/com/ogoglio/viewer/applet/AppletTestWindow.java
spaces/trunk/src/com/ogoglio/viewer/applet/BodyEditorApplet.java
spaces/trunk/src/com/ogoglio/viewer/applet/ViewerApplet.java
spaces/trunk/war/spaceui.js
Added Paths:
-----------
spaces/trunk/src/com/ogoglio/client/AuthenticationFailedException.java
spaces/trunk/src/com/ogoglio/client/WebAPIAuthenticatorFactory.java
spaces/trunk/src/com/ogoglio/client/WebAPIDescriptor.java
spaces/trunk/src/com/ogoglio/client/WebAPIGuestAuthenticator.java
Added: spaces/trunk/src/com/ogoglio/client/AuthenticationFailedException.java
===================================================================
--- spaces/trunk/src/com/ogoglio/client/AuthenticationFailedException.java (rev 0)
+++ spaces/trunk/src/com/ogoglio/client/AuthenticationFailedException.java 2007-08-04 00:19:57 UTC (rev 234)
@@ -0,0 +1,7 @@
+package com.ogoglio.client;
+
+public class AuthenticationFailedException extends Exception {
+ public AuthenticationFailedException(String message) {
+ super(message);
+ }
+}
Modified: spaces/trunk/src/com/ogoglio/client/ClientTests.java
===================================================================
--- spaces/trunk/src/com/ogoglio/client/ClientTests.java 2007-08-02 17:49:59 UTC (rev 233)
+++ spaces/trunk/src/com/ogoglio/client/ClientTests.java 2007-08-04 00:19:57 UTC (rev 234)
@@ -40,6 +40,7 @@
import com.ogoglio.persist.PossessionRecord;
import com.ogoglio.persist.ServiceInitializationPersistTasks;
import com.ogoglio.persist.TemplateSupportFileRecord;
+import com.ogoglio.site.AuthServlet;
import com.ogoglio.util.StreamUtils;
import com.ogoglio.xml.AccountDocument;
import com.ogoglio.xml.AuthDocument;
@@ -70,10 +71,16 @@
URI serviceURI1 = null;
+ WebAPIClientWire wire1 = null;
+
+ WebAPIDescriptor descriptor1 = null;
+
public void setUp() {
try {
- serviceURI1 = new URI("http://127.0.0.1:8080/og/"); //best choice: 127.0.0.1 for tests
- linkURI1 = new URI("http://ogoglio.com/");
+ serviceURI1 = new URI("http://127.0.0.1:8080/og/"); //best choice: 127.0.0.1 for tests
+ linkURI1 = new URI("http://example.com/");
+ wire1 = new WebAPIClientWire();
+ descriptor1 = new WebAPIDescriptor(serviceURI1);
} catch (Throwable e) {
e.printStackTrace();
fail(e.getMessage());
@@ -86,21 +93,23 @@
public void testWebAdmin() {
try {
- String adminAuthCookie = WebAPIUtil.authenticate(serviceURI1, ServiceInitializationPersistTasks.LIBRARY_USERNAME, ServiceInitializationPersistTasks.DEFAULT_LIBRARY_PASSWORD);
- assertNotNull("got null auth cookie", adminAuthCookie);
+ WebAPIAuthenticator adminAuthenticator = new WebAPIAuthenticatorFactory().authenticate(wire1, descriptor1, ServiceInitializationPersistTasks.LIBRARY_USERNAME, ServiceInitializationPersistTasks.DEFAULT_LIBRARY_PASSWORD);
+ assertNotNull("got null auth cookie", adminAuthenticator.getAuthCookie());
+ WebAPIClient adminWebClient = new WebAPIClient(descriptor1, adminAuthenticator, wire1);
try {
- WebAPIClient.createAccount(serviceURI1, adminAuthCookie, USERNAME1, AccountRecord.ACCOUNT_LEVEL_ADVANCED, "Susan", "Examplar", "http://example.com/susan/", "su...@ex...", PASSWORD1);
- WebAPIClient.createAccount(serviceURI1, adminAuthCookie, USERNAME2, AccountRecord.ACCOUNT_LEVEL_ADVANCED, "Tina", "Examplar", "http://example.com/tina/", "ti...@ex...", PASSWORD1);
+ adminWebClient.createAccount(USERNAME1, AccountRecord.ACCOUNT_LEVEL_ADVANCED, "Susan", "Examplar", "http://example.com/susan/", "su...@ex...", PASSWORD1);
+ adminWebClient.createAccount(USERNAME2, AccountRecord.ACCOUNT_LEVEL_ADVANCED, "Tina", "Examplar", "http://example.com/tina/", "ti...@ex...", PASSWORD1);
} catch (IOException e) {
//may already exist
}
- String basicAuthCookie = WebAPIUtil.authenticate(serviceURI1, USERNAME1, PASSWORD1);
- assertNotNull("got null auth cookie", basicAuthCookie);
+ WebAPIAuthenticator basicAuthenticator = new WebAPIAuthenticator(wire1, descriptor1, USERNAME1, PASSWORD1);
+ assertNotNull("got null auth cookie", basicAuthenticator.getAuthCookie());
+ WebAPIClient basicWebClient = new WebAPIClient(descriptor1, basicAuthenticator, wire1);
try {
String failedUsername = "Bogosity" + System.currentTimeMillis();
- AccountDocument doc = WebAPIClient.createAccount(serviceURI1, basicAuthCookie, failedUsername, AccountRecord.ACCOUNT_LEVEL_BASIC, "Shouldnt", "Exist", null, failedUsername + "@example.com", "1234");
+ AccountDocument doc = basicWebClient.createAccount(failedUsername, AccountRecord.ACCOUNT_LEVEL_BASIC, "Shouldnt", "Exist", null, failedUsername + "@example.com", "1234");
if (doc != null) {
fail();
}
@@ -109,9 +118,9 @@
}
String username = "testuser" + Math.abs(new Random().nextLong());
- WebAPIClient.createAccount(serviceURI1, adminAuthCookie, username, AccountRecord.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, username + "@example.com", "1234");
+ adminWebClient.createAccount(username, AccountRecord.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, username + "@example.com", "1234");
- AccountDocument accountDoc = WebAPIClient.getAccountDocument(serviceURI1, adminAuthCookie, username);
+ AccountDocument accountDoc = adminWebClient.getAccountDocument(username);
assertNotNull(accountDoc);
assertEquals("Test", accountDoc.getFirstName());
assertEquals("Sims", accountDoc.getLastName());
@@ -119,14 +128,14 @@
Date frozenDate = new Date(System.currentTimeMillis() + 1000000);
accountDoc.setFrozenUntil(frozenDate);
accountDoc.setAccountLevel(AccountRecord.ACCOUNT_LEVEL_ADMIN);
- WebAPIClient.updateAccount(serviceURI1, adminAuthCookie, accountDoc);
- accountDoc = WebAPIClient.getAccountDocument(serviceURI1, adminAuthCookie, username);
+ adminWebClient.updateAccount(accountDoc);
+ accountDoc = adminWebClient.getAccountDocument(username);
assertTrue(frozenDate.getTime() - accountDoc.getFrozenUntil().getTime() < 1000);
assertEquals(AccountRecord.ACCOUNT_LEVEL_ADMIN, accountDoc.getAccountLevel());
accountDoc.setFrozenUntil(new Date(1000));
accountDoc.setAccountLevel(AccountRecord.ACCOUNT_LEVEL_BASIC);
- WebAPIClient.updateAccount(serviceURI1, adminAuthCookie, accountDoc);
- accountDoc = WebAPIClient.getAccountDocument(serviceURI1, adminAuthCookie, username);
+ adminWebClient.updateAccount(accountDoc);
+ accountDoc = adminWebClient.getAccountDocument(username);
assertTrue(accountDoc.getFrozenUntil() == null);
assertEquals(AccountRecord.ACCOUNT_LEVEL_BASIC, accountDoc.getAccountLevel());
@@ -136,70 +145,60 @@
}
}
- private UserDocument[] verifyUserDocsBySize(WebAPIClient webClient1, int expectedLen, String expectedUsername) throws IOException {
- UserDocument[] userDocs = webClient1.getUserDocuments();
- assertTrue(userDocs.length == expectedLen);
- if (expectedUsername!=null) {
- assertEquals(expectedUsername,userDocs[0].getUsername());
- }
- return userDocs;
- }
-
public void testWebAPIClient() {
SpaceClient spaceClient1 = null;
SpaceClient guestSpaceClient1 = null;
try {
- //this section sets up the key variables
- String authCookie1 = WebAPIUtil.authenticate(serviceURI1, USERNAME1, PASSWORD1);
- assertNotNull("got null auth cookie", authCookie1);
- URI spaceURI1 = WebAPIUtil.appendToURI(serviceURI1, "space/" + WebAPIClient.createSpace(serviceURI1, authCookie1).getSpaceID());
- WebAPIClient webClient1 = new WebAPIClient(spaceURI1, serviceURI1, authCookie1);
- SpaceDocument spaceDocument = webClient1.getSpaceDocument(false);
+ //this section sets up the key variables
+ WebAPIAuthenticator auth1 = new WebAPIAuthenticator(wire1, descriptor1, USERNAME1, PASSWORD1);
+ WebAPIClient webClient1 = new WebAPIClient(descriptor1, auth1, wire1);
+ SpaceDocument spaceDocument = webClient1.createSpace("Susan's Space");
assertNotNull(spaceDocument);
- // IES REFACTOR
- checkNoConnectionToSpaceWithoutAuth(spaceURI1);
+ WebAPIAuthenticator auth2 = new WebAPIAuthenticator(wire1, descriptor1, USERNAME2, PASSWORD1);
+ WebAPIClient webClient2 = new WebAPIClient(descriptor1, auth2, wire1);
- checkAuthDoc(authCookie1);
-
+ checkNoConnectionToSpaceWithoutAuth(spaceDocument.getSpaceID());
+
+ checkAuthDoc(auth1, auth2);
+
spaceDocument = checkSpaceSeaLevel(webClient1, spaceDocument);
- checkSettings(webClient1);
+ checkSettings(spaceDocument.getSpaceID(), webClient1);
- checkBody(webClient1);
+ checkBody(webClient1, auth1);
- checkSpaceMembership(webClient1);
+ checkSpaceMembership(spaceDocument.getSpaceID(), webClient1);
- checkSpaceAuthWithMembership(authCookie1, spaceURI1, webClient1, spaceDocument);
+ checkSpaceAuthWithMembership(auth2, webClient2, webClient1, spaceDocument);
TemplateDocument newTemplateDoc = checkTemplateScriptAPI(webClient1);
- ThingDocument[] thingDocs=checkTemplateGeomMaterialsAndPossessions(webClient1, newTemplateDoc, spaceDocument);
+ ThingDocument[] thingDocs = checkTemplateGeomMaterialsAndPossessions(webClient1, newTemplateDoc, spaceDocument);
//IES CHECK: after messing around above, verify we are are ok
- thingDocs=webClient1.getThingDocuments();
- assertEquals(1,thingDocs.length);
-
- checkPageManipulation(webClient1, thingDocs[0]);
+ thingDocs = webClient1.getThingDocuments(spaceDocument.getSpaceID());
+ assertEquals(1, thingDocs.length);
+ checkPageManipulation(webClient1, thingDocs[0], spaceDocument);
+
//figure out the last template added
TemplateDocument[] templateDocs = webClient1.getTemplateDocuments(USERNAME1);
long lastTemplateID = templateDocs[templateDocs.length - 1].getTemplateID();
checkDoors(webClient1, spaceDocument, lastTemplateID);
- spaceClient1 = checkConnectedUsersToSpace(authCookie1, spaceURI1, webClient1);
+ spaceClient1 = checkConnectedUsersToSpace(auth1, webClient1, spaceDocument);
- checkGeomAndResourceStreamsOfTemplate(webClient1, lastTemplateID);
+ checkGeomAndResourceStreamsOfTemplate(webClient1, auth1.getUsername(), lastTemplateID);
- authThenBuildSpaceClient(spaceURI1);
+ authThenBuildSpaceClient(spaceDocument.getSpaceID(), auth1);
checkGeometryAvailableForSpace(webClient1, thingDocs, spaceClient1.getSpace());
-
- guestSpaceClient1 = checkGuestCookieOperation(spaceURI1, webClient1,
- WebAPIClient.requestGuestCookie(serviceURI1));
- checkDeletingSpaceDestroysThings(webClient1,USERNAME1);
-
+
+ guestSpaceClient1 = checkGuestCookieOperation(spaceDocument.getSpaceID(), webClient1, AuthServlet.GUEST_COOKIE_PREFIX + "Test_Suite_Guest");
+ checkDeletingSpaceDestroysThings(spaceDocument.getSpaceID(), webClient1, USERNAME1);
+
} catch (IOException e) {
e.printStackTrace();
fail();
@@ -214,18 +213,16 @@
}
- private AuthDocument getAuthDoc(String authCookie) {
- try {
- XMLElement element = WebAPIClient.fetchAuthenticatedXML(WebAPIClient.getMeAuthURI(serviceURI1), authCookie);
- return new AuthDocument(element);
- } catch (IOException e) {
- fail("Error fetching auth document with no auth cookie: " + e);
- return null;
+ private UserDocument[] verifyUserDocsBySize(WebAPIClient webClient1, long spaceID, int expectedLen, String expectedUsername) throws IOException {
+ UserDocument[] userDocs = webClient1.getUserDocuments(spaceID);
+ assertTrue(userDocs.length == expectedLen);
+ if (expectedUsername != null) {
+ assertEquals(expectedUsername, userDocs[0].getUsername());
}
+ return userDocs;
}
- private void checkAuthDoc(String authCookie1) {
-
+ private void checkAuthDoc(WebAPIAuthenticator auth1, WebAPIAuthenticator auth2) {
AuthDocument authDoc = getAuthDoc(null);
assertFalse(authDoc.isAuthenticated());
assertNull(authDoc.getUsername());
@@ -234,314 +231,300 @@
assertFalse(authDoc.isAuthenticated());
assertNull(authDoc.getUsername());
- authDoc = getAuthDoc(authCookie1);
+ authDoc = getAuthDoc(auth1.getAuthCookie());
assertTrue(authDoc.isAuthenticated());
assertEquals(USERNAME1, authDoc.getUsername());
+
+ authDoc = getAuthDoc(auth2.getAuthCookie());
+ assertTrue(authDoc.isAuthenticated());
+ assertEquals(USERNAME2, authDoc.getUsername());
}
+ private AuthDocument getAuthDoc(String authCookie) {
+ try {
+ XMLElement element = wire1.fetchAuthenticatedXML(descriptor1.getMeAuthURI(), authCookie);
+ return new AuthDocument(element);
+ } catch (IOException e) {
+ fail("Error fetching auth document with no auth cookie: " + e);
+ return null;
+ }
+ }
- private void checkSpaceAuthWithMembership(String authCookie1, URI spaceURI1, WebAPIClient webClient1, SpaceDocument spaceDocument) throws IOException {
- SpaceMemberDocument[] membershipDocs;
- String authCookie2 = WebAPIUtil.authenticate(serviceURI1, USERNAME2, PASSWORD1);
- assertNotNull("got null auth cookie", authCookie1);
- WebAPIClient webClient2 = new WebAPIClient(spaceURI1, serviceURI1, authCookie2);
- membershipDocs = webClient2.getUsersSpaceMemberships();
- assertEquals(1, membershipDocs.length);
- assertEquals(spaceDocument.getSpaceID(), membershipDocs[0].getSpaceID());
- assertEquals(webClient2.getAuthDocument(true).getUsername(), membershipDocs[0].getMemberUsername());
- SpaceMemberDocument[] spaceMemberDocs = webClient1.getSpaceMemberDocuments();
- assertFalse("member doc length = " + spaceMemberDocs.length, spaceMemberDocs.length == 0);
- assertEquals(spaceMemberDocs[0].getMemberUsername(), USERNAME2);
+ private void checkSpaceAuthWithMembership(WebAPIAuthenticator memberAuth, WebAPIClient memberClient, WebAPIClient ownerClient, SpaceDocument spaceDocument) throws IOException {
+ SpaceMemberDocument[] membershipDocs;
+ membershipDocs = memberClient.getUsersSpaceMemberships();
+ assertEquals(1, membershipDocs.length);
+ assertEquals(spaceDocument.getSpaceID(), membershipDocs[0].getSpaceID());
+ assertEquals(memberAuth.getUsername(), membershipDocs[0].getMemberUsername());
+ SpaceMemberDocument[] spaceMemberDocs = ownerClient.getSpaceMemberDocuments(spaceDocument.getSpaceID());
+ assertFalse("member doc length = " + spaceMemberDocs.length, spaceMemberDocs.length == 0);
+ assertEquals(spaceMemberDocs[0].getMemberUsername(), memberAuth.getUsername());
- webClient1.removeSpaceMember(USERNAME2);
- membershipDocs = webClient2.getUsersSpaceMemberships();
- assertEquals(0, membershipDocs.length);
+ ownerClient.removeSpaceMember(spaceDocument.getSpaceID(), memberAuth.getUsername());
+ membershipDocs = memberClient.getUsersSpaceMemberships();
+ assertEquals(0, membershipDocs.length);
+ }
- SpaceDocument[] spaceDocs = webClient1.getAccountSpaceDocuments(USERNAME1);
- assertTrue("space docs length is " + spaceDocs.length, spaceDocs.length >= 1);
- }
+ private void checkSpaceMembership(long spaceID, WebAPIClient webClient1) throws IOException {
+ SpaceMemberDocument[] membershipDocs = webClient1.getUsersSpaceMemberships();
+ assertNotNull(membershipDocs);
+ assertEquals(0, membershipDocs.length);
- private void checkSpaceMembership(WebAPIClient webClient1) throws IOException {
- SpaceMemberDocument[] membershipDocs = webClient1.getUsersSpaceMemberships();
- assertNotNull(membershipDocs);
- assertEquals(0, membershipDocs.length);
+ webClient1.addSpaceMember(spaceID, USERNAME2, SpaceMemberDocument.MEMBER);
+ membershipDocs = webClient1.getSpaceMemberDocuments(spaceID);
+ assertNotNull(membershipDocs);
+ assertEquals(1, membershipDocs.length);
+ assertEquals(USERNAME2, membershipDocs[0].getMemberUsername());
+ assertEquals(SpaceMemberDocument.MEMBER, membershipDocs[0].getRole());
+ }
- webClient1.addSpaceMember(USERNAME2, SpaceMemberDocument.MEMBER);
- membershipDocs = webClient1.getSpaceMemberDocuments();
- assertNotNull(membershipDocs);
- assertEquals(1, membershipDocs.length);
- assertEquals(USERNAME2, membershipDocs[0].getMemberUsername());
- assertEquals(SpaceMemberDocument.MEMBER, membershipDocs[0].getRole());
- }
+ private void checkSettings(long spaceID, WebAPIClient webClient1) throws IOException {
+ String key1 = "ogoglio.key.1";
+ String value1 = "This is a very fine value which is < 1";
+ assertNull(webClient1.getSpaceSetting(spaceID, key1));
+ webClient1.putSpaceSetting(spaceID, key1, value1);
+ assertEquals(value1, webClient1.getSpaceSetting(spaceID, key1));
- private void checkSettings(WebAPIClient webClient1) throws IOException {
- String key1 = "ogoglio.key.1";
- String value1 = "This is a very fine value which is < 1";
- assertNull(webClient1.getSetting(key1));
- webClient1.putSetting(key1, value1);
- assertEquals(value1, webClient1.getSetting(key1));
+ String key2 = "ogoglio.key.2";
+ String value2 = "This is a very fine value & it's value is > 2";
+ assertNull(webClient1.getSpaceSetting(spaceID, key2));
+ webClient1.putSpaceSetting(spaceID, key2, value2);
+ assertEquals(value2, webClient1.getSpaceSetting(spaceID, key2));
+ assertEquals(value1, webClient1.getSpaceSetting(spaceID, key1));
- String key2 = "ogoglio.key.2";
- String value2 = "This is a very fine value & it's value is > 2";
- assertNull(webClient1.getSetting(key2));
- webClient1.putSetting(key2, value2);
- assertEquals(value2, webClient1.getSetting(key2));
- assertEquals(value1, webClient1.getSetting(key1));
+ webClient1.removeSpaceSetting(spaceID, key1);
+ assertNull(webClient1.getSpaceSetting(spaceID, key1));
+ webClient1.removeSpaceSetting(spaceID, key2);
+ assertNull(webClient1.getSpaceSetting(spaceID, key2));
+ }
- webClient1.removeSetting(key1);
- assertNull(webClient1.getSetting(key1));
- webClient1.removeSetting(key2);
- assertNull(webClient1.getSetting(key2));
- }
+ private void checkBody(WebAPIClient webClient1, WebAPIAuthenticator authenticator) throws IOException {
+ AccountDocument ownerDoc = authenticator.getAccountDocument(true);
+ assertNotNull(ownerDoc);
+ assertEquals(USERNAME1, ownerDoc.getUsername());
+ long defaultBody = ownerDoc.getDefaultBodyID();
+ BodyDocument bodyDoc = webClient1.createBody("Testing Body");
+ assertFalse(bodyDoc.getBodyID() == -1);
+ assertEquals(ownerDoc.getUsername(), bodyDoc.getOwnerUsername());
+ assertEquals(0, bodyDoc.getHairIndex());
+ assertEquals(0, bodyDoc.getEyesIndex());
+ assertEquals(0, bodyDoc.getNoseIndex());
+ assertEquals(0, bodyDoc.getMouthIndex());
+ assertEquals(0, bodyDoc.getFaceIndex());
+ ownerDoc = webClient1.setDefaultBody(bodyDoc.getBodyID());
+ assertEquals(bodyDoc.getBodyID(), ownerDoc.getDefaultBodyID());
+ assertEquals(ownerDoc.getUsername(), bodyDoc.getOwnerUsername());
+ bodyDoc.setEyesIndex(3);
+ bodyDoc = webClient1.updateBody(bodyDoc);
+ assertEquals(3, bodyDoc.getEyesIndex());
+ assertFalse(webClient1.deleteBody(bodyDoc.getBodyID()));
+ webClient1.setDefaultBody(defaultBody);
+ assertTrue(webClient1.deleteBody(bodyDoc.getBodyID()));
+ ownerDoc = webClient1.setDefaultBody(bodyDoc.getBodyID());
+ assertEquals(defaultBody, ownerDoc.getDefaultBodyID());
+ }
- private void checkBody(WebAPIClient webClient1) throws IOException {
- AuthDocument authDoc = webClient1.getAuthDocument(true);
- assertNotNull(authDoc);
- assertEquals(USERNAME1, authDoc.getUsername());
+ private SpaceDocument checkSpaceSeaLevel(WebAPIClient webClient1, SpaceDocument spaceDocument) throws IOException {
+ assertFalse(spaceDocument.getDisplaySea());
+ assertEquals(0, spaceDocument.getSeaLevel(), 0.001);
+ webClient1.setSpaceSeaLevel(spaceDocument.getSpaceID(), -2);
+ spaceDocument = webClient1.getSpaceDocument(spaceDocument.getSpaceID(), false);
+ assertEquals(-2, spaceDocument.getSeaLevel(), 0.000001);
+ webClient1.setSpaceDisplaySea(spaceDocument.getSpaceID(), true);
+ spaceDocument = webClient1.getSpaceDocument(spaceDocument.getSpaceID(), false);
+ assertTrue(spaceDocument.getDisplaySea());
+ return spaceDocument;
+ }
- AccountDocument ownerDoc = webClient1.getAccountDocument(authDoc.getUsername());
- assertNotNull(ownerDoc);
- assertEquals(USERNAME1, ownerDoc.getUsername());
- long defaultBody = ownerDoc.getDefaultBodyID();
- BodyDocument bodyDoc = webClient1.createBody();
- assertFalse(bodyDoc.getBodyID() == -1);
- assertEquals(ownerDoc.getUsername(), bodyDoc.getOwnerUsername());
- assertEquals(0, bodyDoc.getHairIndex());
- assertEquals(0, bodyDoc.getEyesIndex());
- assertEquals(0, bodyDoc.getNoseIndex());
- assertEquals(0, bodyDoc.getMouthIndex());
- assertEquals(0, bodyDoc.getFaceIndex());
- ownerDoc = webClient1.setDefaultBody(bodyDoc.getBodyID());
- assertEquals(bodyDoc.getBodyID(), ownerDoc.getDefaultBodyID());
- assertEquals(ownerDoc.getUsername(), bodyDoc.getOwnerUsername());
- bodyDoc.setEyesIndex(3);
- bodyDoc = webClient1.updateBody(bodyDoc);
- assertEquals(3, bodyDoc.getEyesIndex());
- assertFalse(webClient1.deleteBody(bodyDoc.getBodyID()));
- webClient1.setDefaultBody(defaultBody);
- assertTrue(webClient1.deleteBody(bodyDoc.getBodyID()));
- ownerDoc = webClient1.setDefaultBody(bodyDoc.getBodyID());
- assertEquals(defaultBody, ownerDoc.getDefaultBodyID());
- }
+ private void checkNoConnectionToSpaceWithoutAuth(long spaceID) {
+ try {
+ WebAPIGuestAuthenticator guestAuth = new WebAPIGuestAuthenticator(descriptor1, AuthServlet.GUEST_COOKIE_PREFIX + "Test_Suite_Guest");
+ new WebAPIClient(descriptor1, guestAuth, wire1).getSpaceDocument(spaceID, false);
+ fail("Should get an IOException when not authed");
+ } catch (IOException e) {
+ //this should happen
+ }
+ }
- private SpaceDocument checkSpaceSeaLevel(WebAPIClient webClient1, SpaceDocument spaceDocument) throws IOException {
- assertFalse(spaceDocument.getDisplaySea());
- assertEquals(0, spaceDocument.getSeaLevel(), 0.001);
- webClient1.setSeaLevel(-2);
- spaceDocument = webClient1.getSpaceDocument(false);
- assertEquals(-2, spaceDocument.getSeaLevel(), 0.000001);
- webClient1.setDisplaySea(true);
- spaceDocument = webClient1.getSpaceDocument(false);
- assertTrue(spaceDocument.getDisplaySea());
- return spaceDocument;
- }
+ private SpaceClient authThenBuildSpaceClient(long spaceID, WebAPIAuthenticator auth1) throws IOException {
+ TestSpaceClientListener listener = new TestSpaceClientListener();
+ SpaceClient spaceClient1 = new SpaceClient(spaceID, serviceURI1, auth1.getAuthCookie(), listener);
+ return spaceClient1;
+ }
- private void checkNoConnectionToSpaceWithoutAuth(URI spaceURI1) {
- try {
- new WebAPIClient(spaceURI1, serviceURI1, "BadBadCookie").getSpaceDocument(false);
- fail("Should get an IOException when not authed");
- } catch (IOException e) {
- //this should happen
- }
- }
+ private void checkGeometryAvailableForSpace(WebAPIClient webClient1, ThingDocument[] thingDocs, Space space1) throws IOException {
+ TestListener testListener = new TestListener();
+ space1.addListener(testListener, false);
- private SpaceClient authThenBuildSpaceClient(URI spaceURI1) throws IOException {
- SpaceClient spaceClient1;
- String authCookie1;
- //auth to login to the svc
- authCookie1 = WebAPIUtil.authenticate(serviceURI1, USERNAME1, PASSWORD1);
- assertNotNull("got null auth cookie", authCookie1);
+ //make sure we can get one thing from the space (maybe floor?) and check geom stream
+ assertNotNull(space1.getThing(1));
+ InputStream stream = space1.getThing(1).getGeometryStream(0);
+ assertNotNull(stream);
+ consume(stream);
- //reconnect to space, authenticated this time?
- TestSpaceClientListener listener = new TestSpaceClientListener();
- spaceClient1 = new SpaceClient(spaceURI1, serviceURI1, authCookie1, listener);
- return spaceClient1;
- }
+ // get our possession out of the space
+ long possID = thingDocs[0].getPossessionID();
+ webClient1.removePossessionFromSpace(possID);
+ thingDocs = webClient1.getThingDocuments(space1.getSpaceID());
+ assertEquals(0, thingDocs.length);
- private void checkGeometryAvailableForSpace(WebAPIClient webClient1, ThingDocument[] thingDocs, Space space1) throws IOException {
- TestListener testListener = new TestListener();
- space1.addListener(testListener, false);
-
- //make sure we can get one thing from the space (maybe floor?) and check geom stream
- assertNotNull(space1.getThing(1));
- InputStream stream = space1.getThing(1).getGeometryStream(0);
- assertNotNull(stream);
- consume(stream);
+ //put it back so the world is in the same state
+ //XXX EVIL! DEPENDENCY BETWEEN TESTS! BOO HISS!
+ webClient1.addPossessionToSpace(possID, space1.getSpaceID());
+ }
- // get our possession out of the space
- long possID=thingDocs[0].getPossessionID();
- webClient1.removePossessionFromSpace(thingDocs[0].getOwnerUsername(), possID);
- thingDocs = webClient1.getThingDocuments();
- assertEquals(0, thingDocs.length);
-
- //put it back so the world is in the same state
- //XXX EVIL! DEPENDENCY BETWEEN TESTS! BOO HISS!
- webClient1.addPossessionToSpace(possID, space1.getSpaceID());
- }
+ private SpaceClient checkGuestCookieOperation(long spaceID, WebAPIClient webClient1, String guestCookie1) throws IOException {
+ assertNotNull(guestCookie1);
- private SpaceClient checkGuestCookieOperation(URI spaceURI1, WebAPIClient webClient1, String guestCookie1) throws IOException {
- SpaceClient guestSpaceClient1;
- assertNotNull(guestCookie1);
- try {
- //try to get into the space without proper credentials
- guestSpaceClient1 = new SpaceClient(spaceURI1, serviceURI1, guestCookie1, new TestSpaceClientListener());
- fail("Should not be able to guest into the space yet");
- } catch (IOException e) {
- //this should happen
- }
- //switch to public with 5 possible guests
- webClient1.setPublished(true);
- assertEquals(true, webClient1.getSpaceDocument(false).isPublished());
- webClient1.setMaxGuests(5);
- assertEquals(5, webClient1.getSpaceDocument(false).getMaxGuests());
+ try {
+ //try to get into the space without proper credentials
+ new SpaceClient(spaceID, serviceURI1, guestCookie1, new TestSpaceClientListener());
+ fail("Should not be able to guest into the space yet");
+ } catch (IOException e) {
+ //this should happen
+ }
+ //switch to public with 5 possible guests
+ webClient1.setSpacePublished(spaceID, true);
+ assertEquals(true, webClient1.getSpaceDocument(spaceID, false).isPublished());
+ webClient1.setSpaceMaxGuests(spaceID, 5);
+ assertEquals(5, webClient1.getSpaceDocument(spaceID, false).getMaxGuests());
- //now connect as a guest
- guestSpaceClient1 = new SpaceClient(spaceURI1, serviceURI1, guestCookie1, new TestSpaceClientListener());
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- //two users currently connected and one of them better be same as our cookie?
- UserDocument[] userDocs=verifyUserDocsBySize(webClient1, 2, null);
- assertTrue(guestCookie1.equals(userDocs[1].getUsername()) || guestCookie1.equals(userDocs[0].getUsername()));
- return guestSpaceClient1;
- }
-
- private SpaceClient checkConnectedUsersToSpace(String authCookie1, URI spaceURI1, WebAPIClient webClient1) throws IOException {
- SpaceClient spaceClient1;
- //there are no user documents because there are no current connections?
- verifyUserDocsBySize(webClient1,0,null);
- //create a connection to the space
- spaceClient1 = new SpaceClient(spaceURI1, serviceURI1, authCookie1,
- new TestSpaceClientListener());
- try {
- Thread.sleep(1000);
- } catch (Exception e) {
- }
- //now check that we are the sole client
- verifyUserDocsBySize(webClient1, 1,USERNAME1);
- spaceClient1.cleanup();
- return spaceClient1;
- }
+ //now connect as a guest
+ SpaceClient guestSpaceClient1 = new SpaceClient(spaceID, serviceURI1, guestCookie1, new TestSpaceClientListener());
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
- private void checkDoors(WebAPIClient webClient1, SpaceDocument spaceDocument, long lastTemplateID) throws IOException {
- DoorDocument[] doorDocs = webClient1.getDoorDocuments();
- //no doors yet?
- assertEquals(0, doorDocs.length);
- //make a new door
- DoorDocument doorDoc = webClient1.createDoor(spaceDocument.getSpaceID(), lastTemplateID, USERNAME1, "Test Door", linkURI1, new Transform3D());
- assertNotNull(doorDoc);
- assertFalse(doorDoc.getDoorID() == -1);
- assertEquals(linkURI1, doorDoc.getLink());
- assertEquals("Test Door", doorDoc.getDisplayName());
-
- //make sure the new door is now in the list
- doorDocs = webClient1.getDoorDocuments();
- assertEquals(1, doorDocs.length);
- assertEquals(doorDoc.getDoorID(), doorDocs[0].getDoorID());
- //blow away the door and make sure it's really gone
- assertTrue(webClient1.deleteDoor(doorDoc.getDoorID()));
- doorDocs = webClient1.getDoorDocuments();
- assertEquals(0, doorDocs.length);
+ //two users currently connected and one of them better be same as our cookie?
+ UserDocument[] userDocs = verifyUserDocsBySize(webClient1, spaceID, 2, null);
+ assertTrue(guestCookie1.equals(userDocs[1].getUsername()) || guestCookie1.equals(userDocs[0].getUsername()));
+ return guestSpaceClient1;
+ }
- }
+ private SpaceClient checkConnectedUsersToSpace(WebAPIAuthenticator auth, WebAPIClient webClient1, SpaceDocument spaceDoc) throws IOException {
+ //there are no user documents because there are no current connections?
+ verifyUserDocsBySize(webClient1, spaceDoc.getSpaceID(), 0, null);
+ //create a connection to the space
+ SpaceClient spaceClient1 = new SpaceClient(spaceDoc.getSpaceID(), serviceURI1, auth.getAuthCookie(), new TestSpaceClientListener());
+ try {
+ Thread.sleep(1000);
+ } catch (Exception e) {
+ }
+ //now check that we are the sole client
+ verifyUserDocsBySize(webClient1, spaceDoc.getSpaceID(), 1, USERNAME1);
+ spaceClient1.cleanup();
+ return spaceClient1;
+ }
- private void checkGeomAndResourceStreamsOfTemplate(WebAPIClient webClient1, long templateID) throws IOException {
- URI templateURI = webClient1.getTemplateURI(USERNAME1, templateID);
- //get the geom for a template owned by this user
- InputStream stream = webClient1.getGeometryStream(templateURI, 0);
- assertNotNull(stream);
- consume(stream);
+ private void checkDoors(WebAPIClient webClient1, SpaceDocument spaceDocument, long lastTemplateID) throws IOException {
+ DoorDocument[] doorDocs = webClient1.getDoorDocuments(spaceDocument.getSpaceID());
+ //no doors yet?
+ assertEquals(0, doorDocs.length);
+ //make a new door
+ DoorDocument doorDoc = webClient1.createDoor(spaceDocument.getSpaceID(), lastTemplateID, USERNAME1, "Test Door", linkURI1, new Transform3D());
+ assertNotNull(doorDoc);
+ assertFalse(doorDoc.getDoorID() == -1);
+ assertEquals(linkURI1, doorDoc.getLink());
+ assertEquals("Test Door", doorDoc.getDisplayName());
- //get a material file for the same template
- stream = webClient1.getGeometryStream(templateURI, "TestCube.mtl");
- assertNotNull(stream);
- consume(stream);
-
- assertTrue(webClient1.deleteGeometryStream(templateID, 0));
- try {
- webClient1.getGeometryStream(templateURI, 0);
- fail("Shouldn't be able to get a deleted stream!");
- } catch (IOException e) {
- //can't get the stream because we just deleted it
- assertTrue(e.getMessage().indexOf("404")!=-1); //very weak test
- }
-
- webClient1.putGeometryStream(templateURI,
- new FileInputStream("src/com/ogoglio/persist/resources/TestCylinder.obj"), 0);
- }
+ //make sure the new door is now in the list
+ doorDocs = webClient1.getDoorDocuments(spaceDocument.getSpaceID());
+ assertEquals(1, doorDocs.length);
+ assertEquals(doorDoc.getDoorID(), doorDocs[0].getDoorID());
+ //blow away the door and make sure it's really gone
+ assertTrue(webClient1.deleteDoor(spaceDocument.getSpaceID(), doorDoc.getDoorID()));
+ doorDocs = webClient1.getDoorDocuments(spaceDocument.getSpaceID());
+ assertEquals(0, doorDocs.length);
- private void checkPageManipulation(WebAPIClient webClient1, ThingDocument someThing) throws IOException {
- //no pages, right? ... hasn't this thing already been destroyed?
- PageDocument[] pages = webClient1.getPageDocuments(someThing.getThingID());
- assertEquals(0, pages.length);
-
- //make a new page
- PageDocument pageDoc = webClient1.createPage(someThing.getThingID(), 1, 1, "text/plain");
- assertNotNull(pageDoc);
-
- //set the pages text and make sure we can read it back properly
- String pageText = "This is a test of the emergency broadcast system. This is only a test.";
- webClient1.setPageContents(someThing.getThingID(), pageDoc.getPageID(), pageText);
- InputStream pageStream = webClient1.getPageContents(someThing.getThingID(), pageDoc.getPageID());
- assertNotNull(pageStream);
- String fetchedPageText = StreamUtils.readInput(pageStream);
- assertEquals(pageText + " didn't match " + fetchedPageText, pageText, fetchedPageText);
- //reset page text
- pageText = "Hi ho";
- webClient1.setPageContents(someThing.getThingID(), pageDoc.getPageID(), pageText);
- pageStream = webClient1.getPageContents(someThing.getThingID(), pageDoc.getPageID());
- assertNotNull(pageStream);
- fetchedPageText = StreamUtils.readInput(pageStream);
- assertEquals(pageText, fetchedPageText);
- pageDoc.setX(10);
- pageDoc.setY(20);
- pageDoc.setZ(30);
- PageDocument updatedPageDoc = webClient1.updatePage(someThing.getThingID(), pageDoc);
- assertTrue(10 == updatedPageDoc.getX());
- assertTrue(20 == updatedPageDoc.getY());
- assertTrue(30 == updatedPageDoc.getZ());
- pages = webClient1.getPageDocuments(someThing.getThingID());
- assertEquals(1, pages.length);
- assertTrue(webClient1.deletePage(someThing.getThingID(), pageDoc.getPageID()));
- pages = webClient1.getPageDocuments(someThing.getThingID());
- assertEquals(0, pages.length);
- }
+ }
- private ThingDocument[] checkTemplateGeomMaterialsAndPossessions(WebAPIClient webClient1,
- TemplateDocument newTemplateDoc,
- SpaceDocument spaceDocument) throws IOException, FileNotFoundException {
- URI templateURI;
- TemplateDocument baseDoc, afterCylDoc;
- String CUBE_GIF="TestCube.gif";
- String CUBE_MATERIAL="TestCube.mtl";
-
- templateURI = webClient1.getTemplateURI(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID());
- //start alterning template
- webClient1.putGeometryStream(templateURI, new FileInputStream("src/com/ogoglio/persist/resources/TestCube.obj"), 0);
- webClient1.putTemplateSupportFile(templateURI, new FileInputStream("src/com/ogoglio/persist/resources/TestCube.mtl"), CUBE_MATERIAL);
- webClient1.putTemplateSupportFile(templateURI, new FileInputStream("src/com/ogoglio/persist/resources/TestCube.gif"), CUBE_GIF);
- webClient1.updateTemplateScript(newTemplateDoc.getTemplateID(), StreamUtils.readInput(new FileInputStream("src/com/ogoglio/persist/resources/TestCube.js")));
- //end altering template by changing its support files
+ private void checkGeomAndResourceStreamsOfTemplate(WebAPIClient webClient1, String ownerUsername, long templateID) throws IOException {
+ InputStream stream = webClient1.getTemplateGeometryStream(ownerUsername, templateID, 0);
+ assertNotNull(stream);
+ consume(stream);
- //get a new version of the template document reflecting updated files
- baseDoc = webClient1.getTemplateDocument(newTemplateDoc.getTemplateID());
- //make sure the sequence right above didn't take more than 1 sec
- verifyLastChangedTimes(baseDoc.getScriptModifiedTime(),baseDoc.getGeometryModifiedTime(0),1000, false, false);
- verifyLastChangedTimes(baseDoc.getScriptModifiedTime(),baseDoc.getSupportFileModifiedTime(CUBE_GIF),1000, false, false);
- verifyLastChangedTimes(baseDoc.getScriptModifiedTime(),baseDoc.getSupportFileModifiedTime(CUBE_MATERIAL),1000, false, false);
-
+ //get a material file for the same template
+ stream = webClient1.getTemplateResourceStream(ownerUsername, templateID, "TestCube.mtl");
+ assertNotNull(stream);
+ consume(stream);
+
+ assertTrue(webClient1.deleteTemplateGeometryStream(ownerUsername, templateID, 0));
+ try {
+ webClient1.getTemplateGeometryStream(ownerUsername, templateID, 0);
+ fail("Shouldn't be able to get a deleted stream!");
+ } catch (IOException e) {
+ //can't get the stream because we just deleted it
+ assertTrue(e.getMessage().indexOf("404") != -1); //very weak test
+ }
+
+ webClient1.uploadTemplateGeometryStream(ownerUsername, templateID, 0, new FileInputStream("src/com/ogoglio/persist/resources/TestCylinder.obj"));
+ }
+
+ private void checkPageManipulation(WebAPIClient webClient1, ThingDocument someThing, SpaceDocument spaceDoc) throws IOException {
+ //no pages, right? ... hasn't this thing already been destroyed?
+ PageDocument[] pages = webClient1.getPageDocuments(spaceDoc.getSpaceID(), someThing.getThingID());
+ assertEquals(0, pages.length);
+
+ //make a new page
+ PageDocument pageDoc = webClient1.createPage(spaceDoc.getSpaceID(), someThing.getThingID(), 1, 1, "text/plain");
+ assertNotNull(pageDoc);
+
+ //set the pages text and make sure we can read it back properly
+ String pageText = "This is a test of the emergency broadcast system. This is only a test.";
+ webClient1.setPageContents(spaceDoc.getSpaceID(), someThing.getThingID(), pageDoc.getPageID(), pageText);
+ InputStream pageStream = webClient1.getPageContents(spaceDoc.getSpaceID(), someThing.getThingID(), pageDoc.getPageID());
+ assertNotNull(pageStream);
+ String fetchedPageText = StreamUtils.readInput(pageStream);
+ assertEquals(pageText + " didn't match " + fetchedPageText, pageText, fetchedPageText);
+ //reset page text
+ pageText = "Hi ho";
+ webClient1.setPageContents(spaceDoc.getSpaceID(), someThing.getThingID(), pageDoc.getPageID(), pageText);
+ pageStream = webClient1.getPageContents(spaceDoc.getSpaceID(), someThing.getThingID(), pageDoc.getPageID());
+ assertNotNull(pageStream);
+ fetchedPageText = StreamUtils.readInput(pageStream);
+ assertEquals(pageText, fetchedPageText);
+ pageDoc.setX(10);
+ pageDoc.setY(20);
+ pageDoc.setZ(30);
+ PageDocument updatedPageDoc = webClient1.updatePage(spaceDoc.getSpaceID(), someThing.getThingID(), pageDoc);
+ assertTrue(10 == updatedPageDoc.getX());
+ assertTrue(20 == updatedPageDoc.getY());
+ assertTrue(30 == updatedPageDoc.getZ());
+ pages = webClient1.getPageDocuments(spaceDoc.getSpaceID(), someThing.getThingID());
+ assertEquals(1, pages.length);
+ assertTrue(webClient1.deletePage(spaceDoc.getSpaceID(), someThing.getThingID(), pageDoc.getPageID()));
+ pages = webClient1.getPageDocuments(spaceDoc.getSpaceID(), someThing.getThingID());
+ assertEquals(0, pages.length);
+ }
+
+ private ThingDocument[] checkTemplateGeomMaterialsAndPossessions(WebAPIClient webClient1, TemplateDocument newTemplateDoc, SpaceDocument spaceDocument) throws IOException, FileNotFoundException {
+ URI templateURI;
+ TemplateDocument baseDoc, afterCylDoc;
+ String CUBE_GIF = "TestCube.gif";
+ String CUBE_MATERIAL = "TestCube.mtl";
+
+ webClient1.uploadTemplateGeometryStream(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), 0, new FileInputStream("src/com/ogoglio/persist/resources/TestCube.obj"));
+ webClient1.uploadTemplateResourceStream(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), CUBE_MATERIAL, new FileInputStream("src/com/ogoglio/persist/resources/TestCube.mtl"));
+ webClient1.uploadTemplateResourceStream(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), CUBE_GIF, new FileInputStream("src/com/ogoglio/persist/resources/TestCube.gif"));
+ webClient1.updateTemplateScript(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), StreamUtils.readInput(new FileInputStream("src/com/ogoglio/persist/resources/TestCube.js")));
+
+ baseDoc = webClient1.getTemplateDocument(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID());
+ //make sure the sequence right above didn't take more than 1 sec
+ verifyLastChangedTimes(baseDoc.getScriptModifiedTime(), baseDoc.getGeometryModifiedTime(0), 1000, false, false);
+ verifyLastChangedTimes(baseDoc.getScriptModifiedTime(), baseDoc.getSupportFileModifiedTime(CUBE_GIF), 1000, false, false);
+ verifyLastChangedTimes(baseDoc.getScriptModifiedTime(), baseDoc.getSupportFileModifiedTime(CUBE_MATERIAL), 1000, false, false);
+
//check that there are no things
- ThingDocument[] thingDocs = webClient1.getThingDocuments();
+ ThingDocument[] thingDocs = webClient1.getThingDocuments(spaceDocument.getSpaceID());
assertEquals(0, thingDocs.length);
-
- PossessionDocument[] possDocs = webClient1.getPossessionDocuments(USERNAME1);
- int previousLength =possDocs.length;
+
+ PossessionDocument[] possDocs = webClient1.getPossessionDocuments();
+ int previousLength = possDocs.length;
//create new possession
webClient1.createPossession(newTemplateDoc.getTemplateID());
- possDocs = webClient1.getPossessionDocuments(USERNAME1);
+ possDocs = webClient1.getPossessionDocuments();
PossessionDocument newPossession = possDocs[previousLength];
assertEquals(possDocs.length - 1, previousLength);
@@ -550,151 +533,144 @@
assertNotNull(possDoc);
try {
Thread.sleep(1000); //IES: there was a sleep(100) here before and I didn't know why
- //IES: but I needed a sleep(1000) for my tests that I can do
- //IES: time checks properly so I just changed it
+ //IES: but I needed a sleep(1000) for my tests that I can do
+ //IES: time checks properly so I just changed it
} catch (Exception e) {
}
-
+
//change the geometry to the cylinder
- webClient1.putGeometryStream(templateURI, new FileInputStream("src/com/ogoglio/persist/resources/TestCylinder.obj"), 0);
- afterCylDoc = webClient1.getTemplateDocument(newTemplateDoc.getTemplateID());
+ webClient1.uploadTemplateGeometryStream(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), 0, new FileInputStream("src/com/ogoglio/persist/resources/TestCylinder.obj"));
+ afterCylDoc = webClient1.getTemplateDocument(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID());
verifyLastChangedTimes(baseDoc.getGeometryModifiedTime(0), afterCylDoc.getGeometryModifiedTime(0), 1000, true, false);
-
+
//what's in the space? should be one thing, the one we added above
- thingDocs = webClient1.getThingDocuments();
+ thingDocs = webClient1.getThingDocuments(spaceDocument.getSpaceID());
assertEquals(1, thingDocs.length);
assertEquals(thingDocs[0].getTemplateID(), newPossession.getTemplateID());
assertEquals(thingDocs[0].getTemplateID(), possDoc.getTemplateID());
assertEquals(spaceDocument.getSpaceID(), possDoc.getSpaceID());
assertEquals(thingDocs[0].getThingID(), possDoc.getThingID());
- URI thingeeURI = WebAPIUtil.appendToURI(webClient1.getThingURI(thingDocs[0].getThingID()),
- "?reload=true");
- DecoratedInputStream dis = WebAPIClient.performGET(thingeeURI, webClient1.getAuthCookie(),true);
+
+ ThingDocument reloadedThingDoc = webClient1.reloadThing(spaceDocument.getSpaceID(), thingDocs[0].getThingID());
- byte[] b=new byte[(int)dis.getLength()];
- dis.read(b);
try {
- Thread.sleep(2000);
+ Thread.sleep(2000);
} catch (Exception e) {
-
+
}
+
//we done reload better check again
- thingDocs = webClient1.getThingDocuments();
+ thingDocs = webClient1.getThingDocuments(spaceDocument.getSpaceID());
//get shape doc for our one thing: it should be a thing
ShapeDocument[] shapeDocs = thingDocs[0].getShapeDocuments();
assertEquals(1, shapeDocs.length);
assertEquals("Cylinder", shapeDocs[0].getShapeName());
-
return thingDocs;
-}
+ }
- private void verifyLastChangedTimes(String time1, String time2, int tooLong, boolean reallyTooShort, boolean displayDiff) throws IOException {
- long first,second;
- try {
- first = TemplateSupportFileRecord.fmt.parse(time1).getTime();
- second = TemplateSupportFileRecord.fmt.parse(time2).getTime();
- if (displayDiff) {
- System.out.println("Diff In Time:"+(second-first)+" compared to "+tooLong);
- }
- if (reallyTooShort) {
- if (second-first<tooLong) {
- fail("Not enough time between times given");
- }
- } else {
- if (second-first>tooLong) {
- fail("More than allowed difference between times given");
- }
- }
- } catch (ParseException e) {
- fail("can't parse the date in modified time(s):"+time1+","+time2);
- }
- }
+ private void verifyLastChangedTimes(String time1, String time2, int tooLong, boolean reallyTooShort, boolean displayDiff) throws IOException {
+ long first, second;
+ try {
+ first = TemplateSupportFileRecord.fmt.parse(time1).getTime();
+ second = TemplateSupportFileRecord.fmt.parse(time2).getTime();
+ if (displayDiff) {
+ System.out.println("Diff In Time:" + (second - first) + " compared to " + tooLong);
+ }
+ if (reallyTooShort) {
+ if (second - first < tooLong) {
+ fail("Not enough time between times given");
+ }
+ } else {
+ if (second - first > tooLong) {
+ fail("More than allowed difference between times given");
+ }
+ }
+ } catch (ParseException e) {
+ fail("can't parse the date in modified time(s):" + time1 + "," + time2);
+ }
+ }
- private void checkDeletingSpaceDestroysThings(WebAPIClient webClient1, String possOwner) throws IOException
- {
+ private void checkDeletingSpaceDestroysThings(long spaceID, WebAPIClient webClient1, String possOwner) throws IOException {
PossessionDocument[] possDocs;
int previousLength;
- long NO_TARGET=-827;
+ long NO_TARGET = -827;
//destroy the space then check the possessions have been reset to reflect deleting
//the space
- long toBeKilledID=webClient1.getSpaceDocument(false).getSpaceID(),targetID=NO_TARGET;
- possDocs = webClient1.getPossessionDocuments(possOwner);
- for (int i=0; i<possDocs.length;++i) {
- if (possDocs[i].getSpaceID()==toBeKilledID) {
- targetID=possDocs[i].getPossessionID();
- break;
- }
+ long toBeKilledID = webClient1.getSpaceDocument(spaceID, false).getSpaceID(), targetID = NO_TARGET;
+ possDocs = webClient1.getPossessionDocuments();
+ for (int i = 0; i < possDocs.length; ++i) {
+ if (possDocs[i].getSpaceID() == toBeKilledID) {
+ targetID = possDocs[i].getPossessionID();
+ break;
+ }
}
- assertFalse(targetID==NO_TARGET);
-
- assertTrue(webClient1.deleteSpace());
- possDocs = webClient1.getPossessionDocuments(possOwner);
-
- //IES: this loop seems to be much safer than always assuming that the index of the possession
- //IES: that might be destroyed is some constant (like 0)
- for (int i=0; i<possDocs.length;++i) {
- if (possDocs[i].getPossessionID()==targetID) {
+ assertFalse(targetID == NO_TARGET);
+
+ assertTrue(webClient1.deleteSpace(spaceID));
+ possDocs = webClient1.getPossessionDocuments();
+
+ for (int i = 0; i < possDocs.length; ++i) {
+ if (possDocs[i].getPossessionID() == targetID) {
assertEquals(PossessionRecord.NO_SPACE, possDocs[i].getSpaceID());
assertEquals(PossessionRecord.NO_THING, possDocs[i].getThingID());
- break;
- }
+ break;
+ }
}
previousLength = possDocs.length;
webClient1.deletePossession(targetID);
- possDocs = webClient1.getPossessionDocuments(possOwner);
- assertEquals(previousLength -1, possDocs.length);
+ possDocs = webClient1.getPossessionDocuments();
+ assertEquals(previousLength - 1, possDocs.length);
+ }
- }
- private TemplateDocument checkTemplateScriptAPI(WebAPIClient webClient1) throws IOException {
- String templateName = "Red Hot Pants";
- TemplateDocument newTemplateDoc = webClient1.createTemplate(templateName);
- assertEquals(templateName, newTemplateDoc.getDisplayName());
+ private TemplateDocument checkTemplateScriptAPI(WebAPIClient webClient1) throws IOException {
+ String templateName = "Red Hot Pants";
+ TemplateDocument newTemplateDoc = webClient1.createTemplate(templateName);
+ assertEquals(templateName, newTemplateDoc.getDisplayName());
- templateName = "Test Cube";
- newTemplateDoc.setDisplayName(templateName);
- newTemplateDoc = webClient1.updateTemplate(newTemplateDoc);
- assertEquals(templateName, newTemplateDoc.getDisplayName());
+ templateName = "Test Cube";
+ newTemplateDoc.setDisplayName(templateName);
+ newTemplateDoc = webClient1.updateTemplate(newTemplateDoc);
+ assertEquals(templateName, newTemplateDoc.getDisplayName());
- assertEquals(false,newTemplateDoc.hasScriptFile());
- assertNull(newTemplateDoc.getScriptModifiedTime());
-
- String script = "var i = 1; return ++i;";
- webClient1.updateTemplateScript(newTemplateDoc.getTemplateID(), script);
- assertEquals(script, webClient1.getTemplateScript(newTemplateDoc.getTemplateID()));
- //refresh the document because we changed a field in the object
- newTemplateDoc = webClient1.getTemplateDocument(newTemplateDoc.getTemplateID());
- assertEquals(true,newTemplateDoc.hasScriptFile());
+ assertEquals(false, newTemplateDoc.hasScriptFile());
+ assertNull(newTemplateDoc.getScriptModifiedTime());
- //check that modified time is working
- int interval=2000;
- try {
- Thread.sleep(interval);
- } catch (InterruptedException e) {
- //won't happen
- }
- //change the script
- script = "var i = 2; return i+5;";
- webClient1.updateTemplateScript(newTemplateDoc.getTemplateID(), script);
+ String script = "var i = 1; return ++i;";
+ webClient1.updateTemplateScript(webClient1.getAuthenticator().getUsername(), newTemplateDoc.getTemplateID(), script);
+ assertEquals(script, webClient1.getTemplateScript(webClient1.getAuthenticator().getUsername(), newTemplateDoc.getTemplateID()));
+ //refresh the document because we changed a field in the object
+ newTemplateDoc = webClient1.getTemplateDocument(webClient1.getAuthenticator().getUsername(), newTemplateDoc.getTemplateID());
+ assertEquals(true, newTemplateDoc.hasScriptFile());
- TemplateDocument updatedTemplateDoc = webClient1.getTemplateDocument(newTemplateDoc.getTemplateID());
+ //check that modified time is working
+ int interval = 2000;
+ try {
+ Thread.sleep(interval);
+ } catch (InterruptedException e) {
+ //won't happen
+ }
+ //change the script
+ script = "var i = 2; return i+5;";
+ webClient1.updateTemplateScript(webClient1.getAuthenticator().getUsername(), newTemplateDoc.getTemplateID(), script);
- //at least the interval should have passed
- verifyLastChangedTimes(newTemplateDoc.getScriptModifiedTime(),
- updatedTemplateDoc.getScriptModifiedTime(), 2000, true, false);
+ TemplateDocument updatedTemplateDoc = webClient1.getTemplateDocument(webClient1.getAuthenticator().getUsername(), newTemplateDoc.getTemplateID());
- webClient1.updateTemplateScript(newTemplateDoc.getTemplateID(), null);
- assertEquals(null, webClient1.getTemplateScript(newTemplateDoc.getTemplateID()));
+ //at least the interval should have passed
+ verifyLastChangedTimes(newTemplateDoc.getScriptModifiedTime(), updatedTemplateDoc.getScriptModifiedTime(), 2000, true, false);
- newTemplateDoc = webClient1.getTemplateDocument(newTemplateDoc.getTemplateID());
- assertEquals(false,newTemplateDoc.hasScriptFile());
- return newTemplateDoc;
- }
+ webClient1.updateTemplateScript(webClient1.getAuthenticator().getUsername(), newTemplateDoc.getTemplateID(), null);
+ assertEquals(null, webClient1.getTemplateScript(webClient1.getAuthenticator().getUsername(), newTemplateDoc.getTemplateID()));
+ newTemplateDoc = webClient1.getTemplateDocument(webClient1.getAuthenticator().getUsername(), newTemplateDoc.getTemplateID());
+ assertEquals(false, newTemplateDoc.hasScriptFile());
+ return newTemplateDoc;
+ }
+
private void consume(InputStream input) throws IOException {
byte[] buffer = new byte[2048];
while (input.read(buffer) != -1) {
Modified: spaces/trunk/src/com/ogoglio/client/MultiuserTests.java
===================================================================
--- spaces/trunk/src/com/ogoglio/client/MultiuserTests.java 2007-08-02 17:49:59 UTC (rev 233)
+++ spaces/trunk/src/com/ogoglio/client/MultiuserTests.java 2007-08-04 00:19:57 UTC (rev 234)
@@ -15,7 +15,7 @@
public class MultiuserTests {
- private URI spaceURI = null;
+ private long spaceID = -1;
private URI serviceURI = null;
@@ -23,13 +23,13 @@
Random random = new Random();
- public MultiuserTests(URI spaceURI, URI serviceURI) {
- this.spaceURI = spaceURI;
+ public MultiuserTests(long spaceID, URI serviceURI) {
+ this.spaceID = spaceID;
this.serviceURI = serviceURI;
}
public synchronized void addRobot(Transform3D startPosition, boolean wander) throws IOException {
- UserRobot robot = new UserRobot(spaceURI, serviceURI);
+ UserRobot robot = new UserRobot(spaceID, serviceURI);
robot.teleport(startPosition);
robots.add(robot);
if (wander) {
@@ -56,14 +56,12 @@
WanderThread wanderThread = null;
- public UserRobot(URI spaceURI, URI serviceURI) throws IOException {
- String guestCookie = WebAPIClient.requestGuestCookie(serviceURI);
+ public UserRobot(long spaceID, URI serviceURI) throws IOException {
+ String guestCookie = "guestRobot_Banger_Test_" + System.currentTimeMillis() + "_" + random.nextInt();
if (guestCookie == null) {
throw new IOException("Could not get a guest cookie");
}
- spaceClient = new SpaceClient(spaceURI, serviceURI, guestCookie, this);
- //renderer = new J3DRenderer(spaceClient, true);
- //renderer.startRenderer();
+ spaceClient = new SpaceClient(spaceID, serviceURI, guestCookie, this);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
@@ -169,9 +167,9 @@
//String serviceURI = "http://127.0.0.1:8080/og/";
//String spaceURI = "http://127.0.0.1:8080/og/space/1/";
- URI spaceURI = new URI(args[0]);
+ ...
[truncated message content] |