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

com.googlecode.objectify.test.AllocateTests 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: BeanMixin.java 1075 2009-05-07 06:41:19Z lhoriman $
 * $URL: https://subetha.googlecode.com/svn/branches/resin/rtest/src/org/subethamail/rtest/util/BeanMixin.java $
 */

package com.googlecode.objectify.test;

import java.util.Iterator;
import java.util.logging.Logger;

import org.testng.annotations.Test;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.KeyRange;
import com.googlecode.objectify.test.entity.Child;
import com.googlecode.objectify.test.entity.Criminal;
import com.googlecode.objectify.test.entity.Trivial;

/**
 * Tests of simple key allocations
 * 
 * @author Jeff Schnitzer 
 */
public class AllocateTests extends TestBase
{
	/** */
	private static Logger log = Logger.getLogger(AllocateTests.class.getName());
	
	/** */
	@Test
	public void testBasicAllocation() throws Exception
	{
		KeyRange range = this.fact.allocateIds(Trivial.class, 5);
		
		Iterator> it = range.iterator();
		
		long previousId = 0;
		for (int i=0; i<5; i++)
		{
			Key next = it.next();
			assert next.getId() > previousId;
			previousId = next.getId();
		}
		
		// Create an id with a put and verify it is > than the last
		Trivial triv = new Trivial("foo", 3);
		this.fact.begin().put(triv);
		
		assert triv.getId() > previousId;
	}
	
	/** */
	@Test
	public void testParentAllocation() throws Exception
	{
		Key parentKey = new Key(Trivial.class, 123);
		KeyRange range = this.fact.allocateIds(parentKey, Child.class, 5);
		
		Iterator> it = range.iterator();
		
		long previousId = 0;
		for (int i=0; i<5; i++)
		{
			Key next = it.next();
			assert next.getId() > previousId;
			previousId = next.getId();
		}
		
		// Create an id with a put and verify it is > than the last
		Child ch = new Child(parentKey, "foo");
		this.fact.begin().put(ch);
		
		assert ch.getId() > previousId;
	}

	/** */
	@Test
	public void testKindNamespaceAllocation() throws Exception
	{
		KeyRange rangeTrivial = this.fact.allocateIds(Trivial.class, 1);
		KeyRange rangeCriminal = this.fact.allocateIds(Criminal.class, 1);
		
		Iterator> itTrivial = rangeTrivial.iterator();
		Key trivialKey = itTrivial.next();
		
		Iterator> itCriminal = rangeCriminal.iterator();
		Key criminalKey = itCriminal.next();

		log.warning("Trivial key is " + trivialKey);
		log.warning("Criminal key is " + criminalKey);
		
		// This test is apparently not valid
		//assert trivialKey.getId() == 1;
		//assert criminalKey.getId() == 1;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy