这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions omod/pom.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@
<artifactId>openmrs-test</artifactId>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
</exclusion>
<exclusion>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- End OpenMRS core -->
Expand Down
17 changes: 9 additions & 8 deletions omod/src/test/java/org/openmrs/web/controller/maintenance/SearchIndexControllerTest.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.doThrow;

/**
* Tests the {@link SearchIndexController} controller
Expand Down Expand Up @@ -74,7 +75,7 @@ public void rebuildSearchIndex_shouldReturnTrueForSuccessIfTheUpdateDoesNotFail(
when(userContext.isAuthenticated()).thenReturn(true);
assertTrue(Context.getUserContext().isAuthenticated());

Mockito.when(contextDao.updateSearchIndexAsync()).thenReturn(null);
when(contextDao.updateSearchIndexAsync()).thenReturn(null);
Map<String, Object> response = controller.rebuildSearchIndex();
assertEquals(true, response.get("success"));
}
Expand All @@ -89,7 +90,7 @@ public void rebuildSearchIndex_shouldReturnFalseForSuccessIfARuntimeExceptionIsT
when(userContext.isAuthenticated()).thenReturn(true);
assertTrue(Context.getUserContext().isAuthenticated());

Mockito.doThrow(new RuntimeException("boom")).when(contextDao).updateSearchIndexAsync();
doThrow(new RuntimeException("boom")).when(contextDao).updateSearchIndexAsync();
Map<String, Object> response = controller.rebuildSearchIndex();
assertEquals(false, response.get("success"));
}
Expand All @@ -104,7 +105,7 @@ public void rebuildSearchIndex_shouldReturnFalseForSuccessIfAUnAuthenticatedUser
when(userContext.isAuthenticated()).thenReturn(false);
assertFalse(Context.getUserContext().isAuthenticated());

Mockito.when(contextDao.updateSearchIndexAsync()).thenReturn(null);
when(contextDao.updateSearchIndexAsync()).thenReturn(null);
Map<String, Object> response = controller.rebuildSearchIndex();
assertEquals(false, response.get("success"));
}
Expand All @@ -115,7 +116,7 @@ public void rebuildSearchIndex_shouldReturnFalseForSuccessIfAUnAuthenticatedUser
*/
@Test
public void getStatus_shouldReturnInProgressForStatusIfRebuildSearchIndexIsInProgress() throws Exception {
Mockito.when(contextDao.updateSearchIndexAsync()).thenAnswer((Answer<Future>) invocationOnMock -> {
when(contextDao.updateSearchIndexAsync()).thenAnswer((Answer<Future>) invocationOnMock -> {
Future<String> future = mock(FutureTask.class);
when(future.isDone()).thenReturn(false);
return future;
Expand All @@ -131,7 +132,7 @@ public void getStatus_shouldReturnInProgressForStatusIfRebuildSearchIndexIsInPro
*/
@Test
public void getStatus_shouldReturnSuccessForStatusIfRebuildSearchIndexIsCompletedSuccessfully() throws Exception {
Mockito.when(contextDao.updateSearchIndexAsync()).thenAnswer((Answer<Future>) invocationOnMock -> {
when(contextDao.updateSearchIndexAsync()).thenAnswer((Answer<Future>) invocationOnMock -> {
Future<String> future = mock(FutureTask.class);
when(future.isDone()).thenReturn(true);
when(future.isCancelled()).thenReturn(false);
Expand All @@ -148,7 +149,7 @@ public void getStatus_shouldReturnSuccessForStatusIfRebuildSearchIndexIsComplete
*/
@Test
public void getStatus_shouldReturnErrorForStatusIfRebuildSearchIndexIsCompletedUnsuccessfully() throws Exception {
Mockito.when(contextDao.updateSearchIndexAsync()).thenAnswer((Answer<Future>) invocationOnMock -> {
when(contextDao.updateSearchIndexAsync()).thenAnswer((Answer<Future>) invocationOnMock -> {
Future<String> future = mock(FutureTask.class);
when(future.isDone()).thenReturn(true);
when(future.isCancelled()).thenReturn(true);
Expand Down
Loading