Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
1 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
package gov.va.med.ewv.integration;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
//import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import gov.va.med.ars.configuration.AppConfig;
import gov.va.med.ars.configuration.spring.SpringMvcConfig;
import gov.va.med.ewv.bean.ArchiveFileRequest;
import gov.va.med.ewv.bean.ArchivedPdfReference;
import gov.va.med.ewv.bean.FileUploadRequest;
/**
* These are several JUNit Test Cases that use Spring MockMvc Framework to test the following
* RESTFul Web Services serviced by the EwvClaimController Java class:
* 1) /api/v1/ewvClaim/{pdiNumber}
* 2) /api/v1/pdfReference/getAllPdfReferences
* 3) /api/v1/fileupload
* 4) /api/v1/filearchive
*
* Use this class to test the code for the above mentioned RESTFul Web Services. You selectively
* run one or more of the JUnit Test cases by selectively commenting out the @Ignore annotation(s).
* Testing the business login code using this class eliminates the need to run a full-blown
* Tomcat Web Server to test the code.
*
* @author
DNS
*
*/
@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { AppConfig.class, SpringMvcConfig.class })
@TestPropertySource(properties = {"arsPropFileLocation = ./src/test/resources/development.properties"})
public class EwvClaimControllerIntegrationTest {
private static final Logger logger = LogManager.getLogger(EwvClaimControllerIntegrationTest.class);
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
@Before
public void setup() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
}
/**
* Tests for getting an EWV Dental Claim from the EWV Database using MockMvc Framework call to
* the "/api/v1/ewvClaim/{pdiNumber}" RESTFul Web Service.
*
* @throws Exception - if some error occurs
*/
@Test
@Ignore
public void getDetailDental_success() throws Exception {
//Dental - 200617203000952
//INST - 200617203000959
//Prof - 200617203000825
ResultActions s = mockMvc.perform(get("/api/v1/ewvClaim/{pdiNumber}", "200617203000952")).andDo(print())
.andExpect(status().isOk()).andExpect(content().contentType("application/json;charset=UTF-8"));
logger.info("testGetClaims_Success:" + s.andReturn().getResponse().getStatus());
assertFalse(HttpStatus.OK.value() != s.andReturn().getResponse().getStatus());
}
/**
* Tests for getting an EWV Institutional Claim from an EWV Database using Spring MockMvc Framework call to
* the "/api/v1/ewvClaim/{pdiNumber}" RESTFul Web Service.
*
* @throws Exception - if some error occurs
*/
@Test
@Ignore
public void getiDetailInst_success() throws Exception {
//INST 100000000001399 - test for drug line info
ResultActions s = mockMvc.perform(get("/api/v1/ewvClaim/{pdiNumber}", "201722991001691")).andDo(print())
.andExpect(status().isOk()).andExpect(content().contentType("application/json;charset=UTF-8"));
logger.info("testGetClaims_Success:" + s.andReturn().getResponse().getStatus());
assertFalse(HttpStatus.OK.value() != s.andReturn().getResponse().getStatus());
}
@Test
@Ignore
public void getClaim_Dme_success() throws Exception {
//INST 100000000001399 - test for drug line info
ResultActions s = mockMvc.perform(get("/api/v1/ewvClaim/{pdiNumber}", "200617203000952")).andDo(print())
.andExpect(status().isOk()).andExpect(content().contentType("application/json;charset=UTF-8"));
logger.info("testGetClaims_Success:" + s.andReturn().getResponse().getStatus());
assertFalse(HttpStatus.OK.value() != s.andReturn().getResponse().getStatus());
}
/**
* Tests for an EWV Professional Claim from the EWV Database using Spring MockMvc Framework call to
* the "/api/v1/ewvClaim/{pdiNumber}" RESTFul Web Service.
*
* @throws Exception - if some error occurs
*/
@Test
@Ignore
public void getiDetailProf_success() throws Exception {
ResultActions s = mockMvc.perform(get("/api/v1/ewvClaim/{pdiNumber}", "200617203000606")).andDo(print())
.andExpect(status().isOk()).andExpect(content().contentType("application/json;charset=UTF-8"));
logger.info("testGetClaims_Success:" + s.andReturn().getResponse().getStatus());
assertFalse(HttpStatus.OK.value() != s.andReturn().getResponse().getStatus());
}
/**
* User Story 01.11.24: The EWV system will be able to display a POS at the claim level and at the line level.
* If no line level POS?s are received the system will display the POS at the claim level only. If a line level
* POS is received then the POS will be displayed at the line level for only that line and display the POS at
* the claim level for the remainder of the claim. (BN 2.10) Professional Claims
*
* Acceptance Criteria: Verify The EWV system displays a POS at the claim level and at the line level.
* If no line level POS?s are received the system will display the POS at the claim level only. If a line
* level POS is received then the POS will be displayed at the line level for only that line and display
* the POS at the claim level for the remainder of the claim.
*
* Tests for a Professional Claim that has some Service Lines with POS and some that do not.
* Just visually inspect JSON Response to see that that's the response. Tests using Spring MockMvc Framework
* call to the "/api/v1/ewvClaim/{pdiNumber}" RESTFul Web Service.
*
* @throws Exception - if some error occurs
*/
@Test
@Ignore
public void getDetailProf_pos_success() throws Exception {
ResultActions s = mockMvc.perform(get("/api/v1/ewvClaim/{pdiNumber}", "100000000001800")).andDo(print())
.andExpect(status().isOk()).andExpect(content().contentType("application/json;charset=UTF-8"));
logger.info("testGetClaims_Success:" + s.andReturn().getResponse().getStatus());
assertFalse(HttpStatus.OK.value() != s.andReturn().getResponse().getStatus());
}
/**
* Tests for attempting to obtain an EWV Claim that does not exist in the EWV Database using Spring MockMvc
* Framework call to the "/api/v1/ewvClaim/{pdiNumber}" RESTFul Web Service.
*
* @throws Exception - if an error occurs
*/
@Test
@Ignore
public void getDetail_fail() throws Exception {
ResultActions s = mockMvc.perform(get("/api/v1/ewvClaim/{pdiNumber}", "123")).andDo(print())
.andExpect(content().contentType("application/json;charset=UTF-8"));
logger.info("getDetail_fail:" + s.andReturn().getResponse().getStatus());
}
/**
* Tests for getting all the PDG References in the EWV Database using Spring MockMvc Framework call to
* the "/api/v1/pdfReference/getAllPdfReferences" RESTFul Web Service.
*
* @throws Exception - if an error occurs
*/
@Test
@Ignore
public void getAllPdfReferences_success() throws Exception {
ResultActions s = mockMvc.perform(get("/api/v1/pdfReference/getAllPdfReferences")).andDo(print())
.andExpect(status().isOk()).andExpect(content().contentType("application/json;charset=UTF-8"));
logger.info("test getAllPdfReferences_success: " + s.andReturn().getResponse().getStatus());
assertTrue(HttpStatus.OK.value() == s.andReturn().getResponse().getStatus());
}
/**
* Tests the successful Uploading of one file using Spring MockMvc Framework call to the
* "/api/v1/fileupload" RESTFul Web Service.
*
* @throws Exception - if an error occurs
*/
@Test
@Ignore
public void fileupload_oneFile_success() throws Exception {
FileUploadRequest fileUploadRequest = new FileUploadRequest();
MockMultipartFile file = new MockMultipartFile("file" + System.currentTimeMillis(), "hello" + System.currentTimeMillis() + ".txt",
MediaType.TEXT_PLAIN_VALUE, "Hello, World!".getBytes());
List<MultipartFile> multipartFilesList = new ArrayList<MultipartFile>();
multipartFilesList.add(file);
fileUploadRequest.setMultipartFiles(multipartFilesList);
ResultActions s = mockMvc.perform( post("/api/v1/fileupload").contentType("multipart/form-data;boundary=" + System.currentTimeMillis())
.flashAttr("fileUploadRequest", fileUploadRequest)).andDo(print())
.andExpect(status().isOk()).andExpect(content().contentType("application/json;charset=UTF-8"));
logger.info("test fileupload_oneFile_success: " + s.andReturn().getResponse().getStatus());
assertTrue(HttpStatus.OK.value() == s.andReturn().getResponse().getStatus());
}
/**
* Tests the successful Uploading of two files using Spring MockMvc Framework call to the
* "/api/v1/fileupload" RESTFul Web Service.
*
* @throws Exception - if an error occurs
*/
@Test
@Ignore
public void fileupload_twoFiles_success() throws Exception {
FileUploadRequest fileUploadRequest = new FileUploadRequest();
List<MultipartFile> multipartFilesList = new ArrayList<MultipartFile>();
MockMultipartFile file = new MockMultipartFile("fileHello" + System.currentTimeMillis(), "hello" + System.currentTimeMillis() + ".txt",
MediaType.TEXT_PLAIN_VALUE, "Hello, World!".getBytes());
multipartFilesList.add(file);
file = new MockMultipartFile("fileGoodbye" + System.currentTimeMillis(), "goodbye" + System.currentTimeMillis() + ".txt",
MediaType.TEXT_PLAIN_VALUE, "Goodbye, World!".getBytes());
multipartFilesList.add(file);
fileUploadRequest.setMultipartFiles(multipartFilesList);
ResultActions s = mockMvc.perform( post("/api/v1/fileupload").contentType("multipart/form-data;boundary=" + System.currentTimeMillis())
.flashAttr("fileUploadRequest", fileUploadRequest)).andDo(print())
.andExpect(status().isOk()).andExpect(content().contentType("application/json;charset=UTF-8"));
logger.info("test fileupload_twoFiles_success: " + s.andReturn().getResponse().getStatus());
assertTrue(HttpStatus.OK.value() == s.andReturn().getResponse().getStatus());
}
/**
* Tests the successful Uploading of two files and un-successful Uploading of two files using
* Spring MockMvc Framework call to the "/api/v1/fileupload" RESTFul Web Service.
*
* @throws Exception - if an error occurs
*/
@Test
@Ignore
public void fileupload_twoFiles_success_twoFiles_error() throws Exception {
FileUploadRequest fileUploadRequest = new FileUploadRequest();
List<MultipartFile> multipartFilesList = new ArrayList<MultipartFile>();
MockMultipartFile file = new MockMultipartFile("fileHello" + System.currentTimeMillis(), "hello" + System.currentTimeMillis() + ".txt",
MediaType.TEXT_PLAIN_VALUE, "Hello, World!".getBytes());
multipartFilesList.add(file);
multipartFilesList.add(file);
file = new MockMultipartFile("fileGoodbye" + System.currentTimeMillis(), "goodbye" + System.currentTimeMillis() + ".txt",
MediaType.TEXT_PLAIN_VALUE, "Goodbye, World!".getBytes());
multipartFilesList.add(file);
multipartFilesList.add(file);
fileUploadRequest.setMultipartFiles(multipartFilesList);
ResultActions s = mockMvc.perform( post("/api/v1/fileupload").contentType("multipart/form-data;boundary=" + System.currentTimeMillis())
.flashAttr("fileUploadRequest", fileUploadRequest)).andDo(print())
.andExpect(status().isOk()).andExpect(content().contentType("application/json;charset=UTF-8"));
logger.info("test fileupload_twoFiles_success_twoFiles_error: " + s.andReturn().getResponse().getStatus());
assertTrue(HttpStatus.OK.value() == s.andReturn().getResponse().getStatus());
}
/**
* Tests the successful Archiving of one file using Spring MockMvc Framework call to the
* "/api/v1/filearchive" RESTFul Web Service.
*
* @throws Exception - if an error occurs
*/
@Test
@Ignore
public void filearchive_oneFile_success() throws Exception {
ArchiveFileRequest archiveFileRequest = new ArchiveFileRequest();
List <ArchivedPdfReference> archivedPdfReferencesList = new ArrayList<ArchivedPdfReference>();
ArchivedPdfReference archivedPdfReference = new ArchivedPdfReference();
BigDecimal guid = new BigDecimal(752);
archivedPdfReference.setGuid(guid.toPlainString());
archivedPdfReference.setAlt("hello1530564724915 (old)");
archivedPdfReferencesList.add(archivedPdfReference);
archiveFileRequest.setArchivedPdfReferences(archivedPdfReferencesList);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
String jsonRequest = ow.writeValueAsString(archiveFileRequest);
// System.out.println("jsonRequest = " + jsonRequest);
ResultActions s = mockMvc.perform( post("/api/v1/filearchive").contentType(MediaType.APPLICATION_JSON)
.content(jsonRequest)).andDo(print())
.andExpect(status().isOk()).andExpect(content().contentType("application/json;charset=UTF-8"));
logger.info("test filearchive_oneFile_success: " + s.andReturn().getResponse().getStatus());
assertTrue(HttpStatus.OK.value() == s.andReturn().getResponse().getStatus());
}
/**
* Tests the successful Archiving of two files using Spring MockMvc Framework call to the
* "/api/v1/filearchive" RESTFul Web Service.
*
* @throws Exception - if an error occurs
*/
@Test
@Ignore
public void filearchive_twoFiles_success() throws Exception {
ArchiveFileRequest archiveFileRequest = new ArchiveFileRequest();
List <ArchivedPdfReference> archivedPdfReferencesList = new ArrayList<ArchivedPdfReference>();
ArchivedPdfReference archivedPdfReference = new ArchivedPdfReference();
BigDecimal guid = new BigDecimal(752);
archivedPdfReference.setGuid(guid.toPlainString());
archivedPdfReference.setAlt("hello1530564724915 (old)");
archivedPdfReferencesList.add(archivedPdfReference);
archivedPdfReference = new ArchivedPdfReference();
guid = new BigDecimal(753);
archivedPdfReference.setGuid(guid.toPlainString());
archivedPdfReference.setAlt("goodbye1530564724915 (old)");
archivedPdfReferencesList.add(archivedPdfReference);
archiveFileRequest.setArchivedPdfReferences(archivedPdfReferencesList);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
String jsonRequest = ow.writeValueAsString(archiveFileRequest);
// System.out.println("jsonRequest = " + jsonRequest);
ResultActions s = mockMvc.perform( post("/api/v1/filearchive").contentType(MediaType.APPLICATION_JSON)
.content(jsonRequest)).andDo(print())
.andExpect(status().isOk()).andExpect(content().contentType("application/json;charset=UTF-8"));
logger.info("test filearchive_oneFile_success: " + s.andReturn().getResponse().getStatus());
assertTrue(HttpStatus.OK.value() == s.andReturn().getResponse().getStatus());
}
/**
* Tests the successful Archiving of two files and un-successful Arching of one file using Spring
* MockMvc Framework call to the "/api/v1/filearchive" RESTFul Web Service.
*
* @throws Exception - if an error occurs
*/
@Test
@Ignore
public void filearchive_twoFiles_success_oneFile_error() throws Exception {
ArchiveFileRequest archiveFileRequest = new ArchiveFileRequest();
List <ArchivedPdfReference> archivedPdfReferencesList = new ArrayList<ArchivedPdfReference>();
ArchivedPdfReference archivedPdfReference = new ArchivedPdfReference();
BigDecimal guid = new BigDecimal(752); // exists
archivedPdfReference.setGuid(guid.toPlainString());
archivedPdfReference.setAlt("hello1530564724915 (old)");
archivedPdfReferencesList.add(archivedPdfReference);
archivedPdfReference = new ArchivedPdfReference();
guid = new BigDecimal(753); // exists
archivedPdfReference.setGuid(guid.toPlainString());
archivedPdfReference.setAlt("goodbye1530564724915 (old)");
archivedPdfReferencesList.add(archivedPdfReference);
archivedPdfReference = new ArchivedPdfReference();
guid = new BigDecimal(100); // does not exist
archivedPdfReference.setGuid(guid.toPlainString());
archivedPdfReference.setAlt("goodbye1530564724915 (old)");
archivedPdfReferencesList.add(archivedPdfReference);
archiveFileRequest.setArchivedPdfReferences(archivedPdfReferencesList);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
String jsonRequest = ow.writeValueAsString(archiveFileRequest);
// System.out.println("jsonRequest = " + jsonRequest);
ResultActions s = mockMvc.perform( post("/api/v1/filearchive").contentType(MediaType.APPLICATION_JSON)
.content(jsonRequest)).andDo(print())
.andExpect(status().isOk()).andExpect(content().contentType("application/json;charset=UTF-8"));
logger.info("test filearchive_oneFile_success: " + s.andReturn().getResponse().getStatus());
assertTrue(HttpStatus.OK.value() == s.andReturn().getResponse().getStatus());
}
}