USRE-87 Merge MetaData test to one test

This commit is contained in:
YuCheng Hu 2021-11-30 11:29:03 -05:00
parent 78d4cab9f9
commit 62eeb7792f
4 changed files with 53 additions and 65 deletions

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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);
}
}
}
}