@FXML private void initialize() { personTableNameColumn.setCellValueFactory( (dataFeatures) -> dataFeatures.getValue().nameProperty()); personTableNameColumn.setCellFactory(TextFieldTableCell.forTableColumn()); personTableNameColumn.setOnEditCommit( (cellEditEvent) -> { int row = cellEditEvent.getTablePosition().getRow(); Person person = cellEditEvent.getTableView().getItems().get(row); person.setName(cellEditEvent.getNewValue()); }); personTableEmailColumn.setCellValueFactory( (dataFeatures) -> dataFeatures.getValue().emailProperty()); personTableEmailColumn.setCellFactory(TextFieldTableCell.forTableColumn()); personTableNameColumn.setOnEditCommit( (cellEditEvent) -> { int row = cellEditEvent.getTablePosition().getRow(); Person person = cellEditEvent.getTableView().getItems().get(row); person.setEmail(cellEditEvent.getNewValue()); }); ReadOnlyObjectProperty<Person> selectionProperty = personTableView.getSelectionModel().selectedItemProperty(); selectionProperty.addListener( (observable, oldValue, newValue) -> { personPaneController.setModel(newValue); }); personList = personTableView.getItems(); }
/** Shows the person overview inside the root layout. */ public void showPersonOverview() { try { // Load person overview. FXMLLoader loader = new FXMLLoader(); loader.setLocation(MainApp.class.getResource("PersonView.fxml")); AnchorPane personOverview = (AnchorPane) loader.load(); // Set person overview into the center of root layout. rootLayout.setCenter(personOverview); // Give the controller access to the main app. PersonController controller = loader.getController(); controller.setMainApp(this); } catch (IOException e) { e.printStackTrace(); } }
@Test public void deletePersonsTest() { List<Person> personL = personDao.findAll(); assertEquals(personL.size(), 1); personController.delete(personL.get(0).getId()); assertEquals(personDao.findAll().size(), 0); }
@Test public void shouldReturnPersonListView() { ModelAndView mav = personController.listPeople(); assertEquals("list", mav.getViewName()); @SuppressWarnings("unchecked") List<Person> people = (List<Person>) mav.getModelMap().get("people"); assertNotNull(people); assertEquals(DataInitializer.PERSON_COUNT, people.size()); }
@Test public void shouldReturnSecondPersonWithEditMav() { Long template = dataInitializer.people.get(1); ModelAndView mav = personController.editPerson(template); assertNotNull(mav); assertEquals("edit", mav.getViewName()); Object object = mav.getModel().get("person"); assertTrue(Person.class.isAssignableFrom(object.getClass())); Person person = (Person) object; assertEquals(template, person.getId()); }
public void shouldReturnNewPersonWithEditMav() { ModelAndView mav = personController.editPerson(null); assertNotNull(mav); assertEquals("edit", mav.getViewName()); Object object = mav.getModel().get("person"); assertTrue(Person.class.isAssignableFrom(object.getClass())); Person person = (Person) object; assertNull(person.getId()); assertNull(person.getFirstName()); assertNull(person.getLastName()); }
@Before public void before() { Person person = new Person(); person.setFirstName("TestFirstName"); person.setLastName("TestLastName"); person.setEmail("*****@*****.**"); person.setPassword("123456"); person.setGender("M"); person.setPhone("0123456789"); personController.create(person); }
@Test public void updatePersonsTest() { List<Person> personL = personDao.findAll(); assertEquals(personL.size(), 1); Person person1 = personL.get(0); person1.setFirstName("FirstName"); personController.update(person1); personL = personDao.findAll(); assertEquals(personL.get(0).getFirstName(), "FirstName"); }
@Test public void getPersonsTest() { List<Person> personL = personDao.findAll(); Person person1 = personController.read(personL.get(0).getId()); assertEquals(person1.getFirstName(), "TestFirstName"); assertEquals(person1.getLastName(), "TestLastName"); assertEquals(person1.getEmail(), "*****@*****.**"); assertEquals(person1.getGender(), "M"); assertEquals(person1.getPassword(), "123456"); assertEquals(person1.getPhone(), "0123456789"); log.debug(person1.getId()); }