public static void main(String[] args) throws Exception {
SpringApplication.run(${enclosing_type}.class, args);
}${:import(org.springframework.boot.SpringApplication)}
${:import(org.junit.Rule,org.junit.rules.ExpectedException)}
@Rule
ExpectedException thrown = ExpectedException.none();
${thrown:field(org.junit.rules.ExpectedException)}.expect(${Exception}.class);
${thrown:field(org.junit.rules.ExpectedException)}.expectMessage("${cursor}");
Assert.notNull(${name:var}, "${name} must not be null");${:import(org.springframework.util.Assert)}
Assert.assertNotNull("${name:var} must not be null", ${name});${:import(org.junit.Assert)}
assertThat(${name:var}).isNotNull();${:importStatic('org.assertj.core.api.Assertions.*')}
/*
* Copyright ${year} the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
${:import(org.mockito.Mock)}@Mock ${Type} ${mockName};
${standardImports:import(org.junit.Before,org.springframework.beans.factory.annotation.Autowired,org.springframework.test.web.servlet.MockMvc,org.springframework.test.web.servlet.setup.MockMvcBuilders,org.springframework.web.context.WebApplicationContext)}
${:importStatic('org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*','org.springframework.test.web.servlet.result.MockMvcResultHandlers.*','org.springframework.test.web.servlet.result.MockMvcResultMatchers.*')}
@Autowired
WebApplicationContext context;
MockMvc mockMvc;
@Before
public void setup() {
mockMvc = MockMvcBuilders
.webAppContextSetup(context)
.build();
}
// @formatter:off
${cursor} ${line_selection}
// @formatter:on
${:import(org.slf4j.Logger,org.slf4j.LoggerFactory)}
private static final Logger ${log} = LoggerFactory.getLogger(${enclosing_type}.class);
${log:field(org.slf4j.Logger)}.info("${message}");
${log:field(org.slf4j.Logger)}.error("${message}", ${exception:var(java.lang.Throwable)});
${log:field(org.slf4j.Logger)}.warn("${warning}");
${log:field(org.slf4j.Logger)}.debug("${message}");
${:import(org.springframework.core.ParameterizedTypeReference,org.springframework.hateoas.PagedResources,org.springframework.http.HttpEntity,org.springframework.http.HttpMethod,org.springframework.http.ResponseEntity)}
ResponseEntity<PagedResources<?>> result = ${restTemplate:var(org.springframework.web.client.RestTemplate)}.exchange("",
HttpMethod.GET,
new HttpEntity<Void>((Void) null),
new ParameterizedTypeReference<PagedResources<${cursor}>>() {});
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
${x:import(org.springframework.web.bind.annotation.RequestMapping, org.springframework.web.bind.annotation.RequestMethod, org.springframework.web.bind.annotation.RequestParam)}@RequestMapping(value="${path}", method=RequestMethod.${GET})
public ${SomeData} ${requestMethodName}(@RequestParam ${String} ${param}) {
return new ${SomeData}(${cursor});
}
${x:import(org.springframework.web.bind.annotation.GetMapping, org.springframework.web.bind.annotation.RequestParam)}@GetMapping(value="${path}")
public ${SomeData} ${getMethodName}(@RequestParam ${String} ${param}) {
return new ${SomeData}(${cursor});
}
${x:import(org.springframework.web.bind.annotation.PostMapping, org.springframework.web.bind.annotation.RequestBody)}@PostMapping(value="${path}")
public ${SomeEntityData} ${postMethodName}(@RequestBody ${SomeEntityData} ${entity}) {
//TODO: process POST request
${cursor}
return ${entity};
}
${x:import(org.springframework.web.bind.annotation.PutMapping, org.springframework.web.bind.annotation.RequestBody, org.springframework.web.bind.annotation.PathVariable)}@PutMapping(value="${path}/{${id}}")
public ${SomeEntityData} ${putMethodName}(@PathVariable ${pvt:link(String,int,long)} ${id}, @RequestBody ${SomeEntityData} ${entity}) {
//TODO: process PUT request
${cursor}
return ${entity};
}
${x:import(org.springframework.web.bind.annotation.DeleteMapping, org.springframework.web.bind.annotation.PathVariable)}@DeleteMapping(value="${path}/{${id}}")
public ${r:link(String)} ${deleteMethodName}(@PathVariable ${pv:link(String,int,long)} ${id}) {
//TODO: process DELETE request
${cursor}
return "${Success}";
}