Created
December 25, 2010 15:32
-
-
Save shin1ogawa/754916 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.List; | |
import org.junit.Test; | |
import org.slim3.datastore.Datastore; | |
import org.slim3.tester.AppEngineTestCase; | |
import com.google.appengine.api.datastore.Entity; | |
import com.google.appengine.api.datastore.Key; | |
import static com.google.appengine.api.datastore.Query.FilterOperator.*; | |
import static org.hamcrest.Matchers.*; | |
import static org.junit.Assert.*; | |
public class RangeScanExample extends AppEngineTestCase { | |
@Test | |
public void llapi01() { | |
Key start = Datastore.createKey("MyKind", "score00010:"); | |
Key end = Datastore.createKey("MyKind", "score00030:" + "\ufffd"); | |
List<Key> keyList = | |
Datastore.query("MyKind") | |
.filter(Entity.KEY_RESERVED_PROPERTY, GREATER_THAN_OR_EQUAL, start) | |
.filter(Entity.KEY_RESERVED_PROPERTY, LESS_THAN, end).sort("__key__") | |
.asKeyList(); | |
assertThat(keyList.size(), is(3)); | |
assertThat(keyList.get(0).getName(), endsWith(":userA")); | |
assertThat(keyList.get(1).getName(), endsWith(":userB")); | |
assertThat(keyList.get(2).getName(), endsWith(":userC")); | |
} | |
@Test | |
public void llapi02() { | |
Key start = Datastore.createKey("MyKind", "score00011:"); | |
Key end = Datastore.createKey("MyKind", "score00030:" + "\ufffd"); | |
List<Key> keyList = | |
Datastore.query("MyKind") | |
.filter(Entity.KEY_RESERVED_PROPERTY, GREATER_THAN_OR_EQUAL, start) | |
.filter(Entity.KEY_RESERVED_PROPERTY, LESS_THAN, end).sort("__key__") | |
.asKeyList(); | |
assertThat(keyList.size(), is(2)); | |
assertThat(keyList.get(0).getName(), endsWith(":userB")); | |
assertThat(keyList.get(1).getName(), endsWith(":userC")); | |
} | |
@Test | |
public void llapi03() { | |
Key start = Datastore.createKey("MyKind", "score00030:"); | |
Key end = Datastore.createKey("MyKind", "score00100:" + "\ufffd"); | |
List<Key> keyList = | |
Datastore.query("MyKind") | |
.filter(Entity.KEY_RESERVED_PROPERTY, GREATER_THAN_OR_EQUAL, start) | |
.filter(Entity.KEY_RESERVED_PROPERTY, LESS_THAN, end).sort("__key__") | |
.asKeyList(); | |
assertThat(keyList.size(), is(2)); | |
assertThat(keyList.get(0).getName(), endsWith(":userC")); | |
assertThat(keyList.get(1).getName(), endsWith(":userE")); | |
} | |
@Override | |
public void setUp() throws Exception { | |
super.setUp(); | |
Key[] keys = { | |
Datastore.createKey("MyKind", "score00010:userA"), | |
Datastore.createKey("MyKind", "score00011:userB"), | |
Datastore.createKey("MyKind", "score00030:userC"), | |
Datastore.createKey("MyKind", "score00005:userD"), | |
Datastore.createKey("MyKind", "score00100:userE"), | |
Datastore.createKey("MyKind", "score00009:userF") | |
}; | |
for (Key key : keys) { | |
Entity entity = new Entity(key); | |
Datastore.put(entity); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment