please i need help to write a few words about why we've created each of the tests below. What do they cover? Why do we need them? ========================================================================= @Test @Order(1) publicvoidsignupIntegrationTest()throwsException{   ObjectMapperobjectMapper=JsonMapper.builder().disable(MapperFeature.USE_ANNOTATIONS).build();   /* Check the Rest End Point Response */ this.mockMvc.perform(MockMvcRequestBuilders.post("/user/signup") .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(user))) .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())));   /* Check the DB */ Optionalopt=this.userRepository.findByUsername(this.user.getUsername());   assertTrue(opt.isPresent(),"User Should Exist");   assertEquals(1,opt.get().getUserId()); assertEquals(this.user.getFirstName(),opt.get().getFirstName()); assertEquals(this.user.getLastName(),opt.get().getLastName()); assertEquals(this.user.getUsername(),opt.get().getUsername()); assertEquals(this.user.getPhone(),opt.get().getPhone()); assertEquals(this.user.getEmailId(),opt.get().getEmailId()); assertEquals(false,opt.get().getEmailVerified());   assertTrue(this.passwordEncoder.matches(this.user.getPassword(),opt.get().getPassword())); }   @Test @Order(2) publicvoidsignupUsernameExistsIntegrationTest()throwsException{   ObjectMapperobjectMapper=JsonMapper.builder().disable(MapperFeature.USE_ANNOTATIONS).build();   /* Check the Rest End Point Response */ this.mockMvc.perform(MockMvcRequestBuilders.post("/user/signup") .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(this.user))) .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 already exists, %s",this.user.getUsername())))); }   @Test @Order(3) publicvoidsignupEmailExistsIntegrationTest()throwsException{   ObjectMapperobjectMapper=JsonMapper.builder().disable(MapperFeature.USE_ANNOTATIONS).build();   this.user.setUsername(this.otherUsername);   /* Check the Rest End Point Response */ this.mockMvc.perform(MockMvcRequestBuilders.post("/user/signup") .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(this.user))) .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 already exists, %s",this.user.getEmailId())))); }

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

please i need help to write a few words about why we've created each of the tests below. What do they cover? Why do we need them?

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

@Test

@Order(1)

publicvoidsignupIntegrationTest()throwsException{

 

ObjectMapperobjectMapper=JsonMapper.builder().disable(MapperFeature.USE_ANNOTATIONS).build();

 

/* Check the Rest End Point Response */

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

.contentType(MediaType.APPLICATION_JSON)

.content(objectMapper.writeValueAsString(user)))

.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())));

 

/* Check the DB */

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

 

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

 

assertEquals(1,opt.get().getUserId());

assertEquals(this.user.getFirstName(),opt.get().getFirstName());

assertEquals(this.user.getLastName(),opt.get().getLastName());

assertEquals(this.user.getUsername(),opt.get().getUsername());

assertEquals(this.user.getPhone(),opt.get().getPhone());

assertEquals(this.user.getEmailId(),opt.get().getEmailId());

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

 

assertTrue(this.passwordEncoder.matches(this.user.getPassword(),opt.get().getPassword()));

}

 

@Test

@Order(2)

publicvoidsignupUsernameExistsIntegrationTest()throwsException{

 

ObjectMapperobjectMapper=JsonMapper.builder().disable(MapperFeature.USE_ANNOTATIONS).build();

 

/* Check the Rest End Point Response */

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

.contentType(MediaType.APPLICATION_JSON)

.content(objectMapper.writeValueAsString(this.user)))

.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 already exists, %s",this.user.getUsername()))));

}

 

@Test

@Order(3)

publicvoidsignupEmailExistsIntegrationTest()throwsException{

 

ObjectMapperobjectMapper=JsonMapper.builder().disable(MapperFeature.USE_ANNOTATIONS).build();

 

this.user.setUsername(this.otherUsername);

 

/* Check the Rest End Point Response */

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

.contentType(MediaType.APPLICATION_JSON)

.content(objectMapper.writeValueAsString(this.user)))

.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 already exists, %s",this.user.getEmailId()))));

}

 

Expert Solution
steps

Step by step

Solved in 3 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.
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