You are on page 1of 9

Automatic evaluation[-]

Proposed grade: 98.75 / 100


Result Description
[+]SOURCE CODE ANALYZER REPORT
[+]Grading and Feedback
MobileAccessoriesShop/pom.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance"
3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-
4.0.0.xsd">
4 <modelVersion>4.0.0</modelVersion>
5 <parent>
6 <groupId>org.springframework.boot</groupId>
7 <artifactId>spring-boot-starter-parent</artifactId>
8 <version>2.1.8.RELEASE</version>
9 <relativePath/>
10 </parent>
11 <groupId>com</groupId>
12 <artifactId>MobileAccessoriesShop</artifactId>
13 <version>0.0.1-SNAPSHOT</version>
14 <name>MobileAccessoriesShop</name>
15 <description>Demo project for Spring Boot</description>
16
17 <properties>
18 <java.version>1.8</java.version>
19 </properties>
20
21 <dependencies>
22 <dependency>
23 <groupId>org.springframework.boot</groupId>
24 <artifactId>spring-boot-starter</artifactId>
25 </dependency>
26
27
28 <dependency>
29 <groupId>org.springframework.boot</groupId>
30 <artifactId>spring-boot-starter-web</artifactId>
31 </dependency>
32
33 <dependency>
34 <groupId>org.apache.tomcat.embed</groupId>
35 <artifactId>tomcat-embed-jasper</artifactId>
36 <scope>provided</scope>
37 </dependency>
38 <dependency>
39 <groupId>javax.servlet</groupId>
40 <artifactId>servlet-api</artifactId>
41 <version>2.5</version>
42 <scope>provided</scope>
43 </dependency>
44 <dependency>
45 <groupId>javax.servlet.jsp</groupId>
46 <artifactId>jsp-api</artifactId>
47 <version>2.1</version>
48 <scope>provided</scope>
49 </dependency>
50
51 <dependency>
52 <groupId>taglibs</groupId>
53 <artifactId>standard</artifactId>
54 <version>1.1.2</version>
55 </dependency>
56 <dependency>
57 <groupId>javax.servlet</groupId>
58 <artifactId>jstl</artifactId>
59 <version>1.2</version>
60 </dependency>
61 <dependency>
62 <groupId>org.springframework.boot</groupId>
63 <artifactId>spring-boot-starter-test</artifactId>
64 <scope>test</scope>
65 <exclusions>
66 <exclusion>
67 <groupId>org.junit.vintage</groupId>
68 <artifactId>junit-vintage-engine</artifactId>
69 </exclusion>
70 </exclusions>
71 </dependency>
72 </dependencies>
73
74 <build>
75 <plugins>
76 <plugin>
77 <groupId>org.springframework.boot</groupId>
78 <artifactId>spring-boot-maven-plugin</artifactId>
79 </plugin>
80 </plugins>
81 </build>
82
83 </project>
84
MobileAccessoriesShop/src/main/java/com/controller/BillController.java
1 package com.controller;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import javax.validation.Valid;
7
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.stereotype.Controller;
10 import org.springframework.ui.ModelMap;
11 import org.springframework.validation.BindingResult;
12 import org.springframework.web.bind.annotation.GetMapping;
13 import org.springframework.web.bind.annotation.ModelAttribute;
14 import org.springframework.web.bind.annotation.PostMapping;
15
16 import com.model.Order;
17 import com.service.BillService;
18
19 //use appropriate annotation to configure BillController as Controller
20 @Controller
21 public class BillController {
22 @Autowired
23 private BillService billService;
24
25
26
27
28 @ModelAttribute("productList")
29 public Map<String, String> populateProductType() {
30 Map<String, String> serviceMap = new HashMap<String, String>();
31
32 serviceMap.put("HeadPhone", "HeadPhone");
33 serviceMap.put("TravelAdapter", "TravelAdapter");
34 serviceMap.put("MemoryCard", "MemoryCard");
35 serviceMap.put("PenDrive", "PenDrive");
36 serviceMap.put("USBCable", "USBCable");
37
38 return serviceMap;
39 }
40
41 @GetMapping("/showPage")
42 public String showPage(@ModelAttribute("order") Order order) {
43 return "showpage";
44 }
45
46
47 @PostMapping("/billDesk")
48 public String calculateTotalCost(@Valid @ModelAttribute("order") Order order, BindingResult result,
49 ModelMap model) {
50
51 // fill the code
52 if (result.hasErrors()) {
53 return "showpage";
54 } else {
55 double totalCost = billService.calculateTotalCost(order);
56 model.put("customerName", order.getCustomerName());
57 model.put("totalCost", totalCost);
58 return "billdesk";
59
60 }
61
62 }
63
64 }
65
MobileAccessoriesShop/src/main/java/com/controller/Internationalization
Config.java
1 package com.controller;
2
3 import java.util.Locale;
4
5 import org.springframework.context.MessageSource;
6 import org.springframework.context.annotation.Bean;
7 import org.springframework.context.annotation.Configuration;
8 import org.springframework.context.support.ReloadableResourceBundleMessageSource;
9 import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
10 import org.springframework.web.servlet.LocaleResolver;
11 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
12 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
13 import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
14 import org.springframework.web.servlet.i18n.SessionLocaleResolver;
15
16 @Configuration
17 public class InternationalizationConfig implements WebMvcConfigurer {
18
19 //Create a SessionLocaleResolver object and set the default locale to English return the
SessionLocaleResolver object
20 @Bean
21 public LocaleResolver localeResolver() {
22 SessionLocaleResolver localeResolver = new SessionLocaleResolver();
23 localeResolver.setDefaultLocale(Locale.US);
24 return localeResolver;
25 }
26
27 // Create LocaleChangeInterceptor object and set the parameter name as language
28 // and return the localeChangeInterceptor
29 @Bean
30 public LocaleChangeInterceptor localeChangeInterceptor() {
31 LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor();
32 interceptor.setParamName("language");
33 return interceptor;
34
35 }
36 @Bean
37 public LocalValidatorFactoryBean getValidator() {
38 LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean();
39 bean.setValidationMessageSource(messageSource());
40 return bean;
41 }
42 @Bean
43 public MessageSource messageSource() {
44 ReloadableResourceBundleMessageSource messageSource = new
ReloadableResourceBundleMessageSource();
45
46 messageSource.setBasename("classpath:messages");
47 messageSource.setDefaultEncoding("UTF-8");
48 return messageSource;
49 }
50
51 // register the LocaleChangeInterceptor
52 @Override
53 public void addInterceptors(InterceptorRegistry registry) {
54
55 registry.addInterceptor(localeChangeInterceptor());
56 }
57 }
MobileAccessoriesShop/src/main/java/com/example/demo/MobileAcces
soriesShopApplication.java
1 package com.example.demo;
2
3 import org.springframework.boot.SpringApplication;
4 import org.springframework.boot.autoconfigure.SpringBootApplication;
5 import org.springframework.context.annotation.ComponentScan;
6
7 @SpringBootApplication
8 @ComponentScan("com")
9 public class MobileAccessoriesShopApplication {
10
11 public static void main(String[] args) {
12 SpringApplication.run(MobileAccessoriesShopApplication.class, args);
13 }
14
15 }
MobileAccessoriesShop/src/main/java/com/model/Order.java
1 package com.model;
2
3 import javax.validation.constraints.NotBlank;
4 import javax.validation.constraints.Positive;
5
6
7 public class Order {
8 @NotBlank(message="{error.customerName.blank}")
9 private String customerName;
10 @NotBlank(message="{error.contactNumber.blank}")
11 private String contactNumber;
12 private String productName;
13 @Positive(message="{error.quantity.negative}")
14 private int quantity;
15
16 public String getCustomerName() {
17 return customerName;
18 }
19 public void setCustomerName(String customerName) {
20 this.customerName = customerName;
21 }
22 public String getContactNumber() {
23 return contactNumber;
24 }
25 public void setContactNumber(String contactNumber) {
26 this.contactNumber = contactNumber;
27 }
28 public String getProductName() {
29 return productName;
30 }
31 public void setProductName(String productName) {
32 this.productName = productName;
33 }
34 public int getQuantity() {
35 return quantity;
36 }
37 public void setQuantity(int quantity) {
38 this.quantity = quantity;
39 }
40
41 }
42
MobileAccessoriesShop/src/main/java/com/service/BillService.java
1 package com.service;
2
3 import org.springframework.stereotype.Service;
4
5 import com.model.Order;
6
7 //use appropriate annotation to configure BillService as a Service
8 @Service
9 public class BillService {
10
11 // calculate the totalCost and return the cost
12 public double calculateTotalCost(Order order) {
13 double totalCost = 0.0;
14 double cost = 0.0;
15 int perProductPrice = 0;
16 if (order.getProductName().equalsIgnoreCase("HeadPhone")) {
17 perProductPrice = 450;
18 }
19 else if (order.getProductName().equalsIgnoreCase("TravelAdapter")) {
20 perProductPrice = 1000;
21 }
22 else if (order.getProductName().equalsIgnoreCase("MemoryCard")) {
23 perProductPrice = 300;
24 }
25 else if (order.getProductName().equalsIgnoreCase("PenDrive")) {
26 perProductPrice = 650;
27 }
28 else if (order.getProductName().equalsIgnoreCase("USBCable")) {
29 perProductPrice = 800;
30 }
31 cost = order.getQuantity() * perProductPrice ;
32 totalCost = cost +(cost*3)/100;
33 // fill the code
34 return totalCost;
35 }
36
37 }
38
MobileAccessoriesShop/src/main/resources/application.properties
1 #Do not change the configurations
2 #value for server.port can be changed
3 #include other needed configurations
4 server.port=9095
5 spring.mvc.view.prefix = /WEB-INF/views/
6 spring.mvc.view.suffix = .jsp
7 spring.mvc.static-path-pattern=/resources/**
MobileAccessoriesShop/src/main/resources/messages.properties
1 label.customerName=Customer Name in English
2 label.contactNumber=Contact Number in English
3 label.productName=Product Name in English
4 label.quantity=Quantity in English
5
6 error.customerName.blank=Customer Name cannot be empty in English
7 error.contactNumber.blank=Contact Number cannot be empty in English
8 error.quantity.negative=Quantity should not be zero or a negative number in English
MobileAccessoriesShop/src/main/resources/messages_de.properties
1 label.customerName=Customer Name in German
2 label.contactNumber=Contact Number in German
3 label.productName=Product Name in German
4 label.quantity=Quantity in German
5
6 error.customerName.blank=Customer Name cannot be empty in German
7 error.contactNumber.blank=Contact Number cannot be empty in German
8 error.quantity.negative=Quantity should not be zero or a negative number in German
MobileAccessoriesShop/src/main/resources/messages_fr.properties
1 label.customerName=Customer Name in French
2 label.contactNumber=Contact Number in French
3 label.productName=Product Name in French
4 label.quantity=Quantity in French
5
6 error.customerName.blank=Customer Name cannot be empty in French
7 error.contactNumber.blank=Contact Number cannot be empty in French
8 error.quantity.negative=Quantity should not be zero or a negative number in French
MobileAccessoriesShop/src/main/webapp/WEB-INF/views/billdesk.jsp
1 <%@page isELIgnored="false" %>
2 <html>
3 <body bgcolor="lavender">
4
5 <h2> Hi ${customerName}!!! You need to pay Rs.${totalCost}</h2>
6
7
8 </body>
9 </html>
MobileAccessoriesShop/src/main/webapp/WEB-INF/views/showpage.jsp
1 <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
2 <%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form"%>
3 <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
4 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
5 pageEncoding="ISO-8859-1" isELIgnored="false"%>
6
7
8 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
9 <html>
10 <head>
11 <style>
12 .center {
13 margin-left: auto;
14 margin-right: auto;
15 }
16 </style>
17
18 </head>
19 <body style="background-color: lavender">
20 <h1>
21 <center>Welcome to Mobile Accessories Store</center>
22 </h1>
23
24 <!-- Do not change the below line -->
25 <a href="/showPage?language=en">English</a>|
26 <a href="/showPage?language=de">German</a>|
27 <a href="/showPage?language=fr">French</a>
28 </align>
29 <!-- Design the page as per the requirements-->
30
31
32 <form:form modelAttribute="order" method="post" action="/billDesk">
33 <table class="center">
34
35 <tr>
36 <td id="id1"><spring:message code="label.customerName" /></td>
37 <td><form:input path="customerName" id="customerName"
38 name="customerName" /></td>
39 <td><form:errors path="customerName"></form:errors></td>
40
41 </tr>
42 <tr>
43 <td id="id2"><spring:message code="label.contactNumber" /></td>
44 <td><form:input path="contactNumber" id="contactNumber"
45 name="contactNumber" /></td>
46 <td><form:errors path="contactNumber"></form:errors></td>
47 </tr>
48
49 <tr>
50 <td id="id3"><spring:message code="label.productName" /></td>
51 <td><form:select path="productName" id="productName"
name="productName"
52 items="${productList}" /></td>
53 </tr>
54 <tr>
55 <td id="id2"><spring:message code="label.quantity" /></td>
56 <td><form:input path="quantity" id="quantity"
57 name="quantity" /></td>
58 <td><form:errors path="quantity"></form:errors></td>
59 </tr>
60
61 <tr>
62 <td><input type="submit" id="submit" name="submit"
63 value="CalculateCost" /></td>
64 <td><input type="reset" id="reset" name="reset" value="Cancel"
/></td>
65 </tr>
66
67 </table>
68 </form:form>
69 </body>
70 </html>
71

Grade
Reviewed on Monday, 5 July 2021, 10:00 PM by Automatic grade
Grade 98.75 / 100
Assessment report
[-]SOURCE CODE ANALYZER REPORT
Error Msg: A method should have only one exit point, and that should be the last statement
in the method
Variable Name:
Class Name: BillController

[-]Grading and Feedback


Feature Test - 30.0 / 30.0(Success)
* check whether the controller annotation is present above the Controller - 6.0 /
6.0
* check whether the ModelAttribute annotation is present above the Method - 6.0 /
6.0
* check whether the Service is autowired inside the Controller - 6.0 / 6.0
* check whether Service annotation is present above the Service - 6.0 / 6.0
* check whether the ModelAttribute annotation has the appropriate value above the
Method - 6.0 / 6.0

Functional testing - 20.0 / 20.0(Success)


* check whether the Total cost is calculated correctly for the product MemoryCard
- 4.0 / 4.0
* check whether the Total cost is calculated correctly for the product USBCable -
4.0 / 4.0
* check whether the Total cost is calculated correctly for the product PenDrive -
4.0 / 4.0
* check whether the Total cost is calculated correctly for the product HeadPhone
- 4.0 / 4.0
* check whether the Total cost is calculated correctly for the product
TravelAdapter - 4.0 / 4.0

Spring Testing in the Controller - 20.0 / 20.0(Success)


* check whether the request is mapped for showPage and redirected to showpage -
5.0 / 5.0
* check whether layering is followed that is whether total cost is calculated by
invoking the service method inside the Controller - 10.0 / 10.0
* check whether the request is mapped for calculateTotalCost and redirected to
result page - 5.0 / 5.0

UI Testing - 25.0 / 25.0(Success)


* check whether the showpage jsp is rendered for the product MemoryCard - 1.0 /
1.0
* check whether the showpage jsp is rendered for the product USBCable - 1.0 / 1.0
* check whether the showpage jsp is rendered for the product PenDrive - 1.0 / 1.0
* check whether the showpage jsp is rendered for the product HeadPhone - 1.0 /
1.0
* check whether the showpage jsp is rendered for the product TravelAdapter - 1.0
/ 1.0
* check whether the showpage jsp is rendered with proper constraints for
customerName - 1.0 / 1.0
* check whether the showpage jsp is rendered with proper constraints for
contactNumber - 1.0 / 1.0
* check whether the showpage jsp is rendered with proper constraints for quantity
- 1.0 / 1.0
* check whether UI from showpage to result page is redirected after calculating
the total cost for the product memoryCard - 1.0 / 1.0
* check whether UI from showpage to result page is redirected after calculating
the total cost for the product USBCable - 1.0 / 1.0
* check whether UI from showpage to result page is redirected after calculating
the total cost for the product PenDrive - 1.0 / 1.0
* check whether UI from showpage to result page is redirected after calculating
the total cost for the product HeadPhone - 1.0 / 1.0
* check whether UI from showpage to result page is redirected after calculating
the total cost for the product TravelAdapter - 1.0 / 1.0
* check whether label names from the property file is correctly displayed for
English - 2.0 / 2.0
* check whether label names from the property file is correctly displayed for
German - 2.0 / 2.0
* check whether error message for blank from the property file is correctly
displayed for French - 2.0 / 2.0
* check whether error message for Customer Name in blank from the property file
is correctly displayed for German - 2.0 / 2.0
* check whether error message for Contact Number in blank from the property file
is correctly displayed for German - 2.0 / 2.0
* check whether error message for Quality is negative from the property file is
correctly displayed for French - 2.0 / 2.0

Comments and best practices/standards - 3.75 / 5.0(Partial)

You might also like