1 package org.kuali.ole.editor.controller;
2
3 import org.junit.Before;
4 import org.junit.Test;
5 import org.kuali.ole.editor.bo.DublinEditorField;
6 import org.kuali.ole.editor.contoller.DublinEditorController;
7 import org.kuali.ole.editor.form.DublinEditorForm;
8 import org.kuali.ole.editor.service.DocstoreHelperService;
9 import org.mockito.Mock;
10 import org.mockito.Mockito;
11 import org.mockito.MockitoAnnotations;
12 import org.springframework.validation.BindingResult;
13 import org.springframework.web.servlet.ModelAndView;
14
15 import javax.servlet.http.HttpServletRequest;
16 import javax.servlet.http.HttpServletResponse;
17 import java.util.Arrays;
18
19 import static junit.framework.Assert.assertNotNull;
20
21
22
23
24
25
26
27
28 public class DublinEditorController_UT {
29
30 @Mock
31 private DublinEditorForm mockForm;
32 @Mock
33 private BindingResult mockResult;
34 @Mock
35 private HttpServletRequest mockRequest;
36 @Mock
37 private HttpServletResponse mockResponse;
38 @Mock
39 private ModelAndView mockModelView;
40 @Mock
41 private DocstoreHelperService mockDockstoreHelperService;
42
43 @Before
44 public void setUp() throws Exception {
45 MockitoAnnotations.initMocks(this);
46 }
47
48 @Test
49 public void testSubmit() throws Exception {
50 DublinEditorField dublinEditorField = new DublinEditorField();
51 dublinEditorField.setElement("dc:contributor");
52 dublinEditorField.setValue("Test for Dublin Editor");
53 DublinEditorField dublinEditorField1 = new DublinEditorField();
54 dublinEditorField1.setElement("dc:contributor");
55 dublinEditorField1.setValue("Test for Dublin Editor");
56 Mockito.when(mockForm.getDublinFieldList()).thenReturn(Arrays.asList(dublinEditorField, dublinEditorField1));
57
58 MockDublinEditorController dublinEditorController = new MockDublinEditorController();
59 dublinEditorController.setDocstoreHelperService(mockDockstoreHelperService);
60 ModelAndView modelAndView = dublinEditorController.submit(mockForm, mockResult, mockRequest, mockResponse);
61 assertNotNull(modelAndView);
62 Mockito.verify(mockDockstoreHelperService, Mockito.times(1)).persistToDocstoreForEditor(Mockito.anyString(),Mockito.anyString(), Mockito.anyString());
63 }
64
65 private class MockDublinEditorController extends DublinEditorController {
66 @Override
67 protected ModelAndView callSuper(BindingResult result, HttpServletRequest request, HttpServletResponse response, DublinEditorForm marcEditorForm) {
68 return mockModelView;
69 }
70 }
71 }