REOC-59 Upgrade the Junit version to 4.12

This commit is contained in:
YuCheng Hu 2019-09-22 10:10:55 -04:00
parent 7d3261ea45
commit 3ef2e82f63
4 changed files with 187 additions and 179 deletions

View File

@ -38,10 +38,13 @@ dependencies {
compile group: 'com.google.guava', name: 'guava', version: '11.0.1' compile group: 'com.google.guava', name: 'guava', version: '11.0.1'
// XML
compile 'jdom:jdom:1.0' compile 'jdom:jdom:1.0'
testCompile 'junit:junit:3.8.1' // TEST
testCompile group: 'junit', name: 'junit', version: '4.12'
// DOCS
docs "com.ossez.docresources:ossez-doc-resources:${docResourcesVersion}@zip" docs "com.ossez.docresources:ossez-doc-resources:${docResourcesVersion}@zip"
} }

View File

@ -29,12 +29,15 @@
<version>1.0</version> <version>1.0</version>
<optional>false</optional> <optional>false</optional>
</dependency> </dependency>
<!-- TEST -->
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>3.8.1</version> <version>4.12</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>log4j</groupId> <groupId>log4j</groupId>
<artifactId>log4j</artifactId> <artifactId>log4j</artifactId>

View File

@ -1,197 +1,200 @@
package com.ossez.reoc.rets.client; package com.ossez.reoc.rets.client;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.InputStream; import java.io.InputStream;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.apache.commons.lang3.StringUtils; /**
import org.apache.commons.lang3.math.NumberUtils; * @author YuCheng Hu
import org.apache.commons.logging.Log; */
import org.apache.commons.logging.LogFactory;
public class LoginResponse extends KeyValueResponse { public class LoginResponse extends KeyValueResponse {
private static final String BROKER_KEY = "Broker"; private static final String BROKER_KEY = "Broker";
private static final String MEMBER_NAME_KEY = "MemberName"; private static final String MEMBER_NAME_KEY = "MemberName";
private static final String METADATA_VER_KEY = "MetadataVersion"; private static final String METADATA_VER_KEY = "MetadataVersion";
private static final String MIN_METADATA_VER_KEY = "MinMetadataVersion"; private static final String MIN_METADATA_VER_KEY = "MinMetadataVersion";
private static final String USER_INFO_KEY = "User"; private static final String USER_INFO_KEY = "User";
private static final String OFFICE_LIST_KEY = "OfficeList"; private static final String OFFICE_LIST_KEY = "OfficeList";
private static final String BALANCE_KEY = "Balance"; private static final String BALANCE_KEY = "Balance";
private static final String TIMEOUT_KEY = "TimeoutSeconds"; private static final String TIMEOUT_KEY = "TimeoutSeconds";
private static final String PWD_EXPIRE_KEY = "Expr"; private static final String PWD_EXPIRE_KEY = "Expr";
private static final String METADATA_TIMESTAMP_KEY = "MetadataTimestamp"; private static final String METADATA_TIMESTAMP_KEY = "MetadataTimestamp";
private static final String MIN_METADATA_TIMESTAMP_KEY = "MinMetadataTimestamp"; private static final String MIN_METADATA_TIMESTAMP_KEY = "MinMetadataTimestamp";
private static final Log LOG = LogFactory.getLog(LoginResponse.class); private static final Log LOG = LogFactory.getLog(LoginResponse.class);
private String sessionId; private String sessionId;
private String memberName; private String memberName;
private String userInformation; private String userInformation;
private String broker; private String broker;
private String metadataVersion; private String metadataVersion;
private String minMetadataVersion; private String minMetadataVersion;
private String metadataTimestamp; private String metadataTimestamp;
private String minMetadataTimestamp; private String minMetadataTimestamp;
private String officeList; private String officeList;
private String balance; private String balance;
private int sessionTimeout; private int sessionTimeout;
private String passwordExpiration; private String passwordExpiration;
private CapabilityUrls capabilityUrls; private CapabilityUrls capabilityUrls;
private Set brokerCodes; private Set brokerCodes;
public LoginResponse(String loginUrl) { public LoginResponse(String loginUrl) {
super(); super();
this.brokerCodes = new HashSet(); this.brokerCodes = new HashSet();
URL url = null; URL url = null;
try { try {
url = new URL(loginUrl); url = new URL(loginUrl);
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
LOG.warn("Bad URL: " + loginUrl); LOG.warn("Bad URL: " + loginUrl);
} }
this.capabilityUrls = new CapabilityUrls(url); this.capabilityUrls = new CapabilityUrls(url);
} }
public LoginResponse() { public LoginResponse() {
super(); super();
this.capabilityUrls = new CapabilityUrls(); this.capabilityUrls = new CapabilityUrls();
} }
@Override @Override
public void parse(InputStream stream, RetsVersion version) throws RetsException { public void parse(InputStream stream, RetsVersion version) throws RetsException {
super.parse(stream, version); super.parse(stream, version);
if (ReplyCode.BROKER_CODE_REQUIRED.equals(this.mReplyCode)) { if (ReplyCode.BROKER_CODE_REQUIRED.equals(this.mReplyCode)) {
throw new BrokerCodeRequredException(this.brokerCodes); throw new BrokerCodeRequredException(this.brokerCodes);
} }
} }
@Override @Override
protected boolean isValidReplyCode(int replyCode) { protected boolean isValidReplyCode(int replyCode) {
return (super.isValidReplyCode(replyCode) || ReplyCode.BROKER_CODE_REQUIRED.equals(replyCode)); return (super.isValidReplyCode(replyCode) || ReplyCode.BROKER_CODE_REQUIRED.equals(replyCode));
} }
@Override @Override
protected void handleKeyValue(String key, String value) throws RetsException { protected void handleKeyValue(String key, String value) throws RetsException {
if (ReplyCode.BROKER_CODE_REQUIRED.equals(this.mReplyCode)) { if (ReplyCode.BROKER_CODE_REQUIRED.equals(this.mReplyCode)) {
if (matchKey(key, BROKER_KEY)) { if (matchKey(key, BROKER_KEY)) {
String[] strings = StringUtils.split(value, ","); String[] strings = StringUtils.split(value, ",");
if (strings.length > 0 && strings.length < 3) { if (strings.length > 0 && strings.length < 3) {
this.brokerCodes.add(strings); this.brokerCodes.add(strings);
} else { } else {
throw new RetsException("Invalid broker/branch code: " + value); throw new RetsException("Invalid broker/branch code: " + value);
} }
} }
} }
if (matchKey(key, BROKER_KEY)) { if (matchKey(key, BROKER_KEY)) {
this.broker = value; this.broker = value;
} else if (matchKey(key, MEMBER_NAME_KEY)) { } else if (matchKey(key, MEMBER_NAME_KEY)) {
this.memberName = value; this.memberName = value;
} else if (matchKey(key, METADATA_VER_KEY)) { } else if (matchKey(key, METADATA_VER_KEY)) {
this.metadataVersion = value; this.metadataVersion = value;
} else if (matchKey(key, MIN_METADATA_VER_KEY)) { } else if (matchKey(key, MIN_METADATA_VER_KEY)) {
this.minMetadataVersion = value; this.minMetadataVersion = value;
} else if (matchKey(key, METADATA_TIMESTAMP_KEY)) { } else if (matchKey(key, METADATA_TIMESTAMP_KEY)) {
this.metadataTimestamp = value; this.metadataTimestamp = value;
} else if (matchKey(key, MIN_METADATA_TIMESTAMP_KEY)) { } else if (matchKey(key, MIN_METADATA_TIMESTAMP_KEY)) {
this.minMetadataTimestamp = value; this.minMetadataTimestamp = value;
} else if (matchKey(key, USER_INFO_KEY)) { } else if (matchKey(key, USER_INFO_KEY)) {
this.userInformation = value; this.userInformation = value;
} else if (matchKey(key, OFFICE_LIST_KEY)) { } else if (matchKey(key, OFFICE_LIST_KEY)) {
this.officeList = value; this.officeList = value;
} else if (matchKey(key, BALANCE_KEY)) { } else if (matchKey(key, BALANCE_KEY)) {
this.balance = value; this.balance = value;
} else if (matchKey(key, TIMEOUT_KEY)) { } else if (matchKey(key, TIMEOUT_KEY)) {
this.sessionTimeout = NumberUtils.toInt(value); this.sessionTimeout = NumberUtils.toInt(value);
} else if (matchKey(key, PWD_EXPIRE_KEY)) { } else if (matchKey(key, PWD_EXPIRE_KEY)) {
this.passwordExpiration = value; this.passwordExpiration = value;
} else if (matchKey(key, CapabilityUrls.ACTION_URL)) { } else if (matchKey(key, CapabilityUrls.ACTION_URL)) {
this.capabilityUrls.setActionUrl(value); this.capabilityUrls.setActionUrl(value);
} else if (matchKey(key, CapabilityUrls.CHANGE_PASSWORD_URL)) { } else if (matchKey(key, CapabilityUrls.CHANGE_PASSWORD_URL)) {
this.capabilityUrls.setChangePasswordUrl(value); this.capabilityUrls.setChangePasswordUrl(value);
} else if (matchKey(key, CapabilityUrls.GET_OBJECT_URL)) { } else if (matchKey(key, CapabilityUrls.GET_OBJECT_URL)) {
this.capabilityUrls.setGetObjectUrl(value); this.capabilityUrls.setGetObjectUrl(value);
} else if (matchKey(key, CapabilityUrls.LOGIN_URL)) { } else if (matchKey(key, CapabilityUrls.LOGIN_URL)) {
this.capabilityUrls.setLoginUrl(value); this.capabilityUrls.setLoginUrl(value);
} else if (matchKey(key, CapabilityUrls.LOGIN_COMPLETE_URL)) { } else if (matchKey(key, CapabilityUrls.LOGIN_COMPLETE_URL)) {
this.capabilityUrls.setLoginCompleteUrl(value); this.capabilityUrls.setLoginCompleteUrl(value);
} else if (matchKey(key, CapabilityUrls.LOGOUT_URL)) { } else if (matchKey(key, CapabilityUrls.LOGOUT_URL)) {
this.capabilityUrls.setLogoutUrl(value); this.capabilityUrls.setLogoutUrl(value);
} else if (matchKey(key, CapabilityUrls.SEARCH_URL)) { } else if (matchKey(key, CapabilityUrls.SEARCH_URL)) {
this.capabilityUrls.setSearchUrl(value); this.capabilityUrls.setSearchUrl(value);
} else if (matchKey(key, CapabilityUrls.GET_METADATA_URL)) { } else if (matchKey(key, CapabilityUrls.GET_METADATA_URL)) {
this.capabilityUrls.setGetMetadataUrl(value); this.capabilityUrls.setGetMetadataUrl(value);
} else if (matchKey(key, CapabilityUrls.UPDATE_URL)) { } else if (matchKey(key, CapabilityUrls.UPDATE_URL)) {
this.capabilityUrls.setUpdateUrl(value); this.capabilityUrls.setUpdateUrl(value);
}else if (matchKey(key, CapabilityUrls.SERVER_INFO_URL)) { } else if (matchKey(key, CapabilityUrls.SERVER_INFO_URL)) {
this.capabilityUrls.setServerInfo(value); this.capabilityUrls.setServerInfo(value);
LOG.warn("Depreciated: " + key + " -> " + value); LOG.warn("Depreciated: " + key + " -> " + value);
} else if (matchKey(key, "Get")) { } else if (matchKey(key, "Get")) {
LOG.warn("Found bad key: Get -> " + value); LOG.warn("Found bad key: Get -> " + value);
// FIX ME: Should not get this // FIX ME: Should not get this
} else { } else {
if (key.substring(0, 2).equalsIgnoreCase("X-")) { if (key.substring(0, 2).equalsIgnoreCase("X-")) {
LOG.warn("Unknown experimental key: " + key + " -> " + value); LOG.warn("Unknown experimental key: " + key + " -> " + value);
} else { } else {
assertStrictWarning(LOG, "Invalid login response key: " + key + " -> " + value); assertStrictWarning(LOG, "Invalid login response key: " + key + " -> " + value);
} }
} }
} }
public String getMemberName() { public String getMemberName() {
return this.memberName; return this.memberName;
} }
public String getUserInformation() { public String getUserInformation() {
return this.userInformation; return this.userInformation;
} }
public String getBroker() { public String getBroker() {
return this.broker; return this.broker;
} }
public String getMetadataVersion() { public String getMetadataVersion() {
return this.metadataVersion; return this.metadataVersion;
} }
public String getMinMetadataVersion() { public String getMinMetadataVersion() {
return this.minMetadataVersion; return this.minMetadataVersion;
} }
public String getMetadataTimestamp() {
return this.metadataTimestamp;
}
public String getMinMetadataTimestamp() { public String getMetadataTimestamp() {
return this.minMetadataTimestamp; return this.metadataTimestamp;
} }
public String getOfficeList() { public String getMinMetadataTimestamp() {
return this.officeList; return this.minMetadataTimestamp;
} }
public String getBalance() { public String getOfficeList() {
return this.balance; return this.officeList;
} }
public int getSessionTimeout() { public String getBalance() {
return this.sessionTimeout; return this.balance;
} }
public String getPasswordExpiration() { public int getSessionTimeout() {
return this.passwordExpiration; return this.sessionTimeout;
} }
public CapabilityUrls getCapabilityUrls() { public String getPasswordExpiration() {
return this.capabilityUrls; return this.passwordExpiration;
} }
public String getSessionId() { public CapabilityUrls getCapabilityUrls() {
return this.sessionId; return this.capabilityUrls;
} }
public void setSessionId(String sessionId) { public String getSessionId() {
this.sessionId = sessionId; return this.sessionId;
} }
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
} }

View File

@ -1,27 +1,26 @@
package com.ossez.reoc.rets.client; package com.ossez.reoc.rets.client;
import java.util.Map;
import java.io.InputStream; import java.io.InputStream;
import java.util.Map;
/** /**
* Interface for retrieving useful header fields from a RETS HTTP response * Interface for retrieving useful header fields from a RETS HTTP response
*
* *
* @author YuCheng Hu
*/ */
public interface RetsHttpResponse { public interface RetsHttpResponse {
public int getResponseCode() throws RetsException; public int getResponseCode() throws RetsException;
public Map getHeaders() throws RetsException; public Map getHeaders() throws RetsException;
public String getHeader(String hdr) throws RetsException; public String getHeader(String hdr) throws RetsException;
public String getCookie(String cookie) throws RetsException; public String getCookie(String cookie) throws RetsException;
public String getCharset() throws RetsException; public String getCharset() throws RetsException;
public InputStream getInputStream() throws RetsException;
public Map getCookies() throws RetsException; public InputStream getInputStream() throws RetsException;
public Map getCookies() throws RetsException;
} }