@Test
 public void testMergeOneString() throws Exception {
   c1.setFirstName("ABC");
   c2.setFirstName(null);
   result = (Person) ObjectMerge.merge(c2, c1);
   assertEquals("One String", "ABC", result.getFirstName());
 }
  @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();
  }
 protected Object getControlObject() {
   Person person = new Person();
   person.addItem(CONTROL_ITEM);
   person.setFirstName(CONTROL_FIRST_NAME);
   person.setLastName(CONTROL_LAST_NAME);
   return person;
 }
Beispiel #4
0
 public static Person parsePerson(Element root) {
   Person person = new Person();
   person.setFirstName(getTagValue("first_name", root));
   person.setLastName(getTagValue("last_name", root));
   person.setYearOfBirth(getTagValue("birth_date", root));
   return person;
 }
  @Test
  public void testRequestClientValidation() {
    Person person = new Person();

    try {
      disconnectedClient.saveValidateOut(person);
      fail("Expected exception");
    } catch (SOAPFaultException sfe) {
      assertTrue(sfe.getMessage().contains("Marshalling Error"));
    }

    person.setFirstName(""); // empty string is valid
    try {
      disconnectedClient.saveValidateOut(person);
      fail("Expected exception");
    } catch (SOAPFaultException sfe) {
      assertTrue(sfe.getMessage().contains("Marshalling Error"));
    }

    person.setLastName(""); // empty string is valid

    // this confirms that we passed client validation as we then got the connectivity error
    try {
      disconnectedClient.saveValidateOut(person);
      fail("Expected exception");
    } catch (WebServiceException e) {
      assertTrue(e.getMessage().contains("Could not send Message"));
    }
  }
 @Test
 public void testMergeTwoStrings() throws Exception {
   c1.setFirstName("Ian");
   c2.setLastName("Darwin");
   result = (Person) ObjectMerge.merge(c1, c2);
   assertEquals("Merge Nulls", "Ian Darwin", result.toString());
 }
  @Test
  public void testRPCLit() throws Exception {
    Person person = new Person();
    person.setFirstName("Foo");
    person.setLastName("Bar");
    // this should work
    rpcClient.saveValidateOut(person);

    try {
      person.setFirstName(null);
      rpcClient.saveValidateOut(person);
      fail("Expected exception");
    } catch (SOAPFaultException sfe) {
      assertTrue(sfe.getMessage().contains("Marshalling Error"));
      assertTrue(sfe.getMessage().contains("lastName"));
    }
  }
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    PrintWriter out = resp.getWriter();
    resp.setContentType("text/html");
    out.print("<html><head><title>SimpleBVServlet</title></head><body>");

    javax.validation.Validator beanValidator = configureValidation(req, resp);

    out.print("<h1>");
    out.print("Validating person class using validateValue with valid property");
    out.print("</h1>");

    List<String> listOfString = new ArrayList<String>();
    listOfString.add("one");
    listOfString.add("two");
    listOfString.add("three");

    Set<ConstraintViolation<Person>> violations =
        beanValidator.validateValue(Person.class, "listOfString", listOfString);

    printConstraintViolations(out, violations, "case1");

    out.print("<h1>");
    out.print("Validating person class using validateValue with invalid property");
    out.print("</h1>");

    try {
      violations = beanValidator.validateValue(Person.class, "nonExistentProperty", listOfString);
    } catch (IllegalArgumentException iae) {
      out.print("<p>");
      out.print("case2: caught IllegalArgumentException.  Message: " + iae.getMessage());
      out.print("</p>");
    }
    Person person = new Person();

    out.print("<h1>");
    out.print("Validating invalid person instance using validate.");
    out.print("</h1>");

    violations = beanValidator.validate(person);

    printConstraintViolations(out, violations, "case3");

    out.print("<h1>");
    out.print("Validating valid person.");
    out.print("</h1>");

    person.setFirstName("John");
    person.setLastName("Yaya");
    person.setListOfString(listOfString);

    violations = beanValidator.validate(person);
    printConstraintViolations(out, violations, "case4");

    out.print("</body></html>");
  }
Beispiel #9
0
 public static void main(String[] args) {
   HibernateTemplate template = (HibernateTemplate) Util.getObject("template");
   final Person p1 = new Person();
   p1.setId(109);
   p1.setFirstName("vins");
   p1.setLastName("jains");
   p1.setAge(26);
   Object obj = template.save(p1);
   System.out.println("done with " + obj);
   System.out.println("done");
 }
  @Test
  public void testSaveNoValidationProvider() {
    Person person = new Person();
    client.saveNoValidation(person);

    person.setFirstName(""); // empty string is valid
    client.saveNoValidation(person);

    person.setLastName(""); // empty string is valid
    client.saveNoValidation(person);
  }
  // no validation at all is required
  @Test
  public void testSaveNoValidationAnnotated() {
    Person person = new Person();
    annotatedClient.saveNoValidation(person);

    person.setFirstName(""); // empty string is valid
    annotatedClient.saveNoValidation(person);

    person.setLastName(""); // empty string is valid
    annotatedClient.saveNoValidation(person);
  }
  @Test
  public void testResponseValidationWithClientValidationDisabled() {
    Person person = new Person();

    try {
      person.setFirstName("InvalidResponse");
      person.setLastName("WhoCares");
      annotatedNonValidatingClient.saveValidateOut(person);
    } catch (SOAPFaultException sfe) {
      // has to be server side exception, as all validation is disabled on client
      assertTrue(sfe.getMessage().contains("Marshalling Error"));
    }
  }
  @Test
  public void shouldNotValidateWhenFirstNameEmpty() {

    LocaleContextHolder.setLocale(Locale.ENGLISH);
    Person person = new Person();
    person.setFirstName("");
    person.setLastName("smith");

    Validator validator = createValidator();
    Set<ConstraintViolation<Person>> constraintViolations = validator.validate(person);

    Assert.assertEquals(1, constraintViolations.size());
    ConstraintViolation<Person> violation = constraintViolations.iterator().next();
    assertThat(violation.getPropertyPath().toString()).isEqualTo("firstName");
    assertThat(violation.getMessage()).isEqualTo("may not be empty");
  }
Beispiel #14
0
  @Test
  public void testSerializePerson() throws IOException {
    ObjectMapper mapper = new ObjectMapper();

    Person p = new Person();
    p.setCreditLimit(10000.0);
    p.setFirstName("Pedro");
    p.setSurname("Platinum");
    p.setMiddleInitial("A");
    Calendar cal = Calendar.getInstance();
    cal.set(1971, 5, 1);
    p.setDateOfBirth(cal.getTime());

    String str = mapper.writeValueAsString(p);
    System.out.println(str);
  }
 @Test
 public void testGetOperationOld() {
   Person p = new Person();
   p.setName("Arnold");
   p.setFirstName("André");
   XtendFacade facade =
       XtendFacade.create("org::eclipse::xtend::middleend::xtend::test::expressions");
   facade.registerMetaModel(new JavaMetaModel());
   Boolean result = null;
   try {
     result = (Boolean) facade.call("testGetOperationLess", Arrays.asList(p, _person));
     assertNull(result);
   } catch (Exception e) {
     // TODO verify if this is a bug in old Xtend
   }
 }
 @Test
 public void testGetOperation() {
   Person p = new Person();
   p.setName("Arnold");
   p.setFirstName("André");
   NamedFunction result1 =
       (NamedFunction)
           BackendFacade.invoke(
               _ctx, new QualifiedName("testGetOperation"), Arrays.asList(_person));
   assertEquals(
       "called:call",
       _ctx.getFunctionInvoker()
           .invoke(_ctx, result1.getFunction(), Arrays.asList(_person, "call")));
   Boolean result2 =
       (Boolean)
           BackendFacade.invoke(
               _ctx, new QualifiedName("testGetOperationLess"), Arrays.asList(p, _person));
   assertTrue(result2);
 }
  @Test
  public void testSaveValidationOutProvider() {
    Person person = new Person();

    try {
      client.saveValidateOut(person);
    } catch (SOAPFaultException sfe) {
      // verify its server side outgoing
      assertTrue(sfe.getMessage().contains("Marshalling Error"));
    }

    person.setFirstName(""); // empty string is valid
    try {
      client.saveValidateOut(person);
    } catch (SOAPFaultException sfe) {
      assertTrue(sfe.getMessage().contains("Marshalling Error"));
    }

    person.setLastName(""); // empty string is valid
    client.saveValidateOut(person);
  }
  @Test
  public void testRequestValidationWithClientValidationDisabled() {
    Person person = new Person();

    try {
      annotatedNonValidatingClient.saveValidateIn(person);
    } catch (SOAPFaultException sfe) {
      // has to be server side exception, as all validation is disabled on client
      assertTrue(sfe.getMessage().contains("Marshalling Error"));
    }

    person.setFirstName(""); // empty string is valid
    try {
      annotatedNonValidatingClient.saveValidateIn(person);
    } catch (SOAPFaultException sfe) {
      // has to be server side exception, as all validation is disabled on client
      assertTrue(sfe.getMessage().contains("Marshalling Error"));
    }

    person.setLastName(""); // empty string is valid
    annotatedNonValidatingClient.saveValidateIn(person);
  }
  // so this is the default, we are inheriting from the service level SchemaValidation annotation
  // which is set to BOTH
  @Test
  public void testEndpointSchemaValidationAnnotated() {
    Person person = new Person();

    try {
      annotatedClient.saveInheritEndpoint(person);
      fail("Expected exception");
    } catch (SOAPFaultException sfe) {
      assertTrue(sfe.getMessage().contains("Unmarshalling Error"));
    }

    try {
      person.setFirstName(""); // empty string is valid
      annotatedClient.saveInheritEndpoint(person);
      fail("Expected exception");
    } catch (SOAPFaultException sfe) {
      assertTrue(sfe.getMessage().contains("Unmarshalling Error"));
    }

    person.setLastName(""); // empty string is valid
    annotatedClient.saveInheritEndpoint(person);
  }
  @Test
  public void testSaveValidateInProvider() {
    Person person = new Person();

    try {
      client.saveValidateIn(person);
      fail("Expected exception");
    } catch (SOAPFaultException sfe) {
      assertTrue(sfe.getMessage().contains("Unmarshalling Error"));
    }

    try {
      person.setFirstName(""); // empty string is valid
      client.saveValidateIn(person);
      fail("Expected exception");
    } catch (SOAPFaultException sfe) {
      assertTrue(sfe.getMessage().contains("Unmarshalling Error"));
    }

    person.setLastName(""); // empty string is valid
    client.saveValidateIn(person);
  }
Beispiel #21
0
  @Override
  public void start(Stage primaryStage) throws Exception {
    window = primaryStage;
    window.setTitle("Joe Jung java-fx");

    Person Joe = new Person();
    Joe.firstNameProperty()
        .addListener(
            (v, oldValue, newValue) -> {
              System.out.println("Name Change to " + newValue);
              System.out.println("firstNameProperty" + Joe.firstNameProperty());
              System.out.println("getFirstName()" + Joe.getFirstName());
            });

    Button button = new Button("Submit");
    button.setOnAction(e -> Joe.setFirstName("Porky"));

    StackPane stackpane = new StackPane();
    stackpane.getChildren().addAll(button);
    Scene scene = new Scene(stackpane);
    window.setScene(scene);
    window.show();
  }
  @Test
  public void testResponseClientValidation() {
    Person person = new Person();

    try {
      noValidationServerClient.saveValidateIn(person);
      fail("Expected exception");
    } catch (SOAPFaultException e) {
      assertTrue(e.getMessage().contains("Unmarshalling Error"));
    }

    person.setFirstName(""); // empty string is valid
    try {
      noValidationServerClient.saveValidateIn(person);
      fail("Expected exception");
    } catch (SOAPFaultException sfe) {
      assertTrue(sfe.getMessage().contains("Unmarshalling Error"));
    }

    person.setLastName(""); // empty string is valid

    noValidationServerClient.saveValidateIn(person);
  }
  private void addteammemberActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_addteammemberActionPerformed
    JTextField fname = new JTextField();
    JTextField lname = new JTextField();
    JTextField position = new JTextField();
    Object[] message = {
      "First Name:", fname,
      "Last Name:", lname,
      "Position:", position,
    };
    int option =
        JOptionPane.showConfirmDialog(
            this, message, "Enter Team Member Information", JOptionPane.OK_CANCEL_OPTION);

    if (option == JOptionPane.OK_OPTION) {
      Person tm = new Person();
      tm.setFirstName(fname.getText());
      tm.setLastName(lname.getText());
      tm.setPosition(position.getText());
      currentProject.getTeamMembers().add(tm);
      teammodel.addElement(tm.getFirstName() + " " + tm.getLastName() + " " + tm.getPosition());
      teamlist.setModel(teammodel);
    }
  } // GEN-LAST:event_addteammemberActionPerformed
 @Override
 public void setFirstName(String firstName) {
   mPerson.setFirstName(firstName);
 }
 public static PersonContainer createWithTestData() {
   final String[] fnames = {
     "Peter", "Alice", "Joshua", "Mike", "Olivia", "Nina", "Alex", "Rita", "Dan", "Umberto",
     "Henrik", "Rene", "Lisa", "Marge"
   };
   final String[] lnames = {
     "Smith",
     "Gordon",
     "Simpson",
     "Brown",
     "Clavel",
     "Simons",
     "Verne",
     "Scott",
     "Allison",
     "Gates",
     "Rowling",
     "Barks",
     "Ross",
     "Schneider",
     "Tate"
   };
   final String cities[] = {
     "Amsterdam",
     "Berlin",
     "Helsinki",
     "Hong Kong",
     "London",
     "Luxemburg",
     "New York",
     "Oslo",
     "Paris",
     "Rome",
     "Stockholm",
     "Tokyo",
     "Turku"
   };
   final String streets[] = {
     "4215 Blandit Av.",
     "452-8121 Sem Ave",
     "279-4475 Tellus Road",
     "4062 Libero. Av.",
     "7081 Pede. Ave",
     "6800 Aliquet St.",
     "P.O. Box 298, 9401 Mauris St.",
     "161-7279 Augue Ave",
     "P.O. Box 496, 1390 Sagittis. Rd.",
     "448-8295 Mi Avenue",
     "6419 Non Av.",
     "659-2538 Elementum Street",
     "2205 Quis St.",
     "252-5213 Tincidunt St.",
     "P.O. Box 175, 4049 Adipiscing Rd.",
     "3217 Nam Ave",
     "P.O. Box 859, 7661 Auctor St.",
     "2873 Nonummy Av.",
     "7342 Mi, Avenue",
     "539-3914 Dignissim. Rd.",
     "539-3675 Magna Avenue",
     "Ap #357-5640 Pharetra Avenue",
     "416-2983 Posuere Rd.",
     "141-1287 Adipiscing Avenue",
     "Ap #781-3145 Gravida St.",
     "6897 Suscipit Rd.",
     "8336 Purus Avenue",
     "2603 Bibendum. Av.",
     "2870 Vestibulum St.",
     "Ap #722 Aenean Avenue",
     "446-968 Augue Ave",
     "1141 Ultricies Street",
     "Ap #992-5769 Nunc Street",
     "6690 Porttitor Avenue",
     "Ap #105-1700 Risus Street",
     "P.O. Box 532, 3225 Lacus. Avenue",
     "736 Metus Street",
     "414-1417 Fringilla Street",
     "Ap #183-928 Scelerisque Road",
     "561-9262 Iaculis Avenue"
   };
   PersonContainer c = null;
   Random r = new Random(0);
   try {
     c = new PersonContainer();
     for (int i = 0; i < 100; i++) {
       Person p = new Person();
       p.setFirstName(fnames[r.nextInt(fnames.length)]);
       p.setLastName(lnames[r.nextInt(lnames.length)]);
       p.setCity(cities[r.nextInt(cities.length)]);
       p.setEmail(
           p.getFirstName().toLowerCase() + "." + p.getLastName().toLowerCase() + "@vaadin.com");
       p.setPhoneNumber(
           "+358 02 555 " + r.nextInt(10) + r.nextInt(10) + r.nextInt(10) + r.nextInt(10));
       int n = r.nextInt(100000);
       if (n < 10000) {
         n += 10000;
       }
       p.setPostalCode(n);
       p.setStreetAddress(streets[r.nextInt(streets.length)]);
       c.addItem(p);
     }
   } catch (InstantiationException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return c;
 }
  public ViewProject(int id) {
    initComponents();
    currentProject = new Project();
    currentProject.setProjectID(id);

    try {
      Class.forName("com.mysql.jdbc.Driver");
      Connection con =
          DriverManager.getConnection(
              "jdbc:mysql://127.0.0.1:3306/projectmanagementsystem?zeroDateTimeBehavior=convertToNull",
              "root",
              "password");

      String query2 = "select * from project where idproject = ?";
      PreparedStatement pst2 = con.prepareStatement(query2);
      int projectid = id + 1;
      pst2.setInt(1, projectid);
      ResultSet rs = pst2.executeQuery();

      if (rs.next()) {
        projectname.setText(rs.getString("projectname"));
        projectdescription.setText(rs.getString("projectdesc"));
      }

      String query3 = "select * from teammember where teammember_FK = ?";
      PreparedStatement pst3 = con.prepareStatement(query3);
      pst3.setInt(1, projectid);
      ResultSet rs2 = pst3.executeQuery();

      while (rs2.next()) {
        Person p = new Person();
        p.setFirstName(rs2.getString("firstname"));
        p.setLastName(rs2.getString("lastname"));
        p.setPosition(rs2.getString("position"));
        p.setPersonID(rs2.getInt("idteammember"));
        teammembers.add(p);
        teammodel.addElement(p.getFirstName() + " " + p.getLastName() + " " + p.getPosition());
      }

      teamlist.setModel(teammodel);

      String query4 = "select * from goal where goal_FK = ?";
      PreparedStatement pst4 = con.prepareStatement(query4);
      pst4.setInt(1, projectid);
      ResultSet rs3 = pst4.executeQuery();

      while (rs3.next()) {
        Goal g = new Goal();
        g.setGoalID(rs3.getInt("idgoal"));
        g.setGoalDesc(rs3.getString("goaldesc"));
        g.setGoalType(rs3.getString("goaltype"));
        goals.add(g);
        goalmodel.addElement(g.getGoalType() + " " + g.getGoalDesc());
      }

      goallist.setModel(goalmodel);

      String query5 = "select * from requirement where requirement_FK = ?";
      PreparedStatement pst5 = con.prepareStatement(query5);
      pst5.setInt(1, projectid);
      ResultSet rs4 = pst5.executeQuery();

      while (rs4.next()) {
        Requirement r = new Requirement();
        String type;
        r.setRequirementID(rs4.getInt("idrequirement"));
        r.setRequirementDescription(rs4.getString("requirementdesc"));
        if (rs4.getInt("isFunctionalRequirement") == 0) {
          r.setIsFunctionalRequirement(false);
          type = "Non-functional";
        } else type = "Functional";
        requirements.add(r);
        requirementmodel.addElement(type + " " + r.getRequirementDescription());
      }
      requirementlist.setModel(requirementmodel);

      String query6 = "select * from risk where risk_FK = ?";
      PreparedStatement pst6 = con.prepareStatement(query6);
      pst6.setInt(1, projectid);
      ResultSet rs5 = pst6.executeQuery();

      while (rs5.next()) {
        Risk r = new Risk();
        r.setRiskID(rs5.getInt("idrisk"));
        r.setRiskName(rs5.getString("riskname"));
        r.setRiskStatus(rs5.getString("riskstatus"));
        risks.add(r);
        riskmodel.addElement(r.getRiskStatus() + " " + r.getRiskName());
      }

      risklist.setModel(riskmodel);

      String query7 =
          "select * from effort join requirement on effort.effort_FK = requirement.idrequirement"
              + " where requirement.requirement_FK = ?";
      PreparedStatement pst7 = con.prepareStatement(query7);
      pst7.setInt(1, projectid);
      ResultSet rs6 = pst7.executeQuery();

      while (rs6.next()) {
        Effort e = new Effort();
        e.setEffortID(rs6.getInt("ideffort"));
        e.setEffortDate(rs6.getString("effortdate"));
        e.setEffortDevPhase(rs6.getString("effortdevphase"));
        e.setEffortHours(rs6.getInt("efforthours"));
        e.setRequirementID(rs6.getInt("effort_FK"));
        e.setRequirementDesc(rs6.getString("requirementdesc"));
        efforts.add(e);
        effortmodel.addElement(
            "For req: "
                + e.getRequirementDesc()
                + " "
                + e.getEffortDevPhase()
                + " "
                + e.getEffortDate()
                + " "
                + e.getEffortHours());
      }

      effortlist.setModel(effortmodel);
    } catch (Exception e) {
      System.out.println(e.toString());
    }
  }
Beispiel #27
0
 public void onStart() {
   p.setFirstName(attribute("firstName"));
   p.setLastName(attribute("lastName"));
   people.add(p);
 }
 @Test
 public void testTransitivity() throws Exception {
   c1.setFirstName("Robin");
   assertTrue("Transitivity test", ObjectMerge.merge(c1, c2).equals(ObjectMerge.merge(c2, c1)));
 }