1 /*
2 * Copyright 2007 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl1.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.rice.kns.document;
17
18 import java.lang.reflect.InvocationTargetException;
19 import java.util.List;
20
21 import org.junit.Test;
22 import org.kuali.rice.kew.exception.WorkflowException;
23 import org.kuali.rice.kns.UserSession;
24 import org.kuali.rice.kns.service.KNSServiceLocator;
25 import org.kuali.rice.kns.util.GlobalVariables;
26 import org.kuali.rice.kns.util.KNSConstants;
27 import org.kuali.rice.test.data.UnitTestData;
28 import org.kuali.rice.test.data.UnitTestSql;
29 import org.kuali.test.KNSTestCase;
30 import org.kuali.test.KNSWithTestSpringContext;
31
32 import edu.sampleu.travel.bo.AttachmentSample;
33 import edu.sampleu.travel.bo.MultiAttachmentSample;
34
35
36 /**
37 * This class implements a unit test for a maintenance document
38 * with multiple attachments. The need for this test is tracked
39 * under the JIRA ticket KULRICE-5144.
40 *
41 * @link https://jira.kuali.org/browse/KULRICE-5144
42 *
43 * @author Kuali Rice Team (rice.collab@kuali.org)
44 *
45 */
46
47 @KNSWithTestSpringContext
48 public class MultipleAttachmentsTest extends KNSTestCase {
49 /**
50 MaintenanceDocument document;
51
52 @Override
53 public void setUp() throws Exception {
54 super.setUp();
55 GlobalVariables.setUserSession(new UserSession("quickstart"));
56 document = (MaintenanceDocument) KNSServiceLocator.getDocumentService().getNewDocument("AttachmentSampleMaintenanceDocument");
57 }
58
59 @Test
60 @UnitTestData(sqlStatements = {
61 @UnitTestSql("delete from trv_attach_sample_t"),
62 @UnitTestSql("delete from trv_multi_attach_sample_t")
63 })
64 public void test_MultipleAttachments() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, WorkflowException {
65
66 AttachmentSample as = new AttachmentSample();
67 as.setFileName("test.txt");
68 as.setId("2340");
69 as.setDescription("A test attachment");
70 as.setContentType("text/plain");
71 as.setAttachmentContent("This is a test".getBytes());
72
73 MultiAttachmentSample child1 = new MultiAttachmentSample();
74 child1.setFileName("child1.txt");
75 child1.setDescription("This is the first child");
76 child1.setContentType("text/plain");
77 child1.setAttachmentContent("This is the content of the first child".getBytes());
78 as.getMultiAttachment().add(child1);
79
80 MultiAttachmentSample child2 = new MultiAttachmentSample();
81 child2.setFileName("child2.txt");
82 child2.setDescription("This is the second child");
83 child2.setContentType("text/plain");
84 child2.setAttachmentContent("This is the content of the second child".getBytes());
85 as.getMultiAttachment().add(child2);
86
87 MultiAttachmentSample child3 = new MultiAttachmentSample();
88 child3.setFileName("child3.txt");
89 child3.setDescription("This is the third child");
90 child3.setContentType("text/plain");
91 child3.setAttachmentContent("This is the content of the third child".getBytes());
92 as.getMultiAttachment().add(child3);
93
94
95 document.getOldMaintainableObject().setBusinessObject(null);
96 document.getOldMaintainableObject().setBoClass(as.getClass());
97 document.getNewMaintainableObject().setBusinessObject(as);
98 document.getNewMaintainableObject().setBoClass(as.getClass());
99 document.getNewMaintainableObject().setMaintenanceAction(KNSConstants.MAINTENANCE_NEW_ACTION);
100 document.getDocumentHeader().setDocumentDescription("Testing");
101
102 Document routedDoc = KNSServiceLocator.getDocumentService().routeDocument(document, "Routing", null);
103
104 MaintenanceDocument retrievedDoc = (MaintenanceDocument) KNSServiceLocator.getDocumentService().getByDocumentHeaderId(routedDoc.getDocumentNumber());
105
106 AttachmentSample ras = (AttachmentSample)retrievedDoc.getNewMaintainableObject().getBusinessObject();
107
108 assertEquals("This is a test", new String(ras.getAttachmentContent()));
109 assertEquals("text/plain", ras.getContentType());
110
111 List<MultiAttachmentSample> multiAttachments = ras.getMultiAttachment();
112 assertEquals(3, multiAttachments.size());
113
114 int i=1;
115 for (MultiAttachmentSample multiAttachment : multiAttachments) {
116 String expectedName = "child" + i + ".txt";
117 assertEquals(expectedName, multiAttachment.getFileName());
118 assertEquals("text/plain", multiAttachment.getContentType());
119 i++;
120 }
121 }
122 */
123 }
124