Esempio n. 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));
  }
Esempio n. 2
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.
  }
 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;
 }
 public static Address randomAddress() {
   Address a = create(Address.class);
   a.setAddressee(randomize(ADDRESSEE));
   if (rand.nextBoolean()) {
     a.setAddressLine1(randomize(ADDRESS));
     a.setAddressLine2("");
   } else {
     a.setAddressLine1("");
     a.setAddressLine2(randomize(ADDRESS));
   }
   a.setCity(randomize(CITY));
   a.setPostalCode(generateKey(5));
   a.setState(randomize(STATE));
   return (a);
 }
Esempio n. 9
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);
    }
  }
    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();
    }
Esempio n. 11
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;
          }
        }
      }
    }
  }
Esempio n. 12
0
  public static void main(String[] args) {

    Student student = new Student();
    student.setName("Jeff");

    Address homeAddress = new Address();
    homeAddress.setAddressType(AddressType.HOME);
    homeAddress.setAddressLine1("101 Fifth St.");
    homeAddress.setAddressLine2("Suite 3a");
    homeAddress.setCity("St. Charles");
    homeAddress.setState("MO");
    homeAddress.setPostalCode("63303");

    Set addresses = new HashSet();
    addresses.add(homeAddress);

    student.setAddresses(addresses);

    Instructor instructor = new Instructor();
    instructor.setFirstName("John");
    instructor.setLastName("Smith");
    instructor.setInstructorName(instructor.getFirstName(), instructor.getLastName());

    Instructor instructor2 = new Instructor();
    instructor2.setFirstName("Ron");
    instructor2.setLastName("Regan");
    instructor2.setInstructorName(instructor.getFirstName(), instructor.getLastName());

    Course java = new Course();
    java.setCourseName("CSP 443 Advanced Java");
    java.setCreditHours(3.0f);
    java.setInstructor(instructor);

    Course cSharp = new Course();
    cSharp.setCourseName("CSP 233 Beginning C#");
    cSharp.setCreditHours(5.0f);
    java.setInstructor(instructor2);

    Course algebra = new Course();
    algebra.setCourseName("Beginners Algebra");
    algebra.setCreditHours(3.0f);
    algebra.setInstructor(instructor2);

    Course computer = new Course();
    computer.setCourseName("Intro to Computer Science");
    computer.setCreditHours(4.5f);
    computer.setInstructor(instructor);

    Rating rate = new Rating();
    rate.setCourse(java, 8.5d);

    Rating rate2 = new Rating();
    rate2.setCourse(cSharp, 9.0d);

    Rating rate3 = new Rating();
    rate3.setCourse(algebra, 7.0);

    Rating rate4 = new Rating();
    rate4.setCourse(computer, 8.0);

    Set courses = new HashSet();
    courses.add(java);
    courses.add(cSharp);
    courses.add(computer);
    courses.add(algebra);

    student.setCourses(courses);

    Set instructors = new HashSet();
    instructors.add(instructor);
    instructors.add(instructor2);

    instructor.setInstructors(instructors);

    Grade javaGrade = new Grade(student, java, 3.459f);
    Grade cSharpGrade = new Grade(student, cSharp, 3.975f);
    Grade algebraGrade = new Grade(student, algebra, 3.5f);
    Grade computerGrade = new Grade(student, computer, 3.0f);

    Session session = HibernateUtilities.getSessionFactory().openSession();
    session.beginTransaction();

    session.save(student);
    session.save(javaGrade);
    session.save(cSharpGrade);
    session.save(algebraGrade);
    session.save(computerGrade);

    session.getTransaction().commit();
    session.close();

    double result = GradebookBusinessLogic.calculateCumulativeGPA(student);

    System.out.println(student.getName() + " Cumulative Grade: " + result);
    System.out.println(instructor.getInstructorName() + ":" + rate4.getRate());
    System.out.println(instructor2.getInstructorName() + ";" + rate3.getRate());
  }