forked from OpenLMIS/openlmis-stockmanagement
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OLMIS-7953 Copied solution with multiple program ids to make applicat…
…ion logging performance better. (OpenLMIS#61) * Cherry-pick (modified) from OAM-218 solution, commit 8b82790. OAM-218: Updated programId param to repeatable (OpenLMIS#60) * OAM-218: WIP * OAM-218: Updated programId param to repeatable * OAM-218: Removed unused import, provided constants * OAM-218: Removed unnecessary stubbings * OAM-218: Added extra tests * OAM-218: Provided changes after review * OAM-218: Removed 'Ignore' annotation * OAM-218: Added extra condition to test * OAM-218: Fixed params/method names * OAM-218: Added tests for coverage. --------- Co-authored-by: Piotr Wargulak <[email protected]> Co-authored-by: tsznaj <[email protected]> # Conflicts: # src/integration-test/java/org/openlmis/stockmanagement/web/ValidSourceDestinationControllerIntegrationTest.java # src/main/java/org/openlmis/stockmanagement/repository/SourceDestinationAssignmentRepository.java # src/main/java/org/openlmis/stockmanagement/service/SourceDestinationBaseService.java # src/main/java/org/openlmis/stockmanagement/service/StockCardSummariesService.java # src/main/java/org/openlmis/stockmanagement/service/ValidDestinationService.java # src/main/java/org/openlmis/stockmanagement/service/ValidSourceService.java # src/main/java/org/openlmis/stockmanagement/validators/SourceDestinationGeoLevelAffinityValidator.java # src/main/java/org/openlmis/stockmanagement/web/ValidSourceDestinationController.java # src/test/java/org/openlmis/stockmanagement/service/SourceDestinationBaseServiceTest.java # src/test/java/org/openlmis/stockmanagement/validators/SourceDestinationGeoLevelAffinityValidatorTest.java * OLMIS-7953: coverage test * OLMIS-7953: moved to impl subdirectories * OLMIS-7953: little changes to omit unnecessary coverage tests * OLMIS-7953: added coverage test --------- Co-authored-by: Szymon Radziszewski <[email protected]>
- Loading branch information
Showing
10 changed files
with
197 additions
and
32 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
141 changes: 141 additions & 0 deletions
141
...nlmis/stockmanagement/repository/custom/impl/ValidReasonAssignmentRepositoryImplTest.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,141 @@ | ||
/* | ||
* This program is part of the OpenLMIS logistics management information system platform software. | ||
* Copyright © 2017 VillageReach | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms | ||
* of the GNU Affero General Public License as published by the Free Software Foundation, either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Affero General Public License for more details. You should have received a copy of | ||
* the GNU Affero General Public License along with this program. If not, see | ||
* http://www.gnu.org/licenses. For additional information contact [email protected]. | ||
*/ | ||
|
||
package org.openlmis.stockmanagement.repository.custom.impl; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
import static org.openlmis.stockmanagement.repository.custom.impl.ValidReasonAssignmentRepositoryImpl.FACILITY_TYPE_ID; | ||
import static org.openlmis.stockmanagement.repository.custom.impl.ValidReasonAssignmentRepositoryImpl.PROGRAM_ID; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.TypedQuery; | ||
import javax.persistence.criteria.CriteriaBuilder; | ||
import javax.persistence.criteria.CriteriaQuery; | ||
import javax.persistence.criteria.Path; | ||
import javax.persistence.criteria.Predicate; | ||
import javax.persistence.criteria.Root; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ValidReasonAssignmentRepositoryImplTest { | ||
|
||
@InjectMocks | ||
private ValidReasonAssignmentRepositoryImpl repository; | ||
|
||
@Mock | ||
private EntityManager entityManager; | ||
|
||
@Test | ||
public void shouldSearchForProgramIdsOnly() { | ||
//given | ||
UUID programId1 = UUID.randomUUID(); | ||
UUID programId2 = UUID.randomUUID(); | ||
Collection<UUID> programIds = new ArrayList<>(); | ||
programIds.add(programId1); | ||
programIds.add(programId2); | ||
|
||
List<ValidReasonAssignment> validReasonAssignmentList = mock(List.class); | ||
TypedQuery typedQuery = mock(TypedQuery.class); | ||
when(typedQuery.getResultList()) | ||
.thenReturn(validReasonAssignmentList); | ||
|
||
CriteriaQuery query = mock(CriteriaQuery.class); | ||
Predicate conjunctionPredicate = mock(Predicate.class); | ||
|
||
Predicate inPredicate = mock(Predicate.class); | ||
Path programIdPath = mock(Path.class); | ||
when(programIdPath.in(programIds)).thenReturn(inPredicate); | ||
|
||
Root root = mock(Root.class); | ||
when(root.get(PROGRAM_ID)).thenReturn(programIdPath); | ||
Predicate wherePredicate = mock(Predicate.class); | ||
|
||
CriteriaBuilder criteriaBuilder = mock(CriteriaBuilder.class); | ||
when(criteriaBuilder.createQuery(ValidReasonAssignment.class)) | ||
.thenReturn(query); | ||
when(criteriaBuilder.conjunction()).thenReturn(conjunctionPredicate); | ||
when(criteriaBuilder.and(conjunctionPredicate, inPredicate)).thenReturn(wherePredicate); | ||
|
||
when(query.from(ValidReasonAssignment.class)).thenReturn(root); | ||
|
||
when(entityManager.getCriteriaBuilder()).thenReturn(criteriaBuilder); | ||
when(entityManager.createQuery(query)) | ||
.thenReturn(typedQuery); | ||
|
||
//when | ||
List<ValidReasonAssignment> searchResults = | ||
repository.search(programIds, null, null, null); | ||
|
||
//then | ||
verify(entityManager).createQuery(query); | ||
verify(query).where(wherePredicate); | ||
assertThat(searchResults).isEqualTo(validReasonAssignmentList); | ||
} | ||
|
||
@Test | ||
public void shouldSearchForFacilityTypeIdOnly() { | ||
//given | ||
UUID facilityTypeId = UUID.randomUUID(); | ||
|
||
List<ValidReasonAssignment> validReasonAssignmentList = mock(List.class); | ||
TypedQuery typedQuery = mock(TypedQuery.class); | ||
when(typedQuery.getResultList()) | ||
.thenReturn(validReasonAssignmentList); | ||
|
||
CriteriaQuery query = mock(CriteriaQuery.class); | ||
Predicate conjunctionPredicate = mock(Predicate.class); | ||
|
||
Predicate equalPredicate = mock(Predicate.class); | ||
Path facilityTypeIdPath = mock(Path.class); | ||
|
||
Root root = mock(Root.class); | ||
when(root.get(FACILITY_TYPE_ID)).thenReturn(facilityTypeIdPath); | ||
Predicate wherePredicate = mock(Predicate.class); | ||
|
||
CriteriaBuilder criteriaBuilder = mock(CriteriaBuilder.class); | ||
when(criteriaBuilder.createQuery(ValidReasonAssignment.class)) | ||
.thenReturn(query); | ||
when(criteriaBuilder.conjunction()).thenReturn(conjunctionPredicate); | ||
when(criteriaBuilder.equal(facilityTypeIdPath, facilityTypeId)).thenReturn(equalPredicate); | ||
when(criteriaBuilder.and(conjunctionPredicate, equalPredicate)).thenReturn(wherePredicate); | ||
|
||
when(query.from(ValidReasonAssignment.class)).thenReturn(root); | ||
|
||
when(entityManager.getCriteriaBuilder()).thenReturn(criteriaBuilder); | ||
when(entityManager.createQuery(query)) | ||
.thenReturn(typedQuery); | ||
|
||
//when | ||
List<ValidReasonAssignment> searchResults = | ||
repository.search(null, facilityTypeId, null, null); | ||
|
||
//then | ||
verify(entityManager).createQuery(query); | ||
verify(query).where(wherePredicate); | ||
assertThat(searchResults).isEqualTo(validReasonAssignmentList); | ||
} | ||
} |
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