-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add assertions tests #1411
Merged
Merged
add assertions tests #1411
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6c76b57
add assertions tests
Robert-Costello 19a982c
verify specific error message
Robert-Costello cd051b4
simplify navigate func
Robert-Costello 412016f
add restore with project_role property
Robert-Costello 96daf64
update test suite
Robert-Costello b51c7f6
fix failing test
Robert-Costello e9bcb3a
add test for alternate restore
Robert-Costello 0a4e9aa
update test
Robert-Costello 753b705
Merge branch 'master' into rc/test-assertions-nav
Robert-Costello 0663863
remove unneeded elements
Robert-Costello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
92 changes: 92 additions & 0 deletions
92
src/test/java/org/commcare/formplayer/tests/MenuAssertionsAlternateRestoreTest.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,92 @@ | ||
package org.commcare.formplayer.tests; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.commcare.formplayer.application.MenuController; | ||
import org.commcare.formplayer.beans.menus.BaseResponseBean; | ||
import org.commcare.formplayer.beans.menus.CommandListResponseBean; | ||
import org.commcare.formplayer.configuration.CacheConfiguration; | ||
import org.commcare.formplayer.junit.InitializeStaticsExtension; | ||
import org.commcare.formplayer.junit.Installer; | ||
import org.commcare.formplayer.junit.RestoreFactoryExtension; | ||
import org.commcare.formplayer.junit.StorageFactoryExtension; | ||
import org.commcare.formplayer.junit.request.Response; | ||
import org.commcare.formplayer.junit.request.SessionNavigationRequest; | ||
import org.commcare.formplayer.services.RestoreFactory; | ||
import org.commcare.formplayer.utils.MockRequestUtils; | ||
import org.commcare.formplayer.utils.TestContext; | ||
import org.commcare.formplayer.web.client.WebClient; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
@WebMvcTest | ||
@Import({MenuController.class}) | ||
@ContextConfiguration(classes = {TestContext.class, CacheConfiguration.class}) | ||
@ExtendWith(InitializeStaticsExtension.class) | ||
public class MenuAssertionsAlternateRestoreTest { | ||
|
||
private static final String ASSERTIONS_APP = "basic"; | ||
@Autowired | ||
protected WebClient webClientMock; | ||
|
||
@Autowired | ||
RestoreFactory restoreFactoryMock; | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
private MockRequestUtils mockRequest; | ||
|
||
@RegisterExtension | ||
static RestoreFactoryExtension restoreFactoryExt = new RestoreFactoryExtension.builder() | ||
.withUser("user").withDomain("domain") | ||
.withRestorePath("restores/project_role_admin.xml") | ||
.build(); | ||
|
||
@RegisterExtension | ||
static StorageFactoryExtension storageExt = new StorageFactoryExtension.builder() | ||
.withUser("user").withDomain("domain").build(); | ||
|
||
@BeforeEach | ||
public void setUp() throws Exception { | ||
mockRequest = new MockRequestUtils(webClientMock, restoreFactoryMock); | ||
} | ||
|
||
|
||
@Test | ||
public void testMenuAssertions() { | ||
// Check passing assertion for project_role user property set | ||
Response<CommandListResponseBean> response1 = navigate(new String[]{"0"}, | ||
CommandListResponseBean.class); | ||
assertNotNull(response1); | ||
|
||
// Check failing assertion for menu exclusively for admins, project_role=admin | ||
try { | ||
navigate(new String[]{"18"}, | ||
CommandListResponseBean.class); | ||
} catch (Exception e) { | ||
System.out.println("error message: " + e.getMessage()); | ||
assertTrue(e.getMessage().contains("This menu is for admins only.")); | ||
} | ||
} | ||
|
||
|
||
private <T extends BaseResponseBean> Response<T> navigate( | ||
String[] selections, Class<T> responseClass) { | ||
String installReference = Installer.getInstallReference(ASSERTIONS_APP); | ||
SessionNavigationRequest<T> request = new SessionNavigationRequest<>( | ||
mockMvc, responseClass, installReference); | ||
return request.request(selections); | ||
} | ||
} | ||
|
||
|
98 changes: 98 additions & 0 deletions
98
src/test/java/org/commcare/formplayer/tests/MenuAssertionsTest.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,98 @@ | ||
package org.commcare.formplayer.tests; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.commcare.formplayer.application.MenuController; | ||
import org.commcare.formplayer.beans.SessionNavigationBean; | ||
import org.commcare.formplayer.beans.menus.BaseResponseBean; | ||
import org.commcare.formplayer.beans.menus.CommandListResponseBean; | ||
import org.commcare.formplayer.beans.menus.EntityBean; | ||
import org.commcare.formplayer.beans.menus.EntityListResponse; | ||
import org.commcare.formplayer.configuration.CacheConfiguration; | ||
import org.commcare.formplayer.junit.InitializeStaticsExtension; | ||
import org.commcare.formplayer.junit.Installer; | ||
import org.commcare.formplayer.junit.RestoreFactoryExtension; | ||
import org.commcare.formplayer.junit.StorageFactoryExtension; | ||
import org.commcare.formplayer.junit.request.Response; | ||
import org.commcare.formplayer.junit.request.SessionNavigationRequest; | ||
import org.commcare.formplayer.services.RestoreFactory; | ||
import org.commcare.formplayer.utils.MockRequestUtils; | ||
import org.commcare.formplayer.utils.TestContext; | ||
import org.commcare.formplayer.web.client.WebClient; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
@WebMvcTest | ||
@Import({MenuController.class}) | ||
@ContextConfiguration(classes = {TestContext.class, CacheConfiguration.class}) | ||
@ExtendWith(InitializeStaticsExtension.class) | ||
public class MenuAssertionsTest { | ||
|
||
private static final String ASSERTIONS_APP = "basic"; | ||
@Autowired | ||
protected WebClient webClientMock; | ||
|
||
@Autowired | ||
RestoreFactory restoreFactoryMock; | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
private MockRequestUtils mockRequest; | ||
|
||
@RegisterExtension | ||
static RestoreFactoryExtension restoreFactoryExt = new RestoreFactoryExtension.builder() | ||
.withUser("user").withDomain("domain") | ||
.withRestorePath("restores/basic.xml") | ||
.build(); | ||
|
||
@RegisterExtension | ||
static StorageFactoryExtension storageExt = new StorageFactoryExtension.builder() | ||
.withUser("user").withDomain("domain").build(); | ||
|
||
@BeforeEach | ||
public void setUp() throws Exception { | ||
mockRequest = new MockRequestUtils(webClientMock, restoreFactoryMock); | ||
} | ||
|
||
|
||
@Test | ||
public void testMenuAssertionsFailures() { | ||
// Check assertion failing for project_role user property | ||
try { | ||
assertThrows(Exception.class, ()->{ | ||
navigate(new String[]{"0"}, | ||
CommandListResponseBean.class); | ||
}); | ||
} catch (Exception e) { | ||
assertTrue(e.getMessage().contains("User must have a project role configured.")); | ||
} | ||
// Check assertion failing for fixture | ||
try { | ||
Response<CommandListResponseBean> response1 = navigate(new String[]{"1"}, | ||
CommandListResponseBean.class); | ||
} catch (Exception e) { | ||
assertTrue(e.getMessage().contains("This user must be in exactly one case sharing group.")); | ||
} | ||
} | ||
|
||
|
||
private <T extends BaseResponseBean> Response<T> navigate( | ||
String[] selections, Class<T> responseClass) { | ||
String installReference = Installer.getInstallReference(ASSERTIONS_APP); | ||
SessionNavigationRequest<T> request = new SessionNavigationRequest<>( | ||
mockMvc, responseClass, installReference); | ||
return request.request(selections); | ||
} | ||
} | ||
|
Binary file not shown.
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 @@ | ||
<OpenRosaResponse xmlns="http://openrosa.org/http/response"> | ||
<message nature="ota_restore_success">Successfully restored account vl1!</message> | ||
<Sync xmlns="http://commcarehq.org/sync"> | ||
<restore_id>9f7c4e0a3a8ca4e2ecf54444fb7e70cf</restore_id> | ||
</Sync> | ||
<Registration xmlns="http://openrosa.org/user/registration"> | ||
<username>vl1</username> | ||
<password>sha1$KOXD0OGyqKTP$139e6226da49dd500336dcd189b519da06aeb087</password> | ||
<uuid>7afceb0259b2866be17b3632392f8a4b</uuid> | ||
<date>2014-12-30</date> | ||
<user_data> | ||
<data key="commcare_project">ccqa</data> | ||
<data key="commcare_last_name" /> | ||
<data key="commcare_phone_number" /> | ||
<data key="commcare_first_name" /> | ||
<data key="project_role">basic_user</data> | ||
</user_data>b | ||
</Registration> | ||
<fixture id="user-groups" user_id="7afceb0259b2866be17b3632392f8a4b"> | ||
<groups> | ||
<group id="06545890ff6536cf29136510f265cc7e"> | ||
<name>Test Case Sharing 2</name> | ||
</group> | ||
</groups> | ||
</fixture> | ||
</OpenRosaResponse> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we trim the file to only contain what's necessary for the test. I believe you should be able to remove most of the info in this file for the assertion test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. Yes, I'll trim it down.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
restore updated here 0663863