|
From: <ian...@us...> - 2007-08-27 16:01:32
|
Revision: 263
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=263&view=rev
Author: iansmith
Date: 2007-08-26 15:52:45 -0700 (Sun, 26 Aug 2007)
Log Message:
-----------
First version that has integration tests factored out.
Added Paths:
-----------
maven/trunk/ogoglio-integration-test/.classpath
maven/trunk/ogoglio-integration-test/.project
maven/trunk/ogoglio-integration-test/.settings/
maven/trunk/ogoglio-integration-test/.settings/org.eclipse.jdt.core.prefs
maven/trunk/ogoglio-integration-test/pom.xml
maven/trunk/ogoglio-integration-test/src/
maven/trunk/ogoglio-integration-test/src/main/
maven/trunk/ogoglio-integration-test/src/main/java/
maven/trunk/ogoglio-integration-test/src/main/resources/
maven/trunk/ogoglio-integration-test/src/test/
maven/trunk/ogoglio-integration-test/src/test/java/
maven/trunk/ogoglio-integration-test/src/test/java/com/
maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/
maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/
maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/
maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/ClientTest.java
maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/SpaceDuplicatorTest.java
maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/WebAPITest.java
maven/trunk/ogoglio-integration-test/src/test/resources/
maven/trunk/ogoglio-integration-test/src/test/resources/sample-art3d/
maven/trunk/ogoglio-integration-test/src/test/resources/sample-art3d/TestCube.gif
maven/trunk/ogoglio-integration-test/src/test/resources/sample-art3d/TestCube.js
maven/trunk/ogoglio-integration-test/src/test/resources/sample-art3d/TestCube.mtl
Property Changed:
----------------
maven/trunk/ogoglio-integration-test/
Property changes on: maven/trunk/ogoglio-integration-test
___________________________________________________________________
Name: svn:ignore
+ target
Added: maven/trunk/ogoglio-integration-test/.classpath
===================================================================
--- maven/trunk/ogoglio-integration-test/.classpath (rev 0)
+++ maven/trunk/ogoglio-integration-test/.classpath 2007-08-26 22:52:45 UTC (rev 263)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/test/java"/>
+ <classpathentry excluding="**" kind="src" output="src/main/resources" path="src/main/resources"/>
+ <classpathentry excluding="**" kind="src" output="src/test/resources" path="src/test/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Added: maven/trunk/ogoglio-integration-test/.project
===================================================================
--- maven/trunk/ogoglio-integration-test/.project (rev 0)
+++ maven/trunk/ogoglio-integration-test/.project 2007-08-26 22:52:45 UTC (rev 263)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>ogoglio-integration-test</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
Added: maven/trunk/ogoglio-integration-test/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- maven/trunk/ogoglio-integration-test/.settings/org.eclipse.jdt.core.prefs (rev 0)
+++ maven/trunk/ogoglio-integration-test/.settings/org.eclipse.jdt.core.prefs 2007-08-26 22:52:45 UTC (rev 263)
@@ -0,0 +1,5 @@
+#Sat Aug 25 14:50:50 PDT 2007
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.source=1.3
Added: maven/trunk/ogoglio-integration-test/pom.xml
===================================================================
--- maven/trunk/ogoglio-integration-test/pom.xml (rev 0)
+++ maven/trunk/ogoglio-integration-test/pom.xml 2007-08-26 22:52:45 UTC (rev 263)
@@ -0,0 +1,195 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>ogoglio-integration-test</groupId>
+ <artifactId>ogoglio-integration-test</artifactId>
+ <version>0.0.1</version>
+ <packaging>pom</packaging>
+
+ <build>
+ <plugins>
+ <!-- COMPILER needed b/c POM packaging by default doesn't build the tests -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ </configuration>
+ <executions>
+ <execution>
+ <id>build integration tests</id>
+ <goals>
+ <goal>testCompile</goal>
+ </goals>
+ <phase>test-compile</phase>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- RESOURCES needed b/c POM packaging by default doesn't copy test resources -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <configuration>
+ </configuration>
+ <executions>
+ <execution>
+ <id>build integration tests</id>
+ <goals>
+ <goal>testResources</goal>
+ </goals>
+ <phase>process-test-resources</phase>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- SUREFIRE WITH INTEGRATION TEST -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skip>true</skip><!-- this is critical to avoid running unit tests, sets default value for skip -->
+ </configuration>
+ <executions>
+ <execution>
+ <id>over the wire tests</id>
+ <phase>integration-test</phase>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <excludes>
+ <exclude>
+ **/SpaceDuplicatorTest.java
+ </exclude>
+ </excludes>
+ <skip>false</skip><!-- don't skip integration tests -->
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <!-- CARGO FOR STOP/START THE SERVER -->
+ <plugin>
+ <groupId>org.codehaus.cargo</groupId>
+ <artifactId>cargo-maven2-plugin</artifactId>
+ <version>0.3-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <id>get-up</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>start</goal>
+ </goals>
+ <configuration>
+ <wait>false</wait>
+ </configuration>
+ </execution>
+
+ <execution>
+ <id>get-down</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>stop</goal>
+ </goals>
+ <configuration>
+ <wait>true</wait>
+ </configuration>
+ </execution>
+ <execution>
+ <!-- get rid of leftover tomcat's if they exist -->
+ <id>kill if exists</id>
+ <phase>test</phase> <!-- just needs to be before integration test -->
+ <goals>
+ <goal>stop</goal>
+ </goals>
+ <configuration>
+ <wait>false</wait>
+ </configuration>
+ </execution>
+ </executions>
+
+ <!-- CARGO CONFIG -->
+ <configuration>
+ <!-- tomcat 5.5 running on the same machine...-->
+ <container>
+ <containerId>tomcat5x</containerId>
+ <home>${cargo.tomcat5x.home}</home>
+ <type>installed</type>
+ <log>
+ ${project.build.directory}/tomcat5x.log
+ </log>
+ <output>
+ ${project.build.directory}/tomcat5x.out
+ </output>
+ <logLevel>debug</logLevel>
+ </container>
+
+ <!-- tomcat configuration -->
+ <configuration>
+ <home>${project.build.directory}/tomcat5x</home>
+ <properties>
+ <cargo.servlet.port>
+ 8080
+ </cargo.servlet.port>
+ <cargo.logging>high</cargo.logging>
+ </properties>
+ <!-- our app to deploy -->
+ <deployables>
+ <deployable>
+
+ <groupId>com.ogoglio</groupId>
+ <artifactId>ogoglio-server</artifactId>
+ <type>war</type>
+
+ <properties>
+ <context>ogoglio-server</context>
+ </properties>
+
+ </deployable>
+ </deployables>
+
+ </configuration>
+ </configuration>
+
+ </plugin>
+
+ </plugins>
+ </build>
+ <!-- -->
+ <!-- PLUGIN REPOS -->
+ <!-- -->
+ <pluginRepositories>
+ <!-- CARGO -->
+ <pluginRepository>
+ <id>codehaus snapshot repository</id>
+ <url>http://snapshots.repository.codehaus.org/</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ </pluginRepository>
+ </pluginRepositories>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ </dependency>
+ <!-- -->
+ <!-- OGOGLIO DEPENDENCIES-->
+ <!-- -->
+ <dependency>
+ <groupId>com.ogoglio</groupId>
+ <artifactId>ogoglio-server</artifactId>
+ <version>0.0.1</version>
+ <type>war</type>
+ </dependency>
+ <dependency>
+ <groupId>com.ogoglio</groupId>
+ <artifactId>ogoglio-common</artifactId>
+ <version>0.0.1</version>
+ </dependency>
+
+ </dependencies>
+</project>
+
Added: maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/ClientTest.java
===================================================================
--- maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/ClientTest.java (rev 0)
+++ maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/ClientTest.java 2007-08-26 22:52:45 UTC (rev 263)
@@ -0,0 +1,881 @@
+/* Copyright 2007 Transmutable (http://transmutable.com/)
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License. */
+package com.ogoglio.client.test;
+
+import java.awt.Shape;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.text.ParseException;
+import java.util.Date;
+import java.util.Random;
+import java.util.Vector;
+
+import javax.media.j3d.Transform3D;
+
+import junit.framework.TestCase;
+import nanoxml.XMLElement;
+
+import com.ogoglio.client.SpaceClient;
+import com.ogoglio.client.WebAPIAuthenticator;
+import com.ogoglio.client.WebAPIAuthenticatorFactory;
+import com.ogoglio.client.WebAPIClient;
+import com.ogoglio.client.WebAPIClientWire;
+import com.ogoglio.client.WebAPIDescriptor;
+import com.ogoglio.client.WebAPIGuestAuthenticator;
+import com.ogoglio.client.model.Door;
+import com.ogoglio.client.model.Page;
+import com.ogoglio.client.model.Space;
+import com.ogoglio.client.model.SplinePath;
+import com.ogoglio.client.model.Thing;
+import com.ogoglio.client.model.User;
+import com.ogoglio.util.StreamUtils;
+import com.ogoglio.util.WebConstants;
+import com.ogoglio.xml.AccountDocument;
+import com.ogoglio.xml.AuthDocument;
+import com.ogoglio.xml.BodyDocument;
+import com.ogoglio.xml.DoorDocument;
+import com.ogoglio.xml.PageDocument;
+import com.ogoglio.xml.PossessionDocument;
+import com.ogoglio.xml.ShapeDocument;
+import com.ogoglio.xml.SpaceDocument;
+import com.ogoglio.xml.SpaceMemberDocument;
+import com.ogoglio.xml.TemplateDocument;
+import com.ogoglio.xml.TemplateSupportFileDocument;
+import com.ogoglio.xml.ThingDocument;
+import com.ogoglio.xml.UserDocument;
+import com.sun.org.apache.xalan.internal.xsltc.compiler.Template;
+
+public class ClientTest extends TestCase {
+
+ public static final String PASSWORD1 = "1234";
+
+ public static final String USERNAME1 = "susan";
+
+ public static final String USERNAME2 = "tina";
+
+ public static final String COOKIE1 = "tr5w95nxracntj";
+
+ public static final String COOKIE2 = "trMoonUnitZappa";
+
+ URI linkURI1 = null;
+
+ 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://example.com/");
+ wire1 = new WebAPIClientWire();
+ descriptor1 = new WebAPIDescriptor(serviceURI1);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ public void tearDown() {
+
+ }
+
+ public void testWebAdmin() {
+ try {
+ WebAPIAuthenticator adminAuthenticator =
+ new WebAPIAuthenticatorFactory().authenticate(wire1, descriptor1,
+ //"library","fart98121");
+ WebConstants.getBootstrapUsername(), WebConstants.getBootstrapUserPW());
+ assertNotNull("got null auth cookie", adminAuthenticator.getAuthCookie());
+
+ WebAPIClient adminWebClient = new WebAPIClient(descriptor1, adminAuthenticator, wire1);
+ try {
+ adminWebClient.createAccount(USERNAME1, AccountDocument.ACCOUNT_LEVEL_ADVANCED, "Susan", "Examplar", "http://example.com/susan/", "su...@ex...", PASSWORD1);
+ adminWebClient.createAccount(USERNAME2, AccountDocument.ACCOUNT_LEVEL_ADVANCED, "Tina", "Examplar", "http://example.com/tina/", "ti...@ex...", PASSWORD1);
+ } catch (IOException e) {
+ //may already exist
+ }
+
+ 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 = basicWebClient.createAccount(failedUsername, AccountDocument.ACCOUNT_LEVEL_BASIC, "Shouldnt", "Exist", null, failedUsername + "@example.com", "1234");
+ if (doc != null) {
+ fail();
+ }
+ } catch (Exception e) {
+ //this should happen, because basic accounts can't create new accounts
+ }
+
+ String username = "testuser" + Math.abs(new Random().nextLong());
+ adminWebClient.createAccount(username, AccountDocument.ACCOUNT_LEVEL_BASIC, "Test", "Sims", null, username + "@example.com", "1234");
+
+ AccountDocument accountDoc = adminWebClient.getAccountDocument(username);
+ assertNotNull(accountDoc);
+ assertEquals("Test", accountDoc.getFirstName());
+ assertEquals("Sims", accountDoc.getLastName());
+
+ Date frozenDate = new Date(System.currentTimeMillis() + 1000000);
+ accountDoc.setFrozenUntil(frozenDate);
+ accountDoc.setAccountLevel(AccountDocument.ACCOUNT_LEVEL_ADMIN);
+ adminWebClient.updateAccount(accountDoc);
+ accountDoc = adminWebClient.getAccountDocument(username);
+ assertTrue(frozenDate.getTime() - accountDoc.getFrozenUntil().getTime() < 1000);
+ assertEquals(AccountDocument.ACCOUNT_LEVEL_ADMIN, accountDoc.getAccountLevel());
+ accountDoc.setFrozenUntil(new Date(1000));
+ accountDoc.setAccountLevel(AccountDocument.ACCOUNT_LEVEL_BASIC);
+ accountDoc=adminWebClient.updateAccount(accountDoc);
+ AccountDocument ac2= adminWebClient.getAccountDocument(username);
+ assertNull(accountDoc.getFrozenUntil());
+ assertNull(ac2.getFrozenUntil());
+ assertEquals(AccountDocument.ACCOUNT_LEVEL_BASIC, accountDoc.getAccountLevel());
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Might want to check to make sure database exists and library account exists...");
+ }
+ }
+
+ public void testWebAPIClient() {
+ SpaceClient spaceClient1 = null;
+ SpaceClient guestSpaceClient1 = null;
+
+ try {
+ //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);
+
+ WebAPIAuthenticator auth2 = new WebAPIAuthenticator(wire1, descriptor1, USERNAME2, PASSWORD1);
+ WebAPIClient webClient2 = new WebAPIClient(descriptor1, auth2, wire1);
+
+ checkNoConnectionToSpaceWithoutAuth(spaceDocument.getSpaceID());
+
+ checkAuthDoc(auth1, auth2);
+
+ spaceDocument = checkSpaceSeaLevel(webClient1, spaceDocument);
+
+ checkSettings(spaceDocument.getSpaceID(), webClient1);
+
+ checkBody(webClient1, auth1);
+
+ checkSpaceMembership(spaceDocument.getSpaceID(), webClient1);
+
+ checkSpaceAuthWithMembership(auth2, webClient2, webClient1, spaceDocument);
+
+ TemplateDocument newTemplateDoc = checkTemplateScriptAPI(webClient1);
+ ThingDocument[] thingDocs = checkTemplateGeomMaterialsAndPossessions(webClient1, newTemplateDoc, spaceDocument);
+
+
+ //IES CHECK: after messing around above, verify we are are ok
+ 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(auth1, webClient1, spaceDocument);
+
+ checkGeomAndResourceStreamsOfTemplate(webClient1, auth1.getUsername(), lastTemplateID);
+
+ authThenBuildSpaceClient(spaceDocument.getSpaceID(), auth1);
+
+ checkGeometryAvailableForSpace(webClient1, thingDocs, spaceClient1.getSpace());
+
+ guestSpaceClient1 = checkGuestCookieOperation(spaceDocument.getSpaceID(), webClient1, WebConstants.GUEST_COOKIE_PREFIX + "Test_Suite_Guest");
+ checkDeletingSpaceDestroysThings(spaceDocument.getSpaceID(), webClient1, USERNAME1);
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail();
+ } finally {
+ if (spaceClient1 != null) {
+ spaceClient1.cleanup();
+ }
+ if (guestSpaceClient1 != null) {
+ guestSpaceClient1.cleanup();
+ }
+ }
+
+ }
+
+ 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(WebAPIAuthenticator auth1, WebAPIAuthenticator auth2) {
+ AuthDocument authDoc = getAuthDoc(null);
+ assertFalse(authDoc.isAuthenticated());
+ assertNull(authDoc.getUsername());
+
+ authDoc = getAuthDoc("BadBadCookie");
+ assertFalse(authDoc.isAuthenticated());
+ assertNull(authDoc.getUsername());
+
+ 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(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());
+
+ ownerClient.removeSpaceMember(spaceDocument.getSpaceID(), memberAuth.getUsername());
+ membershipDocs = memberClient.getUsersSpaceMemberships();
+ assertEquals(0, membershipDocs.length);
+ }
+
+ private void checkSpaceMembership(long spaceID, 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());
+ }
+
+ 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";
+ Object v = webClient1.getSpaceSetting(spaceID, key1);
+
+ assertNull(v);
+
+ webClient1.putSpaceSetting(spaceID, key1, value1);
+ 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.getSpaceSetting(spaceID, key2));
+ webClient1.putSpaceSetting(spaceID, key2, value2);
+ assertEquals(value2, webClient1.getSpaceSetting(spaceID, key2));
+ assertEquals(value1, webClient1.getSpaceSetting(spaceID, key1));
+
+ webClient1.removeSpaceSetting(spaceID, key1);
+ assertNull(webClient1.getSpaceSetting(spaceID, key1));
+ webClient1.removeSpaceSetting(spaceID, key2);
+ assertNull(webClient1.getSpaceSetting(spaceID, 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 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;
+ }
+
+ private void checkNoConnectionToSpaceWithoutAuth(long spaceID) {
+ try {
+ WebAPIGuestAuthenticator guestAuth = new WebAPIGuestAuthenticator(descriptor1, WebConstants.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 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 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);
+
+ // get our possession out of the space
+ long possID = thingDocs[0].getPossessionID();
+ webClient1.removePossessionFromSpace(possID);
+ thingDocs = webClient1.getThingDocuments(space1.getSpaceID());
+ 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);
+
+ 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
+ SpaceClient guestSpaceClient1 = new SpaceClient(spaceID, 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, 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 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());
+
+ //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 checkGeomAndResourceStreamsOfTemplate(WebAPIClient webClient1, String ownerUsername, long templateID) throws IOException {
+ InputStream stream = webClient1.getTemplateGeometryStream(ownerUsername, templateID, 0);
+ assertNotNull(stream);
+ consume(stream);
+
+ //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, getClass().getResourceAsStream("/sample-art3d/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 {
+ TemplateDocument baseDoc, afterCylDoc;
+ String CUBE_GIF = "TestCube.gif";
+ String CUBE_MATERIAL = "TestCube.mtl";
+
+ Class clazz=getClass();
+ webClient1.uploadTemplateGeometryStream(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), 0, clazz.getResourceAsStream("/sample-art3d/TestCube.obj"));
+ webClient1.uploadTemplateResourceStream(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), CUBE_MATERIAL, clazz.getResourceAsStream("/sample-art3d/TestCube.mtl"));
+ webClient1.uploadTemplateResourceStream(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), CUBE_GIF, clazz.getResourceAsStream("/sample-art3d/TestCube.gif"));
+ webClient1.updateTemplateScript(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), StreamUtils.readInput(clazz.getResourceAsStream("/sample-art3d/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(spaceDocument.getSpaceID());
+ assertEquals(0, thingDocs.length);
+
+ PossessionDocument[] possDocs = webClient1.getPossessionDocuments();
+ int previousLength = possDocs.length;
+ //create new possession
+ webClient1.createPossession(newTemplateDoc.getTemplateID());
+ possDocs = webClient1.getPossessionDocuments();
+ PossessionDocument newPossession = possDocs[previousLength];
+ assertEquals(possDocs.length - 1, previousLength);
+
+ //make sure we can add poss to space
+ PossessionDocument possDoc = webClient1.addPossessionToSpace(newPossession.getPossessionID(), spaceDocument.getSpaceID());
+ 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
+ } catch (Exception e) {
+ }
+
+ //change the geometry to the cylinder
+ webClient1.uploadTemplateGeometryStream(newTemplateDoc.getOwnerUsername(), newTemplateDoc.getTemplateID(), 0, getClass().getResourceAsStream("/sample-art3d/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(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());
+
+
+ webClient1.reloadThing(spaceDocument.getSpaceID(), thingDocs[0].getThingID());
+
+ try {
+ Thread.sleep(2000);
+ } catch (Exception e) {
+
+ }
+
+ //we done reload better check again
+ 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 = TemplateSupportFileDocument.fmt.parse(time1).getTime();
+ second = TemplateSupportFileDocument.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(long spaceID, WebAPIClient webClient1, String possOwner) throws IOException {
+ PossessionDocument[] possDocs;
+ int previousLength;
+ long NO_TARGET = -827;
+
+ //destroy the space then check the possessions have been reset to reflect deleting
+ //the space
+ 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(spaceID));
+ possDocs = webClient1.getPossessionDocuments();
+
+ for (int i = 0; i < possDocs.length; ++i) {
+ if (possDocs[i].getPossessionID() == targetID) {
+ assertEquals(PossessionDocument.NO_SPACE, possDocs[i].getSpaceID());
+ assertEquals(PossessionDocument.NO_THING, possDocs[i].getThingID());
+ break;
+ }
+ }
+
+ previousLength = possDocs.length;
+ webClient1.deletePossession(targetID);
+ 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());
+
+ 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(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());
+
+ //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);
+
+ TemplateDocument updatedTemplateDoc = webClient1.getTemplateDocument(webClient1.getAuthenticator().getUsername(), newTemplateDoc.getTemplateID());
+
+ //at least the interval should have passed
+ verifyLastChangedTimes(newTemplateDoc.getScriptModifiedTime(), updatedTemplateDoc.getScriptModifiedTime(), 2000, true, false);
+
+ 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) {
+ //throw it away
+ }
+ }
+
+ private class TestSpaceClientListener implements SpaceClient.Listener {
+
+ public void disconnected() {
+ }
+
+ public void receivedChatMessage(String username, String message) {
+ }
+
+ public void receivedSpaceTransfer(URI link) {
+ }
+
+ public void receivedLink(String displayName, String link) {
+ }
+
+ public void receivedCommandFocusRequest() {
+ }
+
+ public void receivedBrowserMessage(long sourceThingID, String message) {
+ }
+
+ public void receivedContextMenuRequest(Thing thing,String shapeName, int x, int y, long nonce) {
+ }
+
+ public void receivedContextMenuData(long nonce, String errorIfAny, Vector contextMenu) {
+ }
+
+ public void contextItemChosen(Thing thing, long nonce, String id) {
+ }
+
+ }
+
+ private class TestListener implements Space.Listener {
+
+ Vector personAdds = new Vector();
+
+ Vector personRemoves = new Vector();
+
+ Vector personMotionStarts = new Vector();
+
+ Vector personMotionStops = new Vector();
+
+ Vector templateAdds = new Vector();
+
+ Vector templateRemoves = new Vector();
+
+ Vector thingAdds = new Vector();
+
+ Vector thingRemoves = new Vector();
+
+ Vector thingMotionStarts = new Vector();
+
+ Vector thingMotionStops = new Vector();
+
+ public void userAdded(User person) {
+ if (person == null) {
+ fail();
+ }
+ personAdds.add(person);
+ }
+
+ public void userRemoved(User person) {
+ if (person == null) {
+ fail();
+ }
+ personRemoves.add(person);
+ }
+
+ public void userMotionStarted(User person, SplinePath path) {
+ if (person == null)
+ fail();
+ if (path == null)
+ fail();
+ personMotionStarts.add(person);
+ personMotionStarts.add(path);
+ }
+
+ public void userMotionStopped(User person, Transform3D position) {
+ if (person == null)
+ fail();
+ if (position == null)
+ fail();
+ personMotionStops.add(person);
+ personMotionStops.add(position);
+ }
+
+ public void templateAdded(Template template) {
+ if (template == null)
+ fail();
+ templateAdds.add(template);
+ }
+
+ public void templateRemoved(Template template) {
+ if (template == null)
+ fail();
+ templateRemoves.add(template);
+ }
+
+ public void thingAdded(Thing thing) {
+ if (thing == null)
+ fail();
+ thingAdds.add(thing);
+ }
+
+ public void thingRemoved(Thing thing) {
+ if (thing == null)
+ fail();
+ thingRemoves.add(thing);
+ }
+
+ public void thingMotionStarted(Thing thing, SplinePath path) {
+ if (thing == null)
+ fail();
+ if (path == null)
+ fail();
+ thingMotionStarts.add(thing);
+ thingMotionStarts.add(path);
+ }
+
+ public void thingMotionStopped(Thing thing, Transform3D position) {
+ if (thing == null)
+ fail();
+ if (position == null)
+ fail();
+ thingMotionStops.add(thing);
+ thingMotionStops.add(position);
+ }
+
+ public void thingReloaded(Thing thing) {
+ }
+
+ public void doorMotionStarted(Door door, SplinePath path) {
+ }
+
+ public void doorMotionStopped(Door door, Transform3D position) {
+ }
+
+ public void doorAdded(Door door) {
+ }
+
+ public void doorRemoved(Door door) {
+ }
+
+ public void pageAdded(Page page) {
+ }
+
+ public void pageRemoved(Page page) {
+ }
+
+ public void pageMoved(Page page, Transform3D position) {
+ }
+
+ public void pageContentChanged(Page page) {
+ }
+
+ public void shapeMotionStarted(Shape shape, SplinePath path) {
+ }
+
+ public void shapeMotionStopped(Shape shape, Transform3D position) {
+ }
+
+ public void userAnimationStarted(User user, long animationID) {
+ }
+
+ public void shapeMotionStarted(com.ogoglio.client.model.Shape shape,
+ SplinePath path) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void shapeMotionStopped(com.ogoglio.client.model.Shape shape,
+ Transform3D position) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void templateAdded(com.ogoglio.client.model.Template template) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void templateRemoved(com.ogoglio.client.model.Template template) {
+ // TODO Auto-generated method stub
+
+ }
+
+ }
+
+}
Added: maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/SpaceDuplicatorTest.java
===================================================================
--- maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/SpaceDuplicatorTest.java (rev 0)
+++ maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/SpaceDuplicatorTest.java 2007-08-26 22:52:45 UTC (rev 263)
@@ -0,0 +1,127 @@
+package com.ogoglio.client.test;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import com.ogoglio.client.SpaceDuplicator;
+import com.ogoglio.client.WebAPIAuthenticator;
+import com.ogoglio.client.WebAPIClient;
+import com.ogoglio.client.WebAPIClientWire;
+import com.ogoglio.client.WebAPIDescriptor;
+import com.ogoglio.xml.DoorDocument;
+import com.ogoglio.xml.PositionedDocument;
+import com.ogoglio.xml.SpaceDocument;
+import com.ogoglio.xml.ThingDocument;
+
+public class SpaceDuplicatorTest extends TestCase {
+
+ long spaceID1 = -1;
+
+ long spaceID2 = -1;
+
+ URI serviceURI1 = null;
+
+ WebAPIDescriptor descriptor = null;
+
+ WebAPIAuthenticator auth = null;
+
+ WebAPIClientWire wire = null;
+
+ WebAPIClient client1 = null;
+
+ String testSettingKey = "test.setting.key";
+
+ String testSettingValue = "A Value for the Test Setting";
+
+ public void setUp() {
+ try {
+ spaceID1 = 1;
+ spaceID2 = 2;
+ serviceURI1 = new URI("http://127.0.0.1:8080/og/");
+ descriptor = new WebAPIDescriptor(serviceURI1);
+ wire = new WebAPIClientWire();
+ auth = new WebAPIAuthenticator(wire, descriptor, ClientTest.USERNAME1, ClientTest.PASSWORD1);
+
+ client1 = new WebAPIClient(descriptor, auth, wire);
+ client1.putSpaceSetting(spaceID1, testSettingKey, testSettingValue);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ public void tearDown() {
+ }
+
+ public void testBasics() {
+ try {
+ SpaceDocument originalSpaceDoc = client1.getSpaceDocument(spaceID1, false);
+ ThingDocument[] originalThingDocs = client1.getThingDocuments(spaceID1);
+ DoorDocument[] originalDoorDocs = client1.getDoorDocuments(spaceID1);
+ Map originalSettings = client1.getSpaceSettings(spaceID1);
+
+ //TODO settings transfer
+
+ SpaceDuplicator duplicator = new SpaceDuplicator(spaceID1, descriptor, auth, wire);
+ duplicator.duplicateSpace(spaceID2, true);
+
+ SpaceDocument newSpaceDoc = client1.getSpaceDocument(spaceID2, false);
+ assertEquals(originalSpaceDoc.getDisplaySea(), newSpaceDoc.getDisplaySea());
+ assertEquals(originalSpaceDoc.getSeaLevel(), newSpaceDoc.getSeaLevel(), 0.001);
+ assertEquals(originalSpaceDoc.getDisplayName(), newSpaceDoc.getDisplayName());
+ assertEquals(originalSpaceDoc.isPublished(), newSpaceDoc.isPublished());
+ assertEquals(originalSpaceDoc.getMaxGuests(), newSpaceDoc.getMaxGuests());
+ assertEquals(originalSpaceDoc.getOwnerUsername(), newSpaceDoc.getOwnerUsername());
+
+ ThingDocument[] newThingDocs = client1.getThingDocuments(spaceID2);
+ Arrays.sort(newThingDocs, new ThingDocComparator());
+ Arrays.sort(originalThingDocs, new ThingDocComparator());
+ assertEquals(originalThingDocs.length, newThingDocs.length);
+ for (int i = 0; i < originalThingDocs.length; i++) {
+ assertEquals(originalThingDocs[i].getTemplateID(), newThingDocs[i].getTemplateID());
+ assertEqualPositions(originalThingDocs[i], newThingDocs[i]);
+ }
+
+ DoorDocument[] newDoorDocs = client1.getDoorDocuments(spaceID2);
+ for (int i = 0; i < originalDoorDocs.length; i++) {
+ assertEquals(originalDoorDocs[i].getDisplayName(), newDoorDocs[i].getDisplayName());
+ assertEquals(originalDoorDocs[i].getLink(), newDoorDocs[i].getLink());
+ assertEqualPositions(originalDoorDocs[i], newDoorDocs[i]);
+ }
+
+ Map newSettings = client1.getSpaceSettings(spaceID2);
+ newSettings.equals(originalSettings);
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail("" + e);
+ }
+ }
+
+ private static class ThingDocComparator implements Comparator {
+ public int compare(Object arg0, Object arg1) {
+ ThingDocument doc1 = (ThingDocument) arg0;
+ ThingDocument doc2 = (ThingDocument) arg1;
+ long idDiff = doc1.getTemplateID() - doc2.getTemplateID();
+ if (idDiff != 0) {
+ return idDiff < 0 ? -1 : 1;
+ }
+ return doc1.getPossessionID() < doc1.getPossessionID() ? -1 : 1;
+ }
+ }
+
+ private static void assertEqualPositions(PositionedDocument doc1, PositionedDocument doc2) {
+ assertEquals(doc1.getX(), doc2.getX(), 0.001);
+ assertEquals(doc1.getY(), doc2.getY(), 0.001);
+ assertEquals(doc1.getZ(), doc2.getZ(), 0.001);
+ assertEquals(doc1.getRW(), doc2.getRW(), 0.001);
+ assertEquals(doc1.getRX(), doc2.getRX(), 0.001);
+ assertEquals(doc1.getRY(), doc2.getRY(), 0.001);
+ assertEquals(doc1.getRZ(), doc2.getRZ(), 0.001);
+ assertEquals(doc1.getScale().x, doc2.getScale().x, 0.001);
+ }
+}
Added: maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/WebAPITest.java
===================================================================
--- maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/WebAPITest.java (rev 0)
+++ maven/trunk/ogoglio-integration-test/src/test/java/com/ogoglio/client/test/WebAPITest.java 2007-08-26 22:52:45 UTC (rev 263)
@@ -0,0 +1,147 @@
+package com.ogoglio.client.test;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import com.ogoglio.client.AuthenticationFailedException;
+import com.ogoglio.client.WebAPIAuthenticator;
+import com.ogoglio.client.WebAPIAuthenticatorFactory;
+import com.ogoglio.client.WebAPIClientWire;
+import com.ogoglio.client.WebAPIDescriptor;
+import com.ogoglio.client.WebAPIGuestAuthenticator;
+import com.ogoglio.util.OgoglioSpecBase;
+import com.ogoglio.xml.AccountDocument;
+import com.ogoglio.xml.AuthDocument;
+
+public class WebAPITest extends OgoglioSpecBase {
+
+ public static final String GOOD_COOKIE = "trGoodCookie";
+
+ private static final String BAD_COOKIE = "badBacCookie";
+
+ private static final String GUEST_COOKIE = "guestMockCookie";
+
+ URI serviceURI = null;
+
+ WebAPIDescriptor descriptor = null;
+
+ WebAPIClientWire mockWire = null;
+
+ WebAPIAuthenticatorFactory mockAuthFactory = null;
+
+ AuthDocument notAuthedAuthDoc = null;
+
+ AuthDocument authedAuthDoc = null;
+
+ AccountDocument accountDoc = null;
+
+ public void setUp() {
+ try {
+ serviceURI = new URI("http://example.com/og/");
+ descriptor = new WebAPIDescriptor(serviceURI);
+
+ mockWire = (WebAPIClientWire) mock_ignoreEqualsAndToString(WebAPIClientWire.class);
+ mockAuthFactory = (WebAPIAuthenticatorFactory) mock_ignoreEqualsAndToString(WebAPIAuthenticatorFactory.class);
+
+ notAuthedAuthDoc = new AuthDocument("Ian", false);
+
+ authedAuthDoc = new AuthDocument("Ian", true);
+ accountDoc = new AccountDocument(authedAuthDoc.getUsername(), AccountDocument.ACCOUNT_LEVEL_ADVANCED, null, null, null, null, null, null, AccountDocument.NO_TIME_VALUE, null, AccountDocument.NO_TIME_VALUE, -1);
+ } catch (URISyntaxException e) {
+ fail("Bad URIL: " + e);
+ }
+ }
+
+ public void tearDown() {
+ }
+
+
+ public void testWebAPIGuestAuthenticator() {
+
+ mockAuthFactory.authenticate(descriptor, GUEST_COOKIE);
+ modify().forward();
+
+ //###################################
+ startVerification();
+
+ WebAPIGuestAuthenticator auth = mockAuthFactory.authenticate(descriptor, GUEST_COOKIE);
+ assertNotNull(auth);
+ assertEquals(GUEST_COOKIE, auth.getAuthCookie());
+ assertNotNull(auth.getUsername());
+ assertNotNull(auth.getAccountDocument(true));
+ assertNotNull(auth.getAuthDocument(true));
+ }
+
+ public void testWebAPIAuthenticatorViaCookie() throws IOException, AuthenticationFailedException {
+ //mockWire should respond to good and bad cookies with good and bad auth docs
+ mockWire.fetchAuthenticatedXML(descriptor.getMeAuthURI(), BAD_COOKIE);
+ modify().returnValue(notAuthedAuthDoc.toElement());
+ mockWire.fetchAuthenticatedXML(descriptor.getMeAuthURI(), GOOD_COOKIE);
+ modify().returnValue(authedAuthDoc.toElement());
+
+ //mockWire should respond to good account requests with a good account doc
+ mockWire.fetchAuthenticatedXML(descriptor.getAccountURI(authedAuthDoc.getUsername()), GOOD_COOKIE);
+ modify().returnValue(accountDoc.toElement());
+
+ mockAuthFactory.authenticate(mockWire, descriptor, GOOD_COOKIE);
+ modify().args(is.AS_RECORDED, is.AS_RECORDED, is.ANYTHING);
+ modify().multiplicity(expect.atMost(2));
+ modify().forward();
+
+ //for reasons I don't understand this doesn't work when running via ant
+ //so we are going to not use it for now
+ //expectThatExceptionThrown(is.instanceOf(AuthenticationFailedException.class));
+ //###################################
+ startVerification();
+
+ WebAPIAuthenticator auth = mockAuthFactory.authenticate(mockWire, descriptor, GOOD_COOKIE);
+ assertNotNull(auth);
+ assertEquals(GOOD_COOKIE, auth.getAuthCookie());
+ assertEquals(authedAuthDoc.getUsername(), auth.getUsername());
+ assertEquals(accountDoc, auth.getAccountDocument(true));
+
+ try {
+ auth = mockAuthFactory.authenticate(mockWire, descriptor, BAD_COOKIE);
+ fail("Should not be able to reach this point after bad authentication!");
+ } catch (AuthenticationFailedException e) {
+ assertThat(e, is.instanceOf(AuthenticationFailedException.class));
+ }
+ }
+
+ public void testWebAPIAuthenticatorViaUsernameAndPass() throws AuthenticationFailedException, URISyntaxException, IOException {
+ mockWire.getAuthCookieViaPost(serviceURI, "username=Ian&password=farts", "text/plain...
[truncated message content] |