Search in sources :

Example 1 with Zipcode

use of jodd.json.mock.Zipcode in project jodd by oblac.

the class JSONSerializationTest method setUp.

@Before
@SuppressWarnings({ "unchecked" })
public void setUp() {
    DataCreator dataCreator = new DataCreator();
    pedroZip = new Zipcode("848485");
    Person pedro = dataCreator.createPedro();
    jodder = dataCreator.createJodder();
    modesty = dataCreator.createModesty();
    colors = dataCreator.createColorMap();
    people = new ArrayList();
    people.add(jodder);
    people.add(modesty);
    people.add(pedro);
    dilbert = dataCreator.createDilbert();
    network = dataCreator.createNetwork("My Network", jodder, modesty);
}
Also used : Zipcode(jodd.json.mock.Zipcode) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Person(jodd.json.mock.Person) Before(org.junit.Before)

Example 2 with Zipcode

use of jodd.json.mock.Zipcode in project jodd by oblac.

the class DataCreator method createJodder.

public Person createJodder() {
    Address home = new Address("173 Hackers Drive", "New York", "NY", new Zipcode("123123"));
    Address work = new Address("42 Computer Center", "Earth", "Milkiway", new Zipcode("42"));
    Phone pagerPhone = new Phone(PhoneNumberType.PAGER, "123 555-1234");
    Phone cellPhone = new Phone(PhoneNumberType.MOBILE, "770 777 5432");
    Calendar cal = Calendar.getInstance();
    cal.set(1988, Calendar.NOVEMBER, 23, 8, 11);
    Person charlie = new Person("Igor", "Spasic", cal.getTime(), home, work);
    cal = Calendar.getInstance();
    cal.set(1993, Calendar.JUNE, 6, 8, 11);
    charlie.setFirstBaseBallGame(new Timestamp(cal.getTime().getTime()));
    charlie.getPhones().add(pagerPhone);
    charlie.getPhones().add(cellPhone);
    charlie.getHobbies().add("read");
    charlie.getHobbies().add("run");
    charlie.getHobbies().add("code");
    return charlie;
}
Also used : Address(jodd.json.mock.Address) Phone(jodd.json.mock.Phone) Calendar(java.util.Calendar) Zipcode(jodd.json.mock.Zipcode) Person(jodd.json.mock.Person) Timestamp(java.sql.Timestamp)

Example 3 with Zipcode

use of jodd.json.mock.Zipcode in project jodd by oblac.

the class DataCreator method createPedro.

public Person createPedro() {
    Zipcode pedroZip = new Zipcode("848485");
    Address pedroHome = new Address("12 Acrelèndia Way", "Rio de Janeiro", "Brazil", pedroZip);
    Address pedroWork = new Address("12 Acrelèndia Way", "Rio de Janeiro", "Brazil", pedroZip);
    Phone pedroPhone = new Phone(PhoneNumberType.MOBILE, "123 555 2323");
    Calendar pedroCal = Calendar.getInstance();
    pedroCal.set(1980, Calendar.APRIL, 12, 11, 45);
    Person pedro = new Person("Pedro", "Sanchez", pedroCal.getTime(), pedroHome, pedroWork);
    pedro.getPhones().add(pedroPhone);
    return pedro;
}
Also used : Address(jodd.json.mock.Address) Phone(jodd.json.mock.Phone) Calendar(java.util.Calendar) Zipcode(jodd.json.mock.Zipcode) Person(jodd.json.mock.Person)

Example 4 with Zipcode

use of jodd.json.mock.Zipcode in project jodd by oblac.

the class DataCreator method createModesty.

public Person createModesty() {
    Address benhome = new Address("NN Island", "Blue Cave", "ta", new Zipcode("82742"));
    Address benwork = new Address("44 Planetary St.", "Neptune", "Milkiway", new Zipcode("12345"));
    Calendar benCal = Calendar.getInstance();
    benCal.set(1986, Calendar.AUGUST, 8, 8, 11);
    Person ben = new Person("Modesty", "Blase", benCal.getTime(), benhome, benwork);
    benCal = Calendar.getInstance();
    benCal.set(1995, Calendar.MAY, 21, 8, 11);
    ben.setFirstBaseBallGame(new Timestamp(benCal.getTime().getTime()));
    ben.getHobbies().add("sneak");
    ben.getHobbies().add("kill");
    ben.getHobbies().add("fight");
    return ben;
}
Also used : Address(jodd.json.mock.Address) Calendar(java.util.Calendar) Zipcode(jodd.json.mock.Zipcode) Person(jodd.json.mock.Person) Timestamp(java.sql.Timestamp)

Example 5 with Zipcode

use of jodd.json.mock.Zipcode in project jodd by oblac.

the class JSONSerializationTest method testObject.

@Test
public void testObject() {
    JoddJson.classMetadataName = "class";
    JsonSerializer serializer = new JsonSerializer();
    String jodderJson = serializer.serialize(jodder);
    assertStringValue(Person.class.getName(), jodderJson);
    assertAttribute("firstname", jodderJson);
    assertStringValue("Igor", jodderJson);
    assertAttribute("lastname", jodderJson);
    assertStringValue("Spasic", jodderJson);
    assertAttribute("work", jodderJson);
    assertAttribute("home", jodderJson);
    assertAttribute("street", jodderJson);
    assertStringValue(Address.class.getName(), jodderJson);
    assertAttribute("zipcode", jodderJson);
    assertStringValue(Zipcode.class.getName(), jodderJson);
    assertAttributeMissing("person", jodderJson);
    assertAttributeMissing("phones", jodderJson);
    assertStringValueMissing(Phone.class.getName(), jodderJson);
    assertAttributeMissing("hobbies", jodderJson);
    JsonSerializer jdrSerializer = new JsonSerializer();
    jdrSerializer.exclude("home", "work");
    String modestyJson = jdrSerializer.serialize(modesty);
    assertStringValue(Person.class.getName(), modestyJson);
    assertAttribute("firstname", modestyJson);
    assertStringValue("Modesty", modestyJson);
    assertAttribute("lastname", modestyJson);
    assertStringValue("Blase", modestyJson);
    assertAttribute("birthdate", modestyJson);
    assertStringValueMissing(Address.class.getName(), modestyJson);
    assertAttributeMissing("work", modestyJson);
    assertAttributeMissing("home", modestyJson);
    assertAttributeMissing("street", modestyJson);
    assertAttributeMissing("city", modestyJson);
    assertAttributeMissing("state", modestyJson);
    assertStringValueMissing(Zipcode.class.getName(), modestyJson);
    assertAttributeMissing("zipcode", modestyJson);
    assertStringValueMissing(Phone.class.getName(), modestyJson);
    assertAttributeMissing("hobbies", modestyJson);
    assertAttributeMissing("person", modestyJson);
    serializer.exclude("home.zipcode", "work.zipcode");
    String json2 = serializer.serialize(jodder);
    assertStringValue(Person.class.getName(), json2);
    assertAttribute("work", json2);
    assertAttribute("home", json2);
    assertAttribute("street", json2);
    assertStringValue(Address.class.getName(), json2);
    assertAttributeMissing("zipcode", json2);
    assertAttributeMissing("phones", json2);
    assertStringValueMissing(Zipcode.class.getName(), json2);
    assertStringValueMissing(Phone.class.getName(), json2);
    assertAttributeMissing("hobbies", json2);
    assertAttributeMissing("type", json2);
    assertStringValueMissing("PAGER", json2);
    serializer.include("hobbies").exclude(true, "phones.areaCode", "phones.exchange", "phones.number");
    String json3 = serializer.serialize(jodder);
    assertStringValue(Person.class.getName(), json3);
    assertAttribute("work", json3);
    assertAttribute("home", json3);
    assertAttribute("street", json3);
    assertStringValue(Address.class.getName(), json3);
    assertAttribute("phones", json3);
    assertAttribute("phoneNumber", json3);
    assertStringValue(Phone.class.getName(), json3);
    assertAttribute("hobbies", json3);
    assertAttributeMissing("zipcode", json3);
    assertAttributeMissing(Zipcode.class.getName(), json3);
    assertAttributeMissing("areaCode", json3);
    assertAttributeMissing("exchange", json3);
    assertAttributeMissing("number", json3);
    assertAttribute("type", json3);
    assertStringValue("PAGER", json3);
    assertTrue(json3.startsWith("{"));
    assertTrue(json3.endsWith("}"));
}
Also used : Address(jodd.json.mock.Address) Phone(jodd.json.mock.Phone) Zipcode(jodd.json.mock.Zipcode) ObjectJsonSerializer(jodd.json.impl.ObjectJsonSerializer) Person(jodd.json.mock.Person) Test(org.junit.Test)

Aggregations

Person (jodd.json.mock.Person)5 Zipcode (jodd.json.mock.Zipcode)5 Address (jodd.json.mock.Address)4 Calendar (java.util.Calendar)3 Phone (jodd.json.mock.Phone)3 Timestamp (java.sql.Timestamp)2 ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 ObjectJsonSerializer (jodd.json.impl.ObjectJsonSerializer)1 Before (org.junit.Before)1 Test (org.junit.Test)1