diff --git a/sharepoint/api/pom.xml b/sharepoint/api/pom.xml
index 89087f6..cff2706 100644
--- a/sharepoint/api/pom.xml
+++ b/sharepoint/api/pom.xml
@@ -258,6 +258,11 @@
org.slf4j
slf4j-api
-
+
+
+ org.slf4j
+ slf4j-log4j12
+ test
+
\ No newline at end of file
diff --git a/sharepoint/api/src/main/java/de/muehlencord/shared/sharepoint/api/SPObject.java b/sharepoint/api/src/main/java/de/muehlencord/shared/sharepoint/api/SPObject.java
index b186750..ace4c5a 100644
--- a/sharepoint/api/src/main/java/de/muehlencord/shared/sharepoint/api/SPObject.java
+++ b/sharepoint/api/src/main/java/de/muehlencord/shared/sharepoint/api/SPObject.java
@@ -1,14 +1,14 @@
package de.muehlencord.shared.sharepoint.api;
import java.io.StringWriter;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@@ -17,6 +17,8 @@ import org.w3c.dom.Node;
* @author jomu
*/
public abstract class SPObject {
+
+ private final static Logger LOGGER = LoggerFactory.getLogger(SPObject.class.getName());
private SPContext context;
@@ -53,7 +55,7 @@ public abstract class SPObject {
//print the XML
returnString = returnString + xmlString;
} catch (TransformerException ex) {
- Logger.getLogger(SPObject.class.getName()).log(Level.SEVERE, null, ex);
+ LOGGER.error (ex.toString(), ex);
}
return returnString;
}
@@ -83,7 +85,7 @@ public abstract class SPObject {
//print the XML
returnString = returnString + xmlString;
} catch (TransformerException ex) {
- Logger.getLogger(SPObject.class.getName()).log(Level.SEVERE, null, ex);
+ LOGGER.error (ex.toString(), ex);
}
return returnString;
}
diff --git a/sharepoint/api/src/main/java/de/muehlencord/shared/sharepoint/api/SharepointConfig.java b/sharepoint/api/src/main/java/de/muehlencord/shared/sharepoint/api/SharepointConfig.java
new file mode 100644
index 0000000..4e5d79b
--- /dev/null
+++ b/sharepoint/api/src/main/java/de/muehlencord/shared/sharepoint/api/SharepointConfig.java
@@ -0,0 +1,73 @@
+package de.muehlencord.shared.sharepoint.api;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ *
+ * @author joern.muehlencord
+ */
+public class SharepointConfig {
+
+ private Properties properties;
+
+ public void loadFromFile() throws IOException {
+ File configFile = new File(getConfigFile());
+ if (!configFile.exists()) {
+ properties = createDefaultConfig();
+ storeToFile("sample");
+
+ System.out.println(createDefaultConfig());
+ throw new FileNotFoundException("Config file " + configFile.toString() + " not found. Please create it");
+ }
+
+ FileInputStream fin = new FileInputStream(configFile);
+ properties = new Properties();
+ properties.loadFromXML(fin);
+ }
+
+ public void storeToFile() throws IOException {
+ storeToFile(null);
+ }
+
+ public String getProperty(String key) {
+ if (properties.containsKey(key)) {
+ return properties.getProperty(key);
+ } else {
+ return null;
+ }
+ }
+
+ private void storeToFile(String postfix) throws IOException {
+ String configFileName = getConfigFile();
+ if (postfix != null) {
+ configFileName += "." + postfix;
+ }
+ File configFile = new File(configFileName);
+ FileOutputStream fos = new FileOutputStream(configFile);
+ properties.storeToXML(fos, "Example config", "UTF-8");
+ }
+
+ private Properties createDefaultConfig() {
+ Properties p = new Properties();
+ p.put("domainname", "domainname");
+ p.put("username", "username");
+ p.put("password", "password");
+ p.put("sharepointurl", "http://server/path/to/root");
+ p.put("workdir", "workdir");
+
+ return p;
+ }
+
+ private String getConfigFile() {
+ String configPath = System.getProperty("user.home");
+ configPath = (configPath.endsWith(File.separator) ? configPath : configPath + File.separator);
+ configPath += ".wincornixdorf/sharepoint/sharepoint.properties";
+ return configPath;
+ }
+
+}
diff --git a/sharepoint/api/src/main/java/de/muehlencord/shared/sharepoint/api/usergroup/SPUserGroup.java b/sharepoint/api/src/main/java/de/muehlencord/shared/sharepoint/api/usergroup/SPUserGroup.java
index 8d55b19..65bcad7 100644
--- a/sharepoint/api/src/main/java/de/muehlencord/shared/sharepoint/api/usergroup/SPUserGroup.java
+++ b/sharepoint/api/src/main/java/de/muehlencord/shared/sharepoint/api/usergroup/SPUserGroup.java
@@ -59,9 +59,8 @@ public class SPUserGroup extends SPObject {
getUserGroupPort().removeUserFromGroup(groupName, user.getUserLoginName());
} else {
getUserGroupPort().removeUserFromGroup(groupName, "i:0#.w|" + user.getUserLoginName());
- }
+ }
LOGGER.info("User " + user.getUserName() + " removed from group " + groupName);
-
}
public boolean isUserMemberOfGroup(String userLoginName, String groupName) throws NoSuchAlgorithmException, KeyManagementException, MalformedURLException {
@@ -193,11 +192,5 @@ public class SPUserGroup extends SPObject {
}
/* *** unsorted *** */
+
}
-
-/**
- * History:
- *
- * $$Log$$
- *
- */
diff --git a/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/BaseTest.java b/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/BaseTest.java
index a5bfe1d..fbfab91 100644
--- a/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/BaseTest.java
+++ b/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/BaseTest.java
@@ -8,30 +8,42 @@ import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import javax.xml.bind.JAXBException;
-import org.junit.Before;
+import org.junit.BeforeClass;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
*
- * @author jomu
+ * @author joern@muehlencord.de
*/
public abstract class BaseTest {
- protected SPContext context = null;
+ private final static Logger LOGGER = LoggerFactory.getLogger(BaseTest.class.getName());
+ private static SPContext context = null;
- @Before
- public void init() throws MalformedURLException, NoSuchAlgorithmException, KeyManagementException, JAXBException {
- // FIXME - needs to be implemented using mock; replace with real data but make sure password is not commited
- NtlmAuthenticator credentials = null;
- context = null;
- // DO NOT COMMMT THE FOLLOWING LINES
- credentials = new NtlmAuthenticator("wincor-nixdorf.com", "joern.muehlencord", "\"34fR4vbHuL");
- context = new SPContext(new java.net.URL("https://troom.wincor-nixdorf.com/rooms/sw_ps_hq_utrecht/hqall/bd/spwin7/"), credentials, SPVersion.SP2010,
- true);
+ @BeforeClass
+ public static void init() throws MalformedURLException, NoSuchAlgorithmException, KeyManagementException, JAXBException, IOException {
+ SharepointConfig config = new SharepointConfig();
+ config.loadFromFile();
+
+ String domainname = config.getProperty("domainname");
+ String username = config.getProperty("username");
+ String password = config.getProperty("password");
+ String sharepointurl = config.getProperty("sharepointurl");
+ // String workDir = config.getProperty("workdir");
+
+ NtlmAuthenticator credentials = new NtlmAuthenticator(domainname, username, password);
+ context = new SPContext(new java.net.URL(sharepointurl), credentials, SPVersion.SP2010, true);
+ LOGGER.info("Sharepoint context initialized");
+
+ // userGroup = new SPUserGroup(context);
}
-
+
+ public SPContext getContext() {
+ return context;
+ }
+
/**
* reads a file availabe in the test source path and returns its content
*
@@ -55,11 +67,9 @@ public abstract class BaseTest {
sb.append(line);
sb.append("\n");
}
- } catch (UnsupportedEncodingException ex) {
- Logger.getLogger(BaseTest.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (UnsupportedEncodingException ex) {
throw ex;
} catch (IOException ioex) {
- Logger.getLogger(BaseTest.class.getName()).log(Level.SEVERE, null, ioex);
throw ioex;
} finally {
try {
@@ -67,7 +77,7 @@ public abstract class BaseTest {
br.close();
}
} catch (IOException ex) {
- Logger.getLogger(BaseTest.class.getName()).log(Level.SEVERE, null, ex);
+ LOGGER.error (ex.toString(), ex);
}
try {
@@ -75,14 +85,14 @@ public abstract class BaseTest {
irs.close();
}
} catch (IOException ex) {
- Logger.getLogger(BaseTest.class.getName()).log(Level.SEVERE, null, ex);
+ LOGGER.error (ex.toString(), ex);
}
try {
if (is != null) {
is.close();
}
} catch (IOException ex) {
- Logger.getLogger(BaseTest.class.getName()).log(Level.SEVERE, null, ex);
+ LOGGER.error (ex.toString(), ex);
}
}
diff --git a/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/NtlmAuthenticatorTest.java b/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/NtlmAuthenticatorTest.java
index f20ba64..6509b38 100644
--- a/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/NtlmAuthenticatorTest.java
+++ b/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/NtlmAuthenticatorTest.java
@@ -17,7 +17,7 @@ public class NtlmAuthenticatorTest extends BaseTest {
@Test
@Ignore // Depends on available sharepoint currently
public void testAuthentication() throws MalformedURLException, NoSuchAlgorithmException, KeyManagementException {
- SPSite instance = new SPSite(context);
+ SPSite instance = new SPSite(getContext());
// instance.getRootWeb();
}
diff --git a/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/SharepointConfigTest.java b/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/SharepointConfigTest.java
new file mode 100644
index 0000000..28fdbb8
--- /dev/null
+++ b/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/SharepointConfigTest.java
@@ -0,0 +1,22 @@
+
+package de.muehlencord.shared.sharepoint.api;
+
+import de.muehlencord.shared.sharepoint.api.SharepointConfig;
+import org.junit.Test;
+
+/**
+ *
+ * @author joern.muehlencord
+ */
+public class SharepointConfigTest {
+
+ public SharepointConfigTest() {
+ }
+
+ @Test
+ public void testLoadFromFile() throws Exception {
+ SharepointConfig c = new SharepointConfig();
+ c.loadFromFile();
+ }
+
+}
diff --git a/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/lists/SPListTest.java b/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/lists/SPListTest.java
index b2da06d..fa2f040 100644
--- a/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/lists/SPListTest.java
+++ b/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/lists/SPListTest.java
@@ -25,7 +25,7 @@ public class SPListTest extends BaseTest {
@Test
public void testFromXML() throws Exception {
String xmlString = readFileContentFromTest("lists/testlist.xml", "UTF-8");
- SPList list = new SPList(context, "{924883B9-41B7-430C-8206-151786A67319}");
+ SPList list = new SPList(getContext(), "{924883B9-41B7-430C-8206-151786A67319}");
assertNotNull(xmlString);
list.setValue(xmlString);
}
@@ -35,7 +35,7 @@ public class SPListTest extends BaseTest {
public void addListItemByTitle() throws NoSuchAlgorithmException, KeyManagementException, JAXBException, SAXException, ParserConfigurationException,
IOException {
- SPLists instance = new SPLists(context);
+ SPLists instance = new SPLists(getContext());
SPList list = instance.getSpListByTitle("Test");
assertNotNull(list);
String listName = list.getListName();
@@ -61,7 +61,7 @@ public class SPListTest extends BaseTest {
public void addListItemBigList() throws NoSuchAlgorithmException, KeyManagementException, JAXBException, SAXException, ParserConfigurationException,
IOException {
- SPLists instance = new SPLists(context);
+ SPLists instance = new SPLists(getContext());
SPList list = instance.getSpListByTitle("Questionnaire");
assertNotNull(list);
String listName = list.getListName();
@@ -94,7 +94,7 @@ public class SPListTest extends BaseTest {
@Test
@Ignore // Depends on available sharepoint currently
public void testGetListItems() throws Exception {
- SPLists instance = new SPLists(context);
+ SPLists instance = new SPLists(getContext());
SPList list = instance.getSpListByTitle("Questionnaire_Countries");
assertNotNull(list);
java.util.List columns = new ArrayList<>();
@@ -112,7 +112,7 @@ public class SPListTest extends BaseTest {
@Test
@Ignore // Depends on available sharepoint currently
public void testGetListItemsQuery() throws Exception {
- SPLists instance = new SPLists(context);
+ SPLists instance = new SPLists(getContext());
SPList list = instance.getSpListByTitle("Questionnaire_Countries");
assertNotNull(list);
java.util.List columns = new ArrayList<>();
@@ -136,7 +136,7 @@ public class SPListTest extends BaseTest {
@Test
@Ignore // Depends on available sharepoint currently
public void testGetLookupValueMap() throws Exception {
- SPLists instance = new SPLists(context);
+ SPLists instance = new SPLists(getContext());
SPList list = instance.getSpListByTitle("Questionnaire_Countries");
Map lookupValues = list.getLookupValueMap("Title", 0);
System.out.println(lookupValues);
@@ -146,7 +146,7 @@ public class SPListTest extends BaseTest {
@Test
@Ignore // Depends on available sharepoint currently
public void testGetColumnNameByDisplayName() throws Exception {
- SPLists instance = new SPLists(context);
+ SPLists instance = new SPLists(getContext());
SPList list = instance.getSpListByTitle("Questionnaire");
assertEquals("Displayname of Current OS", "Current_x0020_OS", list.getColumnNameByDisplayName("Current OS"));
}
@@ -154,7 +154,7 @@ public class SPListTest extends BaseTest {
@Test
@Ignore // Depends on available sharepoint currently
public void testGetItemCount() throws Exception {
- SPLists instance = new SPLists(context);
+ SPLists instance = new SPLists(getContext());
SPList list = instance.getSpListByTitle("Questionnaire");
assertTrue(list.getItemCount() > 0);
}
diff --git a/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/lists/SPListsTest.java b/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/lists/SPListsTest.java
index 5f3e54f..075def5 100644
--- a/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/lists/SPListsTest.java
+++ b/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/lists/SPListsTest.java
@@ -20,7 +20,7 @@ public class SPListsTest extends BaseTest {
@Test
public void testFromXML() throws IOException, JAXBException, SAXException {
String xmlString = readFileContentFromTest("lists/testlists.xml", "UTF-8");
- SPLists lists = new SPLists(context);
+ SPLists lists = new SPLists(getContext());
lists.setValue (xmlString);
System.out.println(xmlString);
}
@@ -28,7 +28,7 @@ public class SPListsTest extends BaseTest {
@Test
@Ignore // Depends on available sharepoint currently
public void testGetListName() throws Exception {
- SPLists instance = new SPLists(context);
+ SPLists instance = new SPLists(getContext());
String listName = instance.getListNameByTitle("Questionnaire");
assertEquals("Listname", "{4728157C-CFA4-447E-8863-170133FDC351}", listName);
}
diff --git a/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/usergroup/SPUserGroupTest.java b/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/usergroup/SPUserGroupTest.java
index 997e432..7948576 100644
--- a/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/usergroup/SPUserGroupTest.java
+++ b/sharepoint/api/src/test/java/de/muehlencord/shared/sharepoint/api/usergroup/SPUserGroupTest.java
@@ -6,17 +6,22 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Ignore;
import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
*
* @author joern.muehlencord
*/
public class SPUserGroupTest extends BaseTest {
+
+ private final static Logger LOGGER = LoggerFactory.getLogger(SPUserGroupTest.class.getName());
@Test
+ @Ignore
public void testFromXML() throws Exception {
String xmlString = readFileContentFromTest("usergroups/user.xml", "UTF-8");
- SPUser user = new SPUser(context);
+ SPUser user = new SPUser(getContext());
assertNotNull(xmlString);
user.setValue(xmlString);
}
@@ -24,7 +29,7 @@ public class SPUserGroupTest extends BaseTest {
@Test
@Ignore // Depends on available sharepoint currently
public void testGetUserInfo() throws Exception {
- SPUserGroup ug = new SPUserGroup(context);
+ SPUserGroup ug = new SPUserGroup(getContext());
String userId = ug.getUserId("wincor-nixdorf\\joern.muehlencord");
assertEquals("Userid", "16", userId);
}
@@ -32,26 +37,47 @@ public class SPUserGroupTest extends BaseTest {
@Test
@Ignore // Depends on available sharepoint currently
public void testAddUserToGroup() throws Exception {
- SPUserGroup ug = new SPUserGroup(context);
+ SPUserGroup ug = new SPUserGroup(getContext());
ug.addUserToGroup("wincor-nixdorf\\joern.muehlencord", "Test Group");
}
@Test
@Ignore // Depends on available sharepoint currently
public void testIsUserMemberOfGroup() throws Exception {
- SPUserGroup ug = new SPUserGroup(context);
+ SPUserGroup ug = new SPUserGroup(getContext());
boolean result = ug.isUserMemberOfGroup("wincor-nixdorf\\joern.muehlencord", "HQ All Members");
- assertEquals ("HQ All membership", true, result);
+ assertEquals("HQ All membership", true, result);
}
-
+
@Test
@Ignore // Depends on available sharepoint currently
public void getUserLoginNameFromEmail() throws Exception {
- SPUserGroup ug = new SPUserGroup(context);
- SPUser user = ug.getUserFromEmail("joern.muehlencord@wincor-nixdorf.com");
- assertEquals ("UserLogin", "wincor-nixdorf\\joern.muehlencord", user.getUserLoginName());
+ SPUserGroup ug = new SPUserGroup(getContext());
+ SPUser user = ug.getUserFromEmail("joern.muehlencord@wincor-nixdorf.com");
+ assertEquals("UserLogin", "wincor-nixdorf\\joern.muehlencord", user.getUserLoginName());
+ }
+
+ @Test
+ // @Ignore // Depends on available sharepoint currently
+ public void getUserFromEmail() throws Exception {
+ SPUserGroup ug = new SPUserGroup(getContext());
+ String user1Email = "nicole.cravo@wincor-nixdorf.com";
+ SPUser user1 = ug.getUserFromEmail(user1Email);
+ String user2Email = "joern.muehlencord@wincor-nixdorf.com";
+ SPUser user2 = ug.getUserFromEmail(user2Email);
+
+
+ LOGGER.info ("loginName1={}", user1.getUserLoginName());
+ LOGGER.info ("userId1={}", ug.getUserId(user1.getUserLoginName()));
+ LOGGER.info ("loginName2={}", user2.getUserLoginName());
+ LOGGER.info ("userId2={}", ug.getUserId(user2.getUserLoginName()));
+ // String userId1 = ug.getUserId(user1.getUserName());
+ // userId1 = user1.getUserID();
+
+ // SPUser user2 = ug.getUserFromEmail(email);
+ // assertNotNull (user2);
+ // String userId2 = user2.getUserID();
+ // assertEquals("userid", "wincor-nixdorf\\joern.muehlencord", userId2);
}
-
-
}
diff --git a/sharepoint/api/src/test/resources/log4j.xml b/sharepoint/api/src/test/resources/log4j.xml
new file mode 100644
index 0000000..5ca8a78
--- /dev/null
+++ b/sharepoint/api/src/test/resources/log4j.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+