Added tests to ValueStore, specifically DeltaValueStoreJsonImpl and RecordJsoImpl
Review at http://gwt-code-reviews.appspot.com/621801
Review by: rjrjr@google.com
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@8261 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/bikeshed/src/com/google/gwt/valuestore/client/DeltaValueStoreJsonImpl.java b/bikeshed/src/com/google/gwt/valuestore/client/DeltaValueStoreJsonImpl.java
index 57e0126..d42bcee 100644
--- a/bikeshed/src/com/google/gwt/valuestore/client/DeltaValueStoreJsonImpl.java
+++ b/bikeshed/src/com/google/gwt/valuestore/client/DeltaValueStoreJsonImpl.java
@@ -256,7 +256,10 @@
}
public Record create(String token) {
- assert !used;
+ if (used) {
+ throw new IllegalStateException(
+ "create can only be called on an un-used DeltaValueStore");
+ }
String futureId = futureIdGenerator.getFutureId();
RecordSchema<? extends Record> schema = recordToTypeMap.getType(token);
@@ -270,8 +273,7 @@
}
public void delete(Record record) {
- assert !used;
- assert record instanceof RecordImpl;
+ checkArgumentsAndState(record, "delete");
RecordImpl recordImpl = (RecordImpl) record;
RecordKey recordKey = new RecordKey(recordImpl);
WriteOperation priorOperation = operations.get(recordKey);
@@ -312,8 +314,7 @@
}
public <V> void set(Property<V> property, Record record, V value) {
- assert !used;
- assert record instanceof RecordImpl;
+ checkArgumentsAndState(record, "set");
RecordImpl recordImpl = (RecordImpl) record;
RecordKey recordKey = new RecordKey(recordImpl);
@@ -424,6 +425,17 @@
return false;
}
+ private void checkArgumentsAndState(Record record, String methodName) {
+ if (used) {
+ throw new IllegalStateException(
+ methodName + " can only be called on an un-used DeltaValueStore");
+ }
+ if (!(record instanceof RecordImpl)) {
+ throw new IllegalArgumentException(record + " + must be an instance of "
+ + RecordImpl.class);
+ }
+ }
+
private String getJsonForOperation(WriteOperation writeOperation) {
Map<RecordKey, RecordJsoImpl> recordsMap = getRecordsMap(writeOperation);
if (recordsMap.size() == 0) {
diff --git a/bikeshed/src/com/google/gwt/valuestore/shared/impl/RecordJsoImpl.java b/bikeshed/src/com/google/gwt/valuestore/shared/impl/RecordJsoImpl.java
index 8ff7638..9ed849f 100644
--- a/bikeshed/src/com/google/gwt/valuestore/shared/impl/RecordJsoImpl.java
+++ b/bikeshed/src/com/google/gwt/valuestore/shared/impl/RecordJsoImpl.java
@@ -51,10 +51,13 @@
}
public static native RecordJsoImpl fromJson(String json) /*-{
- return eval(json);
+ // TODO: clean this
+ eval("xyz=" + json);
+ return xyz;
}-*/;
- private static native RecordJsoImpl create() /*-{
+ /* Made protected, for testing */
+ protected static native RecordJsoImpl create() /*-{
return {};
}-*/;
diff --git a/bikeshed/test/com/google/gwt/valuestore/ValueStoreSuite.java b/bikeshed/test/com/google/gwt/valuestore/ValueStoreSuite.java
new file mode 100644
index 0000000..2c9d81e
--- /dev/null
+++ b/bikeshed/test/com/google/gwt/valuestore/ValueStoreSuite.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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.google.gwt.valuestore;
+
+import com.google.gwt.junit.tools.GWTTestSuite;
+import com.google.gwt.valuestore.client.DeltaValueStoreJsonImplTest;
+import com.google.gwt.valuestore.shared.impl.RecordJsoImplTest;
+
+import junit.framework.Test;
+
+/**
+ *
+ */
+public class ValueStoreSuite {
+ public static Test suite() {
+ GWTTestSuite suite = new GWTTestSuite(
+ "Test suite for all valuestore code.");
+ suite.addTestSuite(DeltaValueStoreJsonImplTest.class);
+ suite.addTestSuite(RecordJsoImplTest.class);
+ return suite;
+ }
+}
diff --git a/bikeshed/test/com/google/gwt/valuestore/ValueStoreTest.gwt.xml b/bikeshed/test/com/google/gwt/valuestore/ValueStoreTest.gwt.xml
new file mode 100644
index 0000000..97b83ce
--- /dev/null
+++ b/bikeshed/test/com/google/gwt/valuestore/ValueStoreTest.gwt.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.0.1//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.0.1/distro-source/core/src/gwt-module.dtd">
+<!--
+ Copyright 2010 Google Inc.
+
+ 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.
+-->
+<module>
+ <inherits name='com.google.gwt.valuestore.ValueStore'/>
+ <!-- use this old inefficient JSON library just for the time being, replace soon -->
+ <inherits name='com.google.gwt.json.JSON'/>
+</module>
diff --git a/bikeshed/test/com/google/gwt/valuestore/client/DeltaValueStoreJsonImplTest.java b/bikeshed/test/com/google/gwt/valuestore/client/DeltaValueStoreJsonImplTest.java
index cf159e6..e766120 100644
--- a/bikeshed/test/com/google/gwt/valuestore/client/DeltaValueStoreJsonImplTest.java
+++ b/bikeshed/test/com/google/gwt/valuestore/client/DeltaValueStoreJsonImplTest.java
@@ -15,21 +15,169 @@
*/
package com.google.gwt.valuestore.client;
+import com.google.gwt.json.client.JSONArray;
+import com.google.gwt.json.client.JSONObject;
+import com.google.gwt.json.client.JSONParser;
import com.google.gwt.junit.client.GWTTestCase;
+import com.google.gwt.valuestore.shared.DeltaValueStore;
+import com.google.gwt.valuestore.shared.Record;
+import com.google.gwt.valuestore.shared.SimpleFooRecord;
+import com.google.gwt.valuestore.shared.ValueStore;
+import com.google.gwt.valuestore.shared.WriteOperation;
+import com.google.gwt.valuestore.shared.impl.RecordImpl;
+import com.google.gwt.valuestore.shared.impl.RecordJsoImpl;
+import com.google.gwt.valuestore.shared.impl.RecordSchema;
+import com.google.gwt.valuestore.shared.impl.RecordToTypeMap;
+import com.google.gwt.valuestore.shared.impl.SimpleFooRecordImpl;
+
+import java.util.Date;
/**
* Tests for {@link DeltaValueStoreJsonImpl}.
*/
public class DeltaValueStoreJsonImplTest extends GWTTestCase {
-
- public String getModuleName() {
- return "com.google.gwt.valuestore.ValueStore";
+
+ /*
+ * sub-classed it here so that the protected constructor of {@link RecordImpl}
+ * can remain as such.
+ */
+ private class MyRecordImpl extends RecordImpl {
+
+ protected MyRecordImpl(RecordJsoImpl record) {
+ super(record);
+ }
}
-
- public void testValidation() {
- ValueStoreJsonImpl valueStore = new ValueStoreJsonImpl(null, null);
+
+ ValueStoreJsonImpl valueStore = null;
+ RecordJsoImpl jso = null;
+
+ public String getModuleName() {
+ return "com.google.gwt.valuestore.ValueStoreTest";
+ }
+
+ @Override
+ public void gwtSetUp() {
+ valueStore = new ValueStoreJsonImpl(null, new RecordToTypeMap() {
+ public RecordSchema<? extends Record> getType(String token) {
+ if (token.equals(SimpleFooRecordImpl.TOKEN)) {
+ return SimpleFooRecordImpl.SCHEMA;
+ }
+ throw new IllegalArgumentException("Unknown token " + token);
+ }
+
+ });
+
+ // add a record
+ jso = RecordJsoImpl.fromJson("{}");
+ jso.set(SimpleFooRecord.id, "42");
+ jso.set(SimpleFooRecord.version, 1);
+ jso.set(SimpleFooRecord.userName, "bovik");
+ jso.set(SimpleFooRecord.password, "bovik");
+ jso.set(SimpleFooRecord.intId, 4);
+ jso.set(SimpleFooRecord.created, new Date());
+ jso.setSchema(SimpleFooRecordImpl.SCHEMA);
+ valueStore.setRecord(jso);
+ }
+
+ public void testCreate() {
DeltaValueStoreJsonImpl deltaValueStore = valueStore.spawnDeltaView();
-
+ Record created = deltaValueStore.create(SimpleFooRecordImpl.TOKEN);
+ assertNotNull(created.getId());
+ assertNotNull(created.getVersion());
+
+ assertTrue(deltaValueStore.isChanged());
+ testAndGetChangeRecord(deltaValueStore.toJson(), WriteOperation.CREATE);
+ }
+
+ public void testCreateDelete() {
+ DeltaValueStoreJsonImpl deltaValueStore = valueStore.spawnDeltaView();
+ Record created = deltaValueStore.create(SimpleFooRecordImpl.TOKEN);
+ assertTrue(deltaValueStore.isChanged());
+ deltaValueStore.delete(created);
+ assertFalse(deltaValueStore.isChanged());
+
+ String jsonString = deltaValueStore.toJson();
+ assertEquals("{}", jsonString);
+ }
+
+ public void testCreateUpdate() {
+ DeltaValueStoreJsonImpl deltaValueStore = valueStore.spawnDeltaView();
+ Record created = deltaValueStore.create(SimpleFooRecordImpl.TOKEN);
+ assertTrue(deltaValueStore.isChanged());
+ deltaValueStore.set(SimpleFooRecord.userName, created, "harry");
+ assertTrue(deltaValueStore.isChanged());
+ JSONObject changeRecord = testAndGetChangeRecord(deltaValueStore.toJson(),
+ WriteOperation.CREATE);
+ changeRecord.get(SimpleFooRecord.userName.getName());
+ }
+
+ public void testDelete() {
+ DeltaValueStoreJsonImpl deltaValueStore = valueStore.spawnDeltaView();
+ deltaValueStore.delete(new MyRecordImpl(jso));
+ assertTrue(deltaValueStore.isChanged());
+ testAndGetChangeRecord(deltaValueStore.toJson(), WriteOperation.DELETE);
+ }
+
+ public void testDeleteUpdate() {
+ DeltaValueStoreJsonImpl deltaValueStore = valueStore.spawnDeltaView();
+ deltaValueStore.delete(new MyRecordImpl(jso));
+ assertTrue(deltaValueStore.isChanged());
+
+ // update after a delete nullifies the delete.
+ deltaValueStore.set(SimpleFooRecord.userName, new MyRecordImpl(jso),
+ "harry");
+ assertTrue(deltaValueStore.isChanged());
+ JSONObject changeRecord = testAndGetChangeRecord(deltaValueStore.toJson(),
+ WriteOperation.UPDATE);
+ changeRecord.get(SimpleFooRecord.userName.getName());
+ }
+
+ public void testOperationAfterJson() {
+ DeltaValueStoreJsonImpl deltaValueStore = valueStore.spawnDeltaView();
+ deltaValueStore.delete(new MyRecordImpl(jso));
+ assertTrue(deltaValueStore.isChanged());
+
+ deltaValueStore.toJson();
+
+ try {
+ deltaValueStore.set(SimpleFooRecord.userName, new MyRecordImpl(jso),
+ "harry");
+ fail("Modifying DeltaValueStore after calling toJson should throw a RuntimeException");
+ } catch (RuntimeException ex) {
+ // expected.
+ }
+
+ deltaValueStore.clearUsed();
+ deltaValueStore.set(SimpleFooRecord.userName, new MyRecordImpl(jso),
+ "harry");
+ }
+
+ public void testUpdate() {
+ DeltaValueStoreJsonImpl deltaValueStore = valueStore.spawnDeltaView();
+ deltaValueStore.set(SimpleFooRecord.userName, new MyRecordImpl(jso),
+ "harry");
+ assertTrue(deltaValueStore.isChanged());
+ JSONObject changeRecord = testAndGetChangeRecord(deltaValueStore.toJson(),
+ WriteOperation.UPDATE);
+ changeRecord.get(SimpleFooRecord.userName.getName());
+ }
+
+ public void testUpdateDelete() {
+ DeltaValueStoreJsonImpl deltaValueStore = valueStore.spawnDeltaView();
+ deltaValueStore.set(SimpleFooRecord.userName, new MyRecordImpl(jso),
+ "harry");
+ assertTrue(deltaValueStore.isChanged());
+
+ // delete after an update nullifies the delete.
+ deltaValueStore.delete(new MyRecordImpl(jso));
+ assertTrue(deltaValueStore.isChanged());
+ testAndGetChangeRecord(deltaValueStore.toJson(), WriteOperation.DELETE);
+ }
+
+ public void testValidation() {
+ ValueStore dummyValueStore = new ValueStoreJsonImpl(null, null);
+ DeltaValueStore deltaValueStore = dummyValueStore.spawnDeltaView();
+
try {
deltaValueStore.addValidation();
fail("Should throw an UnsupportedOperationException");
@@ -37,4 +185,29 @@
// expected
}
}
+
+ private JSONObject testAndGetChangeRecord(String jsonString,
+ WriteOperation currentWriteOperation) {
+ JSONObject jsonObject = (JSONObject) JSONParser.parse(jsonString);
+ for (WriteOperation writeOperation : WriteOperation.values()) {
+ if (writeOperation != currentWriteOperation) {
+ assertFalse(jsonObject.containsKey(writeOperation.name()));
+ } else {
+ assertTrue(jsonObject.containsKey(writeOperation.name()));
+ }
+ }
+
+ JSONArray writeOperationArray = jsonObject.get(currentWriteOperation.name()).isArray();
+ assertEquals(1, writeOperationArray.size());
+
+ JSONObject recordWithName = writeOperationArray.get(0).isObject();
+ assertEquals(1, recordWithName.size());
+ assertTrue(recordWithName.containsKey(SimpleFooRecordImpl.TOKEN));
+
+ JSONObject record = recordWithName.get(SimpleFooRecordImpl.TOKEN).isObject();
+ assertTrue(record.containsKey("id"));
+ assertTrue(record.containsKey("version"));
+
+ return record;
+ }
}
diff --git a/bikeshed/test/com/google/gwt/valuestore/shared/SimpleFooRecord.java b/bikeshed/test/com/google/gwt/valuestore/shared/SimpleFooRecord.java
new file mode 100644
index 0000000..c9b459d
--- /dev/null
+++ b/bikeshed/test/com/google/gwt/valuestore/shared/SimpleFooRecord.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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.google.gwt.valuestore.shared;
+
+import java.util.Date;
+
+/**
+ * A simple entity used for testing. Has an int field and date field. Add other
+ * data types as their support gets built in.
+ */
+public interface SimpleFooRecord extends Record {
+
+ String TOKEN = "SimpleFooRecord";
+
+ Property<String> userName = new Property<String>("userName", "User Name",
+ String.class);
+ Property<String> password = new Property<String>("password", "Password",
+ String.class);
+ Property<Integer> intId = new Property<Integer>("intId", Integer.class);
+ Property<Date> created = new Property<Date>("created", Date.class);
+
+ Date getCreated();
+
+ Integer getIntId();
+
+ String getPassword();
+
+ String getUserName();
+}
\ No newline at end of file
diff --git a/bikeshed/test/com/google/gwt/valuestore/shared/impl/RecordJsoImplTest.java b/bikeshed/test/com/google/gwt/valuestore/shared/impl/RecordJsoImplTest.java
new file mode 100644
index 0000000..680dab3
--- /dev/null
+++ b/bikeshed/test/com/google/gwt/valuestore/shared/impl/RecordJsoImplTest.java
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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.google.gwt.valuestore.shared.impl;
+
+import com.google.gwt.core.client.JsArray;
+import com.google.gwt.junit.client.GWTTestCase;
+import com.google.gwt.valuestore.shared.SimpleFooRecord;
+
+import java.util.Date;
+
+/**
+ * Tests for {@link RecordJsoImpl}.
+ */
+public class RecordJsoImplTest extends GWTTestCase {
+
+ private static final String EMPTY_JSON = "{}";
+ private static final String ID_VERSION_JSON = "{\"id\":\"42\",\"version\":1}";
+ private static final String ID_VERSION_JSON2 = "{\"id\":\"43\",\"version\":1}";
+ private static final String ALL_PROPERTIES_JSON = "{\"id\":\"42\",\"version\":1,\"userName\":\"bovik\",\"password\":\"bovik\",\"intId\":4,\"created\":400}";
+
+ private static final boolean SCHEMA_ABSENT = false;
+ private static final boolean SCHEMA_PRESENT = true;
+
+ @Override
+ public String getModuleName() {
+ return "com.google.gwt.valuestore.ValueStoreTest";
+ }
+
+ public void testEmptyCopy() {
+ RecordJsoImpl emptyCopy = RecordJsoImpl.emptyCopy(new RecordImpl(getPopulatedJso()));
+ testMinimalJso(emptyCopy, SCHEMA_PRESENT);
+ }
+
+ public void testFromJson() {
+ testEmptyJso(RecordJsoImpl.fromJson(EMPTY_JSON), SCHEMA_ABSENT);
+ testMinimalJso(RecordJsoImpl.fromJson(ID_VERSION_JSON), SCHEMA_ABSENT);
+ testPopulatedJso(RecordJsoImpl.fromJson(ALL_PROPERTIES_JSON), SCHEMA_ABSENT);
+ }
+
+ public void testFromJsonArray() {
+ String jsonString = "[" + ID_VERSION_JSON + "," + ID_VERSION_JSON2 + "]";
+ JsArray<RecordJsoImpl> jsArray = RecordJsoImpl.arrayFromJson(jsonString);
+ assertEquals(2, jsArray.length());
+ }
+
+ public void testIsEmpty() {
+ try {
+ getEmptyJso().isEmpty();
+ fail("A Runtime Exception should be thrown because schema is not defined");
+ } catch (RuntimeException ex) {
+ // NullPointerException in dev mode, JavaScriptException in prod mode
+ // expected because schema is not defined.
+ }
+ assertTrue(getMinimalJso().isEmpty());
+ assertFalse(getPopulatedJso().isEmpty());
+ }
+
+ public void testSet() {
+ RecordJsoImpl jso = getMinimalJso();
+ jso.set(SimpleFooRecord.userName, "bovik");
+ jso.set(SimpleFooRecord.password, "bovik");
+ jso.set(SimpleFooRecord.intId, 4);
+ jso.set(SimpleFooRecord.created, new Date(400));
+ testPopulatedJso(jso, SCHEMA_PRESENT);
+ }
+
+ public void testToJson() {
+ assertEquals(ID_VERSION_JSON, getMinimalJso().toJson());
+ }
+
+ public void testToJsonIdVersion() {
+ assertEquals(ID_VERSION_JSON, getPopulatedJso().toJsonIdVersion());
+ assertEquals(ID_VERSION_JSON, getMinimalJso().toJsonIdVersion());
+ }
+
+ private RecordJsoImpl getEmptyJso() {
+ return RecordJsoImpl.create();
+ }
+
+ private RecordJsoImpl getMinimalJso() {
+ return RecordJsoImpl.create("42", 1, SimpleFooRecordImpl.SCHEMA);
+ }
+
+ private RecordJsoImpl getPopulatedJso() {
+ RecordJsoImpl jso = getMinimalJso();
+ jso.set(SimpleFooRecord.userName, "bovik");
+ jso.set(SimpleFooRecord.password, "bovik");
+ jso.set(SimpleFooRecord.intId, 4);
+ jso.set(SimpleFooRecord.created, new Date(400));
+ return jso;
+ }
+
+ private void testEmptyJso(RecordJsoImpl jso, boolean schemaPresent) {
+ assertFalse(jso.isDefined(SimpleFooRecord.id.getName()));
+ assertFalse(jso.isDefined(SimpleFooRecord.version.getName()));
+ assertEquals("{}", jso.toJson());
+ testSchema(jso, schemaPresent);
+ }
+
+ private void testMinimalJso(RecordJsoImpl jso, boolean schemaPresent) {
+ for (String property : new String[] {"id", "version"}) {
+ assertTrue(jso.isDefined(property));
+ }
+ for (String property : new String[] {
+ "created", "intId", "userName", "password"}) {
+ assertFalse(jso.isDefined(property));
+ assertNull(jso.get(property));
+ }
+ assertEquals("42", jso.getId());
+ assertEquals(new Integer(1), jso.getVersion());
+ testSchema(jso, schemaPresent);
+ }
+
+ private void testPopulatedJso(RecordJsoImpl jso, boolean schemaPresent) {
+ for (String property : new String[] {"id", "version", "created", "intId", "userName", "password"}) {
+ assertTrue(jso.isDefined(property));
+ }
+ assertEquals("42", jso.getId());
+ assertEquals(new Integer(1), jso.getVersion());
+ assertEquals("bovik", jso.get(SimpleFooRecord.userName));
+ assertEquals("bovik", jso.get(SimpleFooRecord.password));
+ assertEquals(new Integer(4), jso.get(SimpleFooRecord.intId));
+ assertEquals(new Date(400), jso.get(SimpleFooRecord.created));
+ testSchema(jso, schemaPresent);
+ }
+
+ private void testSchema(RecordJsoImpl jso, boolean schemaPresent) {
+ if (schemaPresent) {
+ assertEquals(SimpleFooRecordImpl.SCHEMA, jso.getSchema());
+ } else {
+ assertNull(jso.getSchema());
+ }
+ }
+
+}
diff --git a/bikeshed/test/com/google/gwt/valuestore/shared/impl/SimpleFooRecordImpl.java b/bikeshed/test/com/google/gwt/valuestore/shared/impl/SimpleFooRecordImpl.java
new file mode 100644
index 0000000..122b485
--- /dev/null
+++ b/bikeshed/test/com/google/gwt/valuestore/shared/impl/SimpleFooRecordImpl.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * 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.google.gwt.valuestore.shared.impl;
+
+import com.google.gwt.valuestore.shared.Property;
+import com.google.gwt.valuestore.shared.Record;
+import com.google.gwt.valuestore.shared.RecordChangedEvent;
+import com.google.gwt.valuestore.shared.SimpleFooRecord;
+import com.google.gwt.valuestore.shared.WriteOperation;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * The actual implementation of {@link SimpleFooRecord}, which is normally
+ * generated.
+ *
+ * TODO: Use the generator here.
+ */
+public class SimpleFooRecordImpl extends RecordImpl implements SimpleFooRecord {
+
+ /**
+ * The Schema class.
+ */
+ public static class MySchema extends RecordSchema<SimpleFooRecordImpl> {
+ private final Set<Property<?>> allProperties;
+ {
+ Set<Property<?>> set = new HashSet<Property<?>>();
+ set.addAll(super.allProperties());
+ set.add(userName);
+ set.add(password);
+ set.add(intId);
+ set.add(created);
+ allProperties = Collections.unmodifiableSet(set);
+ }
+
+ public Set<Property<?>> allProperties() {
+ return allProperties;
+ }
+
+ @Override
+ public SimpleFooRecordImpl create(RecordJsoImpl jso) {
+ return new SimpleFooRecordImpl(jso);
+ }
+
+ @Override
+ public RecordChangedEvent<?, ?> createChangeEvent(Record record,
+ WriteOperation writeOperation) {
+ // ignore
+ return null;
+ }
+
+ public String getToken() {
+ return SimpleFooRecord.TOKEN; // special field
+ }
+ }
+
+ public static final RecordSchema<SimpleFooRecordImpl> SCHEMA = new MySchema();
+
+ private SimpleFooRecordImpl(RecordJsoImpl jso) {
+ super(jso);
+ }
+
+ public java.util.Date getCreated() {
+ return get(created);
+ }
+
+ public java.lang.Integer getIntId() {
+ return get(intId);
+ }
+
+ public java.lang.String getPassword() {
+ return get(password);
+ }
+
+ public java.lang.String getUserName() {
+ return get(userName);
+ }
+
+}