diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2006-08-30 21:12:19 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2006-08-30 21:12:19 +0000 |
commit | ee3de4cabc79aabf21197b24af6d233e5e4a50a4 (patch) | |
tree | 277f9999002bb59481cd74fa7b1c5ad92aa1c484 /src/test/java/com/amazon/carbonado/stored | |
parent | 81533df33e37d45f00b32b5e75aa2917354e204e (diff) |
Added small set of tests that don't need an actual Repository instance.
Diffstat (limited to 'src/test/java/com/amazon/carbonado/stored')
4 files changed, 355 insertions, 0 deletions
diff --git a/src/test/java/com/amazon/carbonado/stored/Address.java b/src/test/java/com/amazon/carbonado/stored/Address.java new file mode 100644 index 0000000..3043e54 --- /dev/null +++ b/src/test/java/com/amazon/carbonado/stored/Address.java @@ -0,0 +1,64 @@ +/*
+ * Copyright 2006 Amazon Technologies, Inc. or its affiliates.
+ * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks
+ * of Amazon Technologies, Inc. or its affiliates. All rights reserved.
+ *
+ * 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.amazon.carbonado.stored;
+
+import com.amazon.carbonado.Alias;
+import com.amazon.carbonado.Independent;
+import com.amazon.carbonado.Storable;
+import com.amazon.carbonado.Nullable;
+import com.amazon.carbonado.PrimaryKey;
+import com.amazon.carbonado.Sequence;
+
+/**
+ *
+ *
+ * @author Brian S O'Neill
+ */
+@Alias("TEST_ADDRESS")
+@PrimaryKey("addressID")
+public interface Address extends Storable {
+ @Sequence("TEST_ADDRESS_ID_SEQ")
+ long getAddressID();
+ void setAddressID(long id);
+
+ String getAddressLine1();
+ void setAddressLine1(String value);
+
+ @Nullable
+ String getAddressLine2();
+ void setAddressLine2(String value);
+
+ String getAddressCity();
+ void setAddressCity(String value);
+
+ @Nullable
+ String getAddressState();
+ void setAddressState(String value);
+
+ String getAddressZip();
+ void setAddressZip(String value);
+
+ String getAddressCountry();
+ void setAddressCountry(String value);
+
+ @Independent
+ String getCustomData();
+ void setCustomData(String str);
+}
+
diff --git a/src/test/java/com/amazon/carbonado/stored/Dummy.java b/src/test/java/com/amazon/carbonado/stored/Dummy.java new file mode 100644 index 0000000..980c718 --- /dev/null +++ b/src/test/java/com/amazon/carbonado/stored/Dummy.java @@ -0,0 +1,145 @@ +/*
+ * Copyright 2006 Amazon Technologies, Inc. or its affiliates.
+ * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks
+ * of Amazon Technologies, Inc. or its affiliates. All rights reserved.
+ *
+ * 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.amazon.carbonado.stored;
+
+import com.amazon.carbonado.*;
+
+/**
+ * Implements all the Storable methods, but each throws
+ * UnsupportedOperationException. Methods defined in Object are left alone.
+ *
+ * @author Brian S O'Neill
+ */
+public class Dummy implements Storable {
+ public void load() throws FetchException {
+ throw error();
+ }
+
+ public boolean tryLoad() throws FetchException {
+ throw error();
+ }
+
+ public void insert() throws PersistException {
+ throw error();
+ }
+
+ public boolean tryInsert() throws PersistException {
+ throw error();
+ }
+
+ public void update() throws PersistException {
+ throw error();
+ }
+
+ public boolean tryUpdate() throws PersistException {
+ throw error();
+ }
+
+ public void delete() throws PersistException {
+ throw error();
+ }
+
+ public boolean tryDelete() throws PersistException {
+ throw error();
+ }
+
+ public Storage storage() {
+ throw error();
+ }
+
+ public Class storableType() {
+ throw error();
+ }
+
+ public void copyAllProperties(Storable target) {
+ throw error();
+ }
+
+ public void copyPrimaryKeyProperties(Storable target) {
+ throw error();
+ }
+
+ public void copyVersionProperty(Storable target) {
+ throw error();
+ }
+
+ public void copyUnequalProperties(Storable target) {
+ throw error();
+ }
+
+ public void copyDirtyProperties(Storable target) {
+ throw error();
+ }
+
+ public boolean hasDirtyProperties() {
+ throw error();
+ }
+
+ public void markPropertiesClean() {
+ throw error();
+ }
+
+ public void markAllPropertiesClean() {
+ throw error();
+ }
+
+ public void markPropertiesDirty() {
+ throw error();
+ }
+
+ public void markAllPropertiesDirty() {
+ throw error();
+ }
+
+ public boolean isPropertyUninitialized(String propertyName) {
+ throw error();
+ }
+
+ public boolean isPropertyDirty(String propertyName) {
+ throw error();
+ }
+
+ public boolean isPropertyClean(String propertyName) {
+ throw error();
+ }
+
+ public boolean isPropertySupported(String propertyName) {
+ throw error();
+ }
+
+ public Storable copy() {
+ throw error();
+ }
+
+ public boolean equalPrimaryKeys(Object obj) {
+ throw error();
+ }
+
+ public boolean equalProperties(Object obj) {
+ throw error();
+ }
+
+ public String toStringKeyOnly() {
+ throw error();
+ }
+
+ protected UnsupportedOperationException error() {
+ return new UnsupportedOperationException();
+ }
+}
diff --git a/src/test/java/com/amazon/carbonado/stored/StorableTestBasic.java b/src/test/java/com/amazon/carbonado/stored/StorableTestBasic.java new file mode 100644 index 0000000..0857518 --- /dev/null +++ b/src/test/java/com/amazon/carbonado/stored/StorableTestBasic.java @@ -0,0 +1,114 @@ +/*
+ * Copyright 2006 Amazon Technologies, Inc. or its affiliates.
+ * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks
+ * of Amazon Technologies, Inc. or its affiliates. All rights reserved.
+ *
+ * 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.amazon.carbonado.stored;
+
+import java.util.Random;
+
+import org.joda.time.DateTime;
+
+import com.amazon.carbonado.Nullable;
+import com.amazon.carbonado.Storable;
+import com.amazon.carbonado.PrimaryKey;
+import com.amazon.carbonado.Storage;
+import com.amazon.carbonado.Repository;
+import com.amazon.carbonado.RepositoryException;
+
+/**
+ * StorableTestBasic
+ *
+ * @author Don Schneider
+ */
+@PrimaryKey("id")
+public abstract class StorableTestBasic implements Storable {
+ public abstract int getId();
+ public abstract void setId(int id);
+
+ // Basic coverage of the primitives
+ public abstract String getStringProp();
+ public abstract void setStringProp(String aStringThing);
+
+ public abstract int getIntProp();
+ public abstract void setIntProp(int anInt);
+
+ public abstract long getLongProp();
+ public abstract void setLongProp(long aLong);
+
+ public abstract double getDoubleProp();
+ public abstract void setDoubleProp(double aDouble);
+
+ @Nullable
+ public abstract DateTime getDate();
+ public abstract void setDate(DateTime aDate);
+
+ public void initPrimaryKeyProperties() {
+ setId(10);
+ }
+
+ public void initBasicProperties() {
+ setStringProp("foo");
+ setIntProp(10);
+ setLongProp(120);
+ setDoubleProp(1.2);
+ }
+
+ public void initPropertiesRandomly(int id) {
+ setId(id);
+
+ Random random = new Random(1000);
+
+ setIntProp(random.nextInt());
+ setLongProp(random.nextLong());
+ setDoubleProp(random.nextDouble());
+ setStringProp("imaString_" + id % 10);
+ }
+
+ public void initPropertiesPredictably(int id) {
+ setId(id);
+
+ setIntProp(id*10);
+ setLongProp(id*10);
+ setDoubleProp(id/2.0);
+ setStringProp("string-" + id % 100);
+ }
+
+ public static void insertBunches(Repository repository, int count)
+ throws RepositoryException
+ {
+ insertBunches(repository, count, 0, true);
+ }
+
+
+ public static void insertBunches(Repository repository,
+ int count, int startId,
+ boolean doRandom)
+ throws RepositoryException
+ {
+ Storage<StorableTestBasic> storage = repository.storageFor(StorableTestBasic.class);
+ StorableTestBasic s;
+
+ for (int i = 0; i < count; i ++) {
+ s = storage.prepare();
+ if (doRandom) {
+ s.initPropertiesRandomly(i);
+ } else {
+ s.initPropertiesPredictably(i+startId);
+ }
+ s.insert();
+ }
+ }
+}
diff --git a/src/test/java/com/amazon/carbonado/stored/StorableTestMinimal.java b/src/test/java/com/amazon/carbonado/stored/StorableTestMinimal.java new file mode 100644 index 0000000..a1aae70 --- /dev/null +++ b/src/test/java/com/amazon/carbonado/stored/StorableTestMinimal.java @@ -0,0 +1,32 @@ +/*
+ * Copyright 2006 Amazon Technologies, Inc. or its affiliates.
+ * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks
+ * of Amazon Technologies, Inc. or its affiliates. All rights reserved.
+ *
+ * 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.amazon.carbonado.stored;
+
+import com.amazon.carbonado.Storable;
+import com.amazon.carbonado.PrimaryKey;
+
+/**
+ * StorableTestBasic
+ *
+ * @author Don Schneider
+ */
+@PrimaryKey("id")
+public interface StorableTestMinimal extends Storable {
+ int getId();
+ void setId(int id);
+}
|