81
|
1 /*package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.nodeeditor;
|
40
|
2
|
|
3 import java.nio.ByteBuffer;
|
80
|
4
|
40
|
5 import org.junit.Assert;
|
80
|
6
|
40
|
7 import fj.P;
|
|
8 import fj.P2;
|
|
9 import fj.data.List;
|
80
|
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode;
|
|
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeAttributes;
|
40
|
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableAttributes;
|
41
|
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditorError;
|
40
|
14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
|
|
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
|
|
16 import junit.framework.TestCase;
|
|
17
|
80
|
18 public abstract class EditableAttributesTest<T extends TreeNode<T>> extends TestCase
|
40
|
19 {
|
80
|
20 public abstract TreeNodeAttributes<T> instance();
|
40
|
21
|
|
22 @SuppressWarnings("unchecked")
|
|
23 public static final List<P2<String,ByteBuffer>> ENTRIES = List.list(
|
|
24 P.p("KEY1",ByteBuffer.wrap("VALUE1".getBytes())),
|
|
25 P.p("KEY2",ByteBuffer.wrap("VALUE2".getBytes())),
|
|
26 P.p("KEY3",ByteBuffer.wrap("VALUE3".getBytes()))
|
|
27 );
|
|
28
|
80
|
29 public TreeNodeAttributes<T> createTestData()
|
40
|
30 {
|
80
|
31 TreeNodeAttributes<T> instance = instance();
|
40
|
32
|
|
33 T node;
|
80
|
34 TreeNodeAttributes<T> attr = instance;
|
40
|
35 for(P2<String,ByteBuffer> entry : ENTRIES){
|
|
36 Either<Error,T> either = attr.put(entry._1(),entry._2());
|
|
37 if(either.isA()){
|
|
38 Assert.fail("error during creating the data.");
|
|
39 }
|
|
40
|
|
41 node = either.b();
|
|
42 attr = node.getAttributes();
|
|
43 }
|
|
44
|
|
45 return attr;
|
|
46 }
|
|
47
|
41
|
48 public void testPutDoesNotAcceptNullValue()
|
|
49 {
|
80
|
50 TreeNodeAttributes<T> instance = instance();
|
41
|
51
|
|
52 Either<Error,T> either = instance.put("KEY",null);
|
|
53 if(!either.isA()){
|
|
54 Assert.fail("put must returns NULL_VALUE_NOT_ALLOWED when the value was null.");
|
|
55 }
|
|
56
|
|
57 Assert.assertEquals(NodeEditorError.NULL_VALUE_NOT_ALLOWED,either.a());
|
|
58
|
|
59 either = instance.put(null,ByteBuffer.wrap("VALUE".getBytes()));
|
|
60
|
|
61 if(!either.isA()){
|
|
62 Assert.fail("put must returns NULL_VALUE_NOT_ALLOWED when the key was null.");
|
|
63 }
|
|
64
|
|
65 Assert.assertEquals(NodeEditorError.NULL_VALUE_NOT_ALLOWED,either.a());
|
|
66 }
|
|
67
|
40
|
68 public void testPut()
|
|
69 {
|
|
70 createTestData();
|
|
71 }
|
|
72
|
|
73 public void testDeleteIfKeyExsist()
|
|
74 {
|
80
|
75 TreeNodeAttributes<T> attr = createTestData();
|
40
|
76
|
|
77 for(P2<String,ByteBuffer> entry : ENTRIES){
|
|
78 Either<Error,T> either = attr.delete(entry._1());
|
|
79 if(either.isA()){
|
|
80 Assert.fail("error during deleting exist key.");
|
|
81 }
|
|
82
|
|
83 attr = either.b().getAttributes();
|
|
84 }
|
|
85 }
|
|
86
|
|
87 public static final String DUMMY_KEY = "dummy";
|
|
88
|
|
89 public void testDeleteIfKeyNotExist()
|
|
90 {
|
80
|
91 TreeNodeAttributes<T> attr = createTestData();
|
40
|
92
|
|
93 Either<Error,T> either = attr.delete(DUMMY_KEY);
|
|
94 if(!either.isA()){
|
|
95 Assert.fail("delete must returns DELETE_KEY_NOT_FOUND when the deleting invalid key.");
|
|
96 }
|
|
97 }
|
|
98 }
|
81
|
99 */ |