Rest assured - Response body displays null value for Success - arrays

Response body displays null value for Success
POJO :
public class Employee {
public String name;
public int salary;
public int age;
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
#Override
public String toString() {
return "Employee[name=" + name + ",salary=" + salary + ",age=" + age + "]";
}
JSON Reader Class :
public class ReadJsonFile < T > {
public < T > List < T > getjsondata(String filepath, Class < T > typeofT) {
//filepath= "src/test/resource/testdataresource/addplacerequest.json";
Gson gson = new Gson();;
BufferedReader bufferReader = null;
try {
bufferReader = new BufferedReader(new FileReader(filepath));
//Type ListType = new TypeToken<ArrayList<Addbook>>(){}.getType();
Type ListType = TypeToken.getParameterized(ArrayList.class, typeofT).getType(); //
//gson.toJson(ReadJsonFile,ListType);
//return new Gson().fromJson(bufferReader, ListType);
List < T > arraylist = gson.fromJson(bufferReader, ListType);
return (arraylist);
} catch (FileNotFoundException e) {
throw new RuntimeException("Json file not found at path : " + filepath);
} finally {
try {
if (bufferReader != null) bufferReader.close();
} catch (IOException ignore) {}
}
}
}
Class to Read Pojo and Json Reader :
public class TestDataBuild {
public static List < Employee > employee() {
ReadJsonFile < Employee > readJson = new ReadJsonFile < Addbook > ();
List < Addbook > employee = readJson.getjsondata("src/test/resource/testDataResource/addplacerequest.json", Employee.class);
//Retrieve data from JsonObject and create Employee bean
for (int i = 0; i < employee.size(); i++) {
//System.out.println(addbook.get(i).name);
addbook.get(i).setName(employee.get(i).name);
addbook.get(i).setAge(employee.get(i).age);
addbook.get(i).setSalary(employee.get(i).salary);
}
return Employee;
}
}

Related

My unity save system doesn't save integer array

I don't get any errors but my script doesn't load or possibly save my array...
here's the first script
[System.Serializable]
public class PlayerData
{
public float health;
public float thirst;
public float hunger;
public float oxygen;
public float[] position;
public int[] inventoryIDs;
public PlayerData (Health healthO, SaveLoad saveload)
{
//Save int items
health = healthO.health;
thirst = healthO.thirst;
hunger = healthO.hunger;
oxygen = healthO.oxygen;
//set and save location array
position = new float[3];
position[0] = healthO.transform.position.x;
position[1] = healthO.transform.position.y;
position[2] = healthO.transform.position.z;
//set and save inventory IDs
inventoryIDs = new int[50];
for(int i = 0; i < 50; i++)
{
inventoryIDs[i] = saveload.IDs[i];
}
}
}
here's the next
public class SaveLoad : MonoBehaviour
{
public GameObject player;
public int[] IDs;
public GameObject[] objects;
Inventory inventory;
Health health;
void Start()
{
IDs = new int[50];
objects = new GameObject[50];
inventory = player.GetComponent<Inventory>();
health = player.GetComponent<Health>();
}
void Update()
{
//Add IDs
for (int i = 0; i < 50; i++)
{
IDs[i] = inventory.slot[i].GetComponent<Slot>().ID;
}
//debug save load test
if (Input.GetKeyDown(KeyCode.Z))
{
SaveP();
}
if (Input.GetKeyDown(KeyCode.X))
{
LoadP();
}
}
public void SaveP()
{
SaveSystem.SavePlayer(health, this);
}
public void LoadP()
{
PlayerData data = SaveSystem.LoadPlayer();
//load stats
health.thirst = data.thirst;
health.hunger = data.hunger;
health.health = data.health;
health.oxygen = data.oxygen;
//Load position
Vector3 position;
position.x = data.position[0];
position.y = data.position[1];
position.z = data.position[2];
player.transform.position = position;
//load IDs
for (int i = 0; i < 50; i++)
{
IDs[i] = data.inventoryIDs[i];
}
//Load Items
for (int i = 0; i < 50; i++)
{
if(objects[IDs[i]] != null)
{
GameObject itemObject = (GameObject)Instantiate(objects[IDs[i]], new Vector3(0, 0, 0), Quaternion.identity);
Item item = itemObject.GetComponent<Item>();
inventory.AddItem(itemObject, item.ID, item.type, item.name, item.description, item.icon);
} else
{
return;
}
}
}
}
Here's the last script
public static class SaveSystem
{
public static string fileName = "FileSave.bin";
public static void SavePlayer(Health health, SaveLoad SL)
{
//Create formatter
BinaryFormatter bf = new BinaryFormatter();
// Create file stream
FileStream file = File.Create(GetFullPath());
//Save data
PlayerData data = new PlayerData(health, SL);
bf.Serialize(file, data);
//Close stream
file.Close();
}
public static PlayerData LoadPlayer()
{
if (SaveExists())
{
try
{
//Create formatter
BinaryFormatter bf = new BinaryFormatter();
//Create file stream
FileStream file = File.Open(GetFullPath(), FileMode.Open);
//Load data
PlayerData pd = (PlayerData)bf.Deserialize(file);
//close stream
file.Close();
//return data
return pd;
}
catch (SerializationException)
{
Debug.Log("Failed to load file at: " + GetFullPath());
}
}
return null;
}
private static bool SaveExists()
{
return File.Exists(GetFullPath());
}
private static string GetFullPath()
{
return Application.persistentDataPath + "/" + fileName;
}
}
there are all connected with the save load script loading and saving the variables into the player and items to the inventory sots. the inventory IDs array isn't saving or loading

Why when I print my array of objects it shows all null?

I want to create a deck of cards(object), and it shows nullnullnull... however i construct the card.
This is the class I use to initialize the deck:
import black.jack.bean.Card;
public class InitDeck {
public InitDeck() {
}
public void createDeck(Card[] cards) {
for(int idx = 0; idx<cards.length; idx++) {
int contValueNum = 1;
boolean valueYes = false;
cards[idx] = new Card((char) idx, idx);
if(!valueYes) {
switch(contValueNum) {
case 1:
cards[idx].setKey('A');
cards[idx].setKeyValue(contValueNum);
break;
case 11:
cards[idx].setKey('J');
cards[idx].setKeyValue(contValueNum);
break;
case 12:
cards[idx].setKey('Q');
cards[idx].setKeyValue(contValueNum);
break;
case 13:
cards[idx].setKey('K');
cards[idx].setKeyValue(contValueNum);
break;
}
if(idx==cards.length) {
valueYes = false;
}
}
}
}
public void visDeck(Card[] cards) {
for(int idx = 0; idx<cards.length; idx++) {
System.out.print(cards[idx]);
}
}
}
This is the class Deck and the class Card
public class Deck {
private static final int CARDS = 52;
//private char[] deck = new char[CARDS];
protected Card[] cards = new Card[CARDS];
public Deck() {
}
public Card[] getCards() {
return cards;
}
public void setCards(Card[] cards) {
this.cards = cards;
}
}
public class Card {
public char key;
public int keyValue;
public Card(char key, int keyValue) {
this.key = key;
this.keyValue = keyValue;
}
public Card() {
}
public char getKey() {
return key;
}
public void setKey(char key) {
this.key = key;
}
public int getKeyValue() {
return keyValue;
}
public void setKeyValue(int keyValue) {
this.keyValue = keyValue;
}
}
And this is my Console
public class Console {
public Console() {
}
public void execute() {
InitDeck initDeck= new InitDeck();
Deck deck = new Deck();
Card card = new Card();
initDeck.visDeck(deck.getCards());
}
}
And the result is:
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
There's someone who could help me out?

Is there any way to pass Observable<String> into AbstractInputStreamContent?

I'm working on uploading a text file to Google Drive
ByteArrayContent content = new ByteArrayContent("text/csv", fileContent.getBytes(Charset.forName("UTF-8")));
Drive.Files.Insert request = drive.files().insert(file, content);
where type(fileContent) = String
I'd like to refactor and change type of fileContent to Observable<String>, is there any nice workaround to pass it to that insert() function (which takes AbstractInputStreamContent as a second argument)?
Thanks
Here is a general Flowable -> InputStream bridge you can delegate to:
import java.io.*;
import java.nio.charset.Charset;
import java.util.concurrent.atomic.AtomicReference;
import org.reactivestreams.*;
import io.reactivex.FlowableSubscriber;
import io.reactivex.internal.subscriptions.SubscriptionHelper;
public final class FlowableStringInputStream {
private FlowableStringInputStream() {
throw new IllegalStateException("No instances!");
}
public static InputStream createInputStream(
Publisher<String> source, Charset charset) {
StringInputStream parent = new StringInputStream(charset);
source.subscribe(parent);
return parent;
}
static final class StringInputStream extends InputStream
implements FlowableSubscriber<String> {
final AtomicReference<Subscription> upstream;
final Charset charset;
volatile byte[] bytes;
int index;
volatile boolean done;
Throwable error;
StringInputStream(Charset charset) {
this.charset = charset;
upstream = new AtomicReference<>();
}
#Override
public void onSubscribe(Subscription s) {
if (SubscriptionHelper.setOnce(upstream, s)) {
s.request(1);
}
}
#Override
public void onNext(String t) {
bytes = t.getBytes(charset);
synchronized (this) {
notifyAll();
}
}
#Override
public void onError(Throwable t) {
error = t;
done = true;
synchronized (this) {
notifyAll();
}
}
#Override
public void onComplete() {
done = true;
synchronized (this) {
notifyAll();
}
}
#Override
public int read() throws IOException {
for (;;) {
byte[] a = awaitBufferIfNecessary();
if (a == null) {
Throwable ex = error;
if (ex != null) {
if (ex instanceof IOException) {
throw (IOException)ex;
}
throw new IOException(ex);
}
return -1;
}
int idx = index;
if (idx == a.length) {
index = 0;
bytes = null;
upstream.get().request(1);
} else {
int result = a[idx] & 0xFF;
index = idx + 1;
return result;
}
}
}
byte[] awaitBufferIfNecessary() throws IOException {
byte[] a = bytes;
if (a == null) {
synchronized (this) {
for (;;) {
boolean d = done;
a = bytes;
if (a != null) {
break;
}
if (d || upstream.get() == SubscriptionHelper.CANCELLED) {
break;
}
try {
wait();
} catch (InterruptedException ex) {
if (upstream.get() != SubscriptionHelper.CANCELLED) {
InterruptedIOException exc = new InterruptedIOException();
exc.initCause(ex);
throw exc;
}
break;
}
}
}
}
return a;
}
#Override
public int read(byte[] b, int off, int len) throws IOException {
if (off < 0 || len < 0 || off >= b.length || off + len > b.length) {
throw new IndexOutOfBoundsException(
"b.length=" + b.length + ", off=" + off + ", len=" + len);
}
for (;;) {
byte[] a = awaitBufferIfNecessary();
if (a == null) {
Throwable ex = error;
if (ex != null) {
if (ex instanceof IOException) {
throw (IOException)ex;
}
throw new IOException(ex);
}
return -1;
}
int idx = index;
if (idx == a.length) {
index = 0;
bytes = null;
upstream.get().request(1);
} else {
int r = 0;
while (idx < a.length && len > 0) {
b[off] = a[idx];
idx++;
off++;
r++;
len--;
}
index = idx;
return r;
}
}
}
#Override
public int available() throws IOException {
byte[] a = bytes;
int idx = index;
return a != null ? Math.max(0, a.length - idx) : 0;
}
#Override
public void close() throws IOException {
SubscriptionHelper.cancel(upstream);
synchronized (this) {
notifyAll();
}
}
}
}
Usage:
#Test(timeout = 10000)
public void async() throws Exception {
AtomicInteger calls = new AtomicInteger();
Flowable<String> f = Flowable.range(100, 10).map(Object::toString)
.doOnCancel(() -> calls.incrementAndGet())
.subscribeOn(Schedulers.computation())
.delay(10, TimeUnit.MILLISECONDS);
try (InputStream is = FlowableStringInputStream.createInputStream(f, utf8)) {
assertEquals('1', is.read());
assertEquals('0', is.read());
assertEquals('0', is.read());
byte[] buf = new byte[3];
assertEquals(3, is.read(buf));
assertArrayEquals("101".getBytes(utf8), buf);
}
assertEquals(1, calls.get());
}

LZH in Byte Array Decompress in .NET?

An LZH archive is embedded within a file. The file was read into a byte[], and the LZH part is identified as a smaller byte[].
How can the embedded LZH bytes be decompressed into another byte[] using .NET Framework 4.6 (C#)? I have only see http://www.infoq.com/news/2008/06/7-Zip-from-.NET which doesn't exactly do what I need.
Thanks.
the code snippet that follows is taken from the sample program from this article
http://www.codeproject.com/Articles/27148/C-NET-Interface-for-Zip-Archive-DLLs
There are no significant changes: instead of reading and writing files, it reads and write byte arrays. Changes are marked by comments
Run with sevenzip.exe e "C:\temp\gwo0.11-sample-win32.lzh" 3 for example
https://dl.dropboxusercontent.com/u/71459360/7z.zip
using System;
using System.Collections.Generic;
using System.Text;
using Nomad.Archive.SevenZip;
using System.IO;
using System.Runtime.InteropServices;
using System.Reflection;
namespace SevenZip
{
class Program
{
private static void ShowHelp()
{
Console.WriteLine("SevenZip");
Console.WriteLine("SevenZip l {ArchiveName}");
Console.WriteLine("SevenZip e {ArchiveName} {FileNumber}");
}
static void Main(string[] args)
{
if (args.Length < 2)
{
ShowHelp();
return;
}
try
{
string ArchiveName;
uint FileNumber = 0xFFFFFFFF;
bool Extract;
switch (args[0])
{
case "l":
ArchiveName = args[1];
Extract = false;
break;
case "e":
ArchiveName = args[1];
Extract = true;
if ((args.Length < 3) || !uint.TryParse(args[2], out FileNumber))
{
ShowHelp();
return;
}
break;
default:
ShowHelp();
return;
}
using (SevenZipFormat Format = new SevenZipFormat(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "7z.dll")))
{
IInArchive Archive = Format.CreateInArchive(SevenZipFormat.GetClassIdFromKnownFormat(KnownSevenZipFormat.Lzh));
if (Archive == null)
{
ShowHelp();
return;
}
try
{
//the byte array is provided by you. here it's coming from a file
byte[] data;
using (var stream = File.OpenRead(ArchiveName))
{
data = new byte[stream.Length];
stream.Read(data, 0, data.Length);
}
using (InStreamWrapper ArchiveStream = new InStreamWrapper(new MemoryStream(data))) //modified here
{
ulong CheckPos = 32 * 1024;
if (Archive.Open(ArchiveStream, ref CheckPos, null) != 0)
ShowHelp();
Console.Write("Archive: ");
Console.WriteLine(ArchiveName);
if (Extract)
{
PropVariant Name = new PropVariant();
Archive.GetProperty(FileNumber, ItemPropId.kpidPath, ref Name);
string FileName = (string) Name.GetObject();
Console.Write("Extracting: ");
Console.Write(FileName);
Console.Write(' ');
MemoryStream ms = new MemoryStream();
Archive.Extract(new uint[] { FileNumber }, 1, 0, new ArchiveMemoryCallback(FileNumber, ms)); //modified here
byte[] output = ms.ToArray(); //here you have the output byte array
output.ToString();
}
else
{
Console.WriteLine("List:");
uint Count = Archive.GetNumberOfItems();
for (uint I = 0; I < Count; I++)
{
PropVariant Name = new PropVariant();
Archive.GetProperty(I, ItemPropId.kpidPath, ref Name);
Console.Write(I);
Console.Write(' ');
Console.WriteLine(Name.GetObject());
}
}
}
}
finally
{
Marshal.ReleaseComObject(Archive);
}
}
}
catch (Exception e)
{
Console.Write("Error: ");
Console.WriteLine(e.Message);
}
}
}
class ArchiveCallback : IArchiveExtractCallback
{
private uint FileNumber;
private string FileName;
private OutStreamWrapper FileStream;
public ArchiveCallback(uint fileNumber, string fileName)
{
this.FileNumber = fileNumber;
this.FileName = fileName;
}
#region IArchiveExtractCallback Members
public void SetTotal(ulong total)
{
}
public void SetCompleted(ref ulong completeValue)
{
}
public int GetStream(uint index, out ISequentialOutStream outStream, AskMode askExtractMode)
{
if ((index == FileNumber) && (askExtractMode == AskMode.kExtract))
{
string FileDir = Path.GetDirectoryName(FileName);
if (!string.IsNullOrEmpty(FileDir))
Directory.CreateDirectory(FileDir);
FileStream = new OutStreamWrapper(File.Create(FileName));
outStream = FileStream;
}
else
outStream = null;
return 0;
}
public void PrepareOperation(AskMode askExtractMode)
{
}
public void SetOperationResult(OperationResult resultEOperationResult)
{
FileStream.Dispose();
Console.WriteLine(resultEOperationResult);
}
#endregion
}
//new
class ArchiveMemoryCallback : IArchiveExtractCallback
{
private uint FileNumber;
private Stream stream;
private OutStreamWrapper FileStream;
public ArchiveMemoryCallback(uint fileNumber, Stream stream)
{
this.FileNumber = fileNumber;
this.stream = stream;
}
#region IArchiveExtractCallback Members
public void SetTotal(ulong total)
{
}
public void SetCompleted(ref ulong completeValue)
{
}
public int GetStream(uint index, out ISequentialOutStream outStream, AskMode askExtractMode)
{
if ((index == FileNumber) && (askExtractMode == AskMode.kExtract))
{
FileStream = new OutStreamWrapper(stream);
outStream = FileStream;
}
else
outStream = null;
return 0;
}
public void PrepareOperation(AskMode askExtractMode)
{
}
public void SetOperationResult(OperationResult resultEOperationResult)
{
FileStream.Dispose();
Console.WriteLine(resultEOperationResult);
}
#endregion
}
}

Ref.get() does not work if comes from a just loaded List<Ref<?>>

I'm going crazy with Objectify because i've a problem with a List<Ref<?>> like this:
#Index
#Load
private LinkedList<Ref<Post>> diary = new LinkedList<Ref<Post>>();
when i save this Profile entity the diary Ref list is ok, and this:
getDiary().get(0).get() give me the correct Post entity.
When i load both Profile and then the first Post like this:
ofy().load().key(myProfileKey).get().getDiary().get(0).get() which should load the first Post in list, i got null, even if the Profile and the diary are correctly loaded (diary contains the correct Ref<Post>).
Any ideas?
Thanks in advance!
Update:
In my previous question i forgot to tell that Post has a #Parent field: the Profile.
Removing #Parent all works... even if i don't understand why.
I reduced all to a TestCase:
public class StandaloneTestCase {
protected static LocalServiceTestHelper helper = null;
protected static Objectify ds = null;
#BeforeClass
public static void setUp() {
LocalDatastoreServiceTestConfig config = new LocalDatastoreServiceTestConfig();
helper = new LocalServiceTestHelper(config);
helper.setUp();
ds = ObjectifyService.ofy();
ObjectifyService.register(Post.class);
ObjectifyService.register(Profile.class);
}
#Test
public void test() {
Profile p = new Profile();
p.setEmail("user1#email.com");
p.setPassword("user1pwd");
p.setRegistrationDate(new Date(0L));
p.setSex("Male");
p.setName("Name1");
p.setSurname("Surname1");
p.setFullName("Name1 Nick1 Surname1");
Key<Profile> pKey = ds.save().entity(p).now();
Profile pro = ds.load().type(Profile.class).filter("name", "Name1").first().get();
Assert.assertEquals(0, ds.load().key(pro.getRef().getKey()).get().getFriends().size());
Post newPost = new Post();
newPost.setDate(new Date());
newPost.setTitle("New Post p1");
newPost.setDescription("New Descr p1");
newPost.setAuthor(pro.getRef());
ds.save().entity(newPost).now();
Ref<Post> postRef = newPost.getRef();
pro.getDiary().addFirst(postRef);
pro.getMessages().addFirst(postRef);
ds.save().entity(pro).now();
newPost.getReceivers().addAll(pro.getFriends());
Collection<Profile> friends = ds.load().refs(pro.getFriends()).values();
for (Profile friend : friends) {
friend.getMessages().addFirst(newPost.getRef());
}
ds.save().entities(friends).now();
ds.save().entity(newPost).now();
Assert.assertEquals(1, ds.load().key(pro.getKey()).get().getDiary().size());
Assert.assertEquals(1, ds.load().key(pro.getKey()).get().getMessages().size());
Assert.assertEquals(newPost.getRef(), ds.load().key(pro.getKey()).get().getDiary().get(0));
// BIG FAT WARNING
Assert.assertEquals(newPost, ds.load().key(pro.getKey()).get().getDiary().get(0).get());
}
#AfterClass
public static void tearDown() {
ds.clear();
helper.tearDown();
}
}
//
#Entity
class Identifable<T> {
#Id
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
#Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
#Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
return equals((Identifable<?>) obj);
}
public boolean equals(Identifable<?> other) {
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
}
#Entity #Cache
class Post extends Identifable<Post> {
#Index(IfNotNull.class)
#Load
#Parent
private Ref<Profile> author = null;
#Index(IfNotNull.class)
private Date date = null;
#Index(IfNotNull.class)
private String title = null;
private String description = null;
#Index(IfNotEmpty.class)
#Load
private Set<Ref<Profile>> receivers = new HashSet<Ref<Profile>>();
public Set<Ref<Profile>> getReceivers() {
return receivers;
}
public Ref<Profile> getAuthor() {
return author;
}
public void setAuthor(Ref<Profile> author) {
this.author = author;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
#Override
public String toString() {
return "Post [author=" + author + ", date=" + date + ", title=" + title
+ ", description=" + description + "]";
}
#Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((author == null) ? 0 : author.hashCode());
result = prime * result + ((date == null) ? 0 : date.hashCode());
result = prime * result
+ ((description == null) ? 0 : description.hashCode());
result = prime * result + ((title == null) ? 0 : title.hashCode());
return result;
}
#Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
Post other = (Post) obj;
if (author == null) {
if (other.author != null)
return false;
} else if (!author.equals(other.author))
return false;
if (date == null) {
if (other.date != null)
return false;
} else if (!date.equals(other.date))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (title == null) {
if (other.title != null)
return false;
} else if (!title.equals(other.title))
return false;
return true;
}
public Key<Post> getKey() {
return Key.create(Post.class, getId());
}
public Ref<Post> getRef() {
return Ref.create(getKey(), this);
}
}
//
#Entity #Cache
class Profile extends Identifable<Profile> {
#Index
private String email = null;
#Index
private String password = null;
private Date registrationDate = null;
#Index(IfNotNull.class)
private String name = null;
#Index(IfNotNull.class)
private String surname = null;
#Index(IfNotNull.class)
private String fullName = null;
#Index
private String sex = null;
#Index
private Date dateOfBirth = null;
#Index(IfNotEmpty.class)
#Load
private LinkedList<Ref<Post>> diary = new LinkedList<Ref<Post>>();
#Index(IfNotEmpty.class)
#Load
private Set<Ref<Profile>> friends = new HashSet<Ref<Profile>>();
#Index(IfNotEmpty.class)
#Load
private LinkedList<Ref<Post>> messages = new LinkedList<Ref<Post>>();
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Date getRegistrationDate() {
return registrationDate;
}
public void setRegistrationDate(Date registrationDate) {
this.registrationDate = registrationDate;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public Date getDateOfBirth() {
return dateOfBirth;
}
public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
public Set<Ref<Profile>> getFriends() {
return friends;
}
public LinkedList<Ref<Post>> getDiary() {
return diary;
}
public LinkedList<Ref<Post>> getMessages() {
return messages;
}
#Override
public String toString() {
return "Profile [email=" + email + ", password=" + password
+ ", registrationDate=" + registrationDate + ", name=" + name
+ ", surname=" + surname + ", fullName=" + fullName + ", sex="
+ sex + ", dateOfBirth=" + dateOfBirth + ", diary=" + diary
+ ", friends=" + friends + ", messages=" + messages + "]";
}
#Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((dateOfBirth == null) ? 0 : dateOfBirth.hashCode());
result = prime * result + ((diary == null) ? 0 : diary.hashCode());
result = prime * result + ((email == null) ? 0 : email.hashCode());
result = prime * result + ((friends == null) ? 0 : friends.hashCode());
result = prime * result
+ ((fullName == null) ? 0 : fullName.hashCode());
result = prime * result
+ ((messages == null) ? 0 : messages.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result
+ ((password == null) ? 0 : password.hashCode());
result = prime
* result
+ ((registrationDate == null) ? 0 : registrationDate.hashCode());
result = prime * result + ((sex == null) ? 0 : sex.hashCode());
result = prime * result + ((surname == null) ? 0 : surname.hashCode());
return result;
}
#Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Profile other = (Profile) obj;
if (dateOfBirth == null) {
if (other.dateOfBirth != null)
return false;
} else if (!dateOfBirth.equals(other.dateOfBirth))
return false;
if (diary == null) {
if (other.diary != null)
return false;
} else if (!diary.equals(other.diary))
return false;
if (email == null) {
if (other.email != null)
return false;
} else if (!email.equals(other.email))
return false;
if (friends == null) {
if (other.friends != null)
return false;
} else if (!friends.equals(other.friends))
return false;
if (fullName == null) {
if (other.fullName != null)
return false;
} else if (!fullName.equals(other.fullName))
return false;
if (messages == null) {
if (other.messages != null)
return false;
} else if (!messages.equals(other.messages))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (password == null) {
if (other.password != null)
return false;
} else if (!password.equals(other.password))
return false;
if (registrationDate == null) {
if (other.registrationDate != null)
return false;
} else if (!registrationDate.equals(other.registrationDate))
return false;
if (sex == null) {
if (other.sex != null)
return false;
} else if (!sex.equals(other.sex))
return false;
if (surname == null) {
if (other.surname != null)
return false;
} else if (!surname.equals(other.surname))
return false;
return true;
}
public Key<Profile> getKey() {
return Key.create(Profile.class, getId());
}
public Ref<Profile> getRef() {
return Ref.create(getKey(), this);
}
}
I use Objectify 4.0a4 and App Engine SDK 1.7.2
If you try to remove #Parent from author Post field the test is ok.
This may be NOT an Objectify bug (quite sure) and may be a my conceptual error.

Resources