Advertisement
Guest User

Untitled

a guest
Aug 7th, 2012
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. /**
  2. * The contents of this file are subject to the OpenMRS Public License
  3. * Version 1.0 (the "License"); you may not use this file except in
  4. * compliance with the License. You may obtain a copy of the License at
  5. * http://license.openmrs.org
  6. *
  7. * Software distributed under the License is distributed on an "AS IS"
  8. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  9. * License for the specific language governing rights and limitations
  10. * under the License.
  11. *
  12. * Copyright (C) OpenMRS, LLC. All Rights Reserved.
  13. */
  14. package org.openmrs.contrib.metadatarepository.webapp.controller;
  15.  
  16. import static org.junit.Assert.assertNotNull;
  17.  
  18. import java.io.ByteArrayOutputStream;
  19.  
  20. import java.io.InputStream;
  21.  
  22. import org.apache.commons.io.IOUtils;
  23. import org.junit.Test;
  24. import org.openmrs.contrib.metadatarepository.model.MetadataPackage;
  25.  
  26. import org.openmrs.contrib.metadatarepository.service.UserManager;
  27.  
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.mock.web.MockHttpServletRequest;
  30.  
  31. import org.springframework.validation.BindingResult;
  32. import org.springframework.validation.DataBinder;
  33.  
  34. public class FileUploadControllerTest extends BaseControllerTestCase {
  35.  
  36. @Autowired
  37. private FileUploadController f = null;
  38. private MockHttpServletRequest request;
  39. private MetadataPackage pkg = new MetadataPackage();
  40. @Autowired
  41. private UserManager umagr;
  42.  
  43. @Test
  44. public void testOnSubmit() throws Exception {
  45.  
  46. request = newPost("/packageupload.html");
  47. request.setRemoteUser("user");
  48. pkg.setDescription("Labmodule");
  49.  
  50. pkg.setName("Lab");
  51. pkg.setUser(umagr.getUserByUsername("user"));
  52. pkg.setVersion(1L);
  53. pkg.setDownloadCount(0L);
  54. InputStream fis = getClass().getResourceAsStream("/sample-data.xml");
  55.  
  56. ByteArrayOutputStream data = new ByteArrayOutputStream(fis.available());
  57. IOUtils.copy(fis, data);
  58. pkg.setFile(data.toByteArray());
  59.  
  60. request.addParameter("upload", "");
  61.  
  62. BindingResult errors = new DataBinder(pkg).getBindingResult();
  63. String test = f.onSubmit(pkg, errors, request);
  64.  
  65. assertNotNull(test);
  66.  
  67. }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement