1 package com.mockobjects.naming.directory; 2 3 import javax.naming.*; 4 import javax.naming.directory.*; 5 6 import com.mockobjects.*; 7 import com.mockobjects.naming.*; 8 9 public class MockDirContext extends MockContext implements DirContext { 10 private final ReturnValue myAttributeToReturn = new ReturnValue("attribute"); 11 private final ExpectationValue myName = new ExpectationValue("myName"); 12 private ExpectationValue mySearchName = 13 new ExpectationValue("mySearchName"); 14 private final ExpectationValue myAttributes = 15 new ExpectationValue("myAttributes"); 16 private final ExpectationValue myModificationOperation = 17 new ExpectationValue("myModificationOperation"); 18 private final ExpectationValue myFilter = new ExpectationValue("myFilter"); 19 private final ExpectationValue mySearchControls = new ExpectationValue("mySearchControls"); 20 private final ReturnValue myResults = new ReturnValue("results"); 21 22 private ExpectationCounter myAttributesCallCount = 23 new ExpectationCounter("getAttributes"); 24 25 public void setupAttributes(Attributes anAttributeToReturn) { 26 this.myAttributeToReturn.setValue(anAttributeToReturn); 27 } 28 29 public void setExpectedGetAttributesName(Object aName) { 30 this.myName.setExpected(aName); 31 } 32 33 public void setExpectedGetAttributesCount(int callCount) { 34 this.myAttributesCallCount.setExpected(callCount); 35 } 36 37 public Attributes getAttributes(Name aName) throws NamingException { 38 return getAttributes(aName.toString()); 39 } 40 41 public Attributes getAttributes(String aName) throws NamingException { 42 return getAttributes(aName, null); 43 } 44 45 public Attributes getAttributes(Name aName, String [] attrIds) 46 throws NamingException { 47 return getAttributes(aName.toString(), attrIds); 48 } 49 50 public Attributes getAttributes(String aName, String [] attrIds) 51 throws NamingException { 52 this.myName.setActual(aName); 53 this.myAttributesCallCount.inc(); 54 return (Attributes) myAttributeToReturn.getValue(); 55 } 56 57 public void setExpectedModifyAttributes(String aName, 58 int aModificationOperation, Attributes attributes) { 59 60 this.myName.setExpected(aName); 61 this.myModificationOperation.setExpected(aModificationOperation); 62 this.myAttributes.setExpected(attributes); 63 } 64 65 public void modifyAttributes(Name aName, int aModificationOperation, 66 Attributes attributes) throws NamingException { 67 68 modifyAttributes(aName.toString(), aModificationOperation, attributes); 69 } 70 71 public void modifyAttributes(String aName, int aModificationOperation, 72 Attributes attributes) throws NamingException { 73 74 this.myName.setActual(aName); 75 this.myModificationOperation.setActual(aModificationOperation); 76 this.myAttributes.setActual(attributes); 77 } 78 79 public void modifyAttributes(Name aName, ModificationItem[] mods) 80 throws NamingException { 81 notImplemented(); 82 } 83 84 public void modifyAttributes(String aName, ModificationItem[] mods) 85 throws NamingException { 86 notImplemented(); 87 } 88 89 public void bind(Name aName, Object object, Attributes attributes) 90 throws NamingException { 91 notImplemented(); 92 } 93 94 public void bind(String aName, Object object, Attributes attributes) 95 throws NamingException { 96 notImplemented(); 97 } 98 99 public void rebind(Name aName, Object object, Attributes attributes) 100 throws NamingException { 101 notImplemented(); 102 } 103 104 public void rebind(String aName, Object object, Attributes attributes) 105 throws NamingException { 106 notImplemented(); 107 } 108 109 public DirContext createSubcontext(Name aName, Attributes attributes) 110 throws NamingException { 111 notImplemented(); 112 return null; 113 } 114 115 public DirContext createSubcontext(String aName, Attributes attributes) 116 throws NamingException { 117 notImplemented(); 118 return null; 119 } 120 121 public DirContext getSchema(Name aName) throws NamingException { 122 notImplemented(); 123 return null; 124 } 125 126 public DirContext getSchema(String aName) throws NamingException { 127 notImplemented(); 128 return null; 129 } 130 131 public DirContext getSchemaClassDefinition(Name aName) 132 throws NamingException { 133 notImplemented(); 134 return null; 135 } 136 137 public DirContext getSchemaClassDefinition(String aName) 138 throws NamingException { 139 notImplemented(); 140 return null; 141 } 142 143 public NamingEnumeration search(Name aName, Attributes attributes, 144 String [] anAttributeToReturn) throws NamingException { 145 return (NamingEnumeration) myResults.getValue(); 146 } 147 148 public NamingEnumeration search(String aName, Attributes attributes, 149 String [] anAttributeToReturn) throws NamingException { 150 return (NamingEnumeration) myResults.getValue(); 151 } 152 153 public NamingEnumeration search(Name aName, Attributes attributes) 154 throws NamingException { 155 return (NamingEnumeration) myResults.getValue(); 156 } 157 158 public NamingEnumeration search(String aName, Attributes attributes) 159 throws NamingException { 160 return (NamingEnumeration) myResults.getValue(); 161 } 162 163 public NamingEnumeration search(Name aName, String aFilter, 164 SearchControls cons) throws NamingException { 165 return (NamingEnumeration) myResults.getValue(); 166 } 167 168 public void setExpectedSearch(String aSearchName, String aFilter, 169 SearchControls searchControls) { 170 this.mySearchName.setExpected(aSearchName); 171 this.myFilter.setExpected(aFilter); 172 this.mySearchControls.setExpected(searchControls); 173 } 174 175 public void setupSearchResult(NamingEnumeration results) { 176 this.myResults.setValue(results); 177 } 178 179 public NamingEnumeration search(String aSearchName, String aFilter, 180 SearchControls searchControls) throws NamingException { 181 this.mySearchName.setActual(aSearchName); 182 this.myFilter.setActual(aFilter); 183 this.mySearchControls.setActual(searchControls); 184 return (NamingEnumeration) myResults.getValue(); 185 } 186 187 public NamingEnumeration search(Name aName, String aFilter, 188 Object [] filterArgs, SearchControls cons) throws NamingException { 189 return (NamingEnumeration) myResults.getValue(); 190 } 191 192 public NamingEnumeration search(String aName, String aFilter, 193 Object [] filterArgs, SearchControls cons) throws NamingException { 194 return (NamingEnumeration) myResults.getValue(); 195 } 196 197 } 198 | Popular Tags |