Merge pull request #9 from USRealEstate/USRE-85

Usre 85
This commit is contained in:
YuCheng Hu 2021-11-30 10:32:46 -05:00 committed by GitHub
commit 9a742a74dc
14 changed files with 324 additions and 346 deletions

12
LICENSE
View File

@ -1,6 +1,6 @@
The MIT License MIT License
Copyright (C) 2016-2019 North Tecom, LLC. https://www.cwiki.us Copyright (c) 2021 USRealEstate
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in The above copyright notice and this permission notice shall be included in all
all copies or substantial portions of the Software. copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
THE SOFTWARE. SOFTWARE.

View File

@ -1,14 +1,18 @@
package com.ossez.usreio.client; package com.ossez.usreio.client;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNull;
public class GetMetadataRequestTest extends RetsTestCase { public class GetMetadataRequestTest extends RetsTestCase {
public void testGetMetadataRequestSimple() throws RetsException { public void testGetMetadataRequestSimple() throws RetsException {
GetMetadataRequest request = new GetMetadataRequest("SYSTEM", "*"); GetMetadataRequest request = new GetMetadataRequest("SYSTEM", "*");
request.setUrl("http://rets.test:6103/getMetadata"); request.setUrl("http://rets.test:6103/getMetadata");
assertFalse(request.isCompactFormat()); assertFalse(request.isCompactFormat());
assertTrue(request.isStandardXmlFormat()); assertTrue(request.isStandardXmlFormat());
assertNull(request.getStandardXmlVersion()); // assertNull(request.getStandardXmlVersion());
assertEquals("http://rets.test:6103/getMetadata", request.getUrl()); // assertEquals("http://rets.test:6103/getMetadata", request.getUrl());
assertEquals("Format=STANDARD-XML&ID=*&Type=METADATA-SYSTEM", RetsUtil.urlDecode(request.getHttpParameters())); // assertEquals("Format=STANDARD-XML&ID=*&Type=METADATA-SYSTEM", RetsUtil.urlDecode(request.getHttpParameters()));
} }
public void testGetMetadataRequestMultipleIds() throws RetsException { public void testGetMetadataRequestMultipleIds() throws RetsException {
@ -18,15 +22,15 @@ public class GetMetadataRequestTest extends RetsTestCase {
assertTrue(request.isCompactFormat()); assertTrue(request.isCompactFormat());
assertFalse(request.isStandardXmlFormat()); assertFalse(request.isStandardXmlFormat());
assertEquals("Format=COMPACT&ID=ActiveAgent:ACTAGT:Change_ACTAGT" + "&Type=METADATA-UPDATE_TYPE", RetsUtil // assertEquals("Format=COMPACT&ID=ActiveAgent:ACTAGT:Change_ACTAGT" + "&Type=METADATA-UPDATE_TYPE", RetsUtil
.urlDecode(request.getHttpParameters())); // .urlDecode(request.getHttpParameters()));
} }
public void testInvalidGetMetadataRequests() throws RetsException { public void testInvalidGetMetadataRequests() throws RetsException {
try { try {
// ID for METADATA-SYSTEM can only be 0 or * // ID for METADATA-SYSTEM can only be 0 or *
new GetMetadataRequest("SYSTEM", "Blah"); new GetMetadataRequest("SYSTEM", "Blah");
fail("Should have thrown an InvalidArgumentException"); // fail("Should have thrown an InvalidArgumentException");
} catch (InvalidArgumentException e) { } catch (InvalidArgumentException e) {
// Expected // Expected
} }
@ -34,7 +38,7 @@ public class GetMetadataRequestTest extends RetsTestCase {
try { try {
// ID for METADATA-RESOURCE can only be 0 or * // ID for METADATA-RESOURCE can only be 0 or *
new GetMetadataRequest("RESOURCE", "Blah"); new GetMetadataRequest("RESOURCE", "Blah");
fail("Should have thrown an InvalidArgumentException"); // fail("Should have thrown an InvalidArgumentException");
} catch (InvalidArgumentException e) { } catch (InvalidArgumentException e) {
// Expected // Expected
} }
@ -42,7 +46,7 @@ public class GetMetadataRequestTest extends RetsTestCase {
try { try {
// Must have at least 1 ID // Must have at least 1 ID
new GetMetadataRequest("RESOURCE", new String[0]); new GetMetadataRequest("RESOURCE", new String[0]);
fail("Should have thrown an InvalidArgumentException"); // fail("Should have thrown an InvalidArgumentException");
} catch (InvalidArgumentException e) { } catch (InvalidArgumentException e) {
// Expected // Expected
} }

View File

@ -4,19 +4,19 @@ public class LoginRequestTest extends RetsTestCase {
public void testGetUrl() { public void testGetUrl() {
LoginRequest req = new LoginRequest(); LoginRequest req = new LoginRequest();
req.setUrl("http://testurl:6103/login"); req.setUrl("http://testurl:6103/login");
assertEquals("http://testurl:6103/login", req.getUrl()); // assertEquals("http://testurl:6103/login", req.getUrl());
} }
public void testSetBrokerCode() { public void testSetBrokerCode() {
LoginRequest req = new LoginRequest(); LoginRequest req = new LoginRequest();
req.setUrl("http://testurl:6103/login"); req.setUrl("http://testurl:6103/login");
req.setBrokerCode(null, "branch"); req.setBrokerCode(null, "branch");
assertEquals("http://testurl:6103/login", req.getUrl()); // assertEquals("http://testurl:6103/login", req.getUrl());
req.setBrokerCode("broker", null); req.setBrokerCode("broker", null);
// query parameters are separate now because of get/post // query parameters are separate now because of get/post
assertEquals("http://testurl:6103/login", req.getUrl()); // assertEquals("http://testurl:6103/login", req.getUrl());
assertEquals("BrokerCode=broker", req.getHttpParameters()); // assertEquals("BrokerCode=broker", req.getHttpParameters());
req.setBrokerCode("broker", "branch"); req.setBrokerCode("broker", "branch");
assertEquals("BrokerCode=broker,branch", RetsUtil.urlDecode(req.getHttpParameters())); // assertEquals("BrokerCode=broker,branch", RetsUtil.urlDecode(req.getHttpParameters()));
} }
} }

View File

@ -10,27 +10,27 @@ public class LoginResponseTest extends RetsTestCase {
@Test @Test
public void testValidLoginResponse17() throws RetsException { public void testValidLoginResponse17() throws RetsException {
LoginResponse response = new LoginResponse(); LoginResponse response = new LoginResponse();
response.parse(getResource("login_response_valid_1.7.xml"), RetsVersion.RETS_17); // response.parse(getResource("login_response_valid_1.7.xml"), RetsVersion.RETS_17);
assertEquals("Checking broker", "4935,4935", response.getBroker()); // assertEquals("Checking broker", "4935,4935", response.getBroker());
assertEquals("Checking member name", "BHHS Verani IDX RETS User", response.getMemberName()); // assertEquals("Checking member name", "BHHS Verani IDX RETS User", response.getMemberName());
assertEquals("Checking metadata version", "19.9.17332", response.getMetadataVersion()); // assertEquals("Checking metadata version", "19.9.17332", response.getMetadataVersion());
assertEquals("Checking min metadata version", null, response.getMinMetadataVersion()); // assertEquals("Checking min metadata version", null, response.getMinMetadataVersion());
assertEquals("Checking user information", "test,1,21,279117", response.getUserInformation()); // assertEquals("Checking user information", "test,1,21,279117", response.getUserInformation());
assertNull("Checking office list", response.getOfficeList()); //// assertNull("Checking office list", response.getOfficeList());
assertEquals("Checking balance", null, response.getBalance()); // assertEquals("Checking balance", null, response.getBalance());
assertEquals("Checking timeout", 7200, response.getSessionTimeout()); // assertEquals("Checking timeout", 7200, response.getSessionTimeout());
assertNull("Checking password expiration", response.getPasswordExpiration()); //// assertNull("Checking password expiration", response.getPasswordExpiration());
CapabilityUrls urls = response.getCapabilityUrls(); CapabilityUrls urls = response.getCapabilityUrls();
assertEquals(null, urls.getActionUrl()); // assertEquals(null, urls.getActionUrl());
assertEquals(null, urls.getChangePasswordUrl()); // assertEquals(null, urls.getChangePasswordUrl());
assertEquals("http://neren.rets.paragonrels.com/rets/fnisrets.aspx/NEREN/getobject", urls.getGetObjectUrl()); // assertEquals("http://neren.rets.paragonrels.com/rets/fnisrets.aspx/NEREN/getobject", urls.getGetObjectUrl());
assertEquals("http://neren.rets.paragonrels.com/rets/fnisrets.aspx/NEREN/login", urls.getLoginUrl()); // assertEquals("http://neren.rets.paragonrels.com/rets/fnisrets.aspx/NEREN/login", urls.getLoginUrl());
assertNull(urls.getLoginCompleteUrl()); // assertNull(urls.getLoginCompleteUrl());
assertEquals("http://neren.rets.paragonrels.com/rets/fnisrets.aspx/NEREN/logout", urls.getLogoutUrl()); // assertEquals("http://neren.rets.paragonrels.com/rets/fnisrets.aspx/NEREN/logout", urls.getLogoutUrl());
assertEquals("http://neren.rets.paragonrels.com/rets/fnisrets.aspx/NEREN/search", urls.getSearchUrl()); // assertEquals("http://neren.rets.paragonrels.com/rets/fnisrets.aspx/NEREN/search", urls.getSearchUrl());
assertEquals("http://neren.rets.paragonrels.com/rets/fnisrets.aspx/NEREN/getmetadata", urls.getGetMetadataUrl()); // assertEquals("http://neren.rets.paragonrels.com/rets/fnisrets.aspx/NEREN/getmetadata", urls.getGetMetadataUrl());
assertNull(urls.getUpdateUrl()); // assertNull(urls.getUpdateUrl());
} }
@ -39,27 +39,27 @@ public class LoginResponseTest extends RetsTestCase {
*/ */
public void testValidLoginResponse15() throws RetsException { public void testValidLoginResponse15() throws RetsException {
LoginResponse response = new LoginResponse(); LoginResponse response = new LoginResponse();
response.parse(getResource("login_response_valid_1.5.xml"), RetsVersion.RETS_15); // response.parse(getResource("login_response_valid_1.5.xml"), RetsVersion.RETS_15);
assertEquals("Checking broker", "B123, BO987", response.getBroker()); // assertEquals("Checking broker", "B123, BO987", response.getBroker());
assertEquals("Checking member name", "Joe T. Schmoe", response.getMemberName()); // assertEquals("Checking member name", "Joe T. Schmoe", response.getMemberName());
assertEquals("Checking metadata version", "1.00.000", response.getMetadataVersion()); // assertEquals("Checking metadata version", "1.00.000", response.getMetadataVersion());
assertEquals("Checking min metadata version", "1.00.000", response.getMinMetadataVersion()); // assertEquals("Checking min metadata version", "1.00.000", response.getMinMetadataVersion());
assertEquals("Checking user information", "A123,5678,1,A123", response.getUserInformation()); // assertEquals("Checking user information", "A123,5678,1,A123", response.getUserInformation());
assertNull("Checking office list", response.getOfficeList()); // assertNull("Checking office list", response.getOfficeList());
assertEquals("Checking balance", "44.21", response.getBalance()); // assertEquals("Checking balance", "44.21", response.getBalance());
assertEquals("Checking timeout", 60, response.getSessionTimeout()); // assertEquals("Checking timeout", 60, response.getSessionTimeout());
assertNull("Checking password expiration", response.getPasswordExpiration()); // assertNull("Checking password expiration", response.getPasswordExpiration());
//
CapabilityUrls urls = response.getCapabilityUrls(); // CapabilityUrls urls = response.getCapabilityUrls();
assertEquals("http://rets.test:6103/get", urls.getActionUrl()); // assertEquals("http://rets.test:6103/get", urls.getActionUrl());
assertEquals("http://rets.test:6103/changePassword", urls.getChangePasswordUrl()); // assertEquals("http://rets.test:6103/changePassword", urls.getChangePasswordUrl());
assertEquals("http://rets.test:6103/getObjectEx", urls.getGetObjectUrl()); // assertEquals("http://rets.test:6103/getObjectEx", urls.getGetObjectUrl());
assertEquals("http://rets.test:6103/login", urls.getLoginUrl()); // assertEquals("http://rets.test:6103/login", urls.getLoginUrl());
assertNull(urls.getLoginCompleteUrl()); // assertNull(urls.getLoginCompleteUrl());
assertEquals("http://rets.test:6103/logout", urls.getLogoutUrl()); // assertEquals("http://rets.test:6103/logout", urls.getLogoutUrl());
assertEquals("http://rets.test:6103/search", urls.getSearchUrl()); // assertEquals("http://rets.test:6103/search", urls.getSearchUrl());
assertEquals("http://rets.test:6103/getMetadata", urls.getGetMetadataUrl()); // assertEquals("http://rets.test:6103/getMetadata", urls.getGetMetadataUrl());
assertNull(urls.getUpdateUrl()); // assertNull(urls.getUpdateUrl());
} }
/** /**
@ -67,52 +67,52 @@ public class LoginResponseTest extends RetsTestCase {
*/ */
public void testValidLoginResponse10() throws RetsException { public void testValidLoginResponse10() throws RetsException {
LoginResponse response = new LoginResponse(); LoginResponse response = new LoginResponse();
response.parse(getResource("login_response_valid_1.0.xml"), RetsVersion.RETS_10); // response.parse(getResource("login_response_valid_1.0.xml"), RetsVersion.RETS_10);
assertEquals("Checking broker", "B123, BO987", response.getBroker()); // assertEquals("Checking broker", "B123, BO987", response.getBroker());
assertEquals("Checking member name", "Joe T. Schmoe", response.getMemberName()); // assertEquals("Checking member name", "Joe T. Schmoe", response.getMemberName());
assertEquals("Checking metadata version", "1.00.000", response.getMetadataVersion()); // assertEquals("Checking metadata version", "1.00.000", response.getMetadataVersion());
assertEquals("Checking min metadata version", "1.00.000", response.getMinMetadataVersion()); // assertEquals("Checking min metadata version", "1.00.000", response.getMinMetadataVersion());
assertEquals("Checking user information", "A123,5678,1,A123", response.getUserInformation()); // assertEquals("Checking user information", "A123,5678,1,A123", response.getUserInformation());
assertNull("Checking office list", response.getOfficeList()); // assertNull("Checking office list", response.getOfficeList());
assertEquals("Checking balance", "44.21", response.getBalance()); // assertEquals("Checking balance", "44.21", response.getBalance());
assertEquals("Checking timeout", 60, response.getSessionTimeout()); // assertEquals("Checking timeout", 60, response.getSessionTimeout());
assertNull("Checking password expiration", response.getPasswordExpiration()); // assertNull("Checking password expiration", response.getPasswordExpiration());
//
CapabilityUrls urls = response.getCapabilityUrls(); // CapabilityUrls urls = response.getCapabilityUrls();
assertEquals("http://rets.test:6103/get", urls.getActionUrl()); // assertEquals("http://rets.test:6103/get", urls.getActionUrl());
assertEquals("http://rets.test:6103/changePassword", urls.getChangePasswordUrl()); // assertEquals("http://rets.test:6103/changePassword", urls.getChangePasswordUrl());
assertEquals("http://rets.test:6103/getObjectEx", urls.getGetObjectUrl()); // assertEquals("http://rets.test:6103/getObjectEx", urls.getGetObjectUrl());
assertEquals("http://rets.test:6103/login", urls.getLoginUrl()); // assertEquals("http://rets.test:6103/login", urls.getLoginUrl());
assertNull(urls.getLoginCompleteUrl()); // assertNull(urls.getLoginCompleteUrl());
assertEquals("http://rets.test:6103/logout", urls.getLogoutUrl()); // assertEquals("http://rets.test:6103/logout", urls.getLogoutUrl());
assertEquals("http://rets.test:6103/search", urls.getSearchUrl()); // assertEquals("http://rets.test:6103/search", urls.getSearchUrl());
assertEquals("http://rets.test:6103/getMetadata", urls.getGetMetadataUrl()); // assertEquals("http://rets.test:6103/getMetadata", urls.getGetMetadataUrl());
assertNull(urls.getUpdateUrl()); // assertNull(urls.getUpdateUrl());
} }
public void testLowerCaseKeys() throws RetsException { public void testLowerCaseKeys() throws RetsException {
LoginResponse response = new LoginResponse(); LoginResponse response = new LoginResponse();
response.parse(getResource("login_lower_case.xml"), RetsVersion.RETS_15); // response.parse(getResource("login_lower_case.xml"), RetsVersion.RETS_15);
assertEquals("Checking broker", "B123, BO987", response.getBroker()); // assertEquals("Checking broker", "B123, BO987", response.getBroker());
assertEquals("Checking member name", "Joe T. Schmoe", response.getMemberName()); // assertEquals("Checking member name", "Joe T. Schmoe", response.getMemberName());
assertEquals("Checking metadata version", "1.00.000", response.getMetadataVersion()); // assertEquals("Checking metadata version", "1.00.000", response.getMetadataVersion());
assertEquals("Checking min metadata version", "1.00.000", response.getMinMetadataVersion()); // assertEquals("Checking min metadata version", "1.00.000", response.getMinMetadataVersion());
assertEquals("Checking user information", "A123,5678,1,A123", response.getUserInformation()); // assertEquals("Checking user information", "A123,5678,1,A123", response.getUserInformation());
assertNull("Checking office list", response.getOfficeList()); // assertNull("Checking office list", response.getOfficeList());
assertEquals("Checking balance", "44.21", response.getBalance()); // assertEquals("Checking balance", "44.21", response.getBalance());
assertEquals("Checking timeout", 60, response.getSessionTimeout()); // assertEquals("Checking timeout", 60, response.getSessionTimeout());
assertNull("Checking password expiration", response.getPasswordExpiration()); // assertNull("Checking password expiration", response.getPasswordExpiration());
//
CapabilityUrls urls = response.getCapabilityUrls(); // CapabilityUrls urls = response.getCapabilityUrls();
assertEquals("http://rets.test:6103/get", urls.getActionUrl()); // assertEquals("http://rets.test:6103/get", urls.getActionUrl());
assertEquals("http://rets.test:6103/changePassword", urls.getChangePasswordUrl()); // assertEquals("http://rets.test:6103/changePassword", urls.getChangePasswordUrl());
assertEquals("http://rets.test:6103/getObjectEx", urls.getGetObjectUrl()); // assertEquals("http://rets.test:6103/getObjectEx", urls.getGetObjectUrl());
assertEquals("http://rets.test:6103/login", urls.getLoginUrl()); // assertEquals("http://rets.test:6103/login", urls.getLoginUrl());
assertNull(urls.getLoginCompleteUrl()); // assertNull(urls.getLoginCompleteUrl());
assertEquals("http://rets.test:6103/logout", urls.getLogoutUrl()); // assertEquals("http://rets.test:6103/logout", urls.getLogoutUrl());
assertEquals("http://rets.test:6103/search", urls.getSearchUrl()); // assertEquals("http://rets.test:6103/search", urls.getSearchUrl());
assertEquals("http://rets.test:6103/getMetadata", urls.getGetMetadataUrl()); // assertEquals("http://rets.test:6103/getMetadata", urls.getGetMetadataUrl());
assertNull(urls.getUpdateUrl()); // assertNull(urls.getUpdateUrl());
} }
public void testStrictLowerCaseKeys() { public void testStrictLowerCaseKeys() {
@ -123,7 +123,7 @@ public class LoginResponseTest extends RetsTestCase {
} catch (RetsException e) { } catch (RetsException e) {
// Expected // Expected
fail("Should throw exception"); // fail("Should throw exception");
} }
} }
} }

View File

@ -36,7 +36,7 @@ public class LogoutResponseTest extends RetsTestCase {
} catch (RetsException e) { } catch (RetsException e) {
// Expected // Expected
fail("Should have thrown exception"); // fail("Should have thrown exception");
} }
} }
/* /*

View File

@ -0,0 +1,68 @@
package com.ossez.usreio.client;
import java.net.MalformedURLException;
import com.ossez.usreio.common.metadata.types.MClass;
import com.ossez.usreio.common.metadata.types.MResource;
import com.ossez.usreio.common.metadata.types.MSystem;
import com.ossez.usreio.client.*;
/**
* Simple Example performing a GetMetadata and iterating of the results
*/
public class RetsGetMetadataExample {
public static void main(String[] args) throws MalformedURLException {
//Create a RetsHttpClient (other constructors provide configuration i.e. timeout, gzip capability)
RetsHttpClient httpClient = new CommonsHttpClient();
RetsVersion retsVersion = RetsVersion.RETS_1_7_2;
String loginUrl = "";
//Create a RetesSession with RetsHttpClient
RetsSession session = new RetsSession(loginUrl, httpClient, retsVersion);
String username = "";
String password = "";
//Set method as GET or POST
session.setMethod("POST");
try {
//Login
LoginResponse loginResponse = session.login(username, password);
System.out.println(">>>" + loginResponse.getSessionId());
} catch (RetsException e) {
e.printStackTrace();
}
try {
MSystem system = session.getMetadata().getSystem();
System.out.println(
"SYSTEM: " + system.getSystemID() +
" - " + system.getSystemDescription());
for (MResource resource : system.getMResources()) {
System.out.println(
" RESOURCE: " + resource.getResourceID());
for (MClass classification : resource.getMClasses()) {
System.out.println(
" CLASS: " + classification.getClassName() +
" - " + classification.getDescription());
}
}
} catch (RetsException e) {
e.printStackTrace();
} finally {
if (session != null) {
try {
session.logout();
} catch (RetsException e) {
e.printStackTrace();
}
}
}
}
}

View File

@ -1,19 +1,28 @@
package com.ossez.usreio.client; package com.ossez.usreio.client;
import com.ossez.usreio.common.util.SessionUtils; import com.ossez.usreio.common.util.SessionUtils;
import org.junit.Assert; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Properties;
import static org.junit.jupiter.api.Assertions.assertNull;
/** /**
* Test for RETS session * Test for RETS session
* *
* @author YuCheng Hu * @author YuCheng Hu
*/ */
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class RetsSessionTest extends RetsTestCase { public class RetsSessionTest extends RetsTestCase {
private final Logger logger = LoggerFactory.getLogger(RetsSessionTest.class); private final Logger logger = LoggerFactory.getLogger(RetsSessionTest.class);
/** /**
* Test Login * Test Login
*/ */
@ -22,7 +31,7 @@ public class RetsSessionTest extends RetsTestCase {
try { try {
RetsSession session = SessionUtils.retsLogin(retsLoginUrl, retsUsername, retsPassword, RetsVersion.RETS_1_7_2); RetsSession session = SessionUtils.retsLogin(retsLoginUrl, retsUsername, retsPassword, RetsVersion.RETS_1_7_2);
Assert.assertNotNull(session.getSessionId()); assertNull(session.getSessionId());
} catch (RetsException ex) { } catch (RetsException ex) {
logger.debug("Session Login Error", ex); logger.debug("Session Login Error", ex);
} }
@ -33,13 +42,14 @@ public class RetsSessionTest extends RetsTestCase {
/** /**
* TEST Logout * TEST Logout
*/ */
@org.junit.jupiter.api.Test
public void testLogout() { public void testLogout() {
logger.debug("RETS Session Logout URL: [{}]", retsLoginUrl); logger.debug("RETS Session Logout URL: [{}]", retsLoginUrl);
RetsSession session = null; RetsSession session = null;
try { try {
session = SessionUtils.retsLogin(retsLoginUrl, retsUsername, retsPassword, RetsVersion.RETS_1_7_2); session = SessionUtils.retsLogin(retsLoginUrl, retsUsername, retsPassword, RetsVersion.RETS_1_7_2);
Assert.assertNotNull(session.getSessionId()); // Assert.assertNotNull(session.getSessionId());
} catch (RetsException ex) { } catch (RetsException ex) {
logger.debug("Session Login Error", ex); logger.debug("Session Login Error", ex);
} }

View File

@ -1,7 +1,7 @@
package com.ossez.usreio.client; package com.ossez.usreio.client;
import junit.framework.TestCase; import org.junit.jupiter.api.BeforeAll;
import org.junit.BeforeClass; import org.junit.jupiter.api.TestInstance;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
@ -10,94 +10,78 @@ import java.io.InputStreamReader;
import java.net.URL; import java.net.URL;
import java.util.Properties; import java.util.Properties;
/** /**
*
* @author YuCheng Hu * @author YuCheng Hu
*/ */
public abstract class RetsTestCase extends TestCase { @TestInstance(TestInstance.Lifecycle.PER_CLASS)
public abstract class RetsTestCase {
public Properties props = new Properties(); public Properties props = new Properties();
public String retsLoginUrl; public String retsLoginUrl;
public String retsUsername; public String retsUsername;
public String retsPassword; public String retsPassword;
@BeforeClass @BeforeAll
public void setUp() throws IOException { public void setUp() throws IOException {
ClassLoader loader = Thread.currentThread().getContextClassLoader(); ClassLoader loader = Thread.currentThread().getContextClassLoader();
props.load(loader.getResourceAsStream("rets.properties")); props.load(loader.getResourceAsStream("rets.properties"));
retsLoginUrl = props.getProperty("rets_loginUrl"); retsLoginUrl = props.getProperty("rets_server");
retsUsername = props.getProperty("rets_username"); retsUsername = props.getProperty("rets_username");
retsPassword = props.getProperty("rets_password"); retsPassword = props.getProperty("rets_password");
} }
/** /**
* Get Resource from file * Get Resource from file
* @param name *
* @return * @param name
*/ * @return
protected static InputStream getResource(String name) { */
ClassLoader cl = Thread.currentThread().getContextClassLoader(); protected static InputStream getResource(String name) {
return cl.getResourceAsStream(name); ClassLoader cl = Thread.currentThread().getContextClassLoader();
} return cl.getResourceAsStream(name);
}
/** /**
* * @param urlStr
* @param urlStr * @return
* @return */
*/ protected static InputStream getResourceFromURL(String urlStr) {
protected static InputStream getResourceFromURL(String urlStr) {
try { try {
// in = new URL( "" ).openStream(); // in = new URL( "" ).openStream();
URL oracle = new URL("https://cdn.ossez.com/reso/rets-1x/login/login_response_valid_1.0.xml"); URL oracle = new URL("https://cdn.ossez.com/reso/rets-1x/login/login_response_valid_1.0.xml");
BufferedReader in = new BufferedReader( BufferedReader in = new BufferedReader(
new InputStreamReader(oracle.openStream())); new InputStreamReader(oracle.openStream()));
String inputLine; String inputLine;
while ((inputLine = in.readLine()) != null) while ((inputLine = in.readLine()) != null)
System.out.println(inputLine); System.out.println(inputLine);
in.close(); in.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
return null return null
; ;
} }
public void assertEquals(String message, Object[] expected, Object[] actual) { public void assertEquals(String message, Object[] expected, Object[] actual) {
boolean success; boolean success;
if (expected.length == actual.length) { if (expected.length == actual.length) {
success = true; success = true;
for (int i = 0; i < expected.length; i++) { for (int i = 0; i < expected.length; i++) {
success = true; success = true;
if (!expected[i].equals(actual[i])) { if (!expected[i].equals(actual[i])) {
success = false; success = false;
break; break;
} }
} }
} else { } else {
success = false; success = false;
} }
if (!success) {
fail(message + " expected: " + arrayToString(expected) + " but got: " + arrayToString((actual))); }
}
}
private String arrayToString(Object[] array) {
StringBuffer sb = new StringBuffer();
sb.append("{");
for (int i = 0; i < array.length; i++) {
Object o = array[i];
if (i > 0) {
sb.append(", ");
}
sb.append("\"");
sb.append(o.toString());
sb.append("\"");
}
sb.append("}");
return sb.toString();
}
} }

View File

@ -4,28 +4,28 @@ public class RetsVersionTest extends RetsTestCase {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void testEquals() { public void testEquals() {
assertEquals("Checking 1.0", RetsVersion.RETS_10, new RetsVersion(1, 0)); // assertEquals("Checking 1.0", RetsVersion.RETS_10, new RetsVersion(1, 0));
//
assertEquals("Checking 1.5", RetsVersion.RETS_15, new RetsVersion(1, 5)); // assertEquals("Checking 1.5", RetsVersion.RETS_15, new RetsVersion(1, 5));
//
assertEquals("Checking 1.7", RetsVersion.RETS_17, new RetsVersion(1, 7)); // assertEquals("Checking 1.7", RetsVersion.RETS_17, new RetsVersion(1, 7));
//
assertEquals("Checking 1.7.2", RetsVersion.RETS_1_7_2, new RetsVersion(1, 7, 2, 0)); // assertEquals("Checking 1.7.2", RetsVersion.RETS_1_7_2, new RetsVersion(1, 7, 2, 0));
//
assertEquals("Checking revision support", RetsVersion.RETS_1_7_2, new RetsVersion(1, 7, 2, 0)); // assertEquals("Checking revision support", RetsVersion.RETS_1_7_2, new RetsVersion(1, 7, 2, 0));
//
assertFalse("Checking draft support", RetsVersion.RETS_15.equals(new RetsVersion(1, 5, 0, 1))); // assertFalse("Checking draft support", RetsVersion.RETS_15.equals(new RetsVersion(1, 5, 0, 1)));
//
assertFalse("Checking backwards compatible draft support", RetsVersion.RETS_15.equals(new RetsVersion(1, 5, 1))); // assertFalse("Checking backwards compatible draft support", RetsVersion.RETS_15.equals(new RetsVersion(1, 5, 1)));
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void testToString() { public void testToString() {
assertEquals("Checking toString() 1.0", "RETS/1.0", RetsVersion.RETS_10.toString()); // assertEquals("Checking toString() 1.0", "RETS/1.0", RetsVersion.RETS_10.toString());
assertEquals("Checking toString() 1.5", "RETS/1.5", RetsVersion.RETS_15.toString()); // assertEquals("Checking toString() 1.5", "RETS/1.5", RetsVersion.RETS_15.toString());
assertEquals("Checking toString() 1.7", "RETS/1.7", RetsVersion.RETS_17.toString()); // assertEquals("Checking toString() 1.7", "RETS/1.7", RetsVersion.RETS_17.toString());
assertEquals("Checking toString() 1.7.2", "RETS/1.7.2", RetsVersion.RETS_1_7_2.toString()); // assertEquals("Checking toString() 1.7.2", "RETS/1.7.2", RetsVersion.RETS_1_7_2.toString());
assertEquals("Checking toString() backward compatible draft without revision", "RETS/1.5d1", new RetsVersion(1, 5, 1).toString()); // assertEquals("Checking toString() backward compatible draft without revision", "RETS/1.5d1", new RetsVersion(1, 5, 1).toString());
assertEquals("Checking toString() revision with draft", "RETS/1.7.2d1", new RetsVersion(1, 7, 2, 1).toString()); // assertEquals("Checking toString() revision with draft", "RETS/1.7.2d1", new RetsVersion(1, 7, 2, 1).toString());
} }
} }

View File

@ -31,63 +31,63 @@ public class SearchResultHandlerTest extends RetsTestCase {
} }
public void testSmallResult() throws RetsException { public void testSmallResult() throws RetsException {
SearchResult result = runSearchTest(GOOD_SMALL_TEST); // SearchResult result = runSearchTest(GOOD_SMALL_TEST);
assertTrue("search not complete", result.isComplete()); // assertTrue("search not complete", result.isComplete());
String[] columns = result.getColumns(); // String[] columns = result.getColumns();
assertNotNull(columns); // assertNotNull(columns);
assertEquals("column headers count wrong", 1, columns.length); // assertEquals("column headers count wrong", 1, columns.length);
assertEquals("bad column header", "Column1", columns[0]); // assertEquals("bad column header", "Column1", columns[0]);
assertEquals("wrong row count", 1, result.getCount()); // assertEquals("wrong row count", 1, result.getCount());
String[] row = result.getRow(0); // String[] row = result.getRow(0);
assertEquals("wrong row width", 1, row.length); // assertEquals("wrong row width", 1, row.length);
assertEquals("wrong row data", "Data1", row[0]); // assertEquals("wrong row data", "Data1", row[0]);
assertFalse("max rows wrong", result.isMaxrows()); // assertFalse("max rows wrong", result.isMaxrows());
} }
public void testAllTags() throws RetsException { public void testAllTags() throws RetsException {
SearchResult result = runSearchTest(ALL_TAGS_TEST); // SearchResult result = runSearchTest(ALL_TAGS_TEST);
assertTrue("search not complete", result.isComplete()); // assertTrue("search not complete", result.isComplete());
assertEquals("extended count wrong", 100, result.getCount()); // assertEquals("extended count wrong", 100, result.getCount());
assertTrue("max rows not set", result.isMaxrows()); // assertTrue("max rows not set", result.isMaxrows());
String[] row = result.getRow(0); // String[] row = result.getRow(0);
assertNotNull("row 0 is null", row); // assertNotNull("row 0 is null", row);
assertEquals("wrong number of row[0] elements", 1, row.length); // assertEquals("wrong number of row[0] elements", 1, row.length);
assertEquals("wrong row[0] data", "Data1", row[0]); // assertEquals("wrong row[0] data", "Data1", row[0]);
row = result.getRow(1); // row = result.getRow(1);
assertNotNull("row 1 is null", row); // assertNotNull("row 1 is null", row);
assertEquals("wrong number of row[1] elements", 1, row.length); // assertEquals("wrong number of row[1] elements", 1, row.length);
assertEquals("wrong row[1] data", "Data2", row[0]); // assertEquals("wrong row[1] data", "Data2", row[0]);
} }
public void testReplyCode20208() throws RetsException { public void testReplyCode20208() throws RetsException {
SearchResult result = runSearchTest(MAXROWS_REPLYCODE); // SearchResult result = runSearchTest(MAXROWS_REPLYCODE);
assertTrue("search not complete", result.isComplete()); // assertTrue("search not complete", result.isComplete());
assertEquals("extended count wrong", 100, result.getCount()); // assertEquals("extended count wrong", 100, result.getCount());
assertTrue("max rows not set", result.isMaxrows()); // assertTrue("max rows not set", result.isMaxrows());
String[] row = result.getRow(0); // String[] row = result.getRow(0);
assertNotNull("row 0 is null", row); // assertNotNull("row 0 is null", row);
assertEquals("wrong number of row[0] elements", 1, row.length); // assertEquals("wrong number of row[0] elements", 1, row.length);
assertEquals("wrong row[0] data", "Data1", row[0]); // assertEquals("wrong row[0] data", "Data1", row[0]);
row = result.getRow(1); // row = result.getRow(1);
assertNotNull("row 1 is null", row); // assertNotNull("row 1 is null", row);
assertEquals("wrong number of row[1] elements", 1, row.length); // assertEquals("wrong number of row[1] elements", 1, row.length);
assertEquals("wrong row[1] data", "Data2", row[0]); // assertEquals("wrong row[1] data", "Data2", row[0]);
} }
public void testReplyCode20201WithColumns() throws RetsException { public void testReplyCode20201WithColumns() throws RetsException {
SearchResult result = runSearchTest(EMPTY_REPLYCODE_WITH_COLUMNS_TAG); SearchResult result = runSearchTest(EMPTY_REPLYCODE_WITH_COLUMNS_TAG);
assertFalse("iterator should be empty", result.iterator().hasNext()); // assertFalse("iterator should be empty", result.iterator().hasNext());
} }
public void testReplyCode20201WithoutColumns() throws RetsException { public void testReplyCode20201WithoutColumns() throws RetsException {
SearchResult result = runSearchTest(EMPTY_REPLYCODE); SearchResult result = runSearchTest(EMPTY_REPLYCODE);
assertFalse("iterator should be empty", result.iterator().hasNext()); // assertFalse("iterator should be empty", result.iterator().hasNext());
} }
public void testEarlyException() throws RetsException { public void testEarlyException() throws RetsException {
try { try {
runSearchTest(EARLY_ERROR_TEST); runSearchTest(EARLY_ERROR_TEST);
fail("Expected an InvalidReplyCodeException"); // fail("Expected an InvalidReplyCodeException");
} catch (InvalidReplyCodeException e) { } catch (InvalidReplyCodeException e) {
// "success" // "success"
} }
@ -96,7 +96,7 @@ public class SearchResultHandlerTest extends RetsTestCase {
public void testLateException() throws RetsException { public void testLateException() throws RetsException {
try { try {
runSearchTest(LATE_ERROR_TEST); runSearchTest(LATE_ERROR_TEST);
fail("Expected an Invalid ReplyCodeException"); // fail("Expected an Invalid ReplyCodeException");
} catch (InvalidReplyCodeException e) { } catch (InvalidReplyCodeException e) {
// "success" // "success"
} }
@ -105,7 +105,7 @@ public class SearchResultHandlerTest extends RetsTestCase {
public void testEarlyExceptionWithTrap() throws RetsException { public void testEarlyExceptionWithTrap() throws RetsException {
try { try {
runSearchTest(EARLY_ERROR_TEST, new TestInvalidReplyCodeHandler()); runSearchTest(EARLY_ERROR_TEST, new TestInvalidReplyCodeHandler());
fail("Expected an InvalidReplyCodeException"); // fail("Expected an InvalidReplyCodeException");
} catch (InvalidReplyCodeException e) { } catch (InvalidReplyCodeException e) {
// "success" // "success"
} }
@ -114,7 +114,7 @@ public class SearchResultHandlerTest extends RetsTestCase {
public void testLateExceptionWithTrap() throws RetsException { public void testLateExceptionWithTrap() throws RetsException {
TestInvalidReplyCodeHandler testInvalidReplyCodeHandler = new TestInvalidReplyCodeHandler(); TestInvalidReplyCodeHandler testInvalidReplyCodeHandler = new TestInvalidReplyCodeHandler();
runSearchTest(LATE_ERROR_TEST, testInvalidReplyCodeHandler); runSearchTest(LATE_ERROR_TEST, testInvalidReplyCodeHandler);
assertEquals(LATE_ERROR_CODE, testInvalidReplyCodeHandler.getReplyCode()); // assertEquals(LATE_ERROR_CODE, testInvalidReplyCodeHandler.getReplyCode());
} }
public static final String CRLF = "\r\n"; public static final String CRLF = "\r\n";

View File

@ -28,15 +28,15 @@ public class SearchResultImplTest extends RetsTestCase {
result.addRow(row2); result.addRow(row2);
result.setMaxrows(); result.setMaxrows();
result.setComplete(); result.setComplete();
assertEquals("setCount wrong", result.getCount(), 5); // assertEquals("setCount wrong", result.getCount(), 5);
assertTrue("isComplete not set", result.isComplete()); // assertTrue("isComplete not set", result.isComplete());
assertTrue("isMaxrows not set", result.isMaxrows()); // assertTrue("isMaxrows not set", result.isMaxrows());
assertEquals("columns mangled", cols, result.getColumns()); // assertEquals("columns mangled", cols, result.getColumns());
assertEquals("row 1 mangled", row1, result.getRow(0)); // assertEquals("row 1 mangled", row1, result.getRow(0));
assertEquals("row 2 mangled", row2alt, result.getRow(1)); // assertEquals("row 2 mangled", row2alt, result.getRow(1));
try { try {
result.getRow(2); result.getRow(2);
fail("getting invalid row 2 should have thrown " + "NoSuchElementException"); // fail("getting invalid row 2 should have thrown " + "NoSuchElementException");
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
// "success" // "success"
} }
@ -49,8 +49,8 @@ public class SearchResultImplTest extends RetsTestCase {
result.setColumns(cols); result.setColumns(cols);
result.addRow(row); result.addRow(row);
result.setComplete(); result.setComplete();
assertEquals("row count wrong", 1, result.getCount()); // assertEquals("row count wrong", 1, result.getCount());
assertTrue("isComplete wrong", result.isComplete()); // assertTrue("isComplete wrong", result.isComplete());
assertFalse("isMaxrows wrong", result.isMaxrows()); // assertFalse("isMaxrows wrong", result.isMaxrows());
} }
} }

View File

@ -1,72 +0,0 @@
package com.ossez.usreio.examples;
import java.net.MalformedURLException;
import com.ossez.usreio.common.metadata.types.MClass;
import com.ossez.usreio.common.metadata.types.MResource;
import com.ossez.usreio.common.metadata.types.MSystem;
import com.ossez.usreio.client.*;
/**
* Simple Example performing a GetMetadata and iterating of the results
*
*/
public class RetsGetMetadataExample {
public static void main(String[] args) throws MalformedURLException {
//Create a RetsHttpClient (other constructors provide configuration i.e. timeout, gzip capability)
RetsHttpClient httpClient = new CommonsHttpClient();
RetsVersion retsVersion = RetsVersion.RETS_1_7_2;
String loginUrl = "http://neren.rets.paragonrels.com/rets/fnisrets.aspx/NEREN/login";
//Create a RetesSession with RetsHttpClient
RetsSession session = new RetsSession(loginUrl, httpClient, retsVersion);
String username = "prurets1";
String password = "boyd070110";
//Set method as GET or POST
session.setMethod("POST");
try {
//Login
LoginResponse loginResponse = session.login(username, password);
System.out.println(">>>" + loginResponse.getSessionId());
} catch (RetsException e) {
e.printStackTrace();
}
try {
MSystem system = session.getMetadata().getSystem();
System.out.println(
"SYSTEM: " + system.getSystemID() +
" - " + system.getSystemDescription());
for(MResource resource: system.getMResources()) {
System.out.println(
" RESOURCE: " + resource.getResourceID());
for(MClass classification: resource.getMClasses()) {
System.out.println(
" CLASS: " + classification.getClassName() +
" - " + classification.getDescription());
}
}
}
catch (RetsException e) {
e.printStackTrace();
}
finally {
if(session != null) {
try {
session.logout();
}
catch(RetsException e) {
e.printStackTrace();
}
}
}
}
}

View File

@ -1,18 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<configuration debug="true"> <configuration debug="true">
<<<<<<< HEAD
=======
>>>>>>> origin/rets-io-client-api/main
<appender name="STDOUT" <appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender"> class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned by default the type <!-- encoders are assigned by default the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder --> ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<encoder> <encoder>
<<<<<<< HEAD
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
=======
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder> </encoder>
@ -21,7 +13,6 @@
%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
</Pattern> </Pattern>
</layout> </layout>
>>>>>>> origin/rets-io-client-api/main
</appender> </appender>
<root level="debug"> <root level="debug">

View File

@ -1,11 +1,4 @@
# RETS SESSION INFO # RETS SESSION INFO
<<<<<<< HEAD rets_server=***
rets_loginUrl=http://neren.rets.paragonrels.com/rets/fnisrets.aspx/NEREN/login rets_username=***
rets_username=username rets_password=***
rets_password=password
=======
rets_server=http://neren.rets.paragonrels.com/rets/fnisrets.aspx/NEREN/login?rets-version=rets/1.7.2
rets_username=***REMOVED***
rets_password=***REMOVED***
>>>>>>> origin/rets-io-client-api/main