Package com.springone.myrestaurants.domain

Examples of com.springone.myrestaurants.domain.UserAccount


        return "redirect:/useraccounts/" + userAccount.getId();
    }

  @RequestMapping(params = "form", method = RequestMethod.GET)
    public String createForm(Model model) {
        model.addAttribute("userAccount", new UserAccount());
        addDateTimeFormatPatterns(model);
        return "useraccounts/create";
    }
View Full Code Here


        if (result.hasErrors()) {
            model.addAttribute("userAccount", userAccount);
            addDateTimeFormatPatterns(model);
            return "useraccounts/update";
        }
        final UserAccount mergedAccount = userAccountRepository.merge(userAccount);
        return "redirect:/useraccounts/" + mergedAccount.getId();
    }
View Full Code Here

        return "useraccounts/update";
    }
 
  @RequestMapping(value = "/{username}", params = "form2", method = RequestMethod.GET)
    public String updateForm(@PathVariable("username") String userName, Model model) {
    UserAccount userAccount = userAccountRepository.findByName(userName);
        model.addAttribute("userAccount", userAccount);
        addDateTimeFormatPatterns(model);
        return "useraccounts/update";
    }
View Full Code Here

    UserAccountRepository repo;

    @Transactional
    @Test
    public void testFindUser() {
      UserAccount o = repo.findUserAccount(userId);
      Assert.assertNotNull("should have found something" ,o);
      Assert.assertEquals("should have found the right one", "user", o.getUserName());
    }
View Full Code Here

    }

    @Transactional
    @Test
    public void testFindByName() {
      UserAccount o = repo.findByName("user");
      Assert.assertNotNull("should have found something" ,o);
      Assert.assertEquals("should have found the right one", "user", o.getUserName());
    }
View Full Code Here

    }

    @Transactional
    @Test
    public void testPersist() {
      UserAccount newUser = new UserAccount();
      newUser.setFirstName("John");
      newUser.setLastName("Doe");
      newUser.setBirthDate(new Date());
      newUser.setNickname("Bubba");
      newUser.setUserName("jdoe");
      repo.persist(newUser);
      em.flush();
    List results = em.createNativeQuery("select id, user_name, first_name from user_account where user_name = ?")
          .setParameter(1, newUser.getUserName()).getResultList();
      Assert.assertEquals("should have found the entry", 1, results.size());
      Assert.assertEquals("should have found the correct entry", "John", ((Object[])results.get(0))[2]);
      UserAccount persistedUser = repo.findByName(newUser.getUserName());
      Assert.assertEquals("should have the correct value", newUser.getFirstName(), persistedUser.getFirstName());
      Assert.assertEquals("should have the correct value", newUser.getLastName(), persistedUser.getLastName());
      Assert.assertEquals("should have the correct value", newUser.getNickname(), persistedUser.getNickname());
      Assert.assertEquals("should have the correct value", newUser.getUserName(), persistedUser.getUserName());
      Assert.assertEquals("should have the correct value", newUser.getBirthDate(), persistedUser.getBirthDate());
    }
View Full Code Here

    @Test
    public void testMerge() {
      EntityManager separateTxEm = emf.createEntityManager();
      EntityTransaction separateTx = separateTxEm.getTransaction();
      separateTx.begin();
      UserAccount user = separateTxEm.find(UserAccount.class, userId);
      separateTxEm.flush();
      Assert.assertTrue("entity is part of separate em", separateTxEm.contains(user));
      separateTx.commit();
      separateTxEm.detach(user);
      Assert.assertFalse("entity is no longer part of separate em", separateTxEm.contains(user));
      Assert.assertFalse("entity is not part of main em", em.contains(user));
      user.setLastName("Hendrix");
      UserAccount mergedUser = repo.merge(user);
      em.flush();
      Assert.assertTrue("entity is now part of main em", em.contains(mergedUser));
    List results = em.createNativeQuery("select id, user_name, last_name from user_account where id = ?")
        .setParameter(1, userId).getResultList();
    Assert.assertEquals("should have found the entry", 1, results.size());
View Full Code Here

    RestaurantRepository restaurantRepository;

    @Transactional
    @Test
    public void listFriends() {
      UserAccount user = userAccountRepo.findUserAccount(userId);
      UserAccount newUser = new UserAccount();
      newUser.setFirstName("John");
      newUser.setLastName("Doe");
      newUser.setBirthDate(new Date());
      newUser.setNickname("Bubba");
      newUser.setUserName("jdoe");
      em.persist(newUser);
        newUser.persist();
      Assert.assertEquals("Should have zero friends", 0, newUser.getFriends().size());     
      newUser.getFriends().add(user);
      Assert.assertEquals("Should have a list of friends", 1, newUser.getFriends().size());
    }
View Full Code Here

    }
   
    @Transactional
    @Test
    public void testAddAndRemoveFriends() {
      UserAccount user = userAccountRepo.findUserAccount(userId);
      UserAccount newUser = new UserAccount();
      newUser.setFirstName("John");
      newUser.setLastName("Doe");
      newUser.setBirthDate(new Date());
      newUser.setNickname("Bubba");
      newUser.setUserName("jdoe");
      userAccountRepo.persist(newUser);
      em.flush();
        newUser.persist();
      user.getFriends().add(newUser);
      UserAccount updatedUser = userAccountRepo.findUserAccount(userId);
      Assert.assertNotNull("should have found something" ,updatedUser);
      Assert.assertEquals("user should now have correct number of friends", 1, updatedUser.getFriends().size());
      user.getFriends().remove(newUser);
      Assert.assertEquals("user should now have correct number of friends", 0, updatedUser.getFriends().size());
    }
View Full Code Here

    }

    @Transactional
    @Test
    public void testAddRecommendation() {
      UserAccount user = userAccountRepo.findUserAccount(userId);
      Restaurant rest = restaurantRepository.findRestaurant(22L);
      user.rate(rest, 3, "Pretty Good");
      em.flush();
      UserAccount updatedUser = userAccountRepo.findUserAccount(userId);
      Assert.assertNotNull("should have found something" ,updatedUser);
      List<Recommendation> recommendations = new ArrayList<Recommendation>();
      for (Recommendation r : updatedUser.getRecommendations()) {
        recommendations.add(r);
      }
      Assert.assertEquals("user should now have correct number of recommendations", 1, recommendations.size());
      Recommendation r = recommendations.get(0);
      Assert.assertEquals("recommendation should have correct rating", 3, r.getStars());
View Full Code Here

TOP

Related Classes of com.springone.myrestaurants.domain.UserAccount

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.