[SOLVED] Coding Assignment - Web API Design with Spring Boot Week 14

30.00 $

Programming resource
Digital learning resource
Category:
✓ Practical programming resource
✓ Suitable for guided study and reference
✓ Tutor guidance available when needed

Description

5/5 - (1 vote)

Project Resources: https://github.com/promineotech/Spring–Boot–Course–StudentResources

 

 

Coding Steps:

  • In the project you started last week, use Lombok to add an info-level logging statement in the controller implementation method that logs the parameters that were input to the method.

 

  • Start the application (not an integration test). Use a browser to navigate to the application passing the parameters required for your selected operation. (A browser, used in this manner, sends an HTTP GET request to the server.) Produce a screenshot showing the browser navigation bar and the log statement that is in the IDE console showing that the controller method was reached (as in the video).

 

  • With the application still running, use the browser to navigate to the OpenAPI documentation. Use the OpenAPI documentation to send a GET request to the server with a valid model and trim level. (You can get the model and trim from the provided sql file.) Produce a screenshot showing the curl command, the request URL, and the response headers.

 

  • Run the integration test and show that the test status is green. Produce a screenshot of the test class and the status bar.

 

Add a method to the test to return a list of expected Jeep (model) objects based on the model and trim level you selected. You can get the expected list of Jeeps from the file src/test/resources/ flyway/migrations/V1.1__Jeep_Data.sql. So, for example, using the model Wrangler and trim level “Sport”, the query should return two rows:

Row 1 Row 2
Model ID WRANGLER WRANGLER
Trim Level Sport Sport
Num Doors 2 4
Wheel Size 17 17
Base Price $28,475.00 $31,975.00

6)

The method should be named buildExpected(), and it should return a List of Jeep. The video put this method into a support superclass but you can include it in the main test class if you want.

  • Write an AssertJ assertion in the test to assert that the actual list of jeeps returned by the server is the same as the expected list. Run the test. Produce a screenshot showing… a) The test with the assertion.
    1. The JUnit status bar (should be red).
    2. The method returning the expected list of Jeeps.

 

  • Add a service layer in your application as shown in the videos:
    1. Add a package named promineotech.jeep.service.
    2. In the new package, create an interface named JeepSalesService.
    3. In the same package (service), create a class named DefaultJeepSalesService that implements the JeepSalesService Add the class-level annotation, @Service.
    4. Inject the service interface into DefaultJeepSalesController using the @Autowired The instance variable should be private, and the variable should be named jeepSalesService.
    5. Define the fetchJeeps method in the interface. Implement the method in the service class. Call the method from the controller (make sure the controller returns the list of Jeeps returned by the service method). The method signature looks like this:

List<Jeep> fetchJeeps(JeepModel model, String trim);

  1. Add a Lombok info-level log statement in the service implementation showing that the service was called. Print the parameters passed to the method. Let the method return null for now.
  2. Run the test again. Produce a screenshot showing the service class implementation, the log line in the console, and the red status bar.

 

  • Add the database dependencies described in the video to the POM file (MySQL driver and Spring Boot Starter JDBC). To find them, nagivate to https://mvnrepository.com/. Search for mysql-connector-j and spring-boot-starter-jdbc. In the POM file you don’t need version numbers for either dependency because the version is included in the Spring Boot Starter Parent.
  • Create yaml in src/main/resources. Add the spring.datasource.url, spring.datasource.username, and spring.datasource.password properties to application.yaml. The url should be the same as shown in the video

(jdbc:mysql://localhost:3306/jeep). The password and username should match your setup. If you created the database under your root user, the username is “root”, and the password is the root user password. If you created a “jeep” user or other user, use the correct username and password.

Be careful with the indentation! YAML allows hierarchical configuration but it reads the hierarchy based on the indentation level. The keyword “spring” MUST start in the first column. It should look similar to this when done:

spring:   datasource:

username: username     password: password     url: jdbc:mysql://localhost:3306/jeep

  • Start the application (the real application, not the test). Produce a screenshot that shows yaml and the console showing that the application has started with no errors.

 

  • Add the H2 database as dependency. Search for the dependency in the Maven repository like you did above. Search for “h2” and pick the latest version. Again, you don’t need the version number, but the scope should be set to “test”.

 

  • Create application-yaml in src/test/resources. Add the setting spring.datasource.url that points to the H2 database. It should look like this: spring: datasource:

url: jdbc:h2:mem:jeep;mode=MYSQL

You do not need to set the username and password because the in-memory H2 database does not require them.

Produce a screenshot showing application-test.yaml.

 

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.