Write a few words about why we've created each of the tests above. What do they cover? Why do we need them? ===================================================================================== @Test @Order(4) publicvoidverifyEmailIntegrationTest()throwsException{   /* Check if the User exists */ Optionalopt=this.userRepository.findByUsername(this.user.getUsername()); assertTrue(opt.isPresent(),"User Should Exist");   /* Check the user emailVerified flag initial value */ assertEquals(false,opt.get().getEmailVerified());   Stringjwt=String.format("Bearer %s",this.jwtService.generateJwtToken(this.user.getUsername(),10_000));   /* Check the Rest End Point Response */ this.mockMvc.perform(MockMvcRequestBuilders.get("/user/verify/email").header(AUTHORIZATION,jwt)).andExpect(status().isOk());   /* Check if the User exists */ opt=this.userRepository.findByUsername(this.user.getUsername()); assertTrue(opt.isPresent(),"User Should Exist");   /* Check the user emailVerified flag was updated */ assertEquals(true,opt.get().getEmailVerified());   }   @Test @Order(5) publicvoidverifyEmailUsernameNotFoundIntegrationTest()throwsException{   /* Check if the User exists */ Optionalopt=this.userRepository.findByUsername(this.otherUsername); assertTrue(opt.isEmpty(),"User Should Not Exist");   Stringjwt=String.format("Bearer %s",this.jwtService.generateJwtToken(this.otherUsername,10_000));   /* Check the Rest End Point Response */this.mockMvc.perform(MockMvcRequestBuilders.get("/user/verify/email").header(AUTHORIZATION,jwt)) .andExpect(status().is4xxClientError()).andExpect(jsonPath("$.httpStatusCode",is(400))) .andExpect(jsonPath("$.httpStatus",is("BAD_REQUEST"))) .andExpect(jsonPath("$.reason",is("BAD REQUEST"))) .andExpect(jsonPath("$.message",is(String.format("Username doesn't exist, %s",this.otherUsername))));   }   @Test @Order(6) publicvoidloginIntegrationTest()throwsException{   /* Create object to generate JSON */ ObjectNoderoot=this.objectMapper.createObjectNode(); root.put("username",this.user.getUsername()); root.put("password",this.user.getPassword());   /* Check the Rest End Point Response */ this.mockMvc.perform(MockMvcRequestBuilders.post("/user/login") .contentType(MediaType.APPLICATION_JSON) .content(this.objectMapper.writeValueAsString(root))) .andExpect(header().exists(AUTHORIZATION)) .andExpect(status().isOk()) .andExpect(jsonPath("$.firstName",is(this.user.getFirstName()))) .andExpect(jsonPath("$.lastName",is(this.user.getLastName()))) .andExpect(jsonPath("$.username",is(this.user.getUsername()))) .andExpect(jsonPath("$.phone",is(this.user.getPhone()))) .andExpect(jsonPath("$.emailId",is(this.user.getEmailId()))) .andExpect(jsonPath("$.emailVerified",is(true))); }   @Test @Order(7) publicvoidloginEmailNotVerifiedIntegrationTest()throwsException{   /* Create object to generate JSON */ ObjectNoderoot=this.objectMapper.createObjectNode(); root.put("username",this.user.getUsername()); root.put("password",this.user.getPassword());   /* Check if the User exists */ Optionalopt=this.userRepository.findByUsername(this.user.getUsername()); assertTrue(opt.isPresent(),"User Should Exist");   /* Set user.emailVerified to false */ opt.ifPresent(u->{u.setEmailVerified(false); this.userRepository.save(u);});   /* Check the Rest End Point Response */ this.mockMvc.perform(MockMvcRequestBuilders.post("/user/login") .contentType(MediaType.APPLICATION_JSON) .content(this.objectMapper.writeValueAsString(root))) .andExpect(status().is4xxClientError()) .andExpect(jsonPath("$.httpStatusCode",is(400))) .andExpect(jsonPath("$.httpStatus",is("BAD_REQUEST"))) .andExpect(jsonPath("$.reason",is("BAD REQUEST"))) .andExpect(jsonPath("$.message",is(String.format("Email requires verification, %s",this.user.getEmailId()))));   /* Check if the User exists */ opt=this.userRepository.findByUsername(this.user.getUsername()); assertTrue(opt.isPresent(),"User Should Exist");

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write a few words about why we've created each of the tests above. What do they cover? Why do we need them?

=====================================================================================

@Test

@Order(4)

publicvoidverifyEmailIntegrationTest()throwsException{

 

/* Check if the User exists */

Optional<User>opt=this.userRepository.findByUsername(this.user.getUsername());

assertTrue(opt.isPresent(),"User Should Exist");

 

/* Check the user emailVerified flag initial value */

assertEquals(false,opt.get().getEmailVerified());

 

Stringjwt=String.format("Bearer %s",this.jwtService.generateJwtToken(this.user.getUsername(),10_000));

 

/* Check the Rest End Point Response */

this.mockMvc.perform(MockMvcRequestBuilders.get("/user/verify/email").header(AUTHORIZATION,jwt)).andExpect(status().isOk());

 

/* Check if the User exists */

opt=this.userRepository.findByUsername(this.user.getUsername());

assertTrue(opt.isPresent(),"User Should Exist");

 

/* Check the user emailVerified flag was updated */

assertEquals(true,opt.get().getEmailVerified());

 

}

 

@Test

@Order(5)

publicvoidverifyEmailUsernameNotFoundIntegrationTest()throwsException{

 

/* Check if the User exists */

Optional<User>opt=this.userRepository.findByUsername(this.otherUsername);

assertTrue(opt.isEmpty(),"User Should Not Exist");

 

Stringjwt=String.format("Bearer %s",this.jwtService.generateJwtToken(this.otherUsername,10_000));

 

/* Check the Rest End Point Response */this.mockMvc.perform(MockMvcRequestBuilders.get("/user/verify/email").header(AUTHORIZATION,jwt))

.andExpect(status().is4xxClientError()).andExpect(jsonPath("$.httpStatusCode",is(400)))

.andExpect(jsonPath("$.httpStatus",is("BAD_REQUEST")))

.andExpect(jsonPath("$.reason",is("BAD REQUEST")))

.andExpect(jsonPath("$.message",is(String.format("Username doesn't exist, %s",this.otherUsername))));

 

}

 

@Test

@Order(6)

publicvoidloginIntegrationTest()throwsException{

 

/* Create object to generate JSON */

ObjectNoderoot=this.objectMapper.createObjectNode();

root.put("username",this.user.getUsername());

root.put("password",this.user.getPassword());

 

/* Check the Rest End Point Response */

this.mockMvc.perform(MockMvcRequestBuilders.post("/user/login")

.contentType(MediaType.APPLICATION_JSON)

.content(this.objectMapper.writeValueAsString(root)))

.andExpect(header().exists(AUTHORIZATION))

.andExpect(status().isOk())

.andExpect(jsonPath("$.firstName",is(this.user.getFirstName())))

.andExpect(jsonPath("$.lastName",is(this.user.getLastName())))

.andExpect(jsonPath("$.username",is(this.user.getUsername())))

.andExpect(jsonPath("$.phone",is(this.user.getPhone())))

.andExpect(jsonPath("$.emailId",is(this.user.getEmailId())))

.andExpect(jsonPath("$.emailVerified",is(true)));

}

 

@Test

@Order(7)

publicvoidloginEmailNotVerifiedIntegrationTest()throwsException{

 

/* Create object to generate JSON */

ObjectNoderoot=this.objectMapper.createObjectNode();

root.put("username",this.user.getUsername());

root.put("password",this.user.getPassword());

 

/* Check if the User exists */

Optional<User>opt=this.userRepository.findByUsername(this.user.getUsername());

assertTrue(opt.isPresent(),"User Should Exist");

 

/* Set user.emailVerified to false */

opt.ifPresent(u->{u.setEmailVerified(false);

this.userRepository.save(u);});

 

/* Check the Rest End Point Response */

this.mockMvc.perform(MockMvcRequestBuilders.post("/user/login")

.contentType(MediaType.APPLICATION_JSON)

.content(this.objectMapper.writeValueAsString(root)))

.andExpect(status().is4xxClientError())

.andExpect(jsonPath("$.httpStatusCode",is(400)))

.andExpect(jsonPath("$.httpStatus",is("BAD_REQUEST")))

.andExpect(jsonPath("$.reason",is("BAD REQUEST")))

.andExpect(jsonPath("$.message",is(String.format("Email requires verification, %s",this.user.getEmailId()))));

 

/* Check if the User exists */

opt=this.userRepository.findByUsername(this.user.getUsername());

assertTrue(opt.isPresent(),"User Should Exist");

 

}

Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Top down approach design
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education