-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Help Desk API * Help Desk Test Case * remove: column query_date * removed: query field from entity * Update changelog-master.xml Co-authored-by: Elvin Shrestha <[email protected]>
- Loading branch information
1 parent
a9068ef
commit dadaec7
Showing
11 changed files
with
353 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
pemits-api/src/main/java/com/pemits/webcare/api/helpdesk/entity/HelpDesk.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.pemits.webcare.api.helpdesk.entity; | ||
|
||
import com.pemits.webcare.core.entity.BaseEntity; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.Entity; | ||
import javax.validation.constraints.NotEmpty; | ||
import java.io.Serializable; | ||
import java.time.LocalDate; | ||
|
||
/** | ||
* @Author Mohammad Hussain | ||
* created on 7/14/2020 | ||
*/ | ||
@Entity | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@EqualsAndHashCode(callSuper = true) | ||
public class HelpDesk extends BaseEntity<Long> implements Serializable { | ||
|
||
@NotEmpty(message = "Name is required") | ||
private String name; | ||
@NotEmpty(message = "Contact number is required") | ||
private String contactNumber; | ||
@NotEmpty(message = "Email is required") | ||
private String email; | ||
@NotEmpty(message = "Query is required") | ||
private String query; | ||
} |
13 changes: 13 additions & 0 deletions
13
pemits-api/src/main/java/com/pemits/webcare/api/helpdesk/repository/HelpDeskRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.pemits.webcare.api.helpdesk.repository; | ||
|
||
import com.pemits.webcare.api.helpdesk.entity.HelpDesk; | ||
import com.pemits.webcare.core.repository.BaseRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
/** | ||
* @Author Mohammad Hussain | ||
* created on 7/14/2020 | ||
*/ | ||
@Repository | ||
public interface HelpDeskRepository extends BaseRepository<HelpDesk, Long> { | ||
} |
38 changes: 38 additions & 0 deletions
38
pemits-api/src/main/java/com/pemits/webcare/api/helpdesk/repository/spec/HelpDeskSpec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.pemits.webcare.api.helpdesk.repository.spec; | ||
|
||
import com.pemits.webcare.api.helpdesk.entity.HelpDesk; | ||
import org.springframework.data.jpa.domain.Specification; | ||
|
||
import javax.persistence.criteria.CriteriaBuilder; | ||
import javax.persistence.criteria.CriteriaQuery; | ||
import javax.persistence.criteria.Predicate; | ||
import javax.persistence.criteria.Root; | ||
|
||
/** | ||
* @Author Mohammad Hussain | ||
* created on 7/14/2020 | ||
*/ | ||
public class HelpDeskSpec implements Specification<HelpDesk> { | ||
|
||
private static final String FILTER_BY_NAME = "name"; | ||
private static final String FILTER_BY_EMAIL = "email"; | ||
|
||
private final String property; | ||
private final String value; | ||
|
||
public HelpDeskSpec(String property, String value) { | ||
this.property = property; | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public Predicate toPredicate(Root<HelpDesk> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) { | ||
switch (property) { | ||
case FILTER_BY_NAME: | ||
return criteriaBuilder.like(root.get(FILTER_BY_NAME), "%"+value+"%"); | ||
case FILTER_BY_EMAIL: | ||
return criteriaBuilder.like(root.get(FILTER_BY_EMAIL), "$"+value+"%"); | ||
} | ||
return null; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...pi/src/main/java/com/pemits/webcare/api/helpdesk/repository/spec/HelpDeskSpecBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.pemits.webcare.api.helpdesk.repository.spec; | ||
|
||
import com.pemits.webcare.api.helpdesk.entity.HelpDesk; | ||
import com.pemits.webcare.core.repository.BaseSpecBuilder; | ||
import org.springframework.data.jpa.domain.Specification; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* @Author Mohammad Hussain | ||
* created on 7/14/2020 | ||
*/ | ||
public class HelpDeskSpecBuilder extends BaseSpecBuilder<HelpDesk> { | ||
|
||
public HelpDeskSpecBuilder(Map<String, String> params) { | ||
super(params); | ||
} | ||
|
||
@Override | ||
protected Specification<HelpDesk> getSpecification(String property, String filterValue) { | ||
return new HelpDeskSpec(property, filterValue); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
pemits-api/src/main/java/com/pemits/webcare/api/helpdesk/service/HelpDeskService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.pemits.webcare.api.helpdesk.service; | ||
|
||
import com.pemits.webcare.api.helpdesk.entity.HelpDesk; | ||
import com.pemits.webcare.core.service.BaseService; | ||
|
||
/** | ||
* @Author Mohammad Hussain | ||
* created on 7/14/2020 | ||
*/ | ||
public interface HelpDeskService extends BaseService<HelpDesk, Long> { | ||
} |
28 changes: 28 additions & 0 deletions
28
pemits-api/src/main/java/com/pemits/webcare/api/helpdesk/service/HelpDeskServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.pemits.webcare.api.helpdesk.service; | ||
|
||
import com.pemits.webcare.api.helpdesk.entity.HelpDesk; | ||
import com.pemits.webcare.api.helpdesk.repository.HelpDeskRepository; | ||
import com.pemits.webcare.api.helpdesk.repository.spec.HelpDeskSpecBuilder; | ||
import com.pemits.webcare.core.repository.BaseRepository; | ||
import com.pemits.webcare.core.repository.BaseSpecBuilder; | ||
import com.pemits.webcare.core.service.BaseServiceImpl; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* @Author Mohammad Hussain | ||
* created on 7/14/2020 | ||
*/ | ||
@Service | ||
public class HelpDeskServiceImpl extends BaseServiceImpl<HelpDesk, Long> implements HelpDeskService { | ||
|
||
public HelpDeskServiceImpl(HelpDeskRepository helpDeskRepository) { | ||
super(helpDeskRepository); | ||
} | ||
|
||
@Override | ||
protected BaseSpecBuilder<HelpDesk> getSpec(Map<String, String> filterParams) { | ||
return new HelpDeskSpecBuilder(filterParams); | ||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
...-api/src/test/java/com/pemits/webcare/api/helpdesk/repository/HelpDeskRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package com.pemits.webcare.api.helpdesk.repository; | ||
|
||
import com.github.springtestdbunit.annotation.DatabaseSetup; | ||
import com.pemits.webcare.BaseJpaTest; | ||
import com.pemits.webcare.api.department.entity.Department; | ||
import com.pemits.webcare.api.helpdesk.entity.HelpDesk; | ||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.hamcrest.Matchers.hasSize; | ||
|
||
/** | ||
* @Author Mohammad Hussain | ||
* created on 7/14/2020 | ||
*/ | ||
public class HelpDeskRepositoryTest extends BaseJpaTest { | ||
|
||
private static final long MOCK_HELP_DESK_ID_1 = 1; | ||
private static final long MOCK_HELP_DESK_ID_2 = 2; | ||
private static final long MOCK_HELP_DESK_ID_3 = 3; | ||
|
||
@Autowired | ||
private HelpDeskRepository helpDeskRepository; | ||
|
||
@Test | ||
public void testSaveShouldReturnSavedHelpDesk() { | ||
HelpDesk helpDesk = new HelpDesk(); | ||
helpDesk.setName("Smith"); | ||
helpDesk.setEmail("[email protected]"); | ||
helpDesk.setContactNumber("1234567890"); | ||
helpDesk.setQuery("My first query"); | ||
|
||
HelpDesk saved = helpDeskRepository.save(helpDesk); | ||
|
||
assertThat(saved.getId(), notNullValue()); | ||
} | ||
|
||
@Test | ||
public void testSaveAllShouldReturnAllSavedHelpDesk() { | ||
HelpDesk helpDesk1 = new HelpDesk(); | ||
helpDesk1.setName("Smith"); | ||
helpDesk1.setEmail("[email protected]"); | ||
helpDesk1.setContactNumber("1234567890"); | ||
helpDesk1.setQuery("My first query"); | ||
|
||
HelpDesk helpDesk2 = new HelpDesk(); | ||
helpDesk2.setName("John"); | ||
helpDesk2.setEmail("[email protected]"); | ||
helpDesk2.setContactNumber("1234567890"); | ||
helpDesk2.setQuery("My second query"); | ||
|
||
List<HelpDesk> saved = helpDeskRepository.saveAll(Arrays.asList(helpDesk1, helpDesk2)); | ||
|
||
assertThat(saved, hasSize(2)); | ||
assertThat(saved.get(0).getId(), notNullValue()); | ||
assertThat(saved.get(1).getId(), notNullValue()); | ||
} | ||
|
||
|
||
@Test | ||
@DatabaseSetup("/dataset/helpdesk/helpdesk-config.xml") | ||
public void testFindHelpDeskByIdShouldReturnHelpDesk() { | ||
final Optional<HelpDesk> helpDesk = helpDeskRepository.findById(MOCK_HELP_DESK_ID_1); | ||
|
||
assertThat(helpDesk.isPresent(), equalTo(true)); | ||
assertThat(helpDesk.get().getName(), is("Smith")); | ||
} | ||
|
||
@Test | ||
@DatabaseSetup("/dataset/helpdesk/helpdesk-config.xml") | ||
public void testFindAllShouldReturnNotEmptyList() { | ||
final List<HelpDesk> helpDeskList = helpDeskRepository.findAll(); | ||
|
||
assertThat(helpDeskList.size(), greaterThan(0)); | ||
} | ||
|
||
@Test | ||
@DatabaseSetup("/dataset/helpdesk/helpdesk-config.xml") | ||
public void testGetOneShouldReturnHelpDesk() { | ||
final HelpDesk helpDesk = helpDeskRepository.getOne(MOCK_HELP_DESK_ID_2); | ||
|
||
assertThat(helpDesk.getName(), is("Jack")); | ||
} | ||
|
||
@Test | ||
@DatabaseSetup("/dataset/helpdesk/helpdesk-config.xml") | ||
public void testDeleteByIdShouldDeleteHelpDesk() { | ||
long count = helpDeskRepository.count(); | ||
|
||
helpDeskRepository.deleteById(MOCK_HELP_DESK_ID_3); | ||
|
||
assertThat(helpDeskRepository.findAll(), hasSize((int) count - 1)); | ||
} | ||
|
||
@Test | ||
@DatabaseSetup("/dataset/helpdesk/helpdesk-config.xml") | ||
public void testDeleteShouldDeleteHelpDesk() { | ||
long count = helpDeskRepository.count(); | ||
|
||
final HelpDesk helpDesk = helpDeskRepository.getOne(MOCK_HELP_DESK_ID_2); | ||
helpDeskRepository.delete(helpDesk); | ||
|
||
assertThat(helpDeskRepository.findAll(), hasSize((int) count - 1)); | ||
} | ||
|
||
@Test | ||
@DatabaseSetup("/dataset/helpdesk/helpdesk-config.xml") | ||
public void testDeleteAllShouldReturnCountZero() { | ||
helpDeskRepository.deleteAll(); | ||
|
||
assertThat(helpDeskRepository.findAll(), hasSize(0)); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
pemits-api/src/test/resources/dataset/helpdesk/helpdesk-config.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<dataset> | ||
<help_desk | ||
id="1" | ||
created_at="2020-07-14 15:30:00" | ||
last_modified_at="2020-07-14 15:30:00" | ||
version="0" | ||
name="Smith" | ||
contact_number="1234567890" | ||
email="[email protected]" | ||
query="My first query" | ||
/> | ||
<help_desk | ||
id="2" | ||
created_at="2020-07-14 15:30:00" | ||
last_modified_at="2020-07-14 15:30:00" | ||
version="0" | ||
name="Jack" | ||
contact_number="9876543210" | ||
email="[email protected]" | ||
query="My second query" | ||
/> | ||
<help_desk | ||
id="3" | ||
created_at="2020-07-14 15:30:00" | ||
last_modified_at="2020-07-14 15:30:00" | ||
version="0" | ||
name="John" | ||
contact_number="1234567890" | ||
email="[email protected]" | ||
query="My third query" | ||
/> | ||
</dataset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
pemits-web/src/main/java/com/pemits/webcare/web/helpdesk/HelpDeskController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.pemits.webcare.web.helpdesk; | ||
|
||
import com.pemits.webcare.api.helpdesk.entity.HelpDesk; | ||
import com.pemits.webcare.api.helpdesk.service.HelpDeskService; | ||
import com.pemits.webcare.core.controller.BaseController; | ||
import com.pemits.webcare.core.service.BaseService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import static com.pemits.webcare.web.helpdesk.HelpDeskController.URL; | ||
|
||
/** | ||
* @Author Mohammad Hussain | ||
* created on 7/14/2020 | ||
*/ | ||
@RestController | ||
@RequestMapping(URL) | ||
@Slf4j | ||
public class HelpDeskController extends BaseController<HelpDesk, Long> { | ||
static final String URL = "/v1/helpdesk"; | ||
|
||
protected HelpDeskController(HelpDeskService helpDeskService) { | ||
super(helpDeskService, log.getClass()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters