From 62eeb7792fec170b3264842ff04bd72176a5e978 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Tue, 30 Nov 2021 11:29:03 -0500 Subject: [PATCH] USRE-87 Merge MetaData test to one test --- .../client => resources}/metadata_tables.xml | 0 .../usreio/tests/client/MetadataTest.java | 55 ------------------- ...dataExample.java => RetsMetadataTest.java} | 43 ++++++++++++++- .../usreio/tests/client/RetsSessionTest.java | 20 ++++--- 4 files changed, 53 insertions(+), 65 deletions(-) rename src/main/{java/com/ossez/usreio/client => resources}/metadata_tables.xml (100%) delete mode 100644 src/test/java/com/ossez/usreio/tests/client/MetadataTest.java rename src/test/java/com/ossez/usreio/tests/client/{RetsGetMetadataExample.java => RetsMetadataTest.java} (59%) diff --git a/src/main/java/com/ossez/usreio/client/metadata_tables.xml b/src/main/resources/metadata_tables.xml similarity index 100% rename from src/main/java/com/ossez/usreio/client/metadata_tables.xml rename to src/main/resources/metadata_tables.xml diff --git a/src/test/java/com/ossez/usreio/tests/client/MetadataTest.java b/src/test/java/com/ossez/usreio/tests/client/MetadataTest.java deleted file mode 100644 index ca595d7..0000000 --- a/src/test/java/com/ossez/usreio/tests/client/MetadataTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.ossez.usreio.tests.client; - -import org.junit.jupiter.api.Test; -import com.ossez.usreio.client.retsapi.RETSConnection; -import com.ossez.usreio.client.retsapi.RETSGetMetadataTransaction; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.InputStream; -import java.util.Properties; - -/** - * @author YuCheng - */ -public class MetadataTest { - - private final static Logger logger = LoggerFactory.getLogger(MetadataTest.class); - - /** - * Do RetsServerConnection Test - */ - @Test - public void testStaticVariableChange() { - - // BasicConfigurator.configure(); - - RETSConnection rc = new RETSConnection(); -// RETSLoginTransaction trans = new RETSLoginTransaction(); - RETSGetMetadataTransaction trans = new RETSGetMetadataTransaction(); - - - try { - Properties props = new Properties(); - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - InputStream inputStream = loader.getResourceAsStream("rets.properties"); - - props.load(inputStream); - - // Add the optional request parameters if they exist, are non-null and non-zero-length - // rc.setRequestHeaderField("Authorization", (String)props.get("login.AUTHORIZATION")); - rc.setServerUrl((String) props.getProperty("rets_server")); -// trans.setUrl((String) props.getProperty("rets_server")); -// trans.setUsername((String) props.getProperty("rets_username")); -// trans.setPassword((String) props.getProperty("rets_password")); - } catch (Exception e) { - e.printStackTrace(); - } - rc.execute(trans); -// rc.execute(transaction); - -// transaction.getVersion(); - - } - -} diff --git a/src/test/java/com/ossez/usreio/tests/client/RetsGetMetadataExample.java b/src/test/java/com/ossez/usreio/tests/client/RetsMetadataTest.java similarity index 59% rename from src/test/java/com/ossez/usreio/tests/client/RetsGetMetadataExample.java rename to src/test/java/com/ossez/usreio/tests/client/RetsMetadataTest.java index eaa87d2..d55d8b9 100644 --- a/src/test/java/com/ossez/usreio/tests/client/RetsGetMetadataExample.java +++ b/src/test/java/com/ossez/usreio/tests/client/RetsMetadataTest.java @@ -1,16 +1,21 @@ package com.ossez.usreio.tests.client; +import java.io.InputStream; import java.net.MalformedURLException; +import java.util.Properties; +import com.ossez.usreio.client.retsapi.RETSConnection; +import com.ossez.usreio.client.retsapi.RETSGetMetadataTransaction; import com.ossez.usreio.tests.common.metadata.types.MClass; import com.ossez.usreio.tests.common.metadata.types.MResource; import com.ossez.usreio.tests.common.metadata.types.MSystem; import com.ossez.usreio.client.*; +import org.junit.jupiter.api.Test; /** * Simple Example performing a GetMetadata and iterating of the results */ -public class RetsGetMetadataExample { +public class RetsMetadataTest { public static void main(String[] args) throws MalformedURLException { @@ -65,4 +70,40 @@ public class RetsGetMetadataExample { } } } + + /** + * Do RetsServerConnection Test + */ + @Test + public void testStaticVariableChange() { + + // BasicConfigurator.configure(); + + RETSConnection rc = new RETSConnection(); +// RETSLoginTransaction trans = new RETSLoginTransaction(); + RETSGetMetadataTransaction trans = new RETSGetMetadataTransaction(); + + + try { + Properties props = new Properties(); + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + InputStream inputStream = loader.getResourceAsStream("rets.properties"); + + props.load(inputStream); + + // Add the optional request parameters if they exist, are non-null and non-zero-length + // rc.setRequestHeaderField("Authorization", (String)props.get("login.AUTHORIZATION")); + rc.setServerUrl((String) props.getProperty("rets_server")); +// trans.setUrl((String) props.getProperty("rets_server")); +// trans.setUsername((String) props.getProperty("rets_username")); +// trans.setPassword((String) props.getProperty("rets_password")); + } catch (Exception e) { + e.printStackTrace(); + } + rc.execute(trans); +// rc.execute(transaction); + +// transaction.getVersion(); + + } } diff --git a/src/test/java/com/ossez/usreio/tests/client/RetsSessionTest.java b/src/test/java/com/ossez/usreio/tests/client/RetsSessionTest.java index de83dc2..be9839a 100644 --- a/src/test/java/com/ossez/usreio/tests/client/RetsSessionTest.java +++ b/src/test/java/com/ossez/usreio/tests/client/RetsSessionTest.java @@ -4,12 +4,13 @@ import com.ossez.usreio.client.RetsException; import com.ossez.usreio.client.RetsSession; import com.ossez.usreio.client.RetsVersion; import com.ossez.usreio.util.SessionUtils; +import org.apache.commons.lang3.ObjectUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * Test for RETS session @@ -22,14 +23,15 @@ public class RetsSessionTest extends RetsTestCase { /** - * Test Login + * Test Login should return SessionID from server */ @Test public void testLogin() { + logger.debug("Test Rets Session Login by URL: [{}]", retsLoginUrl); try { RetsSession session = SessionUtils.retsLogin(retsLoginUrl, retsUsername, retsPassword, RetsVersion.RETS_1_7_2); - assertNull(session.getSessionId()); + assertNotNull(session.getSessionId()); } catch (RetsException ex) { logger.debug("Session Login Error", ex); } @@ -40,28 +42,28 @@ public class RetsSessionTest extends RetsTestCase { /** * TEST Logout */ - @org.junit.jupiter.api.Test + @Test public void testLogout() { - logger.debug("RETS Session Logout URL: [{}]", retsLoginUrl); + logger.debug("RETS Session Login URL: [{}]", retsLoginUrl); RetsSession session = null; try { session = SessionUtils.retsLogin(retsLoginUrl, retsUsername, retsPassword, RetsVersion.RETS_1_7_2); -// Assert.assertNotNull(session.getSessionId()); + assertNotNull(session.getSessionId()); } catch (RetsException ex) { logger.debug("Session Login Error", ex); } - if (session != null) { + // If Session is not Empty then Logout + if (ObjectUtils.isNotEmpty(session)) { try { session.logout(); } catch (RetsException e) { - e.printStackTrace(); + logger.error("Logout Error: ", e); } } } - }