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