Search in sources :

Example 1 with TemplateManagerDAO

use of org.wso2.carbon.identity.template.mgt.dao.TemplateManagerDAO in project carbon-identity-framework by wso2.

the class TemplateManagerDAOImplTest method testGetTemplateByName.

@Test(dataProvider = "getTemplateByNameDataProvider")
public void testGetTemplateByName(Object templateObject, Integer tenantId) throws Exception {
    DataSource dataSource = mock(DataSource.class);
    mockDataSource(dataSource);
    try (Connection connection = getConnection()) {
        when(dataSource.getConnection()).thenReturn(connection);
        TemplateManagerDAO templateManagerDAO = new TemplateManagerDAOImpl();
        addTemplates(templateManagerDAO, Collections.singletonList(templateObject), dataSource);
        try (Connection connection1 = getConnection()) {
            when(dataSource.getConnection()).thenReturn(connection1);
            Template templateByName = templateManagerDAO.getTemplateByName(((Template) templateObject).getTemplateName(), tenantId);
            Assert.assertEquals(((Template) templateObject).getTemplateName(), templateByName.getTemplateName());
            Assert.assertEquals(((Template) templateObject).getDescription(), templateByName.getDescription());
            Assert.assertEquals(((Template) templateObject).getTemplateScript(), templateByName.getTemplateScript());
        }
    }
}
Also used : Connection(java.sql.Connection) TestUtils.spyConnection(org.wso2.carbon.identity.template.mgt.util.TestUtils.spyConnection) TestUtils.getConnection(org.wso2.carbon.identity.template.mgt.util.TestUtils.getConnection) TemplateManagerDAO(org.wso2.carbon.identity.template.mgt.dao.TemplateManagerDAO) DataSource(javax.sql.DataSource) TestUtils.mockDataSource(org.wso2.carbon.identity.template.mgt.util.TestUtils.mockDataSource) Template(org.wso2.carbon.identity.template.mgt.model.Template) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with TemplateManagerDAO

use of org.wso2.carbon.identity.template.mgt.dao.TemplateManagerDAO in project carbon-identity-framework by wso2.

the class TemplateManagerDAOImplTest method testAddTemplateServerException.

@Test(dataProvider = "TemplateDataProvider", expectedExceptions = TemplateManagementServerException.class)
public void testAddTemplateServerException(Object template) throws Exception {
    DataSource dataSource = mock(DataSource.class);
    mockDataSource(dataSource);
    try (Connection connection = getConnection()) {
        when(dataSource.getConnection()).thenReturn(connection);
    }
    TemplateManagerDAO templateManagerDAO = new TemplateManagerDAOImpl();
    templateManagerDAO.addTemplate(((Template) template));
    Assert.fail("Expected: " + TemplateManagementServerException.class.getName());
}
Also used : Connection(java.sql.Connection) TestUtils.spyConnection(org.wso2.carbon.identity.template.mgt.util.TestUtils.spyConnection) TestUtils.getConnection(org.wso2.carbon.identity.template.mgt.util.TestUtils.getConnection) TemplateManagerDAO(org.wso2.carbon.identity.template.mgt.dao.TemplateManagerDAO) DataSource(javax.sql.DataSource) TestUtils.mockDataSource(org.wso2.carbon.identity.template.mgt.util.TestUtils.mockDataSource) Template(org.wso2.carbon.identity.template.mgt.model.Template) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with TemplateManagerDAO

use of org.wso2.carbon.identity.template.mgt.dao.TemplateManagerDAO in project carbon-identity-framework by wso2.

the class TemplateManagerDAOImplTest method testDeleteTemplateDataAccessException.

@Test(dataProvider = "TemplateDataProvider", expectedExceptions = TemplateManagementServerException.class)
public void testDeleteTemplateDataAccessException(Object template) throws Exception {
    DataSource dataSource = mock(DataSource.class);
    mockDataSource(dataSource);
    TemplateManagerDAO templateManagerDAO = new TemplateManagerDAOImpl();
    try (Connection connection = getConnection()) {
        Connection spyConnection = spyConnection(connection);
        when(dataSource.getConnection()).thenReturn(spyConnection);
        Template templateResult = templateManagerDAO.addTemplate(((Template) template));
        Assert.assertEquals(templateResult.getTemplateName(), ((Template) template).getTemplateName());
    }
    templateManagerDAO.deleteTemplate(((Template) template).getTemplateName(), ((Template) template).getTenantId());
    Assert.fail("Expected: " + TemplateManagementServerException.class.getName());
}
Also used : Connection(java.sql.Connection) TestUtils.spyConnection(org.wso2.carbon.identity.template.mgt.util.TestUtils.spyConnection) TestUtils.getConnection(org.wso2.carbon.identity.template.mgt.util.TestUtils.getConnection) TemplateManagerDAO(org.wso2.carbon.identity.template.mgt.dao.TemplateManagerDAO) DataSource(javax.sql.DataSource) TestUtils.mockDataSource(org.wso2.carbon.identity.template.mgt.util.TestUtils.mockDataSource) Template(org.wso2.carbon.identity.template.mgt.model.Template) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with TemplateManagerDAO

use of org.wso2.carbon.identity.template.mgt.dao.TemplateManagerDAO in project carbon-identity-framework by wso2.

the class TemplateManagerDAOImplTest method testDeleteTemplate.

@Test(dataProvider = "TemplateDataProvider")
public void testDeleteTemplate(Object template) throws Exception {
    DataSource dataSource = mock(DataSource.class);
    mockDataSource(dataSource);
    try (Connection connection = getConnection()) {
        Connection spyConnection = spyConnection(connection);
        when(dataSource.getConnection()).thenReturn(spyConnection);
        TemplateManagerDAO templateManagerDAO = new TemplateManagerDAOImpl();
        Template templateResult = templateManagerDAO.addTemplate(((Template) template));
        Assert.assertEquals(templateResult.getTemplateName(), ((Template) template).getTemplateName());
        templateManagerDAO.deleteTemplate(templateResult.getTemplateName(), templateResult.getTenantId());
    }
}
Also used : Connection(java.sql.Connection) TestUtils.spyConnection(org.wso2.carbon.identity.template.mgt.util.TestUtils.spyConnection) TestUtils.getConnection(org.wso2.carbon.identity.template.mgt.util.TestUtils.getConnection) TemplateManagerDAO(org.wso2.carbon.identity.template.mgt.dao.TemplateManagerDAO) DataSource(javax.sql.DataSource) TestUtils.mockDataSource(org.wso2.carbon.identity.template.mgt.util.TestUtils.mockDataSource) Template(org.wso2.carbon.identity.template.mgt.model.Template) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with TemplateManagerDAO

use of org.wso2.carbon.identity.template.mgt.dao.TemplateManagerDAO in project carbon-identity-framework by wso2.

the class TemplateManagerDAOImplTest method testUpdateTemplateServerException.

@Test(dataProvider = "UpdateTemplateDataProvider", expectedExceptions = TemplateManagementServerException.class)
public void testUpdateTemplateServerException(String oldTemplateName, Object oldtemplate, Object newTemplate) throws Exception {
    DataSource dataSource = mock(DataSource.class);
    mockDataSource(dataSource);
    try (Connection connection = getConnection()) {
        when(dataSource.getConnection()).thenReturn(connection);
        TemplateManagerDAO templateManagerDAO = new TemplateManagerDAOImpl();
        addTemplates(templateManagerDAO, Collections.singletonList(oldtemplate), dataSource);
        templateManagerDAO.updateTemplate(oldTemplateName, ((Template) newTemplate));
        Assert.fail("Expected: " + TemplateManagementServerException.class.getName());
    }
}
Also used : Connection(java.sql.Connection) TestUtils.spyConnection(org.wso2.carbon.identity.template.mgt.util.TestUtils.spyConnection) TestUtils.getConnection(org.wso2.carbon.identity.template.mgt.util.TestUtils.getConnection) TemplateManagerDAO(org.wso2.carbon.identity.template.mgt.dao.TemplateManagerDAO) DataSource(javax.sql.DataSource) TestUtils.mockDataSource(org.wso2.carbon.identity.template.mgt.util.TestUtils.mockDataSource) Template(org.wso2.carbon.identity.template.mgt.model.Template) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

TemplateManagerDAO (org.wso2.carbon.identity.template.mgt.dao.TemplateManagerDAO)13 Connection (java.sql.Connection)10 DataSource (javax.sql.DataSource)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 Test (org.testng.annotations.Test)10 TestUtils.getConnection (org.wso2.carbon.identity.template.mgt.util.TestUtils.getConnection)10 TestUtils.mockDataSource (org.wso2.carbon.identity.template.mgt.util.TestUtils.mockDataSource)10 TestUtils.spyConnection (org.wso2.carbon.identity.template.mgt.util.TestUtils.spyConnection)10 Template (org.wso2.carbon.identity.template.mgt.model.Template)9 TemplateManagerDAOImpl (org.wso2.carbon.identity.template.mgt.dao.impl.TemplateManagerDAOImpl)3 TemplateInfo (org.wso2.carbon.identity.template.mgt.model.TemplateInfo)1