}
@Test
public void testLoadUserByUsername() throws JAXBException {
UserDetails userDetails1 = null;
UserDetailsService accountService = new UserService();
Users users1 = new Users();
User user1 = new User();
user1.setName("serengeti");
users1.setUsers(Arrays.asList(user1));
String confPath = System.getProperties().get("serengeti.home.dir") + File.separator + "conf";
new File(confPath).mkdir();
String userXmlPath = confPath + File.separator + UsersFile;
File usrXmlFile = new File(userXmlPath);
TestFileUtils.createXMLFile(users1, usrXmlFile);
try {
userDetails1 = accountService.loadUserByUsername("root");
} catch (UsernameNotFoundException e) {
}
Assert.assertNull(userDetails1);
UserDetails userDetails2 = accountService.loadUserByUsername("serengeti");
assertNotNull(userDetails2);
TestFileUtils.deleteXMLFile(usrXmlFile);
Users users2 = new Users();
User user2 = new User();
user2.setName("*");
users2.setUsers(Arrays.asList(user2));
TestFileUtils.createXMLFile(users2, usrXmlFile);
userDetails1 = accountService.loadUserByUsername("root");
assertNotNull(userDetails1);
assertEquals(userDetails1.getUsername(), "Guest");
TestFileUtils.deleteXMLFile(usrXmlFile);
Users users3 = new Users();
users3.setUsers(Arrays.asList(user2, user1));
TestFileUtils.createXMLFile(users3, usrXmlFile);
userDetails1 = accountService.loadUserByUsername("serengeti");
assertNotNull(userDetails1);
assertEquals(userDetails1.getUsername(), "serengeti");
TestFileUtils.deleteXMLFile(usrXmlFile);
}