LEFT | RIGHT |
1 package com.google.enterprise.adaptor.sharepoint; | 1 package com.google.enterprise.adaptor.sharepoint; |
2 | 2 |
| 3 import com.google.enterprise.adaptor.Acl; |
3 import static org.junit.Assert.*; | 4 import static org.junit.Assert.*; |
4 | 5 |
5 | 6 |
6 import com.google.enterprise.adaptor.Config; | 7 import com.google.enterprise.adaptor.Config; |
7 import com.google.enterprise.adaptor.DocId; | 8 import com.google.enterprise.adaptor.DocId; |
8 import com.google.enterprise.adaptor.GroupPrincipal; | 9 import com.google.enterprise.adaptor.GroupPrincipal; |
9 | 10 |
10 import com.google.enterprise.adaptor.sharepoint.SharePointUserProfileAdaptor.Use
rProfileServiceClient; | 11 import com.google.enterprise.adaptor.sharepoint.SharePointUserProfileAdaptor.Use
rProfileServiceClient; |
11 import com.google.enterprise.adaptor.sharepoint.SharePointUserProfileAdaptor.Use
rProfileServiceFactory; | 12 import com.google.enterprise.adaptor.sharepoint.SharePointUserProfileAdaptor.Use
rProfileServiceFactory; |
12 import com.google.enterprise.adaptor.sharepoint.SharePointUserProfileAdaptor.Use
rProfileServiceWS; | 13 import com.google.enterprise.adaptor.sharepoint.SharePointUserProfileAdaptor.Use
rProfileServiceWS; |
13 import com.microsoft.schemas.sharepoint.soap.Authentication.AuthenticationMode; | 14 import com.microsoft.schemas.sharepoint.soap.authentication.AuthenticationMode; |
14 import com.microsoft.schemas.sharepoint.soap.Authentication.AuthenticationSoap; | 15 import com.microsoft.schemas.sharepoint.soap.authentication.AuthenticationSoap; |
15 import com.microsoft.schemas.sharepoint.soap.Authentication.LoginResult; | 16 import com.microsoft.schemas.sharepoint.soap.authentication.LoginResult; |
16 | 17 |
17 import com.microsoft.webservices.sharepointportalserver.userprofilechangeservice
.ArrayOfUserProfileChangeData; | 18 import com.microsoft.webservices.sharepointportalserver.userprofilechangeservice
.ArrayOfUserProfileChangeData; |
18 import com.microsoft.webservices.sharepointportalserver.userprofilechangeservice
.UserProfileChangeData; | 19 import com.microsoft.webservices.sharepointportalserver.userprofilechangeservice
.UserProfileChangeData; |
19 import com.microsoft.webservices.sharepointportalserver.userprofilechangeservice
.UserProfileChangeDataContainer; | 20 import com.microsoft.webservices.sharepointportalserver.userprofilechangeservice
.UserProfileChangeDataContainer; |
20 import com.microsoft.webservices.sharepointportalserver.userprofilechangeservice
.UserProfileChangeQuery; | 21 import com.microsoft.webservices.sharepointportalserver.userprofilechangeservice
.UserProfileChangeQuery; |
21 import com.microsoft.webservices.sharepointportalserver.userprofileservice.Array
OfContactData; | 22 import com.microsoft.webservices.sharepointportalserver.userprofileservice.Array
OfContactData; |
22 import com.microsoft.webservices.sharepointportalserver.userprofileservice.Array
OfPropertyData; | 23 import com.microsoft.webservices.sharepointportalserver.userprofileservice.Array
OfPropertyData; |
23 import com.microsoft.webservices.sharepointportalserver.userprofileservice.Array
OfValueData; | 24 import com.microsoft.webservices.sharepointportalserver.userprofileservice.Array
OfValueData; |
24 import com.microsoft.webservices.sharepointportalserver.userprofileservice.Conta
ctData; | 25 import com.microsoft.webservices.sharepointportalserver.userprofileservice.Conta
ctData; |
25 import com.microsoft.webservices.sharepointportalserver.userprofileservice.GetUs
erProfileByIndexResult; | 26 import com.microsoft.webservices.sharepointportalserver.userprofileservice.GetUs
erProfileByIndexResult; |
26 import com.microsoft.webservices.sharepointportalserver.userprofileservice.Priva
cy; | 27 import com.microsoft.webservices.sharepointportalserver.userprofileservice.Priva
cy; |
27 import com.microsoft.webservices.sharepointportalserver.userprofileservice.Prope
rtyData; | 28 import com.microsoft.webservices.sharepointportalserver.userprofileservice.Prope
rtyData; |
28 import com.microsoft.webservices.sharepointportalserver.userprofileservice.Value
Data; | 29 import com.microsoft.webservices.sharepointportalserver.userprofileservice.Value
Data; |
29 | 30 |
30 import org.junit.*; | 31 import org.junit.*; |
31 | 32 |
32 import org.w3c.dom.DOMImplementation; | 33 import org.w3c.dom.DOMImplementation; |
33 | 34 |
34 import java.io.ByteArrayInputStream; | 35 import java.io.ByteArrayInputStream; |
35 import java.io.ByteArrayOutputStream; | 36 import java.io.ByteArrayOutputStream; |
36 import java.io.IOException; | 37 import java.io.IOException; |
37 import java.net.URLDecoder; | 38 import java.net.URLDecoder; |
| 39 import java.nio.charset.Charset; |
38 import java.util.ArrayList; | 40 import java.util.ArrayList; |
39 import java.util.Arrays; | 41 import java.util.Arrays; |
40 | 42 |
41 import java.util.HashMap; | 43 import java.util.HashMap; |
42 import java.util.List; | 44 import java.util.List; |
43 import java.util.Map; | 45 import java.util.Map; |
44 | 46 |
45 | 47 |
46 import javax.xml.parsers.DocumentBuilder; | 48 import javax.xml.parsers.DocumentBuilder; |
47 import javax.xml.parsers.DocumentBuilderFactory; | 49 import javax.xml.parsers.DocumentBuilderFactory; |
48 | 50 |
49 import javax.xml.ws.WebServiceException; | 51 import javax.xml.ws.WebServiceException; |
50 | 52 |
51 /** Test cases for {@link SharePointUserProfileAdaptor}. */ | 53 /** Test cases for {@link SharePointUserProfileAdaptor}. */ |
52 public class SharePointUserProfileAdaptorTest { | 54 public class SharePointUserProfileAdaptorTest { |
53 | 55 |
54 private Config config; | 56 private Config config; |
55 private SharePointUserProfileAdaptor adaptor; | 57 private SharePointUserProfileAdaptor adaptor; |
| 58 private final Charset charset = Charset.forName("UTF-8"); |
56 | 59 |
57 @Before | 60 @Before |
58 public void setup() { | 61 public void setup() { |
59 config = new Config(); | 62 config = new Config(); |
60 new SharePointUserProfileAdaptor().initConfig(config); | 63 new SharePointUserProfileAdaptor().initConfig(config); |
61 config.overrideKey("sharepoint.server", "http://sharepoint.example.com"); | 64 config.overrideKey("sharepoint.server", "http://sharepoint.example.com"); |
62 config.overrideKey("sharepoint.username", "adminUser"); | 65 config.overrideKey("sharepoint.username", "adminUser"); |
63 config.overrideKey("sharepoint.password", "password"); | 66 config.overrideKey("sharepoint.password", "password"); |
64 config.overrideKey("profile.setacl", "true"); | 67 config.overrideKey("profile.setacl", "true"); |
65 } | 68 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 } | 141 } |
139 | 142 |
140 @Test | 143 @Test |
141 public void testGetDocContent() throws IOException, Exception { | 144 public void testGetDocContent() throws IOException, Exception { |
142 MockUserProfileServiceFactoryImpl serviceFactory = | 145 MockUserProfileServiceFactoryImpl serviceFactory = |
143 new MockUserProfileServiceFactoryImpl(null); | 146 new MockUserProfileServiceFactoryImpl(null); |
144 ArrayOfPropertyData profile = new ArrayOfPropertyData(); | 147 ArrayOfPropertyData profile = new ArrayOfPropertyData(); |
145 poulateProfileProperties(profile, | 148 poulateProfileProperties(profile, |
146 SharePointUserProfileAdaptor.PROFILE_ACCOUNTNAME_PROPERTY, | 149 SharePointUserProfileAdaptor.PROFILE_ACCOUNTNAME_PROPERTY, |
147 new String[] {"user1"}); | 150 new String[] {"user1"}); |
| 151 poulateProfileProperties(profile, |
| 152 SharePointUserProfileAdaptor.PROFILE_PREFERRED_NAME_PROPERTY, |
| 153 new String[] {"First & Last"}); |
148 String[] skills = | 154 String[] skills = |
149 new String[] {"Java", "SharePoint", "C++", "Design"}; | 155 new String[] {"Java", "SharePoint", "C++", "Design"}; |
150 poulateProfileProperties(profile, "SPS-Skills", skills); | 156 poulateProfileProperties(profile, "SPS-Skills", skills); |
151 poulateProfileProperties(profile, "SP Single Value Property", | 157 poulateProfileProperties(profile, "SP Single Value Property", |
152 new String[] {"Value1"}); | 158 new String[] {"Value1"}); |
153 poulateProfileProperties(profile, "SP Multi Value Property", | 159 poulateProfileProperties(profile, "SP Multi Value Property", |
154 new String[] {"Value1", "Value2", "Value3"}); | 160 new String[] {"Value1", "Value2", "Value3"}); |
155 poulateProfileProperties(profile, "Empty Property", null); | 161 poulateProfileProperties(profile, "Empty Property", null); |
156 poulateProfileProperties(profile, "Private Property", | 162 poulateProfileProperties(profile, "Private Property", |
157 new String[] {"Private Value"}, Privacy.PRIVATE); | 163 new String[] {"Private Value"}, Privacy.PRIVATE); |
(...skipping 23 matching lines...) Expand all Loading... |
181 adaptor = new SharePointUserProfileAdaptor(serviceFactory); | 187 adaptor = new SharePointUserProfileAdaptor(serviceFactory); |
182 | 188 |
183 AccumulatingDocIdPusher pusher = new AccumulatingDocIdPusher(); | 189 AccumulatingDocIdPusher pusher = new AccumulatingDocIdPusher(); |
184 adaptor.init(new MockAdaptorContext(config, pusher)); | 190 adaptor.init(new MockAdaptorContext(config, pusher)); |
185 | 191 |
186 ByteArrayOutputStream baos = new ByteArrayOutputStream(); | 192 ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
187 GetContentsRequest request = new GetContentsRequest( | 193 GetContentsRequest request = new GetContentsRequest( |
188 new DocId(SharePointUserProfileAdaptor.SOCIAL_ID_PREFIX + "user1")); | 194 new DocId(SharePointUserProfileAdaptor.SOCIAL_ID_PREFIX + "user1")); |
189 GetContentsResponse response = new GetContentsResponse(baos); | 195 GetContentsResponse response = new GetContentsResponse(baos); |
190 adaptor.getDocContent(request, response); | 196 adaptor.getDocContent(request, response); |
| 197 ···· |
| 198 String responseString = new String(baos.toByteArray(), charset); |
| 199 final String golden = "<html><head><title>First & Last" |
| 200 + "</title></head><body><h1>First & Last</h1></body></html>"; |
| 201 assertEquals(golden, responseString); |
191 | 202 |
192 assertFalse(response.isNotFound()); | 203 assertFalse(response.isNotFound()); |
193 assertEquals("user1", response.getMetadata().getOneValue( | 204 assertEquals("user1", response.getMetadata().getOneValue( |
194 "google_social_user_accountname")); | 205 "google_social_user_accountname")); |
195 assertEquals("Value1", response.getMetadata().getOneValue( | 206 assertEquals("Value1", response.getMetadata().getOneValue( |
196 "SP Single Value Property")); | 207 "SP Single Value Property")); |
197 assertEquals(4, response.getMetadata().getAllValues( | 208 assertEquals(4, response.getMetadata().getAllValues( |
198 "google_social_user_skills").size()); | 209 "google_social_user_skills").size()); |
199 assertEquals(3, response.getMetadata().getAllValues( | 210 assertEquals(3, response.getMetadata().getAllValues( |
200 "SP Multi Value Property").size()); | 211 "SP Multi Value Property").size()); |
(...skipping 25 matching lines...) Expand all Loading... |
226 assertEquals("public group", URLDecoder.decode(group, "UTF-8")); | 237 assertEquals("public group", URLDecoder.decode(group, "UTF-8")); |
227 String name = pubContact.getAttributes().getNamedItem("gsa:name").getNodeVal
ue(); | 238 String name = pubContact.getAttributes().getNamedItem("gsa:name").getNodeVal
ue(); |
228 assertEquals("Public Colleague", URLDecoder.decode(name, "UTF-8")); | 239 assertEquals("Public Colleague", URLDecoder.decode(name, "UTF-8")); |
229 String isInWorkGroup | 240 String isInWorkGroup |
230 = pubContact.getAttributes().getNamedItem("gsa:isinworkinggroup").getNod
eValue(); | 241 = pubContact.getAttributes().getNamedItem("gsa:isinworkinggroup").getNod
eValue(); |
231 assertEquals("true", URLDecoder.decode(isInWorkGroup, "UTF-8")); | 242 assertEquals("true", URLDecoder.decode(isInWorkGroup, "UTF-8")); |
232 | 243 |
233 | 244 |
234 | 245 |
235 //ACL Verification | 246 //ACL Verification |
236 assertNotNull(response.getAcl()); | 247 List<GroupPrincipal> groups = new ArrayList<GroupPrincipal>(); |
237 assertNotNull(response.getAcl().getPermitGroups()); | 248 groups.add(new GroupPrincipal("NT AUTHORITY\\Authenticated Users")); |
238 assertEquals(1, response.getAcl().getPermitGroups().size()); | 249 assertEquals(new Acl.Builder() |
239 assertTrue(response.getAcl().getPermitGroups().contains( | 250 .setEverythingCaseInsensitive() |
240 new GroupPrincipal("NT AUTHORITY\\Authenticated Users"))); | 251 .setInheritanceType(Acl.InheritanceType.LEAF_NODE) |
241 assertTrue(response.getAcl().getPermitUsers().isEmpty()); | 252 .setPermitGroups(groups).build(), |
242 assertTrue(response.getAcl().getDenyGroups().isEmpty()); | 253 response.getAcl()); |
243 assertTrue(response.getAcl().getDenyUsers().isEmpty()); | |
244 } | 254 } |
245 | 255 |
246 @Test | 256 @Test |
247 public void testGetDocContentNotFound() throws IOException { | 257 public void testGetDocContentNotFound() throws IOException { |
248 MockUserProfileServiceFactoryImpl serviceFactory = | 258 MockUserProfileServiceFactoryImpl serviceFactory = |
249 new MockUserProfileServiceFactoryImpl(null); | 259 new MockUserProfileServiceFactoryImpl(null); |
250 adaptor = new SharePointUserProfileAdaptor(serviceFactory); | 260 adaptor = new SharePointUserProfileAdaptor(serviceFactory); |
251 | 261 |
252 AccumulatingDocIdPusher pusher = new AccumulatingDocIdPusher(); | 262 AccumulatingDocIdPusher pusher = new AccumulatingDocIdPusher(); |
253 adaptor.init(new MockAdaptorContext(config, pusher)); | 263 adaptor.init(new MockAdaptorContext(config, pusher)); |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 private static class MockUserProfileServiceFactoryImpl | 576 private static class MockUserProfileServiceFactoryImpl |
567 implements UserProfileServiceFactory { | 577 implements UserProfileServiceFactory { |
568 MockUserProfileServiceWS proxy; | 578 MockUserProfileServiceWS proxy; |
569 | 579 |
570 public MockUserProfileServiceFactoryImpl(String changeTokenOnRepository) { | 580 public MockUserProfileServiceFactoryImpl(String changeTokenOnRepository) { |
571 proxy = | 581 proxy = |
572 new MockUserProfileServiceWS(changeTokenOnRepository); | 582 new MockUserProfileServiceWS(changeTokenOnRepository); |
573 } | 583 } |
574 @Override | 584 @Override |
575 public UserProfileServiceWS newUserProfileService(String endpoint, | 585 public UserProfileServiceWS newUserProfileService(String endpoint, |
576 String endpointChangeService) { | 586 String endpointChangeService, List<String> cookies) { |
577 return proxy; | 587 return proxy; |
578 } | 588 } |
579 | 589 |
580 public void addUserProfileToCollection (int index, int nextIndex, | 590 public void addUserProfileToCollection (int index, int nextIndex, |
581 String userAccountName, ArrayOfPropertyData profileProperties, | 591 String userAccountName, ArrayOfPropertyData profileProperties, |
582 ArrayOfContactData colleagues) { | 592 ArrayOfContactData colleagues) { |
583 proxy.addUserProfileToCollection(index, nextIndex, | 593 proxy.addUserProfileToCollection(index, nextIndex, |
584 userAccountName, profileProperties, colleagues); | 594 userAccountName, profileProperties, colleagues); |
585 } | 595 } |
586 | 596 |
(...skipping 12 matching lines...) Expand all Loading... |
599 public LoginResult login(String string, String string1) { | 609 public LoginResult login(String string, String string1) { |
600 throw new UnsupportedOperationException(); | 610 throw new UnsupportedOperationException(); |
601 } | 611 } |
602 | 612 |
603 @Override | 613 @Override |
604 public AuthenticationMode mode() { | 614 public AuthenticationMode mode() { |
605 return AuthenticationMode.WINDOWS; | 615 return AuthenticationMode.WINDOWS; |
606 }···· | 616 }···· |
607 } | 617 } |
608 } | 618 } |
LEFT | RIGHT |