LAB_ATKJE004 - Spring Core - Skill Based Assessment [201-INTERMEDIATE]
17-Feb-2020 11:47
17-Feb-2020 11:48
1 Mins
6 / 6
0 / 6
| Section Name | Total Questions | Answered | Not Answered | Correct Marks | Partial Marks | Penalty Marks | Score |
|---|---|---|---|---|---|---|---|
| Spring Core MCQ | 5 | 5 | 0 | 0.00 | 0.00 | 0.00 | 0.00 |
| Spring Core Skill | 1 | 1 | 0 | 0.00 | 53.25 | 0.00 | 53.25 |
| Priority | No of Violations | Percentage of Violations | Score |
|---|---|---|---|
| Total Score | 8.25 | ||
| P1 | 1 | 14 | 3.00 |
| P2 | 0 | 0 | 3.00 |
| P3 | 8 | 9 | 2.25 |
3 seconds InCorrect
William wants to test the method 'addEmployee' using Spring Test framework. He deletes all the data from T_EMPLOYEE, saves 1 record and attempts to retrieve it, by invoking findAll() method.
The test case ends in failure and the data is not retrieved back.
Choose and apply an appropriate solution for the given problem:
// imports omitted
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {ServiceTestConfig.class})
public abstract class EmployeeServiceTest extends
AbstractTransactionalJUnit4SpringContextTests {
@PersistenceContext
protected EntityManager em;
@Test
public void testAddCustomer() throws Exception {
// Clear all existing data in T_EMPLOYEE table
deleteFromTables("T_EMPLOYEE");
Employee employee = new Employee();
employee.setFirstName("Mitchell");
employee.setLastName("Johnson");
employee = employeeService.save(contact); //line 13
List<Contact> contacts = employeeService.findAll(); //line 14
assertEquals(1, contacts.size());
}
}
According to Spring Test framework, the data will never be persisted in the original persistent store. Hence findAll() metthod will be always a failure.
William need to explicitly flush the data into persistent database by calling commit or flush before invoking the findAll() method
William need to create a transaction and wrap it around the save and findAll() operations
None of the listed options
None of the listed options
2 seconds InCorrect
What is the Join Point that is supported by Spring?
2 seconds InCorrect
What are the declaration parts of PointCuts?
Select all that apply
1 seconds InCorrect
Consider a Service class that retrieves the list of Tourist places available in TamilNadu. This class reads the values from Property file to retrieve the tourist places. City name is the key and the Tourist places will be the values.
Positive Scenario : If the provided city name is available in the property file, then the service class will return the list of tourist places against the given city
Negative Scenario : If the provided city name is not available in the property file, then service class will return the NoDataFound exception with no values in the output list.Write a test case, that test the negative scenario.
// Import Statements
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "file:src/applicationcontext.xml" })
public class ServiceTest {
@Autowired
private ResourceReaderService resourcereader;
@Test(expected = NoDataFoundException.class)
public void testPropertyValuesInCorrectData() throws NoDataFoundException {
HashMap> propValues = resourcereader .getPropertyValues("TRICHY");
assertTrue(propValues.isEmpty());
}
}
// Import Statements
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "file:src/applicationcontext.xml" })
public class ServiceTest {
@Autowired
private ResourceReaderService resourcereader;
@Test(expected = NoDataFoundException.class)
public void testPropertyValuesInCorrectData() throws NoDataFoundException {
HashMap> propValues = resourcereader.getPropertyValues("TRICHY");
assertTrue(propValues.isNull());
}
}
// Import Statements
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "file:src/applicationcontext.xml" })
public class ServiceTest {
@Autowired
private ResourceReaderService resourcereader;
public void testPropertyValuesInCorrectData() throws NoDataFoundException {
HashMap> propValues = resourcereader .getPropertyValues("TRICHY");
assertTrue(propValues.isEmpty());
}
}
// Import Statements
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "file:src/applicationcontext.xml" })
public class ServiceTest {
@Autowired
private ResourceReaderService resourcereader;
@Test(expected = NoDataFoundException.class)
public void testPropertyValuesInCorrectData() {
HashMap> propValues = resourcereader .getPropertyValues("TRICHY");
assertTrue(propValues.isEmpty());
}
}
// Import Statements
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "file:src/applicationcontext.xml" })
public class ServiceTest {
@Autowired
private ResourceReaderService resourcereader;
@Test(expected = NoDataFoundException.class)
public void testPropertyValuesInCorrectData() {
HashMap> propValues = resourcereader .getPropertyValues("TRICHY");
assertTrue(propValues.isEmpty());
}
}
2 seconds InCorrect
What will happen if the below test case is executed? Assume that the save() method will throw 'MandatoryFieldConstraintVoilation' Exception if UserId is empty.
@Test(expected=MandatoryFieldConstraintViolationException.class)
public void testAddUserInvalidInput() throws Exception {
User user = new User();
user.setUserName("XXX");
user = userService.save(user);
}
Test will not get executed
Test case will get passed, the data will not get saved
Test case will fail, the data will get saved
The data will not get saved and the test case will also fail
Test will not get executed
39 seconds Partially Correct
Important Instructions
1.Business Requirement
Member Policy Management System is a system, which holds various Health Insurance Policies for Corporates. As the first phase of the work, they have intended to automate the process of maintaining the Member and Plan details.
1.1 Target Audience
Admin team will be the target audience of the Member Policy Management System.
2.Technical SpecificationsDatabase Connectivity Details
Use MYSQL database for all the database activities. The script needed for the case study and the Connection details is given below:
|
Driver Class |
com.mysql.jdbc.Driver |
|
URI Name |
jdbc:mysql://localhost/member_policy |
|
UserName |
root |
|
Password |
<PASSWORD IS BLANK> |
Create the tables before proceeding with the source code. The detailed steps on how to execute the SQL file are available in the user manuals.
Code Skeleton for the Case Study
The code skeleton to be used for developing the case study will be given as a zip file. This will start as the base code for you to work on the solution.
3.1 Get Plan Details of the Member
Background
The member details are already recorded in the database in the table named “MEMBER_DETAILS”. Also the plan details are recorded in the table named “PLAN_DETAILS” (these tables would have been created by running the DB script). Based on the input, the relevant details need to be retrieved from the database.
Requirement Description:
This requirement is to retrieve the plan and the member details of the respective Member.
The functionality gets the member id, plan id and corporate name and retrieve the values from the database.
If the member holds the given plan id, then retrieve member_id, plan_id, plan_value, tenure, corporate_name, monthly_due_date from the database.
The retrieved values need to be set in MemberVO, which is already provided as part of the skeleton.
If the member does not hold the given plan, then a user defined exception named “MemberPolicyException” should be thrown with the message “Invalid Plan Id for the given Member”
Design Rules:
i. MemberPolicyBO should be injected in MemberPolicyService and MemberPolicyDAO must be injected in MemberPolicyBO
ii. Do not change the package definitions or class names or method signatures in the code.
iii. You can use either Annotation or XML based configuration to inject the necessary beans, unless specified. If you are using XML based configuration, define your beans in applicationcontext.xml file ONLY. If you are using annotation based configuration, define your beans in ‘MemberPolicyConfig’ class only.
Method Specification:
|
Component Name |
Method |
Input |
Output |
Exceptional Case |
|
MemberPolicyDAO |
getPlanDetailsOfMember |
String memberId, String planId, String corporateName |
MemberVO |
MemberPolicyException |
3.2 Get Discount Details
Background
Each member can avail the discount percentage for the plan they hold. These discount percentages will be offered based on the Corporate Function Scheme.
Requirement Description:
This requirement is to retrieve the discount percentage for the respective Corporate Scheme.
If the given corporate name is present in the Map, it returns the discount percentage
If the given corporate name is not present in the Map, then a user defined exception named “MemberPolicyException” should be thrown with the message “There is no discount for this Corporate Function”
Design Rules:
MemberPolicyBO should have the method ‘getDiscountToBePaid’ which must return the discount percentage
Map should be configured with the below data. Please DO NOT change the corporate name or the discount percentage values while injecting the map in the Application Context
|
Corporate Name |
Discount Percentage |
|
IT |
50 |
|
Automobiles |
30 |
|
Manufacturing |
20 |
3.You can use either Annotation or XML based configuration to inject the necessary beans, unless specified. If you are using XML based configuration, define your beans in applicationcontext.xml file ONLY. If you are using annotation based configuration, define your beans in ‘MemberPolicyConfig’ class only.
Method Specification:
|
Component Name |
Method |
Input |
Output |
Exceptional Case |
|
MemberPolicyBO |
getDiscountDetails |
String corporateName |
Double discountPercentage |
MemberPolicyException |
3.3 Update Premium Amount of the Member
Background
The premium details of the member should be persisted in the database in the table named
“MEMBER_DETAILS”. (this table would have been created by running the DB script). Based on the discount amount retrieved from requirement 3.2, the premium amount should be calculated and should be persisted into the database.
Requirement Description:
This requirement is to update the premium amount of the member based on the discount percentage of the respective Member. The functionality gets the plan value from the database and calculate the premium amount based on the discount percentage.
From Requirement 3.1, the memberVO would have been returned to MemberPolicyBO layer with the values retrieved from the database.
Extract the plan value from the memberVO. The discount percentage would have been returned from the Map using requirement 3.2.
Calculate the Premium amount as per the below formula in the method ‘calculatePremiumAmount’
PREMIUM = (PLAN_VALUE * DISCOUNT_PERCENTAGE) /100;
The calculated premium amount needs to be updated in the database for the given member_id.
Design Rules:
i. MemberPolicyBO should be injected in MemberPolicyService and MemberPolicyDAO must be injected in MemberPolicyBO
ii. Do not change the package definitions or class names or method signatures in the code.
iii. Do not change the property files provided in the application
iv. Use ONLY DriverManagerDataSource for creating the datasource. You MUST NOT change the database properties file (mysql.properties) provided as part of the Skeleton. Use PropertyPlaceHolder configuration to read the properties and create the datasource bean. All the values from mysql.properties file should be read by using the PropertyPlaceHolder, except for driverclassname. The Driver Class name should be hard coded as it and should not be read using PropertyPlaceHolder.
v. Use ONLY Declarative Transaction management for updating the premium_amount into the database. We expect you to have this transaction in the ‘MemberPolicyBO’ class, for the method ‘updatePremiumAmount’.
vi. You can use either Annotation or XML based configuration to inject the necessary beans, unless specified. If you are using XML based configuration, define your beans in applicationcontext.xml file ONLY. If you are using annotation based configuration, define your beans in ‘MemberPolicyConfig’ class only.
Method Specification:
|
Component Name |
Method |
Input |
Output |
Exceptional Case |
|
MemberPolicyService |
UpdatePremiumAmount |
String memberId, String planId, String corporateName |
void |
MemberPolicyException |
|
MemberPolicyBO |
UpdatePremiumAmount |
String memberId, String planId, String corporateName |
void |
MemberPolicyException |
|
MemberPolicyBO |
calculatePremiumAmount |
Double discountPercentage, MemberVO memberVO |
Integer |
MemberPolicyException |
|
MemberPolicyDAO |
updatePremiumAmount |
String memberId, String planId, String corporateName |
MemberVO |
MemberPolicyException |
| Criteria Name | Comments for Associates | Status |
|---|---|---|
| Destructive | Test the Invalid Corporate Name In BO | Success |
| Test the Invalid Corporate Name In Service | Success | |
| Test the Invalid Plan Details Of Member In Service | Failure | |
| Test the Invalid plan Details Of Member In DAO | Failure | |
| Test the Invalid plan Details Of Member In BO | Failure | |
| Feature Test | Test the Premium Update In Database From Service | Failure |
| Test the Premium Calculation | Failure | |
| Test the Valid plan Details Of Member In DAO | Success | |
| Test the Premium Update In Database From BO | Failure | |
| Test the Valid Corporate Name In BO | Success | |
| Functional | Test the Dependency Injection Service Layer | Success |
| Test the Dependency Injection BO Layer | Success | |
| Test the Property Place Holder Configurer | Success | |
| Test the Collections | Failure | |
| Test the JDBC | Success | |
| Test the Transactions | Failure |
| RuleSet | Line No | File Name | Violation | Priority |
|---|---|---|---|---|
| Design | 52 | src\com\spring\memberpolicy\constants\SQLConstants.java | A class which only has private constructors should be final | 1 |
| Design | 31 | src\MemberPolicyMain.java | All methods are static. Consider using Singleton instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning. | 3 |
| Naming | 40 | src\MemberPolicyMain.java | Avoid variables with short names like bo | 3 |
| Java Logging | 46 | src\MemberPolicyMain.java | Avoid printStackTrace(); use a logger call instead. | 3 |
| Design | 94 | src\com\spring\memberpolicy\bo\MemberPolicyBO.java | Deeply nested if..then statements are hard to read | 3 |
| Naming | 58 | src\com\spring\memberpolicy\constants\SQLConstants.java | Avoid excessively long variable names like SELECT_ALL_MEMBER_DETAILS | 3 |
| Naming | 59 | src\com\spring\memberpolicy\constants\SQLConstants.java | Avoid excessively long variable names like SELECT_MEMBERS_WITH_PLAN_ID | 3 |
| Naming | 60 | src\com\spring\memberpolicy\constants\SQLConstants.java | Avoid excessively long variable names like SELECT_WITH_PLAN_ID | 3 |
| Naming | 61 | src\com\spring\memberpolicy\constants\SQLConstants.java | Avoid excessively long variable names like UPDATE_MEMBERS_WITH_PREMIUM | 3 |
| Import Statements | 1 | src\MemberPolicyMain.java | Avoid unused imports such as 'java.sql.ResultSet' | 4 |
| Import Statements | 2 | src\MemberPolicyMain.java | Avoid unused imports such as 'java.sql.SQLException' | 4 |
| Import Statements | 3 | src\MemberPolicyMain.java | Avoid unused imports such as 'java.util.ArrayList' | 4 |
| Import Statements | 4 | src\MemberPolicyMain.java | Avoid unused imports such as 'java.util.List' | 4 |
| Import Statements | 7 | src\MemberPolicyMain.java | Avoid unused imports such as 'org.springframework.jdbc.core.JdbcTemplate' | 4 |
| Import Statements | 8 | src\MemberPolicyMain.java | Avoid unused imports such as 'org.springframework.jdbc.core.RowCallbackHandler' | 4 |
| Import Statements | 9 | src\MemberPolicyMain.java | Avoid unused imports such as 'org.springframework.jdbc.core.RowMapper' | 4 |
| Import Statements | 11 | src\MemberPolicyMain.java | Avoid unused imports such as 'com.spring.memberpolicy.bo.MemberPolicyBO' | 4 |
| Import Statements | 13 | src\MemberPolicyMain.java | Avoid unused imports such as 'com.spring.memberpolicy.constants.SQLConstants' | 4 |
| Import Statements | 14 | src\MemberPolicyMain.java | Avoid unused imports such as 'com.spring.memberpolicy.dao.MemberPolicyDAO' | 4 |
| Import Statements | 17 | src\MemberPolicyMain.java | Avoid unused imports such as 'com.spring.memberpolicy.vo.MemberVO' | 4 |
| Import Statements | 49 | src\com\spring\memberpolicy\config\MemberPolicyConfig.java | Avoid unused imports such as 'java.sql.DriverManager' | 4 |
| Import Statements | 51 | src\com\spring\memberpolicy\config\MemberPolicyConfig.java | Avoid unused imports such as 'javax.sql.DataSource' | 4 |
| Import Statements | 53 | src\com\spring\memberpolicy\config\MemberPolicyConfig.java | Avoid unused imports such as 'org.springframework.beans.factory.annotation.Value' | 4 |
| Import Statements | 54 | src\com\spring\memberpolicy\config\MemberPolicyConfig.java | Avoid unused imports such as 'org.springframework.beans.factory.config.PropertyPlaceholderConfigurer' | 4 |
| Import Statements | 55 | src\com\spring\memberpolicy\config\MemberPolicyConfig.java | Avoid unused imports such as 'org.springframework.context.annotation.Bean' | 4 |
| Import Statements | 58 | src\com\spring\memberpolicy\config\MemberPolicyConfig.java | Avoid unused imports such as 'org.springframework.core.io.DefaultResourceLoader' | 4 |
| Import Statements | 59 | src\com\spring\memberpolicy\config\MemberPolicyConfig.java | Avoid unused imports such as 'org.springframework.core.io.Resource' | 4 |
| Import Statements | 60 | src\com\spring\memberpolicy\config\MemberPolicyConfig.java | Avoid unused imports such as 'org.springframework.core.io.ResourceLoader' | 4 |
| Import Statements | 61 | src\com\spring\memberpolicy\config\MemberPolicyConfig.java | Avoid unused imports such as 'org.springframework.jdbc.core.JdbcTemplate' | 4 |
| Import Statements | 62 | src\com\spring\memberpolicy\config\MemberPolicyConfig.java | Avoid unused imports such as 'org.springframework.jdbc.datasource.DriverManagerDataSource' | 4 |
| Import Statements | 63 | src\com\spring\memberpolicy\config\MemberPolicyConfig.java | Avoid unused imports such as 'org.springframework.orm.hibernate3.AbstractSessionFactoryBean' | 4 |
| Import Statements | 64 | src\com\spring\memberpolicy\config\MemberPolicyConfig.java | Avoid unused imports such as 'org.springframework.orm.hibernate3.HibernateTemplate' | 4 |
| Import Statements | 65 | src\com\spring\memberpolicy\config\MemberPolicyConfig.java | Avoid unused imports such as 'org.springframework.orm.hibernate3.LocalSessionFactoryBean' | 4 |
| Import Statements | 66 | src\com\spring\memberpolicy\config\MemberPolicyConfig.java | Avoid unused imports such as 'org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean' | 4 |
| Import Statements | 55 | src\com\spring\memberpolicy\dao\MemberPolicyDAO.java | Avoid unused imports such as 'java.util.Date' | 4 |
Report generated time : 18-02-2020 12:08 PM
Powered by