Search in sources :

Example 26 with Project

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");
    }
}
Also used : Project(org.eclipse.persistence.sessions.Project) XMLContext(org.eclipse.persistence.oxm.XMLContext) InputStream(java.io.InputStream) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller)

Example 27 with Project

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;
}
Also used : Project(org.eclipse.persistence.sessions.Project) DOMPlatform(org.eclipse.persistence.oxm.platform.DOMPlatform) StringWriter(java.io.StringWriter) SAXPlatform(org.eclipse.persistence.oxm.platform.SAXPlatform) FileWriter(java.io.FileWriter) StringReader(java.io.StringReader) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) FileReader(java.io.FileReader) File(java.io.File) FileInputStream(java.io.FileInputStream) ValidationException(org.eclipse.persistence.exceptions.ValidationException) IOException(java.io.IOException)

Example 28 with Project

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);
}
Also used : Project(org.eclipse.persistence.sessions.Project) Before(org.junit.Before)

Example 29 with Project

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.");
    }
}
Also used : Project(org.eclipse.persistence.sessions.Project) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) Test(org.junit.Test)

Example 30 with Project

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.");
    }
}
Also used : Project(org.eclipse.persistence.sessions.Project) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) Test(org.junit.Test)

Aggregations

Project (org.eclipse.persistence.sessions.Project)216 StringReader (java.io.StringReader)92 ObjectPersistenceWorkbenchXMLProject (org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject)83 Test (org.junit.Test)83 XMLContext (org.eclipse.persistence.oxm.XMLContext)80 NonJDBCTestHelper.buildTestProject (org.eclipse.persistence.testing.tests.nonJDBC.NonJDBCTestHelper.buildTestProject)60 NonJDBCTestHelper.buildWorkbenchXMLProject (org.eclipse.persistence.testing.tests.nonJDBC.NonJDBCTestHelper.buildWorkbenchXMLProject)60 Document (org.w3c.dom.Document)53 XMLMarshaller (org.eclipse.persistence.oxm.XMLMarshaller)49 PLSQLStoredProcedureCall (org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall)37 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)30 DatabaseLogin (org.eclipse.persistence.sessions.DatabaseLogin)28 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)27 XMLLogin (org.eclipse.persistence.oxm.XMLLogin)25 SchemaModelProject (org.eclipse.persistence.internal.oxm.schema.SchemaModelProject)24 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)23 DataModifyQuery (org.eclipse.persistence.queries.DataModifyQuery)22 Schema (org.eclipse.persistence.internal.oxm.schema.model.Schema)17 Descriptor (org.eclipse.persistence.internal.oxm.mappings.Descriptor)16 XMLUnmarshaller (org.eclipse.persistence.oxm.XMLUnmarshaller)16