예제 #1
0
  public final void testEquals() {

    Address address1 = new AddressImpl();

    Address address2 = new AddressImpl();

    assertTrue(address1.equals(address2));

    address1.setCity("lyon");

    assertFalse(address1.equals(address2));

    address1.setCity(null);
    address1.setCountry("France");

    assertFalse(address1.equals(address2));

    address1.setCountry(null);
    address1.setPostalCode("69");

    assertFalse(address1.equals(address2));

    address1.setPostalCode(null);
    address1.setStreetName("rue");

    assertFalse(address1.equals(address2));

    address1.setStreetName(null);
    address1.setStreetNumber("1");

    assertFalse(address1.equals(address2));
  }
예제 #2
0
  @PostConstruct
  public void startup() throws Exception {
    Query q = entityManager.createNativeQuery("DELETE from ADDRESS");
    q.executeUpdate();
    q = entityManager.createNativeQuery("DELETE from PERSON");
    q.executeUpdate();
    entityManager.flush();

    p = new Person();
    p.setFirstName("Shane");
    p.setLastName("Bryzak");
    p.setDateOfBirth(df.parse("1901-01-01"));
    p.setAddresses(new ArrayList<Address>());

    a = new Address();
    a.setPerson(p);
    a.setStreetNo(100);
    a.setStreetName("Main");
    a.setSuburb("Pleasantville");
    a.setPostCode("32123");
    a.setCountry("Australia");
    p.getAddresses().add(a);

    a = new Address();
    a.setPerson(p);
    a.setStreetNo(57);
    a.setStreetName("1st Avenue");
    a.setSuburb("Pittsville");
    a.setPostCode("32411");
    a.setCountry("Australia");
    p.getAddresses().add(a);
    entityManager.persist(p);
    entityManager.flush();

    p = new Person();
    p.setFirstName("Jozef");
    p.setLastName("Hartinger");
    p.setDateOfBirth(df.parse("1901-01-01"));
    p.setAddresses(new ArrayList<Address>());

    a = new Address();
    a.setPerson(p);
    a.setStreetNo(99);
    a.setStreetName("Purkynova");
    a.setSuburb("Kralovo pole");
    a.setPostCode("60200");
    a.setCountry("Czech republic");
    p.getAddresses().add(a);
    entityManager.persist(p);
    entityManager.flush();
  }
예제 #3
0
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // TODO Auto-generated method stub
    String name = request.getParameter("name");
    String street = request.getParameter("street");

    HttpSession session = request.getSession();
    ServletContext context = request.getServletContext();

    Person p = new Person();
    p.setName(name);

    Address address = new Address();
    address.setStreetName(street);

    p.setAddress(address);

    request.setAttribute("person", "Person Request");
    session.setAttribute("person", "Person Session ");
    context.setAttribute("person", "Person Context");

    RequestDispatcher rd = request.getRequestDispatcher("/el/nestedProperties.jsp");
    rd.forward(request, response);
  }