use of org.eclipse.persistence.sessions.Project in project eclipselink by eclipse-ee4j.
the class XMLChoiceCollectionWithGroupingElementTestCases method testReadDeploymentXML.
public void testReadDeploymentXML() {
try {
// Read the deploymentXML-file.xml back in with XMLProjectReader
Project newProject = XMLProjectReader.read(DEPLOYMENT_XML_RESOURCE, Thread.currentThread().getContextClassLoader());
XMLContext ctx = new XMLContext(newProject);
XMLUnmarshaller unmarshaller = ctx.createUnmarshaller();
InputStream instream = ClassLoader.getSystemResourceAsStream(XML_RESOURCE);
Employee emp = (Employee) unmarshaller.unmarshal(instream);
instream.close();
Object[] choices = emp.choice.toArray();
assertTrue("Choice collection did not unmarshal properly", (choices != null && choices.length > 0));
} catch (Exception x) {
x.printStackTrace();
fail("Deployment XML read test failed");
}
}
use of org.eclipse.persistence.sessions.Project in project eclipselink by eclipse-ee4j.
the class OXTestCase method getNewProject.
public Project getNewProject(Project originalProject, ClassLoader classLoader) {
Project newProject = originalProject;
switch(metadata) {
case JAVA:
break;
default:
try {
// Write the deployment XML file to deploymentXML-file.xml
String fileName = "deploymentXML-file.xml";
FileWriter fWriter = new FileWriter(fileName);
write(originalProject, fWriter);
fWriter.close();
// Also write the deployment XML file to a stringwriter for logging
if (useLogging) {
StringWriter stringWriter = new StringWriter();
write(originalProject, stringWriter);
log("DEPLOYMENT XML " + stringWriter.toString());
}
// Read the deploymentXML-file.xml back in with XMLProjectReader
FileInputStream inStream = new FileInputStream(fileName);
FileReader fileReader = new FileReader(fileName);
newProject = XMLProjectReader.read(fileReader, classLoader);
inStream.close();
fileReader.close();
File f = new File(fileName);
f.delete();
} catch (Exception e) {
e.printStackTrace();
StringWriter stringWriter = new StringWriter();
write(originalProject, stringWriter);
StringReader reader = new StringReader(stringWriter.toString());
log("DEPLOYMENT XML" + stringWriter.toString());
newProject = XMLProjectReader.read(reader, classLoader);
}
}
if ((newProject.getDatasourceLogin() == null) || (!(newProject.getDatasourceLogin() instanceof XMLLogin))) {
newProject.setDatasourceLogin(new XMLLogin());
}
switch(platform) {
case SAX:
newProject.getDatasourceLogin().setPlatform(new SAXPlatform());
break;
default:
newProject.getDatasourceLogin().setPlatform(new DOMPlatform());
}
return newProject;
}
use of org.eclipse.persistence.sessions.Project in project eclipselink by eclipse-ee4j.
the class OrderQueueTest method setUp.
/**
* Set up this test suite.
*/
@Before
public void setUp() {
// Use temporary relational database session to initialize the model.
final Project project = SessionHelper.createModelProject(SessionHelper.createDatabaseLogin(), AQTestSuite.class);
rDBSession = SessionHelper.createDatabaseSession(project);
ModelHelper.setupRawOrderQueue(rDBSession);
}
use of org.eclipse.persistence.sessions.Project in project eclipselink by eclipse-ee4j.
the class AuthenticationTest method testInvalidUsernameDBSession.
/**
* Test database session login with invalid user name and valid password.
*/
@Test
public void testInvalidUsernameDBSession() throws Exception {
final String userName = "invaliduser";
login.setUserName(userName);
boolean failure = false;
DatabaseSession session = new Project(login).createDatabaseSession();
session.setSessionLog(LOG);
try {
session.login();
session.logout();
} catch (Exception ex) {
if (ex.getMessage().indexOf("invalid username/password") == -1) {
throw ex;
}
failure = true;
}
if (!failure) {
throw new TestErrorException("Authentication did not fail as expected.");
}
}
use of org.eclipse.persistence.sessions.Project in project eclipselink by eclipse-ee4j.
the class AuthenticationTest method testValidUsernameAndPasswordDBSession.
/**
* Test database session login with valid user name and password.
*/
@Test
public void testValidUsernameAndPasswordDBSession() throws Exception {
boolean failure = false;
final DatabaseSession session = new Project(login).createDatabaseSession();
session.setSessionLog(LOG);
try {
session.login();
session.logout();
} catch (Exception ex) {
if (ex.getMessage().indexOf("invalid username/password") == -1) {
throw ex;
}
failure = true;
}
if (failure) {
throw new TestErrorException("Authentication failed unexpectedly.");
}
}
Aggregations