1 package org.mmbase.storage.search.implementation; 2 3 import junit.framework.*; 4 import java.util.*; 5 6 import org.mmbase.bridge.Field; 7 import org.mmbase.core.CoreField; 8 import org.mmbase.module.core.*; 9 import org.mmbase.module.corebuilders.*; 10 import org.mmbase.storage.search.*; 11 12 18 public class NodeSearchQueryTest extends TestCase { 19 20 21 private NodeSearchQuery instance = null; 22 23 24 private MMBase mmbase = null; 25 26 27 private MMObjectBuilder images = null; 28 private MMObjectBuilder news = null; 29 private InsRel insrel = null; 30 31 32 private CoreField imagesTitle = null; 33 private CoreField newsTitle = null; 34 35 public NodeSearchQueryTest(java.lang.String testName) { 36 super(testName); 37 } 38 39 public static void main(java.lang.String [] args) { 40 junit.textui.TestRunner.run(suite()); 41 } 42 43 46 public void setUp() throws Exception { 47 MMBaseContext.init(); 48 mmbase = MMBase.getMMBase(); 49 images = mmbase.getBuilder("images"); 50 news = mmbase.getBuilder("news"); 51 insrel = mmbase.getInsRel(); 52 imagesTitle = images.getField("title"); 53 newsTitle = news.getField("title"); 54 instance = new NodeSearchQuery(images); 55 } 56 57 60 public void tearDown() throws Exception {} 61 62 63 public void testConstructor() { 64 try { 65 new NodeSearchQuery(null); 67 fail("Null builder, should throw IllegalArgumentException."); 68 } catch (IllegalArgumentException e) {} 69 70 try { 71 new NodeSearchQuery(new ClusterBuilder(mmbase)); 73 fail("Virtual builder, should throw IllegalArgumentException."); 74 } catch (IllegalArgumentException e) {} 75 76 Collection fields = images.getFields(); 77 List stepFields = instance.getFields(); 78 Iterator iStepFields = stepFields.iterator(); 79 while (iStepFields.hasNext()) { 81 StepField stepField = (StepField) iStepFields.next(); 82 CoreField field = images.getField(stepField.getFieldName()); 83 assertTrue(field.inStorage()); 86 } 87 Iterator iFields = fields.iterator(); 89 while (iFields.hasNext()) { 90 CoreField field = (CoreField) iFields.next(); 91 if (field.getType() != Field.TYPE_BINARY && field.inStorage()) { 92 assertTrue(instance.getField(field) != null); 93 } 94 } 95 } 96 97 98 public void testGetField() { 99 Step step = (Step) instance.getSteps().get(0); 100 Collection fields = images.getFields(); 101 for (Iterator iFields = fields.iterator(); iFields.hasNext();) { 102 CoreField field = (CoreField) iFields.next(); 103 if (field.inStorage()) { 104 StepField stepField = instance.getField(field); 105 assertTrue(stepField != null); 106 assertTrue(stepField.getFieldName().equals(field.getName())); 107 assertTrue(stepField.getAlias() == null); 108 assertTrue(stepField.getType() == field.getType()); 109 assertTrue(stepField.getStep().equals(step)); 110 } else { 111 try { 113 instance.getField(field); 114 fail("Non-persistent field: '" + field + "' should throw IllegalArgumentException."); 115 } catch (IllegalArgumentException e) {} 116 } 117 } 118 119 try { 121 instance.getField(newsTitle); 122 fail("Field not belonging to images: should throw IllegalArgumentException."); 123 } catch (IllegalArgumentException e) {} 124 } 125 126 127 public void testAddStep() { 128 try { 130 instance.addStep(news); 131 fail("Adding step, should throw UnsupportedOperationException."); 132 } catch (UnsupportedOperationException e) {} 133 } 134 135 136 public void testAddRelationStep() { 137 try { 139 instance.addRelationStep(insrel, news); 140 fail("Adding relation step, should throw UnsupportedOperationException."); 141 } catch (UnsupportedOperationException e) {} 142 } 143 144 145 public void testAddField() { 146 Step step = (Step) instance.getSteps().get(0); 147 148 try { 150 instance.addField(step, imagesTitle); 151 fail("Adding field, should throw UnsupportedOperationException."); 152 } catch (UnsupportedOperationException e) {} 153 } 154 155 156 public void testAddAggregatedField() { 157 Step step = (Step) instance.getSteps().get(0); 158 159 try { 161 instance.addAggregatedField(step, imagesTitle, 162 AggregatedField.AGGREGATION_TYPE_MIN); 163 fail("Adding field, should throw UnsupportedOperationException."); 164 } catch (UnsupportedOperationException e) {} 165 } 166 167 168 public void testGetBuilder() { 169 assertTrue(new NodeSearchQuery(images).getBuilder() == images); 170 assertTrue(new NodeSearchQuery(news).getBuilder() == news); 171 } 172 173 public static Test suite() { 174 TestSuite suite = new TestSuite(NodeSearchQueryTest.class); 175 176 return suite; 177 } 178 179 } 180 | Popular Tags |