Changeset 10494 for extensions/jiwigo-ws-api/src/test/java/fr
- Timestamp:
- Apr 19, 2011, 3:36:26 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/jiwigo-ws-api/src/test/java/fr/mael/jiwigo/service/ServicesTest.java
r10089 r10494 1 1 package fr.mael.jiwigo.service; 2 3 import java.io.File; 4 import java.io.IOException; 5 import java.util.List; 2 6 3 7 import junit.framework.Assert; … … 17 21 public class ServicesTest { 18 22 19 23 private SessionManager sessionManager; 20 24 21 @Before 22 public void setUp() { 23 sessionManager = new SessionManagerImpl("mael", "motdepasse", "http://mael.piwigo.com", "Unit Test"); 24 sessionManager.processLogin(); 25 @Before 26 public void setUp() { 27 sessionManager = new SessionManagerImpl("mael", "motdepasse", "http://mael.piwigo.com", "Unit Test"); 28 sessionManager.processLogin(); 29 } 30 31 @Test 32 public void testCreer() throws Exception { 33 Category cat = null; 34 CategoryServiceImpl categoryService = new CategoryServiceImpl(); 35 CategoryDaoImpl categoryDao = new CategoryDaoImpl(); 36 categoryDao.setSessionManager(sessionManager); 37 categoryService.setDao(categoryDao); 38 39 ImageServiceImpl imageService = new ImageServiceImpl(); 40 ImageDaoImpl imageDao = new ImageDaoImpl(); 41 imageDao.setSessionManager(sessionManager); 42 imageService.setDao(imageDao); 43 //we choose category number 3 44 for (Category category : categoryService.list(true)) { 45 if (category.getIdentifier().equals(3)) { 46 cat = category; 47 break; 48 } 49 } 50 //we look for the first picture of category 3 51 Image image = imageService.listByCategory(cat.getIdentifier(), true).get(0); 52 Assert.assertEquals("test de test do not delete", cat.getName()); 53 Assert.assertEquals("20110329194915-0c0b3f36.jpg", image.getFile()); 54 55 } 56 57 @Test 58 public void addSimpleTest() { 59 60 // we prepare the service implementing add-simple 61 ImageServiceImpl imageService = new ImageServiceImpl(); 62 ImageDaoImpl dao = new ImageDaoImpl(); 63 dao.setSessionManager(sessionManager); 64 imageService.setDao(dao); 65 66 //we prepare the resource to send 67 File imageFile = new File(this.getClass().getClassLoader().getResource("piwigo_org.png").getPath()); 68 // File imageFile = new File("piwigo_org.png"); 69 Integer categoryTest = 98; 70 String title = "title" + System.currentTimeMillis(); 71 try { 72 imageService.addSimple(imageFile, categoryTest, title); 73 } catch (IOException e) { 74 Assert.fail("An exception was thrown while trying to send the pictures" + e.getMessage()); 25 75 } 26 76 27 @Test 28 public void testCreer() throws Exception { 29 Category cat = null; 30 CategoryServiceImpl categoryService = new CategoryServiceImpl(); 31 CategoryDaoImpl categoryDao = new CategoryDaoImpl(); 32 categoryDao.setSessionManager(sessionManager); 33 categoryService.setDao(categoryDao); 77 //the image should be sent, let's check if piwigo added it to the category. 78 boolean found = false; 79 List<Image> listByCategory; 80 try { 81 listByCategory = imageService.listByCategory(categoryTest, true); 82 for (Image image : listByCategory) { 83 if (image.getName().equals(title)) { 84 found = true; 85 break; 86 } 87 } 88 } catch (Exception e) { 89 Assert.fail("An exception was thrown while trying to fetch the pictures from category " + categoryTest 90 + "exception was : " + e.getMessage()); 91 } 92 Assert.assertTrue("The picture just sent could not be found", found); 34 93 35 ImageServiceImpl imageService = new ImageServiceImpl(); 36 ImageDaoImpl imageDao = new ImageDaoImpl(); 37 imageDao.setSessionManager(sessionManager); 38 imageService.setDao(imageDao); 39 40 for (Category category : categoryService.list(true)) { 41 if (category.getIdentifier().equals(3)) { 42 cat = category; 43 break; 44 } 45 } 46 Image image = imageService.listByCategory(cat.getIdentifier(), true).get(0); 47 Assert.assertEquals("test de test do not delete", cat.getName()); 48 Assert.assertEquals("20110329194915-0c0b3f36.jpg", image.getFile()); 49 50 } 94 } 51 95 }
Note: See TracChangeset
for help on using the changeset viewer.