Created
June 9, 2012 11:24
-
-
Save sue445/2900611 to your computer and use it in GitHub Desktop.
Datastote#getAsMap sample
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
package net.sue445.service; | |
import static org.hamcrest.Matchers.*; | |
import static org.junit.Assert.*; | |
import java.util.Map; | |
import net.sue445.model.Slim3Model; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.slim3.datastore.Datastore; | |
import org.slim3.tester.AppEngineTestCase; | |
import com.google.appengine.api.datastore.Key; | |
public class SampleServiceTest extends AppEngineTestCase { | |
private Key key1; | |
private Key key2; | |
private Key key3; | |
@Before | |
public void setUpModels(){ | |
key1 = Datastore.createKey(Slim3Model.class, "key1"); | |
key2 = Datastore.createKey(Slim3Model.class, "key2"); | |
key3 = Datastore.createKey(Slim3Model.class, "key3"); | |
Slim3Model model1 = new Slim3Model(); | |
model1.setKey(key1); | |
Datastore.put(model1); | |
Slim3Model model2 = new Slim3Model(); | |
model2.setKey(key2); | |
Datastore.put(model2); | |
} | |
@Test | |
public void getAsMap() throws Exception { | |
// exercise | |
Map<Key, Slim3Model> actual = Datastore.getAsMap(Slim3Model.class, key1, key2, key3); | |
// assertion | |
assertThat(actual.size(), is(2)); | |
assertThat(actual, hasKey(key1)); | |
assertThat(actual.get(key1).getKey(), is(key1)); | |
assertThat(actual, hasKey(key2)); | |
assertThat(actual.get(key2).getKey(), is(key2)); | |
assertThat(actual, not(hasKey(key3))); | |
assertThat(actual.get(key3), is(nullValue())); | |
} | |
} |
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
package net.sue445.model; | |
import org.slim3.datastore.Attribute; | |
import org.slim3.datastore.Model; | |
import com.google.appengine.api.datastore.Key; | |
@Model | |
public class Slim3Model { | |
@Attribute(primaryKey=true) | |
private Key key; | |
private String prop1; | |
/** | |
* @return the key | |
*/ | |
public Key getKey() { | |
return key; | |
} | |
/** | |
* @param key the key to set | |
*/ | |
public void setKey(Key key) { | |
this.key = key; | |
} | |
/** | |
* @return the prop1 | |
*/ | |
public String getProp1() { | |
return prop1; | |
} | |
/** | |
* @param prop1 the prop1 to set | |
*/ | |
public void setProp1(String prop1) { | |
this.prop1 = prop1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment