Clover coverage report -
Coverage timestamp: Fri Nov 19 2004 13:41:51 PST
file stats: LOC: 99   Methods: 2
NCLOC: 81   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
EditControllerTest.java - 100% 100% 100%
coverage
 1    package photospace.web.spring;
 2   
 3    import java.io.*;
 4    import java.util.*;
 5    import org.apache.commons.io.*;
 6    import org.springframework.context.support.*;
 7    import org.springframework.context.*;
 8    import org.springframework.web.servlet.*;
 9    import org.springframework.web.bind.*;
 10    import org.springframework.validation.*;
 11    import junit.framework.*;
 12    import photospace.vfs.*;
 13    import photospace.meta.*;
 14    import photospace.search.*;
 15    import com.mockobjects.servlet.*;
 16   
 17    public class EditControllerTest
 18    extends TestCase
 19    {
 20    EditController controller;
 21    PersisterImpl persister;
 22    String path1;
 23    String path2;
 24   
 25  1 public void setUp() throws Exception
 26    {
 27  1 File root = new File(System.getProperty("java.io.tmpdir"), "EditControllerTest");
 28  1 File subdir = new File(root, "subdir");
 29  1 subdir.mkdirs();
 30  1 File photo = new File(System.getProperty("project.root"), "build/test/exif-nordf.jpg");
 31  1 FileUtils.copyFileToDirectory(photo, root);
 32  1 FileUtils.copyFileToDirectory(photo, subdir);
 33   
 34  1 path1 = "/exif-nordf.jpg";
 35  1 path2 = "/subdir/exif-nordf.jpg";
 36   
 37  1 FileSystem filesystem = new FileSystemImpl();
 38  1 filesystem.setRoot(root);
 39   
 40  1 persister = new PersisterImpl();
 41  1 persister.setFilesystem(filesystem);
 42  1 persister.setTranslator(new Translator());
 43   
 44  1 FileSystemBrowser browser = new FileSystemBrowser();
 45  1 browser.setFilesystem(filesystem);
 46  1 browser.setPersister(persister);
 47   
 48   
 49  1 File index = new File(System.getProperty("java.io.tmpdir"), "test-index");
 50  1 SearchIndex searchIndex = new SearchIndex(index);
 51   
 52  1 Searcher searcher = new Searcher();
 53  1 searcher.setIndex(searchIndex);
 54   
 55  1 controller = new EditController();
 56  1 controller.setFilesystem(filesystem);
 57  1 controller.setPersister(persister);
 58  1 controller.setSearcher(searcher);
 59   
 60  1 StaticApplicationContext context = new StaticApplicationContext();
 61  1 context.registerSingleton(StaticApplicationContext.MESSAGE_SOURCE_BEAN_NAME,
 62    StaticMessageSource.class,
 63    null);
 64  1 context.refresh();
 65  1 context.addMessage("format.dateTime", Locale.US, "MM/dd/yyyy hh:mm aaa");
 66  1 context.addMessage("message.edit.success", Locale.US, "success");
 67  1 controller.setApplicationContext(context);
 68    }
 69   
 70  1 public void testEdit() throws Exception
 71    {
 72  1 MockHttpServletRequest viewRequest = new MockHttpServletRequest();
 73  1 viewRequest.setSession(new MockHttpSession());
 74  1 viewRequest.setupAddParameter("paths", new String[] { path1, path2 });
 75   
 76  1 EditCommand command = (EditCommand) controller.formBackingObject(viewRequest);
 77  1 assertEquals(2, command.getMetas().size());
 78   
 79  1 ServletRequestDataBinder binder = new ServletRequestDataBinder(command, "");
 80  1 controller.initBinder(null, binder);
 81   
 82  1 MockHttpServletRequest editRequest = new MockHttpServletRequest();
 83  1 Vector names = new Vector(Arrays.asList(new String[] { "meta.labels" }));
 84  1 editRequest.setupGetParameterNames(names.elements());
 85  1 editRequest.setupAddParameter("meta.labels", "foo bar");
 86   
 87  1 binder.bind(editRequest);
 88  1 assertTrue(Arrays.asList(command.getMeta().getLabels()).contains("foo"));
 89  1 assertTrue(Arrays.asList(command.getMeta().getLabels()).contains("bar"));
 90   
 91  1 controller.onSubmit(editRequest, null, command, new BindException(command, ""));
 92  1 Meta meta1 = persister.getMeta(path1);
 93  1 Meta meta2 = persister.getMeta(path2);
 94  1 assertTrue(Arrays.asList(meta1.getLabels()).contains("foo"));
 95  1 assertTrue(Arrays.asList(meta1.getLabels()).contains("bar"));
 96  1 assertTrue(Arrays.asList(meta2.getLabels()).contains("foo"));
 97  1 assertTrue(Arrays.asList(meta2.getLabels()).contains("bar"));
 98    }
 99    }