cvs commit: spice/sandbox/repository/componenthaus/src/tests/org/componenthaus/tests MockComponentRepositoryMonitor.java MockComponent.java MockComponentRepository.java MockSearchService.java
Mike Hogan <[email protected]> Mon, 10 Nov 2003 12:21:44 -0800
| Newsgroups | gmane.comp.java.spice.cvs |
|---|---|
| Message-ID | <[email protected]> |
hogie 03/11/10 12:21:44
Modified: sandbox/repository/componenthaus/src/tests/org/componenthaus/tests
MockComponent.java MockComponentRepository.java
MockSearchService.java
Added: sandbox/repository/componenthaus/src/tests/org/componenthaus/tests
MockComponentRepositoryMonitor.java
Log:
Preview release with plexus-utils components
Revision Changes Path
1.3 +8 -6 spice/sandbox/repository/componenthaus/src/tests/org/componenthaus/tests/MockComponent.java
Index: MockComponent.java
===================================================================
RCS file: /cvsroot/spice/spice/sandbox/repository/componenthaus/src/tests/org/componenthaus/tests/MockComponent.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MockComponent.java 9 Nov 2003 14:00:51 -0000 1.2
+++ MockComponent.java 10 Nov 2003 20:21:44 -0000 1.3
@@ -6,16 +6,18 @@
public class MockComponent implements Component {
private String componentId = null;
+ private String fullDescription;
public MockComponent(String componentId) {
this.componentId = componentId;
}
public String getId() {
- return null;
+ return componentId;
}
public void setId(String id) {
+ componentId = id;
}
public String getServiceInterface() {
@@ -34,10 +36,6 @@
return null;
}
- public String getAuthorsCSV() {
- return null;
- }
-
public List getAuthors() {
return null;
}
@@ -47,6 +45,10 @@
}
public String getFullDescription() {
- return null;
+ return fullDescription;
+ }
+
+ public void setFullDescription(String fullDescription) {
+ this.fullDescription = fullDescription;
}
}
1.4 +36 -4 spice/sandbox/repository/componenthaus/src/tests/org/componenthaus/tests/MockComponentRepository.java
Index: MockComponentRepository.java
===================================================================
RCS file: /cvsroot/spice/spice/sandbox/repository/componenthaus/src/tests/org/componenthaus/tests/MockComponentRepository.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MockComponentRepository.java 9 Nov 2003 14:00:51 -0000 1.3
+++ MockComponentRepository.java 10 Nov 2003 20:21:44 -0000 1.4
@@ -3,6 +3,8 @@
import junit.framework.Assert;
import org.componenthaus.repository.api.Component;
import org.componenthaus.repository.api.ComponentRepository;
+import org.prevayler.AlarmClock;
+import org.prevayler.implementation.AbstractPrevalentSystem;
import java.io.File;
import java.util.ArrayList;
@@ -10,19 +12,29 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.Collections;
-public class MockComponentRepository implements ComponentRepository {
+public class MockComponentRepository extends AbstractPrevalentSystem implements ComponentRepository {
private Map downloadables = new HashMap();
private Map components = new HashMap();
private Collection expectedAddComponents = new ArrayList();
private Collection actualAddComponents = new ArrayList();
+ private String expectedRegisterDownloadableComponentId = null;
+ private File expectedRegisterDownloadableFile = null;
+ private String actualRegisterDownloadableComponentId = null;
+ private File actualRegisterDownloadableFile = null;
+ private String preparedResult = null;
+ private int expectedListComponentsCalls = -1;
+ private int actualListComponentsCalls = 0;
public String add(Component component) {
- return null;
+ actualAddComponents.add(component);
+ return preparedResult;
}
public Collection listComponents() {
- return null;
+ actualListComponentsCalls++;
+ return Collections.EMPTY_LIST;
}
public Component getComponent(String id) {
@@ -30,6 +42,8 @@
}
public void registerDownloadable(String componentId, File downloadable) {
+ this.actualRegisterDownloadableComponentId = componentId;
+ this.actualRegisterDownloadableFile = downloadable;
}
public File getDownloadable(String componentId) {
@@ -44,8 +58,9 @@
components.put(component.getId(),component);
}
- public void setupExpectedAddComponent(Component component) {
+ public void setupExpectedAddComponent(Component component, String preparedResult) {
this.expectedAddComponents.add(component);
+ this.preparedResult = preparedResult;
}
public void verify() {
@@ -53,5 +68,22 @@
for(Iterator i=expectedAddComponents.iterator();i.hasNext();) {
Assert.assertTrue(actualAddComponents.contains(i.next()));
}
+ if ( expectedRegisterDownloadableComponentId != null ) {
+ Assert.assertEquals(expectedRegisterDownloadableComponentId, actualRegisterDownloadableComponentId);
+ Assert.assertSame(expectedRegisterDownloadableFile, actualRegisterDownloadableFile);
+ }
+ if ( expectedListComponentsCalls >= 0) {
+ Assert.assertEquals(expectedListComponentsCalls, actualListComponentsCalls);
+ }
+ }
+
+ public void setupExpectedRegisterDownloadable(String componentId, File file) {
+ this.expectedRegisterDownloadableComponentId = componentId;
+ this.expectedRegisterDownloadableFile = file;
}
+
+ public void setupExpectedListComponentsCalls(int num) {
+ expectedListComponentsCalls = num;
+ }
+
}
1.2 +23 -0 spice/sandbox/repository/componenthaus/src/tests/org/componenthaus/tests/MockSearchService.java
Index: MockSearchService.java
===================================================================
RCS file: /cvsroot/spice/spice/sandbox/repository/componenthaus/src/tests/org/componenthaus/tests/MockSearchService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MockSearchService.java 28 Oct 2003 19:36:06 -0000 1.1
+++ MockSearchService.java 10 Nov 2003 20:21:44 -0000 1.2
@@ -15,12 +15,22 @@
private String actualQuery;
private int actualBeginIndex;
private int actualEndIndex;
+ private String expectedIndexComponentId;
+ private String expectedIndexFullDescription;
+ private String actualIndexComponentId;
+ private String actualIndexFullDescription;
+ private SearchService.Exception preparedIndexException;
public void setToBeThrown(SearchService.Exception toBeThrown) {
this.toBeThrown = toBeThrown;
}
public void index(String componentId, String componentDescription) throws SearchService.Exception {
+ if ( preparedIndexException != null ) {
+ throw preparedIndexException;
+ }
+ this.actualIndexComponentId = componentId;
+ this.actualIndexFullDescription = componentDescription;
}
public int search(String query, int beginIndex, int endIndex, List collector) throws SearchService.Exception {
@@ -48,5 +58,18 @@
Assert.assertEquals("Did not get expected query",expectedQuery,actualQuery);
Assert.assertEquals("Did not get expected beginIndex",expectedBeginIndex,actualBeginIndex);
Assert.assertEquals("Did not get expected endIndex",expectedEndIndex,actualEndIndex);
+
+ Assert.assertEquals("Did not get expected component id during index",expectedIndexComponentId,actualIndexComponentId);
+ Assert.assertEquals("Did not get expected component desc during index",expectedIndexFullDescription,actualIndexFullDescription);
+
+ }
+
+ public void setupExpectedIndexCall(String componentId, String fullDescription) {
+ this.expectedIndexComponentId = componentId;
+ this.expectedIndexFullDescription = fullDescription;
+ }
+
+ public void setupIndexCallException(SearchService.Exception preparedException) {
+ preparedIndexException = preparedException;
}
}
1.1 spice/sandbox/repository/componenthaus/src/tests/org/componenthaus/tests/MockComponentRepositoryMonitor.java
Index: MockComponentRepositoryMonitor.java
===================================================================
package org.componenthaus.tests;
import org.componenthaus.repository.api.ComponentRepository;
import org.componenthaus.repository.api.Component;
import junit.framework.Assert;
public class MockComponentRepositoryMonitor implements ComponentRepository.Monitor {
private Component expectedComponent;
private Component actualComponent;
public void componentAdded(Component component) {
actualComponent = component;
}
public void setupExpectedComponent(Component component) {
this.expectedComponent = component;
}
public void verify() {
Assert.assertSame(expectedComponent,actualComponent);
}
}
-------------------------------------------------------
This SF.Net email sponsored by: ApacheCon 2003,
16-19 November in Las Vegas. Learn firsthand the latest
developments in Apache, PHP, Perl, XML, Java, MySQL,
WebDAV, and more! http://www.apachecon.com/