예제 #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();
  }
  /**
   * Accuracy test for the method <code>setCountry(Country country)</code>.<br>
   * The value should be properly set.
   */
  @Test
  public void test_setCountry() {
    Country value = new Country();
    instance.setCountry(value);

    assertSame("'setCountry' should be correct.", value, TestsHelper.getField(instance, "country"));
  }
  /**
   * Accuracy test for the method <code>getCountry()</code>.<br>
   * The value should be properly retrieved.
   */
  @Test
  public void test_getCountry() {
    Country value = new Country();
    instance.setCountry(value);

    assertSame("'getCountry' should be correct.", value, instance.getCountry());
  }
예제 #5
0
  public void test() {
    Employee emp1 = new EmployeeImpl();
    emp1.setFirstName("Kevin");
    emp1.setLastName("Moore");
    emp1.setGender("Male");
    emp1.setAge(30);

    Address add = new AddressImpl();
    add.setStreet("600 Chromakey Dr.");
    add.setCity("Roswell");
    add.setState("NM");
    add.setCountry("USA");
    add.setPostalCode("21872");

    Cubicle cube1 = new CubicleImpl();
    cube1.setLength(7.7f);
    cube1.setWidth(12.2f);
    cube1.setHeight(5.0f);

    emp1.setAddress(add);
    cube1.setEmployee(emp1);

    ((DatabaseSession) getSession()).insertObject(add);
    getAbstractSession().insertObject(cube1);
    // Employee is private owned so should be inserted along with Cubicle.
  }
예제 #6
0
 public static Address readConfig(InputStream in) {
   Address address = new Address();
   try {
     // First create a new XMLInputFactory
     XMLInputFactory inputFactory = XMLInputFactory.newInstance();
     // Setup a new eventReader
     // InputStream in = new FileInputStream(configFile);
     XMLEventReader eventReader = inputFactory.createXMLEventReader(in);
     // Read the XML document
     while (eventReader.hasNext()) {
       XMLEvent event = eventReader.nextEvent();
       if (event.isStartElement()) {
         if (event.asStartElement().getName().getLocalPart() == ("country")) {
           event = eventReader.nextEvent();
           address.setCountry(event.asCharacters().getData());
           continue;
         }
         if (event.asStartElement().getName().getLocalPart() == ("county")) {
           event = eventReader.nextEvent();
           address.setCity(event.asCharacters().getData());
           continue;
         }
       }
     }
   } catch (XMLStreamException e) {
     e.printStackTrace();
   }
   return address;
 }
 private Address getAddress() {
   Address address = new Address();
   address.setCountry("Belgium");
   address.setCity("Zaventem");
   address.setPostalCode("1930");
   address.setStreet("Airportstreet");
   address.setNumber("1");
   return address;
 }
 public static Address addressExample2() {
   Address address = new Address();
   address.setCity("Ekumseekum");
   address.setCountry("Canada");
   address.setPostalCode("B2N 2C0");
   address.setProvince("Nova Scotia");
   address.setStreet("2 Main");
   return address;
 }
 public static Address addressExample1() {
   Address address = new Address();
   address.setCity("Washabuc");
   address.setCountry("Canada");
   address.setPostalCode("K2T3A4");
   address.setProvince("Ontario");
   address.setStreet("1734 Wallywoo Drive");
   return address;
 }
 public static Address addressExample4() {
   Address address = new Address();
   address.setCity("Gander");
   address.setCountry("Canada");
   address.setPostalCode("A2C1B1");
   address.setProvince("Newfoundland");
   address.setStreet("324 Bay Street");
   return address;
 }
 public static Address addressExample3() {
   Address address = new Address();
   address.setCity("Shoolee");
   address.setCountry("Canada");
   address.setPostalCode("B1M 1C2");
   address.setProvince("Nova Scotia");
   address.setStreet("3 Main");
   return address;
 }
예제 #12
0
  public static Customer createCustomer(
      String name, String shippingStreet, String billingStreet, int contactSuffix, String annDate) {

    Customer c = new Customer();
    c.setName(name);
    c.setStatus(Customer.Status.NEW);
    if (annDate == null) {
      annDate = "2010-04-14";
    }
    c.setAnniversary(Date.valueOf(annDate));
    if (contactSuffix > 0) {
      Contact jim = new Contact("Jim" + contactSuffix, "Cricket");
      jim.getNotes().add(new ContactNote("ORM Lives", "And it is cool!"));
      c.addContact(jim);
      c.addContact(new Contact("Fred" + contactSuffix, "Blue"));
      c.addContact(new Contact("Bugs" + contactSuffix, "Bunny"));
    }

    if (shippingStreet != null) {
      Address shippingAddr = new Address();
      shippingAddr.setLine1(shippingStreet);
      shippingAddr.setLine2("Sandringham");
      shippingAddr.setCity("Auckland");
      shippingAddr.setCountry(Ebean.getReference(Country.class, "NZ"));

      c.setShippingAddress(shippingAddr);
    }

    if (billingStreet != null) {
      Address billingAddr = new Address();
      billingAddr.setLine1(billingStreet);
      billingAddr.setLine2("St Lukes");
      billingAddr.setCity("Auckland");
      billingAddr.setCountry(Ebean.getReference(Country.class, "NZ"));

      c.setBillingAddress(billingAddr);
    }

    return c;
  }
예제 #13
0
  @Override
  public Address parseAddress(JsonObject json) {
    JsonArray results = json.getJsonArray("results");

    if (!results.isEmpty()) {
      Address address = new Address();

      JsonObject result = (JsonObject) results.get(0);
      JsonArray components = result.getJsonArray("address_components");

      for (JsonObject component : components.getValuesAs(JsonObject.class)) {

        String value = component.getString("short_name");

        typesLoop:
        for (JsonString type : component.getJsonArray("types").getValuesAs(JsonString.class)) {

          switch (type.getString()) {
            case "street_number":
              address.setHouse(value);
              break typesLoop;
            case "route":
              address.setStreet(value);
              break typesLoop;
            case "locality":
              address.setSettlement(value);
              break typesLoop;
            case "administrative_area_level_2":
              address.setDistrict(value);
              break typesLoop;
            case "administrative_area_level_1":
              address.setState(value);
              break typesLoop;
            case "country":
              address.setCountry(value);
              break typesLoop;
            case "postal_code":
              address.setPostcode(value);
              break typesLoop;
            default:
              break;
          }
        }
      }

      return address;
    }

    return null;
  }
예제 #14
0
  public void testAddAndRemoveUser() throws Exception {
    User user = new User("testuser");
    user.setPassword("testpass");
    user.setFirstName("Test");
    user.setLastName("Last");
    Address address = new Address();
    address.setCity("Denver");
    address.setProvince("CO");
    address.setCountry("USA");
    address.setPostalCode("80210");
    user.setAddress(address);
    user.setEmail("*****@*****.**");
    user.setWebsite("http://tek42.com");
    user.setTimeZone("US/Central");

    // Here we are creating an org that should already be in the database...
    // Ideally, we somehow have an org object... from the other dao or whatever...
    /*
     * Account org = new Account(); org.setName("Tek42"); org.setId(1L);
     */
    Account org = adao.get(2L);
    System.out.println("Have org: " + org);
    user.setAccount(org);

    Role role = rdao.getRoleByName(Constants.USER_ROLE);
    assertNotNull(role.getId());
    user.addRole(role);

    user = dao.saveUser(user);

    assertNotNull(user.getId());

    user = dao.get(user.getId());

    assertEquals("Vigilant", user.getAccount().getName());
    assertEquals("testpass", user.getPassword());
    assertEquals("US/Central", user.getTimeZone());

    dao.remove(user.getId());

    try {
      dao.get(user.getId());
      fail("getUser didn't throw DataAccessException");
    } catch (DataAccessException d) {
      assertNotNull(d);
    }
  }
    @Override
    public Address next() {
      try {
        if (line == null) line = reader.readLine();
      } catch (IOException e) {
        throw new UncheckedIOException(e);
      }
      if (line == null) throw new NoSuchElementException();

      final String[] fields = CsvUtils.parseCsvLine(SEP, QUOTE, line);

      line = null;

      final Address address = new Address();
      address.setId(readField(fields, idIndex));
      address.setStreet(readField(fields, streetIndex));
      address.setNumber(readField(fields, numberIndex));
      address.setZipcode(readField(fields, zipIndex));
      address.setMunicipality(readField(fields, municipalityIndex));
      final String country = readField(fields, countryIndex);
      address.setCountry(country != null ? country : "CH");

      return address;
    }
    private void prepare() {
      Session s = openSession();
      Transaction txn = s.beginTransaction();

      polliwog = new Animal();
      polliwog.setBodyWeight(12);
      polliwog.setDescription("Polliwog");

      catepillar = new Animal();
      catepillar.setBodyWeight(10);
      catepillar.setDescription("Catepillar");

      frog = new Animal();
      frog.setBodyWeight(34);
      frog.setDescription("Frog");

      polliwog.setFather(frog);
      frog.addOffspring(polliwog);

      butterfly = new Animal();
      butterfly.setBodyWeight(9);
      butterfly.setDescription("Butterfly");

      catepillar.setMother(butterfly);
      butterfly.addOffspring(catepillar);

      s.save(frog);
      s.save(polliwog);
      s.save(butterfly);
      s.save(catepillar);

      Dog dog = new Dog();
      dog.setBodyWeight(200);
      dog.setDescription("dog");
      s.save(dog);

      Cat cat = new Cat();
      cat.setBodyWeight(100);
      cat.setDescription("cat");
      s.save(cat);

      zoo = new Zoo();
      zoo.setName("Zoo");
      Address add = new Address();
      add.setCity("MEL");
      add.setCountry("AU");
      add.setStreet("Main st");
      add.setPostalCode("3000");
      zoo.setAddress(add);

      pettingZoo = new PettingZoo();
      pettingZoo.setName("Petting Zoo");
      Address addr = new Address();
      addr.setCity("Sydney");
      addr.setCountry("AU");
      addr.setStreet("High st");
      addr.setPostalCode("2000");
      pettingZoo.setAddress(addr);

      s.save(zoo);
      s.save(pettingZoo);

      Joiner joiner = new Joiner();
      joiner.setJoinedName("joined-name");
      joiner.setName("name");
      s.save(joiner);

      Car car = new Car();
      car.setVin("123c");
      car.setOwner("Kirsten");
      s.save(car);

      Truck truck = new Truck();
      truck.setVin("123t");
      truck.setOwner("Steve");
      s.save(truck);

      SUV suv = new SUV();
      suv.setVin("123s");
      suv.setOwner("Joe");
      s.save(suv);

      Pickup pickup = new Pickup();
      pickup.setVin("123p");
      pickup.setOwner("Cecelia");
      s.save(pickup);

      BooleanLiteralEntity bool = new BooleanLiteralEntity();
      s.save(bool);

      txn.commit();
      s.close();
    }
  @Test
  public void testAdd() {
    HibernateDatabaseUserManager userManager = HibernateDatabaseUserManager.getDefault();
    HibernateDatabaseAddressManager addrManager = HibernateDatabaseAddressManager.getDefault();
    HibernateDatabaseArenaManager arenaManager = HibernateDatabaseArenaManager.getDefault();
    HibernateDatabaseGameManager gameManager = HibernateDatabaseGameManager.getDefault();

    addrManager.setupTable();
    arenaManager.setupTable();
    gameManager.setupTable();
    userManager.setupTable();

    Address addr1 = new Address();
    addr1.setStreetAddress("2185 Arch St.");
    addr1.setCity("Ottawa");
    addr1.setPostalOrZipCode("K1G 2H5");
    addr1.setProvinceOrState("Ontario");
    addr1.setCountry("Canada");

    Arena arena1 = new Arena();
    arena1.setArenaName("Cantebury");
    arena1.setAddress(addr1);
    addr1.setArena(arena1);

    Game game1 = new Game();
    game1.setGameDay("Tuesday");
    game1.setGameTime("7:30 PM");

    arena1.addGame(game1);

    Address addr = new Address();
    addr.setStreetAddress("1264 Walkley Rd. ");
    addr.setCity("Ottawa");
    addr.setPostalOrZipCode("K1V 6P9");
    addr.setProvinceOrState("Ontario");
    addr.setCountry("Canada");

    Arena arena = new Arena();
    arena.setArenaName("Jim Durell");

    Game game = new Game();
    game.setGameDay("Monday");
    game.setGameTime("9:30 PM");

    Game game2 = new Game();
    game2.setGameDay("Wednesday");
    game2.setGameTime("10:30 PM");

    Address addr3 = new Address();
    addr3.setStreetAddress("210 Hopewell Ave.");
    addr3.setCity("Ottawa");
    addr3.setPostalOrZipCode("K1S 2Z5");
    addr3.setProvinceOrState("Ontario");
    addr3.setCountry("Canada");

    Arena arena3 = new Arena();
    arena3.setArenaName("Brewer");
    arena3.setAddress(addr3);
    addr3.setArena(arena3);

    Game game3 = new Game();
    game3.setGameDay("Friday");
    game3.setGameTime("10:30 PM");

    arena3.addGame(game3);

    arena.setAddress(addr);
    addr.setArena(arena);

    arena.addGame(game);
    arena.addGame(game2);

    arenaManager.add(arena);
    arenaManager.add(arena1);
    arenaManager.add(arena3);

    User client = new User();
    client.setFirstName("John");
    client.setLastName("Marsh");
    client.setEmailAddress("*****@*****.**");
    client.setPassword(BCrypt.hashpw("password", BCrypt.gensalt()));
    client.setCity("Ottawa");
    client.setCountry("Canada");
    client.setProvinceORstate("Ontario");
    client.setBirthdate(Timestamp.valueOf("1993-07-21 00:00:00"));

    User client2 = new User();
    client2.setFirstName("Dougall");
    client2.setLastName("Percival");
    client2.setEmailAddress("*****@*****.**");
    client2.setPassword(BCrypt.hashpw("password", BCrypt.gensalt()));
    client2.setCity("Ottawa");
    client2.setCountry("Canada");
    client2.setProvinceORstate("Ontario");
    client2.setBirthdate(Timestamp.valueOf("1993-12-21 00:00:00"));
    client2.addGame(game2);

    assertTrue(userManager.add(client));
    assertTrue(userManager.add(client2));

    userManager.update(client2);
    userManager.update(client);
  }
예제 #18
0
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    // Loginse user bilgilerini al, textboxlari readonly yap, degilse textboxtakileri al

    User user = (User) request.getSession().getAttribute("user");
    if (user == null) {

      String name = request.getParameter("reservation-name");
      String lastName = request.getParameter("reservation-lastname");
      String email = request.getParameter("reservation-email");
      String phone = request.getParameter("reservation-phone");

    } else {
      String name = user.getFirstName();
      String lastName = user.getLastName();
      String email = user.getEmail();
      String phone = user.getPhoneNumber();
    }

    Address pickup = new Address();
    pickup.setBuildingNo(Integer.parseInt(request.getParameter("pickupbuilding-no")));
    pickup.setStreet(request.getParameter("pickupstreet"));
    pickup.setCity(request.getParameter("pickuphomecity"));
    pickup.setState(request.getParameter("pickupstate"));
    pickup.setZip(Integer.parseInt(request.getParameter("pickuphomezip")));
    pickup.setCountry(request.getParameter("pickupcountry"));

    Address destination = new Address();
    destination.setBuildingNo(Integer.parseInt(request.getParameter("destinationbuilding-no")));
    destination.setStreet(request.getParameter("destinationstreet"));
    destination.setCity(request.getParameter("destinationhomecity"));
    destination.setState(request.getParameter("destinationstate"));
    destination.setZip(Integer.parseInt(request.getParameter("destinationzip")));
    destination.setCountry(request.getParameter("destinationcountry"));

    int passengerNo = Integer.parseInt(request.getParameter("passenger-no"));
    int luggageNo = Integer.parseInt(request.getParameter("luggage-no"));

    double fareMultiplier = 0;
    String vehicleType = request.getParameter("vehicle-radio");
    if ("sedan".equals(vehicleType)) {
      fareMultiplier = 3;
    } else if ("suv".equals(vehicleType)) {
      fareMultiplier = 5;
    } else if ("blackcar".equals(vehicleType)) {
      fareMultiplier = 4.5;
    }

    ReservationService service = new ReservationService();
    double distance = service.calculateDistance(pickup, destination);
    double initialFare = 10;

    double amount = fareMultiplier * distance + initialFare;
    boolean isPet = false;
    // isPet is going to be retrieved from checkbox

    // boolean isCash = request.getParameter("payment-method");
    boolean isCash = false;

    Payment payment = new Payment(isCash);
    payment.setAmount(amount);

    if (!isCash) {
      if (!payment.isPaid()) {
        // chargeCustormer();
      }
      //	payment.setCredit()

    }

    Reservation reservation = new Reservation();
    reservation.setComment("Write a comment");
  }
예제 #19
0
  private static void parseAddressComponents(
      @NonNull final JSONObject result, @NonNull final Address address) throws JSONException {
    if (result.has(ADDRESS_COMPONENTS)) {
      final JSONArray addressComponents = result.getJSONArray(ADDRESS_COMPONENTS);
      for (int a = 0; a < addressComponents.length(); a++) {
        final JSONObject addressComponent = addressComponents.getJSONObject(a);
        if (!addressComponent.has(TYPES)) {
          continue;
        }
        String value = null;
        if (addressComponent.has(LONG_NAME)) {
          value = addressComponent.getString(LONG_NAME);
        } else if (addressComponent.has(SHORT_NAME)) {
          value = addressComponent.getString(SHORT_NAME);
        }
        if (value == null || value.isEmpty()) {
          continue;
        }
        final JSONArray types = addressComponent.getJSONArray(TYPES);
        for (int t = 0; t < types.length(); t++) {
          final String type = types.getString(t);
          switch (type) {
            case "street_address":
              address.setStreetAddress(value);
              break;

            case "route":
              address.setRoute(value);
              break;

            case "intersection":
              address.setIntersection(value);
              break;

            case "political":
              address.setPolitical(value);
              break;

            case "country":
              address.setCountry(value);
              break;

            case "administrative_area_level_1":
              address.setAdministrativeAreaLevel1(value);
              break;

            case "administrative_area_level_2":
              address.setAdministrativeAreaLevel2(value);
              break;

            case "administrative_area_level_3":
              address.setAdministrativeAreaLevel3(value);
              break;

            case "administrative_area_level_4":
              address.setAdministrativeAreaLevel4(value);
              break;

            case "administrative_area_level_5":
              address.setAdministrativeAreaLevel5(value);
              break;

            case "colloquial_area":
              address.setColloquialArea(value);
              break;

            case "locality":
              address.setLocality(value);
              break;

            case "ward":
              address.setWard(value);
              break;

            case "sublocality":
              address.setSubLocality(value);
              break;

            case "sublocality_level_1":
              address.setSubLocalityLevel1(value);
              break;

            case "sublocality_level_2":
              address.setSubLocalityLevel2(value);
              break;

            case "sublocality_level_3":
              address.setSubLocalityLevel3(value);
              break;

            case "sublocality_level_4":
              address.setSubLocalityLevel4(value);
              break;

            case "sublocality_level_5":
              address.setSubLocalityLevel5(value);
              break;

            case "neighborhood":
              address.setNeighborhood(value);

            case "premise":
              address.setPremise(value);
              break;

            case "subpremise":
              address.setSubPremise(value);
              break;

            case "postal_code":
              address.setPostalCode(value);
              break;

            case "natural_feature":
              address.setNaturalFeature(value);
              break;

            case "airport":
              address.setAirport(value);
              break;

            case "park":
              address.setPark(value);
              break;

            case "point_of_interest":
              address.setPointOfInterest(value);
              break;

            case "floor":
              address.setFloor(value);
              break;

            case "establishment":
              address.setEstablishment(value);
              break;

            case "parking":
              address.setParking(value);
              break;

            case "post_box":
              address.setPostBox(value);
              break;

            case "postal_town":
              address.setPostTown(value);
              break;

            case "room":
              address.setRoom(value);
              break;

            case "street_number":
              address.setStreetNumber(value);
              break;

            case "bus_station":
              address.setBusStation(value);
              break;

            case "train_station":
              address.setTrainStation(value);
              break;

            case "transit_station":
              address.setTransitStation(value);
              break;

            default:
              // Unhandled
              break;
          }
        }
      }
    }
  }