/*
* This file is part of Catfish.
* Copyright (C) 2010 Namazu Studios LLC
*
* Catfish is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* Catfish is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Catfish. If not, please visit:
*
* http://www.gnu.org/licenses/
*
*/
package com.namazustudios.catfish.gae;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.google.appengine.api.datastore.Key;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.namazustudios.catfish.BaseTest;
import com.namazustudios.catfish.Catfish;
public class TestGaeMarshaller extends BaseTest {
private Catfish catfish;
private GaeMarshaller marshaller;
@Before
public void setUp() throws Exception {
Injector injector;
super.setUp();
injector = Guice.createInjector(new Module());
catfish = injector.getInstance(Catfish.class);
marshaller = injector.getInstance(GaeMarshaller.class);
}
@After
public void tearDown() throws Exception {
super.tearDown();
}
@Test
public final void testMarshall() {
Referenced ref = catfish.instantiate(Referenced.class);
RootEntity root = catfish.instantiate(RootEntity.class);
root.ref.set(ref);
com.google.appengine.api.datastore.Entity entity;
Map<Object, com.google.appengine.api.datastore.Entity> result = marshaller.marshall(root);
entity = result.get(root);
assertEquals(root.key, entity.getKey());
assertEquals(root.sprimitive, entity.getProperty("sprimitive"));
assertEquals(root.sobject, entity.getProperty("sobject"));
assertEquals(root.iprimitive, entity.getProperty("iprimitive"));
assertEquals(root.iobject, entity.getProperty("iobject"));
assertEquals(root.bprimitive, entity.getProperty("bprimitive"));
assertEquals(root.bobject, entity.getProperty("bobject"));
assertEquals(root.string, entity.getProperty("string"));
assertEquals(root.child0.key, entity.getProperty("child0"));
assertEquals(root.child1.key, entity.getProperty("child1"));
assertEquals(root.enumValue, DummyEnum.valueOf((String) entity.getProperty("enumValue")));
assertEquals(root.flat.email, entity.getProperty("email"));
assertEquals(null, root.enumNull);
assertEquals(null, entity.getProperty("enumNull"));
assertEquals(null, entity.getProperty("childNull"));
assertEquals(new ArrayList<Key>(Arrays.asList(root.children.get(0).key, root.children.get(1).key)), entity.getProperty("children"));
assertEquals(root.ref.getKey(), entity.getProperty("ref"));
entity = result.get(root.child0);
assertEquals(root.child0.key, entity.getKey());
assertEquals(root.child0.string, entity.getProperty("string"));
entity = result.get(root.child1);
assertEquals(root.child1.key, entity.getKey());
assertEquals(root.child1.string, entity.getProperty("string"));
}
}
|