{"id":96628,"date":"2020-10-30T11:00:00","date_gmt":"2020-10-30T09:00:00","guid":{"rendered":"https:\/\/examples.javacodegeeks.com\/?p=96628"},"modified":"2020-10-27T17:33:31","modified_gmt":"2020-10-27T15:33:31","slug":"spring-boot-mockmvc-tutorial","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/","title":{"rendered":"Spring Boot MockMVC Tutorial"},"content":{"rendered":"<p>In this article, we provide a tutorial about Spring Boot MockMVC.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-1-introduction\">1. Introduction<\/h2>\n<p>As a software developer, you need to validate that your code is working correctly. You accomplish this by testing. There are different types of tests:<\/p>\n<ul class=\"wp-block-list\">\n<li>Unit tests target a specific section of code, such as a method<\/li>\n<li>Integration tests verify that the interactions between your code and other parts of the system work as designed<\/li>\n<li>Functional tests are end-to-end (E2E) tests and are executed against an application that has been deployed to a DEV, QA, or pre-production environment<\/li>\n<\/ul>\n<p>In this article, we will limit our discussion to unit testing.<\/p>\n<p>A <strong>unit test<\/strong> has limited scope and tests your code separately from other collaborators. Unit tests should not involve any external dependencies directly. Examples of external dependencies are databases, message brokers, and web services.<\/p>\n<p>Since well-written unit tests run in isolation, we require a mechanism for emulating collaborators. This can be achieved by using mock objects.<\/p>\n<p>A mock object implements the interface of the real object but provides only enough code to simulate its behavior. This is acceptable in unit tests since we are not testing the collaborator, only that our code is calling its methods correctly and receiving the expected response.<\/p>\n<p>However, some objects depend on the infrastructure to function. This is especially true of web MVC applications that require a Tomcat or other application server. This can be expensive for unit testing because of the overhead associated with starting and instantiating the various tiers of the infrastructure. For Spring applications, the Spring Test Framework provides us with options to help you write unit tests in these cases.<\/p>\n<p>MockMvc is one such option. MockMvc is a utility class that gives you the ability to send mock HTTP servlet requests in a simulated MVC environment. This gives us the ability to test MVC applications without incurring the cost of instantiating an application server, In this example, we will demonstrate how to write unit tests for a Spring Boot MVC application using MockMVC.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-1-1-technologies-used\">1.1 Technologies Used<\/h3>\n<ul class=\"wp-block-list\">\n<li>Eclipse IDE for Enterprise Java Developers Version: 2020-09 (4.17.0)Spring Tools 4 \u2013 for Spring Boot<\/li>\n<li>Spring Tools 4 \u2013 for Spring Boot<\/li>\n<\/ul>\n<p>Spring Tools 4 for Spring Boot is a set of plugins for Eclipse that support building and running Spring Boot applications. You can add Spring Tools 4 to your existing Eclipse installation by going to the Eclipse Marketplace and searching for \u201cSpring Tools 4\u201d.<\/p>\n<p>Note: The sample projects were compiled with Java 11.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-2-spring-boot-mockmvc-tutorial\">2. Spring Boot MockMvc Tutorial<\/h2>\n<h3 class=\"wp-block-heading\" id=\"h-2-1-download-the-archive-file\">2.1 Download the Archive File<\/h3>\n<p>We will use a sample Spring Boot project as the basis or our JUnit tests. Begin by downloading the spring-boot-mockmvc.zip archive from the <a href=\"#download\">download<\/a>&nbsp;section and extracting it to a folder of your choice.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-2-2-import-the-sample-project\">2.2 Import the Sample Project<\/h3>\n<p>Click&nbsp;<em>File -&gt; Import\u2026<\/em>&nbsp;and select&nbsp;<em>Projects from Folder or Archive<\/em>.&nbsp; Click&nbsp;<em>Next<\/em>.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/01\/project-archive-wm.jpeg\" alt=\"Spring Boot MockMVC - Select Projects\"\/><figcaption>Select Projects from Folder or Archive<\/figcaption><\/figure>\n<\/div>\n<p>Click on the&nbsp;<em>Archive\u2026<\/em>&nbsp;button and select the&nbsp;<em>spring-boot-mockmvc-init.zip<\/em>&nbsp;file from the folder where the archive was extracted.&nbsp; Select the Eclipse project from the list and click&nbsp;<em>Finish<\/em>.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"740\" height=\"603\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/10\/Import-init-proj-wm.jpg\" alt=\"Spring Boot MockMVC - Import Eclipse Project\" class=\"wp-image-96652\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/10\/Import-init-proj-wm.jpg 740w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/10\/Import-init-proj-wm-300x244.jpg 300w\" sizes=\"(max-width: 740px) 100vw, 740px\" \/><figcaption>Import Eclipse Project<\/figcaption><\/figure>\n<\/div>\n<p>The sample application has three controllers:<\/p>\n<ul class=\"wp-block-list\">\n<li>Hello World controller<\/li>\n<li>Rest controller that exposes endpoints for CRUD operations<\/li>\n<li>MVC controller that displays a web page<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\" id=\"h-2-3-spring-boot-test-starter\">2.3 Spring Boot Test Starter<\/h3>\n<p>When you create a Spring Boot application using the Spring Boot initializer, the Spring Boot Starter Test dependency is automatically added to your classpath. Spring Boot Starter Test contains many useful frameworks\/libraries to help you test your application including JUnit, Mockito, Hamcrest, and Spring Boot Test.<\/p>\n<p>The dependency also includes the Spring MVC Test Framework. The framework provides some options for using MockMvc. For example, you can:<\/p>\n<ul class=\"wp-block-list\">\n<li>Bootstrap the entire application context. This option adds all beans that have been configured in your application.<\/li>\n<li>Bootstrap the web layer. This option adds only MVC components to the application context.<\/li>\n<li>Bootstrap the minimum infrastructure to run your tests. This option gives the developer more control in configuring the MockMvc object.<\/li>\n<\/ul>\n<p>Let us see how each of these options is implemented.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-2-4-using-mockmvc-with-entire-application-context\">2.4 Using MockMvc with Entire Application Context<\/h3>\n<p>One annotation that you can apply to your test case classes is <code>@SpringBootTest<\/code>. This annotation uses the <code>SpringBootTestContextBootstrapper<\/code> class to create the application context. When you use <code>@SpringBootTest<\/code>, all beans configured in your application are added to the context.<\/p>\n<p>The <code>@AutoConfigureMockMvc<\/code> annotation will automatically configure the <code>MockMvc<\/code> object when used in combination with <code>@SpringBootTest<\/code>. Let us see how this is achieved. Create a JUnit test case (under <em>\/src\/test\/java<\/em>) with the following boilerplate code:<\/p>\n<p><span style=\"text-decoration: underline\"><em>HelloBootTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false\">import org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;\nimport org.springframework.boot.test.context.SpringBootTest;\nimport org.springframework.test.web.servlet.MockMvc;\n\n@SpringBootTest\n@AutoConfigureMockMvc\nclass HelloBootTest {\n\n\t@Autowired\n\tMockMvc mockMvc;\n}\n<\/pre>\n<p>We will create two tests to verify the <code>HelloController<\/code> request handler method. The controller looks like this:<\/p>\n<p><span style=\"text-decoration: underline\"><em>HelloController.java<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false\">import org.springframework.web.bind.annotation.GetMapping;\nimport org.springframework.web.bind.annotation.RequestParam;\nimport org.springframework.web.bind.annotation.RestController;\n\n@RestController\npublic class HelloController {\n\t\n\t@GetMapping(\"hello\")\n\tString hello(@RequestParam(defaultValue = \"world!\") String name) {\n\t\treturn \"Hello \" + name;\n\t}\n\n}\n<\/pre>\n<p>Let&#8217;s add some tests to <code>HelloBootTest<\/code>:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline\"><em>HelloBootTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false\">import static org.hamcrest.CoreMatchers.containsString;\nimport static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;\nimport static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;\nimport static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;\nimport static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;\n\nimport org.junit.jupiter.api.Test;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;\nimport org.springframework.boot.test.context.SpringBootTest;\nimport org.springframework.test.web.servlet.MockMvc;\n\n@SpringBootTest\n@AutoConfigureMockMvc\nclass HelloBootTest {\n\n\t@Autowired\n\tMockMvc mockMvc;\n\n\t@Test\n\tvoid whenNoRequestParam_returnDefault() throws Exception {\n\t\tthis.mockMvc.perform(get(\"\/hello\"))\n\t\t\t.andExpect(status().isOk())\n\t\t\t.andExpect(content().string(containsString(\"Hello world!\")))\n\t\t\t.andDo(print());\n\t}\n\n\t@Test\n\tvoid whenRequestParam_returnCustom() throws Exception {\n\t\tthis.mockMvc.perform(\n\t\t\t\tget(\"\/hello\")\n\t\t\t\t.queryParam(\"name\", \"JCG!\")\n\t\t\t)\n\t\t\t.andExpect(status().isOk())\n\t\t\t.andExpect(content().string(containsString(\"Hello JCG!\")))\n\t\t\t.andDo(print());\n\t}\n\n}\n\n<\/pre>\n<p>The <code>MockMvc::perform<\/code> method is used to send mock HTTP servlet requests to the <code>TestDispatcherServlet<\/code>. It accepts a <code>RequestBuilder<\/code> as a parameter.<\/p>\n<p>The <code>MockMvcRequestBuilders<\/code> class has static factory methods used to create a <code>MockMvcRequestBuilder<\/code>. (<code>MockMvcRequestBuilder<\/code> is an implementation of <code>RequestBuilder<\/code>.) This argument is passed to the <code>MockMvc::perform<\/code> method.<\/p>\n<p>In our example, we use <code><em>get<\/em>(\"\/hello\")<\/code> to create a <code>MockHttpServletRequestBuilder<\/code> for a GET request and set it to be routed to the \u201c<em>\/hello<\/em>\u201d URI. <code>MockMvcRequestBuilders::get<\/code> returns a <code>MockHttpServletRequestBuilder<\/code> that we can use to set the properties of the request.<\/p>\n<p>To summarize, <code>MockMvcRequestBuilders<\/code> static factory methods are used to create a specific type of <code>MockMvcRequestBuilder<\/code>, such as a GET or POST builder, which can then be used to further shape the <code>MockMvcServletRequest<\/code>.<\/p>\n<p><code>MockMvcRequestBuilder<\/code> can be used to set the content type and content, to add request parameters, query parameters, headers, and more. This is done using a builder pattern. In the second test, for example, we add a query parameter to the request using <code>MockMvcRequestBuilder::queryParam(String name, String \u2026values)<\/code>.<\/p>\n<p>When we are finished preparing the request the <code>MockMvcRequestBuilder::buildRequest (ServletContext servletContext)<\/code> method is called behind the scenes to create the <code>MockHttpServletRequest<\/code>. The request is then sent and a <code>ResultsActions<\/code> object is returned.<\/p>\n<p>We use the <code>ResultsActions<\/code> object to work with the response. For example, we can assert an expectation (using a <code>ResultMatcher<\/code>), perform an action (using a <code>ResultHandler<\/code>), and return a <code>MvcResult <\/code>(which gives us direct access to the result). We can chain <code>ResultMatcher<\/code>s and <code>ResultHandler<\/code>s.<\/p>\n<p>There are many types of <code>ResultMatcher<\/code>s, which we typically access through <code>MockMvcResultMatcher<\/code>s static factory methods. In this example, we use a <code>StatusResultMatcher <\/code>to assert the status code is 200 (status().isOK()) and &nbsp;<code>ContentResultMatcher<\/code>s <code>(<em>content<\/em>().string(<em>containsString<\/em>(\"Hello world!\")<\/code> and <code><em>content<\/em>().string(<em>containsString<\/em>(\"Hello JCG!\"))<\/code> to assert the content returned in the response matches \u201cHello World!\u201d and \u201cHello JCG\u201d, respectively.<\/p>\n<p>If you want to see the result printed to the standard output, you can use a <code>ResultHandler<\/code>. This we have done with <code>andDo(<em>print<\/em>()<\/code>.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-2-5-using-mockmvc-with-web-layer-only\">2.5 Using MockMvc with Web Layer Only<\/h3>\n<p>In some cases, you may want to limit your tests to the web layer only. The web layer consists of MVC components like <code>@Controller<\/code>, <code>@ControllerAdvice<\/code>, and <code>@JsonComponent<\/code> beans. The web layer does <strong>not <\/strong>include <code>@Component<\/code>, <code>@Service<\/code>, or <code>@Repository<\/code> beans. You can use the <code>@WebMvcTest<\/code> annotation for this purpose. Let us create a new JUnit test case to demonstrate. Begin by creating a new JUnit test case with the following boilerplate code:<\/p>\n<p><span style=\"text-decoration: underline\"><em>RestWebTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false\">@WebMvcTest(controllers = StudentRestController.class)\nclass RestWebTest {\n\n\t@Autowired\n\tMockMvc mockMvc;\n\n\t@MockBean\n\tStudentService service;\n}\n<\/pre>\n<p>By default, <code>@WebMvcTest<\/code> adds all <code>@Controller<\/code> beans to the application context. We can specify a subset of controllers by using the <code>controllers <\/code>attribute, as we have done here. <code>@WebMvcTest <\/code>auto-configures the <code>MockMvc <\/code>object by default. (The <code>@AutoConfigureMockMvc<\/code> annotation is not required though it can be used for further tweaking.)<\/p>\n<p>We also create a mock <code>StudentService <\/code>object with <code>@MockBean<\/code>. This object will used in our tests to mock the behavior of the actual service by using Mockito\u2019s <code>when(service.call).thenReturn(Object)<\/code> paradigm. This allows us to test our controller without instantiating or injecting any actual collaborators.<\/p>\n<p>Here is an excerpt of the <code>StudentRestController <\/code>we will exercise in this test case:<\/p>\n<p><span style=\"text-decoration: underline\"><em>StudentRestController.java<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false\">@RestController\n@RequestMapping(\"students\")\npublic class StudentRestController {\n\n\tprivate final StudentService service;\n\t\n\tpublic StudentRestController(StudentService service) {\n\t\tthis.service = service;\n\t}\n\t\n\t@GetMapping\n\tCollection&lt;Student&gt; readStudents(){\n\t\treturn this.service.findAll();\n\t}\n\t\n\t@GetMapping(\"\/{id}\")\n\tStudent readStudent(@PathVariable Long id) {\n\t\treturn this.service.findById(id)\n\t\t\t\t.orElseThrow(StudentNotFoundException::new);\n\t}\n\t\n\t@PostMapping\n\tResponseEntity&lt;?&gt; addStudent(@RequestBody Student student){\n\t\tStudent result = this.service.save(student);\n\t\tURI location = ServletUriComponentsBuilder\n\t\t\t\t.fromCurrentRequest()\n\t\t\t\t.path(\"\/{id}\")\n\t\t\t\t.buildAndExpand(result.getId())\n\t\t\t\t.toUri();\n\n\t\treturn ResponseEntity.created(location).build();\t\t\n\t}\n}\t\n<\/pre>\n<p>Let&#8217;s add some tests to <code>RestWebTest<\/code>:<\/p>\n<p><span style=\"text-decoration: underline\"><em>RestWebTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false\">\t@Test\n\tvoid whenReadStudent_returnJsonContent() throws Exception {\n\t\tStudent student = new Student(\"Bill\", \"Gates\", \"Freshman\");\n\t\tstudent.setId(102L);\n\t\t\n\t\twhen(service.findById(102L)).thenReturn(Optional.of(student));\n\t\t\n\n\t\tthis.mockMvc.perform(get(\"\/students\/102\"))\n\t\t\t.andExpect(status().isOk())\n\t\t\t.andExpect(content().string(containsString(\n\t\t\t\t\"{\\\"id\\\":102,\\\"firstName\\\":\\\"Bill\\\",\\\"lastName\\\":\\\"Gates\\\",\\\"year\\\":\\\"Freshman\\\"}\")))\n\t\t\t.andDo(print());\n\t}\n\n\t@Test\n\tvoid whenAddStudent_returnCreatedStatus() throws Exception {\n\t\tStudent newStudent = new Student(\"Bill\", \"Gates\", \"Freshman\");\n\t\tnewStudent.setId(100L);\n\n\t\twhen(service.save(newStudent)).thenReturn(newStudent);\n\n\t\t\n\t\tthis.mockMvc\n\t\t\t.perform(post(\"\/students\")\n\t\t\t\t.contentType(MediaType.APPLICATION_JSON)\n\t\t\t\t.content(\"{\\\"id\\\": \\\"100\\\",\\\"firstName\\\": \\\"Bill\\\",\\\"lastName\\\": \\\"Gates\\\",\\\"year\\\": \\\"Freshman\\\"}\")\n\t\t\t\t)\n\t\t\t.andExpect(status().isCreated())\n\t\t\t.andExpect(header().exists(\"Location\"))\n\t\t\t.andExpect(header().string(\"Location\", Matchers.containsString(\n\t\t\t\t\t\"http:\/\/localhost\/students\/100\"))).andDo(print());\n\t}\n<\/pre>\n<p>The first test exercises the <code>StudentRestController::readStudent <\/code>method. Notice that we are verifying that the student object is returned in JSON format. This is expected since <code>@RestController<\/code> request handlers return objects in the response body as JSON by default.<\/p>\n<p>In the second test, we use the <code>MockMvcRequestBuilders::post<\/code> static factory method to create a M<code>ockMvcRequestBuilder<\/code> of type POST. We then set the content type and content to be posted using builder methods.<\/p>\n<p>The <code>MockMvc::perform<\/code> method &nbsp;returns a <code>ResultsActions <\/code>object that we can use to test the response. We use static factory methods from&nbsp;<code>MockMvcResultMatchers<\/code> to:<\/p>\n<ul class=\"wp-block-list\">\n<li>check that the returned status response is 201 (created)<\/li>\n<li>check that a location header was set in the response<\/li>\n<li>check that the location is set correctly, based on the dummy student we set in the mocked service<\/li>\n<\/ul>\n<p>We can also use <code>MockMvc <\/code>to test traditional web applications, i.e. those that display views. Let us write a test for the <code>StudentMvcController <\/code>controller, which looks like this:<\/p>\n<p><span style=\"text-decoration: underline\"><em>StudentMvcController.java<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false\">import org.springframework.stereotype.Controller;\nimport org.springframework.ui.Model;\nimport org.springframework.web.bind.annotation.GetMapping;\nimport org.springframework.web.bind.annotation.RequestMapping;\n\nimport com.javacodegeeks.service.StudentService;\n\n@Controller\n@RequestMapping(\"mvc\")\npublic class StudentMvcController {\n\t\n\tprivate final StudentService service;\n\t\n\tpublic StudentMvcController(StudentService service) {\n\t\tthis.service = service;\n\t}\n\t\n\t@GetMapping(\"students\")\n\tpublic String getStudents(Model model) {\n\t\tmodel.addAttribute(\"students\", service.findAll());\n\t\treturn \"student-list\";\n\t}\n\n}\n<\/pre>\n<p>Create a new test case with the following code:<\/p>\n<p><span style=\"text-decoration: underline\"><em>MvcWebTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false\">import static org.mockito.Mockito.when;\nimport static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;\nimport static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;\nimport static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;\nimport static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;\nimport static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;\n\nimport java.util.List;\n\nimport org.hamcrest.Matchers;\nimport org.junit.jupiter.api.Test;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;\nimport org.springframework.boot.test.mock.mockito.MockBean;\nimport org.springframework.test.web.servlet.MockMvc;\n\nimport com.javacodegeeks.domain.Student;\nimport com.javacodegeeks.service.StudentService;\n\n@WebMvcTest(controllers = StudentMvcController.class)\nclass MvcWebTest {\n\n\t@Autowired\n\tMockMvc mockMvc;\n\n\t@MockBean\n\tStudentService service;\n\n\t@Test\n\tvoid shouldReturnStudentListView() throws Exception {\n\t\tStudent s1 = new Student(\"Jane\", \"Doe\", \"Junior\");\n\t\tStudent s2 = new Student(\"Martin\", \"Fowler\", \"Senior\");\n\t\tStudent s3 = new Student(\"Roy\", \"Fielding\", \"Freshman\");\n\t\tList&lt;Student&gt; studentList = List.of(s1, s2, s3);\n\n\t\twhen(service.findAll()).thenReturn(studentList);\n\n\t\tthis.mockMvc.perform(get(\"\/mvc\/students\"))\n\t\t\t.andExpect(status().isOk())\n\t\t\t.andExpect(view().name(\"student-list\"))\n\t\t\t.andExpect(model().attribute(\"students\", studentList))\n\t\t\t.andExpect(model().attribute(\"students\", Matchers.hasSize(3)))\n\t\t\t.andDo(print());\n\t}\n\n}\n<\/pre>\n<p>Here we use a <code>ViewResultMatcher <\/code>to assert the name of the view and <code>ModelResultMatcher<\/code>s to assert different characteristics of the model.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-2-6-using-mockmvc-with-minimal-infrastructure\">2.6 Using MockMvc with Minimal Infrastructure<\/h3>\n<p>In some cases, you may not even want to test with the entire web layer but only want to use the bare minimum infrastructure required by the <code>TestDispatcherServlet<\/code>. You can use the <code>MockMvcBuilders <\/code>class for this purpose.<\/p>\n<pre class=\"brush:java; wrap-lines:false\">MockMvcBuilders.standaloneSetup(Object\u2026 controllers).build();\n<\/pre>\n<p>This creates a <code>StandaloneMockMvcBuilder<\/code>, which allows for full customization of your web controllers. For instance, you can register <code>ControllerAdvice<\/code> beans, <code>ViewResolver<\/code> beans, and add interceptors for incoming requests.<\/p>\n<p>With this option, a <code>MockServletContext <\/code>is used to initialize the <code>TestServletDispatcher<\/code>. &nbsp;The <code>MockServletContext <\/code>has a smaller footprint than the <code>ApplicationContext<\/code>. Consequently, the tests run faster. Here is a sample test case:<\/p>\n<p><span style=\"text-decoration: underline\"><em>HelloControllerTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false\">import static org.hamcrest.CoreMatchers.containsString;\nimport static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;\nimport static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;\nimport static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;\nimport static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;\n\nimport org.junit.jupiter.api.BeforeEach;\nimport org.junit.jupiter.api.Test;\nimport org.springframework.test.web.servlet.MockMvc;\nimport org.springframework.test.web.servlet.setup.MockMvcBuilders;\n\nclass HelloControllerTest {\n\t\n\tMockMvc mockMvc;\n\n\t@BeforeEach\n\tvoid setUp() throws Exception {\n\t\tthis.mockMvc = MockMvcBuilders.standaloneSetup(new HelloController()).build();\n\t}\n\n\t@Test\n\tvoid whenNoRequestParam_returnDefault() throws Exception {\n\t\tthis.mockMvc.perform(get(\"\/hello\"))\n\t\t\t.andExpect(status().isOk())\n\t\t\t.andExpect(content().string(containsString(\"Hello world!\")))\n\t\t\t.andDo(print());\n\t}\n}\n<\/pre>\n<p><code>MockMvcBuilders <\/code>can also be used to create a <code>DefaultMockMvcBuilder<\/code>.<\/p>\n<pre class=\"brush:java; wrap-lines:false\">MockMvcBuilders.webAppContextSetup(WebApplicationContext context)\n<\/pre>\n<p>The <code>DefaultMockMvcBuilder <\/code>is an option if you want to apply to one or more <code>ResultMatcher<\/code>s (for your expectations) or a <code>ResultHandler <\/code>(e.g. print result actions to system output) across all responses. Here is an example.<\/p>\n<p><span style=\"text-decoration: underline\"><em>RestControllerTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false\">@WebMvcTest(controllers = StudentRestController.class)\nclass RestControllerTest {\n\n\tMockMvc mockMvc;\n\t\n\t@MockBean\n\tStudentService service;\n\n\t@BeforeEach\n\tvoid setUp(WebApplicationContext wac) throws Exception {\n\t\tthis.mockMvc = MockMvcBuilders.webAppContextSetup(wac)\n\t\t\t\t\t\t.alwaysExpect(status().isOk())\n\t\t\t\t\t\t.alwaysExpect(content().contentType(MediaType.APPLICATION_JSON))\n\t\t\t\t\t\t.alwaysDo(print())\n\t\t\t\t\t\t.build();\n\t}\n\n\t@Test\n\tvoid whenReadStudent_returnJsonContent() throws Exception {\n\t\tStudent student = new Student(\"Bill\", \"Gates\", \"Freshman\");\n\t\tstudent.setId(102L);\n\t\twhen(service.findById(102L)).thenReturn(Optional.of(student));\n\n\t\tthis.mockMvc.perform(get(\"\/students\/102\"));\n\t}\n\n\t@Test\n\tvoid whenReadStudents_returnList() throws Exception {\n\t\tStudent s1 = new Student(\"Jane\", \"Doe\", \"Junior\");\n\t\tStudent s2 = new Student(\"Martin\", \"Fowler\", \"Senior\");\n\t\tStudent s3 = new Student(\"Roy\", \"Fielding\", \"Freshman\");\n\t\tList&lt;Student&gt; studentList = List.of(s1, s2, s3);\n\n\t\twhen(service.findAll()).thenReturn(studentList);\n\n\t\tthis.mockMvc.perform(get(\"\/students\"));\n\t}\t\n}\n<\/pre>\n<p>The <code>DefaultMockMvcBuilder<\/code> requires a <code>WebApplicationContext <\/code>so it is not as light as the <code>StandaloneMockMvcBuilder<\/code>.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-3-spring-boot-mockmvc-summary\">3. Spring Boot MockMVC &#8211; Summary<\/h2>\n<p>In this article, we showed how to test Spring Boot web applications with MockMvc. We explored the different options available to bootstrap the test environment. <\/p>\n<p>We also demonstrated how to build a MockMvcServletRequest and how to use ResultMatchers to verify the code being tested.<\/p>\n<p>If you want to find more Spring boot tutorials, follow <a href=\"https:\/\/www.javacodegeeks.com\/spring-boot-tutorials\">this link<\/a>.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-4-download-the-source-code\"><a name=\"download\"><\/a>4. Download the Source Code<\/h2>\n<p>This was a Spring Boot MockMvc Tutorial.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here:<br \/>\n<a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/10\/spring-boot-mockmvc.zip\"><strong>Spring Boot MockMvc Tutorial<\/strong><\/a>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we provide a tutorial about Spring Boot MockMVC. 1. Introduction As a software developer, you need to validate that your code is working correctly. You accomplish this by testing. There are different types of tests: Unit tests target a specific section of code, such as a method Integration tests verify that the &hellip;<\/p>\n","protected":false},"author":121,"featured_media":1248,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1390],"tags":[1032,918,474,1386,1213,46669,1675,46670],"class_list":["post-96628","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-boot","tag-junit","tag-mockito","tag-rest-2","tag-spring-boot","tag-spring-mvc","tag-spring-test","tag-spring-tutorial","tag-unit-testing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Spring Boot MockMVC Tutorial - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this article, we provide a tutorial about Spring Boot MockMVC. 1. Introduction As a software developer, you need to validate that your code is working\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring Boot MockMVC Tutorial - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this article, we provide a tutorial about Spring Boot MockMVC. 1. Introduction As a software developer, you need to validate that your code is working\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2020-10-30T09:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Gilbert Lopez\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@gillopez_dev\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Gilbert Lopez\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/\"},\"author\":{\"name\":\"Gilbert Lopez\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6169578062b8f6f6a1f79c82aafdb9ce\"},\"headline\":\"Spring Boot MockMVC Tutorial\",\"datePublished\":\"2020-10-30T09:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/\"},\"wordCount\":1659,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\",\"keywords\":[\"junit\",\"mockito\",\"REST\",\"spring boot\",\"Spring MVC\",\"spring test\",\"spring tutorial\",\"unit testing\"],\"articleSection\":[\"Boot\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/\",\"name\":\"Spring Boot MockMVC Tutorial - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\",\"datePublished\":\"2020-10-30T09:00:00+00:00\",\"description\":\"In this article, we provide a tutorial about Spring Boot MockMVC. 1. Introduction As a software developer, you need to validate that your code is working\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"spring\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/spring\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Boot\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/spring\/boot\/\"},{\"@type\":\"ListItem\",\"position\":6,\"name\":\"Spring Boot MockMVC Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6169578062b8f6f6a1f79c82aafdb9ce\",\"name\":\"Gilbert Lopez\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Gilbert-Lopez_avatar_1492457226-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Gilbert-Lopez_avatar_1492457226-96x96.jpg\",\"caption\":\"Gilbert Lopez\"},\"description\":\"Gilbert Lopez is an application developer and systems integration developer with experience building business solutions for large and medium-sized companies. He has worked on many Java EE projects. His roles have included lead developer, systems analyst, business analyst and consultant. Gilbert graduated from California State University in Los Angeles with a Bachelor of Science degree in Business.\",\"sameAs\":[\"https:\/\/www.javacodegeeks.com\",\"https:\/\/www.linkedin.com\/in\/gilbertlopezdeveloper\",\"https:\/\/x.com\/gillopez_dev\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/gilbert-lopez\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring Boot MockMVC Tutorial - Java Code Geeks","description":"In this article, we provide a tutorial about Spring Boot MockMVC. 1. Introduction As a software developer, you need to validate that your code is working","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Spring Boot MockMVC Tutorial - Java Code Geeks","og_description":"In this article, we provide a tutorial about Spring Boot MockMVC. 1. Introduction As a software developer, you need to validate that your code is working","og_url":"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2020-10-30T09:00:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Gilbert Lopez","twitter_card":"summary_large_image","twitter_creator":"@gillopez_dev","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Gilbert Lopez","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/"},"author":{"name":"Gilbert Lopez","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6169578062b8f6f6a1f79c82aafdb9ce"},"headline":"Spring Boot MockMVC Tutorial","datePublished":"2020-10-30T09:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/"},"wordCount":1659,"commentCount":1,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","keywords":["junit","mockito","REST","spring boot","Spring MVC","spring test","spring tutorial","unit testing"],"articleSection":["Boot"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/","url":"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/","name":"Spring Boot MockMVC Tutorial - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","datePublished":"2020-10-30T09:00:00+00:00","description":"In this article, we provide a tutorial about Spring Boot MockMVC. 1. Introduction As a software developer, you need to validate that your code is working","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/spring-boot-mockmvc-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/"},{"@type":"ListItem","position":4,"name":"spring","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/spring\/"},{"@type":"ListItem","position":5,"name":"Boot","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/spring\/boot\/"},{"@type":"ListItem","position":6,"name":"Spring Boot MockMVC Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6169578062b8f6f6a1f79c82aafdb9ce","name":"Gilbert Lopez","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Gilbert-Lopez_avatar_1492457226-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Gilbert-Lopez_avatar_1492457226-96x96.jpg","caption":"Gilbert Lopez"},"description":"Gilbert Lopez is an application developer and systems integration developer with experience building business solutions for large and medium-sized companies. He has worked on many Java EE projects. His roles have included lead developer, systems analyst, business analyst and consultant. Gilbert graduated from California State University in Los Angeles with a Bachelor of Science degree in Business.","sameAs":["https:\/\/www.javacodegeeks.com","https:\/\/www.linkedin.com\/in\/gilbertlopezdeveloper","https:\/\/x.com\/gillopez_dev"],"url":"https:\/\/examples.javacodegeeks.com\/author\/gilbert-lopez\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/96628","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/121"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=96628"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/96628\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1248"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=96628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=96628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=96628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}