Java Magazine, Jan/Feb 2016
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2016 21 web apps @ Test public void contextLoads throws Exception this mockMvc perform get reservations accept this mediaType andExpect content contentType this mediaType andExpect status isOk This code uses the Spring MVC test framework which is a custom test runner that works with JUnit or TestNG This test framework is ideal for pseudo integration tests Here I use it to stand up our Spring Boot application completely without actually connecting to a socket The Spring MVC test framework dispatches calls through the whole Spring MVC machinery and actually exercises all the web components but does so without sitting on a socket somewhere listening for actual TCP packets coming in as HTTP This means that you dont have to stand up a container just to test the framework machinery or the components responsible for processing requests Production The application is now interesting but being interesting just isnt enough We need to get the software deployed If youve ever read Michael Nygards excellent book Release It then you know that the last mile between code complete and production ready can be a long mile indeed Talk to enough organizations and youll realize that theres a litany of nonfunctional requirements usually buried in some wiki page somewhere that each organization requires its applications to satisfy before code can be moved to production These arent exciting things either Theyre not diferentiators What does the applications environment look like How do you capture growth metrics Does your application provide an endpoint to answer questions about its health How do you identify which version of the service is running Which HTTP resources are exposed to trafic These questions and many more besides are answered thanks to automatically created endpoints provided by the Spring Boot Actuator which is a module in Spring Boot designed to support operationalizing applications for production Spring Boot Actuator helps reduce or remove the list of nonfunctional requirements that commonly gate our ability to move code to production It furnishes management endpoints such as health beans trace mappings metrics env and many more These endpoints are useful and easily customized Lets change the management endpoints prefix with a property specified in the application properties file where along with application yml Spring Boot will look to find configuration keys and values management context path admin With this property users will need to go to admin health admin env and so on If I add spring bootstarter security to the CLASSPATH Ill get the default HTTP BASIC authentication prompt with a default username and password that will be printed on the console I can delegate the HTTP BASIC authentication challenge to a Spring Security AuthenticationProvider instead by configuring the appropriate Spring Security options The health endpoint is interesting because it measures the health of the system It automatically tells us whatever it can about the technologies in play It knows about the file system a DataSource connection pool JavaMail JMS Cassandra Elasticsearch Solr MongoDB RabbitMQ Redis and many more technologies We can augment this data with a semantic HealthIndicator if we want to
You must have JavaScript enabled to view digital editions.