diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/java/com/amazon/carbonado/layout/TestLayout.java | 78 | ||||
| -rw-r--r-- | src/test/java/com/amazon/carbonado/stored/SomeText.java | 68 |
2 files changed, 146 insertions, 0 deletions
diff --git a/src/test/java/com/amazon/carbonado/layout/TestLayout.java b/src/test/java/com/amazon/carbonado/layout/TestLayout.java index 44559b0..3ef47d6 100644 --- a/src/test/java/com/amazon/carbonado/layout/TestLayout.java +++ b/src/test/java/com/amazon/carbonado/layout/TestLayout.java @@ -32,9 +32,11 @@ import org.cojen.classfile.MethodInfo; import org.cojen.classfile.Modifiers;
import org.cojen.classfile.TypeDesc;
import org.cojen.classfile.attribute.Annotation;
+import org.cojen.classfile.constant.ConstantUTFInfo;
import org.cojen.util.ClassInjector;
+import com.amazon.carbonado.adapter.TextAdapter;
import com.amazon.carbonado.adapter.YesNoAdapter;
import com.amazon.carbonado.CorruptEncodingException;
import com.amazon.carbonado.Nullable;
@@ -51,10 +53,13 @@ import com.amazon.carbonado.info.StorablePropertyAdapter; import com.amazon.carbonado.repo.sleepycat.BDBRepositoryBuilder;
import com.amazon.carbonado.stored.FileInfo;
+import com.amazon.carbonado.stored.SomeText;
import com.amazon.carbonado.stored.StorableDateIndex;
import com.amazon.carbonado.stored.StorableTestBasic;
import com.amazon.carbonado.stored.StorableTestMinimal;
+import com.amazon.carbonado.util.AnnotationDescParser;
+
import com.amazon.carbonado.TestUtilities;
/**
@@ -184,6 +189,79 @@ public class TestLayout extends TestCase { }
}
+ public void testAdapter2() throws Exception {
+ // Run test twice: First time, records get inserted. Second time, they are loaded.
+ for (int i=0; i<2; i++) {
+ Layout layout = mFactory.layoutFor(SomeText.class);
+
+ assertEquals(SomeText.class.getName(), layout.getStorableTypeName());
+
+ List<LayoutProperty> properties = layout.getAllProperties();
+
+ assertEquals(8, properties.size());
+
+ LayoutProperty property;
+
+ int charsetCount = 0;
+ int altCharsetsCount = 0;
+
+ for (int j=1; j<=7; j++) {
+ property = properties.get(j);
+ assertEquals("text" + j, property.getPropertyName());
+ assertEquals("Ljava/lang/String;", property.getPropertyTypeDescriptor());
+ assertTrue(property.isNullable());
+ assertFalse(property.isPrimaryKeyMember());
+ assertEquals(TextAdapter.class.getName(), property.getAdapterTypeName());
+
+ String desc = property.getAdapterParams();
+ assertTrue(desc.startsWith
+ ("@Lcom/amazon/carbonado/adapter/TextAdapter;altCharsets=["));
+
+ ClassFile cf = new ClassFile("test");
+ final MethodInfo mi = cf.addMethod(Modifiers.PUBLIC_ABSTRACT, "test", null, null);
+
+ Annotation ann = new AnnotationDescParser(desc) {
+ protected Annotation buildRootAnnotation(TypeDesc rootAnnotationType) {
+ return mi.addRuntimeVisibleAnnotation(rootAnnotationType);
+ }
+ }.parse(null);
+
+ assertEquals("Lcom/amazon/carbonado/adapter/TextAdapter;",
+ ann.getTypeConstant().getValue());
+
+ Map<String, Annotation.MemberValue> mvMap = ann.getMemberValues();
+
+ if (mvMap.containsKey("charset")) {
+ charsetCount++;
+ Annotation.MemberValue mv = mvMap.get("charset");
+ assertEquals(Annotation.MEMBER_TAG_STRING, mv.getTag());
+ ConstantUTFInfo value = (ConstantUTFInfo) mv.getValue();
+ assertEquals("UTF-8", value.getValue());
+ }
+
+ if (mvMap.containsKey("altCharsets")) {
+ altCharsetsCount++;
+ Annotation.MemberValue mv = mvMap.get("altCharsets");
+ assertEquals(Annotation.MEMBER_TAG_ARRAY, mv.getTag());
+ Annotation.MemberValue[] values = (Annotation.MemberValue[]) mv.getValue();
+ for (int k=0; k<values.length; k++) {
+ Annotation.MemberValue element = values[k];
+ assertEquals(Annotation.MEMBER_TAG_STRING, element.getTag());
+ ConstantUTFInfo value = (ConstantUTFInfo) element.getValue();
+ if (k == 0) {
+ assertEquals("ASCII", value.getValue());
+ } else if (k == 1) {
+ assertEquals("UTF-16", value.getValue());
+ }
+ }
+ }
+ }
+
+ assertEquals(4, charsetCount);
+ assertTrue(altCharsetsCount >= 6);
+ }
+ }
+
public void testAddProperty() throws Exception {
for (int i=0; i<2; i++) {
{
diff --git a/src/test/java/com/amazon/carbonado/stored/SomeText.java b/src/test/java/com/amazon/carbonado/stored/SomeText.java new file mode 100644 index 0000000..99ea852 --- /dev/null +++ b/src/test/java/com/amazon/carbonado/stored/SomeText.java @@ -0,0 +1,68 @@ +/*
+ * Copyright 2008 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.*;
+import com.amazon.carbonado.adapter.*;
+
+/**
+ *
+ *
+ * @author Brian S O'Neill
+ */
+@PrimaryKey("id")
+public interface SomeText extends Storable {
+ int getId();
+ void setId(int id);
+
+ @TextAdapter(charset="UTF-8")
+ @Nullable
+ String getText1();
+ void setText1(String text);
+
+ @TextAdapter(altCharsets={}, charset="UTF-8")
+ @Nullable
+ String getText2();
+ void setText2(String text);
+
+ @TextAdapter(altCharsets={"ASCII"}, charset="UTF-8")
+ @Nullable
+ String getText3();
+ void setText3(String text);
+
+ @TextAdapter(altCharsets={"ASCII", "UTF-16"}, charset="UTF-8")
+ @Nullable
+ String getText4();
+ void setText4(String text);
+
+ @TextAdapter(altCharsets={})
+ @Nullable
+ String getText5();
+ void setText5(String text);
+
+ @TextAdapter(altCharsets="ASCII")
+ @Nullable
+ String getText6();
+ void setText6(String text);
+
+ @TextAdapter(altCharsets={"ASCII", "UTF-16"})
+ @Nullable
+ String getText7();
+ void setText7(String text);
+}
|
