Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user service tests added #91

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/test/java/csse/ItemServiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,14 @@ public void allItems() throws Exception {
List<Item> allItems = itemService.fetchAll();
Assert.assertEquals("Approved item size should be 2", 2, allItems.size());
}


@Test
public void allItemsFail() throws Exception {
logger.info("Running setsItemIdOnSave");
Item savedItem1 =itemService.saveItem(item1);
Item savedItem2 =itemService.saveItem(item2);
List<Item> allItems = itemService.fetchAll();
Assert.assertNotEquals("list is 2 but asked for 3", 3, allItems.size());
}
}
160 changes: 61 additions & 99 deletions src/test/java/csse/UserServiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public void setUp() throws IOException {
InputStream userInput = TypeReference.class.getResourceAsStream("/json/user.json");
testUser = mapper.readValue(userInput, typeReference);
logger.info("loaded create User type User");

// InputStream userInput1 = TypeReference.class.getResourceAsStream("/json/testuser3.json");
// testUser1 = mapper.readValue(userInput1, typeReference);
// logger.info("loaded create User type User3");
}

@After
Expand All @@ -58,112 +62,70 @@ public void tearDown() {
logger.info("database renewed");
}

//register=>pass
@Test
public void setsUserIdOnSaveTest() throws Exception {
public void setsUserIdOnSavePassTest() throws Exception {
logger.info("Running setsUserIdOnSave");
String savedUser = service.register(testAdmin);
String savedUser1 = service.register(testUser);
Assert.assertNotNull("After creation UserID should not be null", testAdmin.get_id());
}

// @Test
// public void getAllUsersTest() throws Exception {
// logger.info("Running setsUserIdOnSave");
// //String savedUser1 = service.register(testAdmin);
// String savedAdmin1 = service.register(testUser);
//
// List<ApplicationUser> list = service.all();
// Assert.assertEquals("user size should be 2", 2, list.size());
//
// }

// @Test
// public void getUserByUsernameTest() throws Exception {
// logger.info("Running getUserByUsername");
// ApplicationUser user = service.findByUsername("Mathew99");
//
// Assert.assertEquals("user's Address Attribute shud be Negombo", "Negombo", user.getAddress());
//
// }

// @Test
// public void getUserByEmpIDTest() throws Exception {
// logger.info("Running getUserByEmpID");
// ApplicationUser user = service.findByemp("A5099");
//
// Assert.assertEquals("user's Address Attribute shud be Negombo", "Negombo", user.getAddress());
//
// }
//list=>pass
@Test
public void getAllUsersPassTest() throws Exception {
logger.info("Running setsUserIdOnSave");
String savedUser = service.register(testAdmin);
String savedUser1 = service.register(testUser);
String savedAdmin1 = service.register(testUser);

List<ApplicationUser> list = service.all();
Assert.assertEquals("user size should be 2", 2, list.size());

}

// @Test
// public void getUserByEmpIDFailTest() throws Exception {
// logger.info("Running fail getUserByEmpID");
// ApplicationUser user = service.findByemp("A5088");
//
// Assert.assertEquals("user shud be null", null, user);
//
// }
//
// @Test
// public void resetPasswordPassedTest() throws Exception {
// logger.info("Running pass resetPassword");
// String response = service.resetPassword("Sam99", "Sam99", "sam99", "sam99");
// Assert.assertEquals("user's pwd is reset", "Password reset successfully", response);
//
// }

// @Test
// public void resetPasswordFailTest() throws Exception {
// logger.info("Running fail resetPassword");
// String response = service.resetPassword("Sam99", "Sam99", "sam88", "sam99");
// Assert.assertEquals("user's pwd is not reset", "The new passwords don't match", response);
//
// }

// @Test
// public void resetPasswordFailTest() throws Exception {
// logger.info("Running fail resetPassword");
// String response = service.resetPassword("Sam99", "Sam9999", "sam99", "sam99");
// Assert.assertEquals("user's pwd is not reset", "Current password is incorrect!", response);
//
// }

//
// @Test
// public void forgotPasswordPassTest() throws Exception {
// logger.info("Running pass forgotPassword");
// String response = service.forgotPassword("Mathew99", "math", "math");
// Assert.assertEquals("user's pwd is reset", "Password reset successfully", response);
//
// }

// @Test
// public void forgotPasswordFailTest() throws Exception {
// logger.info("Running fail forgotPassword");
// String response = service.forgotPassword("Mathew99", "math123", "math");
// Assert.assertEquals("user's pwd is not reset", "Password reset failed", response);
//
// }

//
// @Test
// public void editProfileTest() throws Exception{
// logger.info("Running editProfile");
// ApplicationUser user = service.editProfile("Mathew99", "math" , "mathtest", "kandy", "0764565789", "[email protected]");
// Assert.assertEquals("user's profile is reset","[email protected]" , user.getEmail());
// }
//
// @Test
// public void deactivatePassTest() throws Exception{
// logger.info("Running pass deactivate");
// String response = service.deactivate("A5001");
// Assert.assertEquals("user is deleted","Successfully deactivated" ,response);
// }
//
//get Username => pass
@Test
public void getUserByUsernamePassTest() throws Exception {
logger.info("Running getUserByUsername");
String savedUser = service.register(testAdmin);
String savedUser1 = service.register(testUser);
ApplicationUser user = service.findByUsername("Mathew99");

Assert.assertEquals("user's Address Attribute shud be Negombo", "Negombo", user.getAddress());

}

// @Test
// public void deactivateFailTest() throws Exception{
// logger.info("Running fail deactivate");
// String response = service.deactivate("A9001");
// Assert.assertEquals("user is not deleted","User doesn't exist" ,response);
// }
//get by empID=> pass
@Test
public void getUserByEmpIDPassTest() throws Exception {
logger.info("Running getUserByEmpID");
String savedUser = service.register(testAdmin);
String savedUser1 = service.register(testUser);
ApplicationUser user = service.findByemp("A5099");
Assert.assertEquals("user's Address Attribute shud be Negombo", "Negombo", user.getAddress());

}

//get by empID=> fail
@Test(expected=NullPointerException.class)
public void getUserByEmpIDFailTest() throws Exception {
logger.info("Running fail getUserByEmpID");
String savedUser = service.register(testAdmin);
String savedUser1 = service.register(testUser);
ApplicationUser user = service.findByemp("A6000");
Assert.assertFalse("Negombo"== user.getAddress().toString());
}
//password reset=> pass
@Test
public void resetPasswordPassTest() throws Exception {
logger.info("Running pass resetPassword");
String savedUser = service.register(testAdmin);
String savedUser1 = service.register(testUser);
String response = service.resetPassword("Sam99", "Sam99", "sam99", "sam99");
Assert.assertEquals("user's pwd is reset", "Password reset successfully", response);

}

}
16 changes: 16 additions & 0 deletions src/test/resources/json/testuser3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"emp_ID": "A50",
"emp_type": "Site Manager",
"firstname": "Mark",
"lastname": "Rodrigo",
"address": "Colombo",
"email": "[email protected]",
"phone": "0777707531",
"username": "Mark99",
"password": "Mark99",
"authorities": [
"ADMIN",
"SITE_MANAGER"
]
}