Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MAVEN PROJECT User Registration and login Application Spring Boot Currently I have an API with methods(UserController.java) that interact with the database MongoAtlas(UserRepository.java) that get called

MAVEN PROJECT User Registration and login Application Spring Boot

Currently I have an API with methods(UserController.java) that interact with the database MongoAtlas(UserRepository.java) that get called by the UI. The methods that I have in UserController are the working methods for my application. What I want to do now is create JUnit testing for each of the methods. I have sent screenshots of the methods in UserController.java and my UserControllerTest.java. My Junit test cases that I have written are failing. Could someone fix or rewrite my test cases so they work. thank you!

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

38 UserController.java X De D2 userserver > mongo1 > O UserController.java > Language Support for Java(TM) by Red Hat > PO System.out.println(userEmail); 39 User userInfo = repository.findByUserEmail(userEmail); 40 System.out.println(userInfo); 41 String role = userInfo.getUserRole(); 42 return role; 43 44 } 45 @GetMapping ("/Users") 46 public List getUsers() { 47 return repository.findAll(); 48 } 49 50 @GetMapping("/Users/{id}") 51 public User getUsers(@PathVariable String id) { 52 return repository.findById(id); 53 } 54 55 @DeleteMapping("/Users/{id}") 56 public String deleteUser(@PathVariable String id) { 57 repository.deleteById(id); 58 return "user deleted with id : " + id; 59 } 60 61 //Deletes all users 62 @DeleteMapping("/Users") 63 public String deleteAllUsers() { 64 repository.deleteAll(); 65 return "All users delete."; 66 } 67 68 } 69 o UserController Test.java. src > test > java > com > userserver > mongo1 > UserControllerTest.java > User ControllerTest > deleteAUser() . 1/2.) Pull from fake repository //3.) Test pulled data against the original data 55 56 57 58 59 60 61 62 63 } 64 65 66 67 @Test Run Test Debug Test void deleteAuser() throws Exception { } Rose Wallace, 7 days ago Worked on junit testing 68 69 70 71 72 73 74 75 76 77 78 @Test Run Test | Debug Test void saveUsertriali() { List testList1 = new ArrayList(); List testList2 = new ArrayList(); User testUser2 = new User("fakeEmail1@gmail.com", "fakeName1","fakePassword1","fakeRole1", "fakeStatus1"); User testUser1 = new User("fakeEmail1@gmail.com", "fakeName1","fakePassword1","fakeRole1", "fakeStatus1"); userController.saveUser(testUseri); userController.saveUser(testUser2); assertEquals(testListi, testList2); } 79 80 81 82 83 84 85 86 @Test Run Test | Debug Test public void saveUsertrial2() throws Exception { List testList = new ArrayList(); User testuseri = new User("fakeEmaill@gmail.com", "fakeName1","fakePassword1","fakeRole1", "fakeStatus1"); saveUser Service.saveUser(testUseri); assertEquals(testRepository.findByuserName("fakeName1"), testUser1); } 87 88 89 no @Test Run Test | Debug Test public void DeleteAllusers() { List testList = new ArrayList(); userController.deleteAllUsers(); ngonthultagtigt o UserControllerTest.java. src > test > java > com > userserver > mongo1 > UserControllerTest.java > UserControllerTest > deleteAUser() 77 78 @Test Run Test Debug Test 79 public void saveUsertrial2() throws Exception { 80 List testList = new ArrayList(); 81 User testUser1 = new User("fakeEmail1@gmail.com", "fakeName1","fakePassword1","fakeRo lel", "fakeStatus1"); 82 saveUserService.saveUser(testUseri); 83 assertEquals(testRepository.findByuserName("fakeNamel"), testUser1); 84 } 85 86 @Test Run Test Debug Test 87 public void DeleteAllusers() { 88 List testList = new ArrayList(); 89 userController.deleteAllUsers(); 90 assertNull(testList); 91 92 } 93 94 @Test Run Test Debug Test 95 public void ReturningallusersInData(){ 96 List testList = new ArrayList(); 97 //Maybe I have to turn the method into a object for assert to check it? 98 testRepository.findAll(); 99 assertEquals(testRepository.findAll(), testList); 100 }} 38 UserController.java X De D2 userserver > mongo1 > O UserController.java > Language Support for Java(TM) by Red Hat > PO System.out.println(userEmail); 39 User userInfo = repository.findByUserEmail(userEmail); 40 System.out.println(userInfo); 41 String role = userInfo.getUserRole(); 42 return role; 43 44 } 45 @GetMapping ("/Users") 46 public List getUsers() { 47 return repository.findAll(); 48 } 49 50 @GetMapping("/Users/{id}") 51 public User getUsers(@PathVariable String id) { 52 return repository.findById(id); 53 } 54 55 @DeleteMapping("/Users/{id}") 56 public String deleteUser(@PathVariable String id) { 57 repository.deleteById(id); 58 return "user deleted with id : " + id; 59 } 60 61 //Deletes all users 62 @DeleteMapping("/Users") 63 public String deleteAllUsers() { 64 repository.deleteAll(); 65 return "All users delete."; 66 } 67 68 } 69 o UserController Test.java. src > test > java > com > userserver > mongo1 > UserControllerTest.java > User ControllerTest > deleteAUser() . 1/2.) Pull from fake repository //3.) Test pulled data against the original data 55 56 57 58 59 60 61 62 63 } 64 65 66 67 @Test Run Test Debug Test void deleteAuser() throws Exception { } Rose Wallace, 7 days ago Worked on junit testing 68 69 70 71 72 73 74 75 76 77 78 @Test Run Test | Debug Test void saveUsertriali() { List testList1 = new ArrayList(); List testList2 = new ArrayList(); User testUser2 = new User("fakeEmail1@gmail.com", "fakeName1","fakePassword1","fakeRole1", "fakeStatus1"); User testUser1 = new User("fakeEmail1@gmail.com", "fakeName1","fakePassword1","fakeRole1", "fakeStatus1"); userController.saveUser(testUseri); userController.saveUser(testUser2); assertEquals(testListi, testList2); } 79 80 81 82 83 84 85 86 @Test Run Test | Debug Test public void saveUsertrial2() throws Exception { List testList = new ArrayList(); User testuseri = new User("fakeEmaill@gmail.com", "fakeName1","fakePassword1","fakeRole1", "fakeStatus1"); saveUser Service.saveUser(testUseri); assertEquals(testRepository.findByuserName("fakeName1"), testUser1); } 87 88 89 no @Test Run Test | Debug Test public void DeleteAllusers() { List testList = new ArrayList(); userController.deleteAllUsers(); ngonthultagtigt o UserControllerTest.java. src > test > java > com > userserver > mongo1 > UserControllerTest.java > UserControllerTest > deleteAUser() 77 78 @Test Run Test Debug Test 79 public void saveUsertrial2() throws Exception { 80 List testList = new ArrayList(); 81 User testUser1 = new User("fakeEmail1@gmail.com", "fakeName1","fakePassword1","fakeRo lel", "fakeStatus1"); 82 saveUserService.saveUser(testUseri); 83 assertEquals(testRepository.findByuserName("fakeNamel"), testUser1); 84 } 85 86 @Test Run Test Debug Test 87 public void DeleteAllusers() { 88 List testList = new ArrayList(); 89 userController.deleteAllUsers(); 90 assertNull(testList); 91 92 } 93 94 @Test Run Test Debug Test 95 public void ReturningallusersInData(){ 96 List testList = new ArrayList(); 97 //Maybe I have to turn the method into a object for assert to check it? 98 testRepository.findAll(); 99 assertEquals(testRepository.findAll(), testList); 100 }}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The World Wide Web And Databases International Workshop Webdb 98 Valencia Spain March 27 28 1998 Selected Papers Lncs 1590

Authors: Paolo Atzeni ,Alberto Mendelzon ,Giansalvatore Mecca

1st Edition

3540658904, 978-3540658900

More Books

Students also viewed these Databases questions