All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.googlecode.objectify.test.EntityTests Maven / Gradle / Ivy

Go to download

*** THIS VERSION UPLOADED FOR USE WITH CEDAR-COMMON, TO AVOID DEPENDENCIES ON GOOGLE CODE-BASED MAVEN REPOSITORIES. *** The simplest convenient interface to the Google App Engine datastore

The newest version!
/*
 * $Id: EntityTests.java 556 2010-06-30 02:16:58Z lhoriman $
 * $URL: https://objectify-appengine.googlecode.com/svn/trunk/src/com/googlecode/objectify/test/EntityTests.java $
 */

package com.googlecode.objectify.test;

import java.util.logging.Logger;

import org.testng.annotations.Test;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.test.entity.Apple;
import com.googlecode.objectify.test.entity.Banana;
import com.googlecode.objectify.test.entity.HolderOfString;
import com.googlecode.objectify.test.entity.HolderOfStringAndLong;

/**
 * Tests of basic entity manipulation.
 *
 * @author Jeff Schnitzer 
 */
public class EntityTests extends TestBase
{
	/** */
	@SuppressWarnings("unused")
	private static Logger log = Logger.getLogger(EntityTests.class.getName());

	/** */
	@Test
	public void testApple() throws Exception
	{
		Objectify ofy = this.fact.begin();
		Apple a = new Apple(Apple.COLOR, Apple.TASTE);
		Key aKey = ofy.put(a);
		Apple a2 = ofy.get(aKey);
		assert a2.getColor().equals(a.getColor()) : "Colors were different after stored/retrieved";
		assert a2.getSize().equals(a.getSize()) : "Sizes were different after stored/retrieved";
		assert a2.getTaste().equals(a.getTaste()) : "Tastes were different after stored/retrieved";
	}
	/** */
	@Test
	public void testBanana() throws Exception
	{
		Objectify ofy = this.fact.begin();
		Banana b = new Banana(Banana.COLOR, Banana.TASTE);
		Key bKey = ofy.put(b);
		Banana b2 = ofy.get(bKey);
		assert b2.getColor().equals(b.getColor()) : "Colors were different after stored/retrieved";
		assert b2.getShape().equals(b.getShape()) : "Shapes were different after stored/retrieved";
		assert b2.getTaste().equals(b.getTaste()) : "Tastes were different after stored/retrieved";
	}

	/** */
	@Test
	public void testStringHolder() throws Exception
	{
		Objectify ofy = this.fact.begin();
		String s = "my secret";
		HolderOfString hos = new HolderOfString(s);
		Key hosKey = ofy.put(hos);
		HolderOfString hos2 = ofy.get(hosKey);
		
		assert hos.getThing().equals(hos2.getMyThing()) : "Strings were different after stored/retrieved";
		assert hos.getThing().getClass().equals(hos2.getMyThing().getClass()) : "Classes were differnt";
	}

	/** */
	@Test
	public void testStringHolderWithALong() throws Exception
	{
		Objectify ofy = this.fact.begin();
		String s = "my secret";
		HolderOfStringAndLong hosal = new HolderOfStringAndLong(s,2L);
		Key hosKey = ofy.put(hosal);
		HolderOfStringAndLong hosal2 = ofy.get(hosKey);
		
		assert hosal.getMyPrecious().equals(hosal2.getMyPrecious()) : "Longs were different after stored/retrieved";
		assert hosal.getThing().equals(hosal2.getMyThing()) : "Strings were different after stored/retrieved";
		assert hosal.getThing().getClass().equals(hosal2.getMyThing().getClass()) : "Classes were differnt";
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy