Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define how to deal with test classes using DataSourceDefinition templates #1472

Open
starksm64 opened this issue Aug 21, 2024 · 1 comment
Open
Assignees
Labels
11.0 Issues related to the Jakarta EE 11 Platform TCK release

Comments

@starksm64
Copy link
Contributor

starksm64 commented Aug 21, 2024

Related to #1360 , there are tests like com.sun.ts.tests.ejb30.misc.datasource.twowars that have template classes like:

package com.sun.ts.tests.ejb30.misc.datasource.twowars;

import java.io.IOException;
import java.sql.Connection;

import jakarta.annotation.sql.DataSourceDefinition;
import jakarta.annotation.sql.DataSourceDefinitions;
import jakarta.ejb.EJB;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import com.sun.ts.tests.ejb30.assembly.appres.common.AppResRemoteIF;
import com.sun.ts.tests.ejb30.assembly.appres.common.TestServletBase;
import com.sun.ts.tests.ejb30.common.helper.Helper;
import com.sun.ts.tests.ejb30.common.helper.ServiceLocator;
import com.sun.ts.tests.ejb30.lite.packaging.war.datasource.common.DataSourceTest;

@WebServlet(urlPatterns = "/TestServlet", loadOnStartup = 1)

@DataSourceDefinitions({
    @DataSourceDefinition(name="java:comp/env/compdsservlet",
            className="@className@",
            portNumber=@portNumber@,
            serverName="@serverName@",
            databaseName="@databaseName@",
            user="@user@",
            password="@password@",
            
            description="ds1",
            initialPoolSize=1,
            
            loginTimeout=300,
            maxIdleTime=1000,
            maxPoolSize=2,
            minPoolSize=1,
            transactional=false,
            properties={@jdbc.datasource.props@},
            url="jdbc:derby://${derby.server}:${derby.port}/${derby.dbName};create=true"
    ),
    @DataSourceDefinition(name="defaultdsservlet",
            className="@className@",
            portNumber=@portNumber@,
            serverName="@serverName@",
            databaseName="@databaseName@",
            user="@user@",
            password="@password@",
            properties={@jdbc.datasource.props@}),
            
    @DataSourceDefinition(name="java:module/env/moduledsservlet",
            className="@className@",
            portNumber=@portNumber@,
            serverName="@serverName@",
            databaseName="@databaseName@",
            user="@user@",
            password="@password@",
            properties={@jdbc.datasource.props@},
            isolationLevel=Connection.TRANSACTION_SERIALIZABLE),
            
    @DataSourceDefinition(name="java:app/env/servlet/appds",
            className="@className@",
            portNumber=@portNumber@,
            serverName="@serverName@",
            databaseName="@databaseName@",
            user="@user@",
            password="@password@",
            properties={@jdbc.datasource.props@}),
            
    @DataSourceDefinition(name="java:global/env/ts/datasource/servlet/globalds",
            className="@className@",
            portNumber=@portNumber@,
            serverName="@serverName@",
            databaseName="@databaseName@",
            user="@user@",
            password="@password@",
            properties={@jdbc.datasource.props@})
    })

public class TestServlet extends TestServletBase {

    @EJB(beanName="DataSourceBean")
    private AppResRemoteIF dataSourceBean;
    
    private void nonPostConstruct() {
        postConstructRecords = new StringBuilder();
        ServiceLocator.lookupShouldFail("java:app/env/servlet2/appds", getPostConstructRecords());
        Helper.getLogger().info(getPostConstructRecords().toString());
        
        DataSourceTest.verifyDataSource(postConstructRecords, false, 
                //"java:app/datasource/twowars/ejb/appds",
                //"java:global/env/ts/datasource/servlet2/globalds",
                
                "java:comp/env/compdsservlet",
                "java:comp/env/defaultdsservlet",
                "java:module/env/moduledsservlet",
                "java:app/env/servlet/appds",
                "java:global/env/ts/datasource/servlet/globalds"
                );
    }

    public void servletPostConstruct(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        nonPostConstruct();
        verifyRecords(request, response, postConstructRecords);
    }


    public void ejbPostConstruct(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        verifyRecords(request, response, dataSourceBean.getPostConstructRecords());
    }
}

Where the @DataSourceDefinition annotation is filled in during test execution by the ant build scripts when the test artifact is assembled. This does not work well with maven when you are producing the test artifact and then simply consuming it in a test runner project.

We need to replace with template approach with one that fits the maven/arquillian/junit5 approach.

@starksm64
Copy link
Contributor Author

One way would be to generate the TestServlet.java/TestServlet2.java classes using the javadb glassfish settings and if a vendor is running against a different database, they would replace these classes with their correctly annotated version in their tck.arquillian.porting.lib.spi.TestArchiveProcessor implementation. The user guide would have to document this as an allowed test modification.

@starksm64 starksm64 self-assigned this Aug 28, 2024
@gurunrao gurunrao added the 11.0 Issues related to the Jakarta EE 11 Platform TCK release label Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
11.0 Issues related to the Jakarta EE 11 Platform TCK release
Projects
Status: In review
Development

No branches or pull requests

2 participants