From e09e9d197db5d2a664e13852e72b3daa42be0497 Mon Sep 17 00:00:00 2001 From: mherman22 Date: Tue, 19 Nov 2024 17:16:03 +0300 Subject: [PATCH] fix test --- .../BaseWebContextSensitiveTest.java | 2 +- .../DictionaryMenuRestControllerTest.java | 31 +++++-------------- 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/test/java/org/openelisglobal/BaseWebContextSensitiveTest.java b/src/test/java/org/openelisglobal/BaseWebContextSensitiveTest.java index 8516c80775..dae952e56b 100644 --- a/src/test/java/org/openelisglobal/BaseWebContextSensitiveTest.java +++ b/src/test/java/org/openelisglobal/BaseWebContextSensitiveTest.java @@ -56,7 +56,7 @@ protected BaseWebContextSensitiveTest(List tablesToRestore) { this.tablesToRestore = tablesToRestore != null ? tablesToRestore : new ArrayList<>(); } - protected void setUp() { + protected void setUp() throws Exception { mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext).build(); } diff --git a/src/test/java/org/openelisglobal/dictionary/rest/controller/DictionaryMenuRestControllerTest.java b/src/test/java/org/openelisglobal/dictionary/rest/controller/DictionaryMenuRestControllerTest.java index 27b0cf13fe..8380924e19 100644 --- a/src/test/java/org/openelisglobal/dictionary/rest/controller/DictionaryMenuRestControllerTest.java +++ b/src/test/java/org/openelisglobal/dictionary/rest/controller/DictionaryMenuRestControllerTest.java @@ -20,8 +20,10 @@ import org.openelisglobal.dictionarycategory.valueholder.DictionaryCategory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; +import org.springframework.test.annotation.Rollback; import org.springframework.test.web.servlet.MvcResult; +@Rollback public class DictionaryMenuRestControllerTest extends BaseWebContextSensitiveTest { @Autowired @@ -32,8 +34,9 @@ public class DictionaryMenuRestControllerTest extends BaseWebContextSensitiveTes @Before @Override - public void setUp() { + public void setUp() throws Exception { super.setUp(); + executeDataSetWithStateManagement("testdata/dictionary.xml"); } @Test @@ -47,9 +50,9 @@ public void getDictionaryMenuList_shouldReturnDictionaryMenu() throws Exception List menuList = Arrays.asList(super.mapFromJson(content, DictionaryMenuForm[].class)); assertThat(menuList.get(0).getMenuList().get(0).getId(), is("1")); assertThat(menuList.get(0).getMenuList().get(0).getIsActive(), is("Y")); - assertThat(menuList.get(0).getMenuList().get(0).getDictEntry(), is("INFLUENZA VIRUS A RNA DETECTED")); - assertThat(menuList.get(0).getMenuList().get(0).getSortOrder(), is(100)); - assertThat(menuList.get(0).getMenuList().get(0).getDictionaryCategory().getCategoryName(), is("CG")); + assertThat(menuList.get(0).getMenuList().get(0).getDictEntry(), is("Dictionary Entry 1")); + assertThat(menuList.get(0).getMenuList().get(0).getSortOrder(), is(1)); + assertThat(menuList.get(0).getMenuList().get(0).getDictionaryCategory().getCategoryName(), is("Category Name 1")); } @Test @@ -64,26 +67,6 @@ public void fetchDictionaryCategories_shouldFetchDictionaryDescriptions() throws assertThat(menuList, notNullValue()); } - // TODO: To be looked into later - - // @Test - // public void createDictionary_shouldSuccessfullyCreateDictionary() throws - // Exception { - // Dictionary dictionary = createDictionaryObject(); - // String toJson = super.mapToJson(dictionary); - // - // MvcResult mvcResult = super.mockMvc.perform( - // post("/rest/dictionary") - // .accept(MediaType.APPLICATION_JSON_VALUE) - // .contentType(MediaType.APPLICATION_JSON_VALUE) - // .content(toJson)).andReturn(); - // - // int status = mvcResult.getResponse().getStatus(); - // assertEquals(201, status); - // String content = mvcResult.getResponse().getContentAsString(); - // assertEquals(content, "Dictionary created successfully"); - // } - @Test public void showDeleteDictionary_shouldSuccessfullyDeleteDictionary() throws Exception { MvcResult getMenu = super.mockMvc.perform(get("/rest/DictionaryMenu").accept(MediaType.APPLICATION_JSON_VALUE)