converted logging to slf4j
This commit is contained in:
@ -259,5 +259,10 @@
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -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;
|
||||
|
||||
@ -18,6 +18,8 @@ import org.w3c.dom.Node;
|
||||
*/
|
||||
public abstract class SPObject {
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(SPObject.class.getName());
|
||||
|
||||
private SPContext context;
|
||||
|
||||
public SPObject(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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -61,7 +61,6 @@ public class SPUserGroup extends SPObject {
|
||||
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$$
|
||||
*
|
||||
*/
|
||||
}
|
||||
|
||||
@ -8,28 +8,40 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,10 +68,8 @@ public abstract class BaseTest {
|
||||
sb.append("\n");
|
||||
}
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
Logger.getLogger(BaseTest.class.getName()).log(Level.SEVERE, null, 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@ -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<String> 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<String> 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<String, String> 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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -6,6 +6,8 @@ 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;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -13,10 +15,13 @@ import org.junit.Test;
|
||||
*/
|
||||
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,14 +37,14 @@ 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);
|
||||
}
|
||||
@ -47,11 +52,32 @@ public class SPUserGroupTest extends BaseTest {
|
||||
@Test
|
||||
@Ignore // Depends on available sharepoint currently
|
||||
public void getUserLoginNameFromEmail() throws Exception {
|
||||
SPUserGroup ug = new SPUserGroup(context);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
25
sharepoint/api/src/test/resources/log4j.xml
Normal file
25
sharepoint/api/src/test/resources/log4j.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
|
||||
debug="true">
|
||||
|
||||
<appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%d{ISO8601} %-5p [%c] %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<category name="de.muehlencord">
|
||||
<priority value="TRACE"/>
|
||||
</category>
|
||||
|
||||
<category name="com.wincornixdorf">
|
||||
<priority value="DEBUG"/>
|
||||
</category>
|
||||
|
||||
<root>
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="consoleAppender" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
||||
Reference in New Issue
Block a user