Summary Table

Categories Total Count
PII 0
URL 0
DNS 0
EKL 0
IP 0
PORT 0
VsID 0
CF 0
AI 0
VPD 0
PL 0
Other 0

File Content

package gov.va.med.ars.controller;

import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
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.status;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.SerializationFeature;

import gov.va.med.ars.filter.CORSFilter;
import gov.va.med.ars.model.request.JsonArrayModel;
import gov.va.med.ars.service.IArchiveService;

@RunWith(MockitoJUnitRunner.class)
public class ArchiveRestControllerTest {

private MockMvc mockMvc;
public static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(),
MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));

@Mock
private IArchiveService archiveService;

@InjectMocks
private ArchiveRestController archiveController;

@Before
public void init() throws Exception {
MockitoAnnotations.initMocks(this);
mockMvc = MockMvcBuilders.standaloneSetup(archiveController).addFilters(new CORSFilter()).build();
}

@Test
public void testGetAttachmentsArchived() throws Exception {

JsonArrayModel archiveAttachments = new JsonArrayModel();
List<String> acceptedValues = new ArrayList<>();
acceptedValues.add("121212");
boolean status = true;
archiveAttachments.setAcceptedValues(acceptedValues);
archiveAttachments.setStatus(status);

Boolean response = Boolean.TRUE;

when(archiveService.archiveAttachments(archiveAttachments)).thenReturn(response);

ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
String jsonRequest = ow.writeValueAsString(archiveAttachments);

mockMvc.perform(post("/api/v1/archive").contentType(MediaType.APPLICATION_JSON)
.content(jsonRequest)).andDo(print()).andExpect(status().isOk());
verify(archiveService, times(1)).archiveAttachments(archiveAttachments);
}
}