use of org.wso2.carbon.identity.template.mgt.TemplateManager in project carbon-identity-framework by wso2.
the class TemplateManagerImplTest method testErrorCodes.
@Test()
public void testErrorCodes() throws Exception {
DataSource dataSource = mock(DataSource.class);
mockDataSource(dataSource);
Template template = new Template(SUPER_TENANT_ID, null, "sample description", sampleScript);
String errorCode = TemplateMgtConstants.ErrorMessages.ERROR_CODE_TEMPLATE_NAME_REQUIRED.getCode();
try (Connection connection = getConnection()) {
Connection spyConnection = spyConnection(connection);
when(dataSource.getConnection()).thenReturn(spyConnection);
TemplateManager templateManager = new TemplateManagerImpl();
try {
((TemplateManagerImpl) templateManager).addTemplateUsingTemplateMgtDAO(template);
} catch (TemplateManagementClientException e) {
String errorCode1 = e.getErrorCode();
Assert.assertEquals(errorCode, errorCode1);
}
}
}
use of org.wso2.carbon.identity.template.mgt.TemplateManager in project carbon-identity-framework by wso2.
the class TemplateManagerImplTest 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);
TemplateManager templateManager = new TemplateManagerImpl();
Template templateResult = ((TemplateManagerImpl) templateManager).addTemplateUsingTemplateMgtDAO(((Template) template));
Assert.assertEquals(templateResult.getTemplateName(), ((Template) template).getTemplateName());
templateManager.deleteTemplate(templateResult.getTemplateName());
}
}
use of org.wso2.carbon.identity.template.mgt.TemplateManager in project carbon-identity-framework by wso2.
the class TemplateManagerImplTest method testUpdateTemplate.
@Test(dataProvider = "UpdateTemplateDataProvider")
public void testUpdateTemplate(String oldTemplateName, Object oldtemplate, Object newTemplate) throws Exception {
DataSource dataSource = mock(DataSource.class);
mockDataSource(dataSource);
try (Connection connection = getConnection()) {
Connection spyConnection = spyConnection(connection);
when(dataSource.getConnection()).thenReturn(spyConnection);
TemplateManager templateManager = new TemplateManagerImpl();
addTemplates(templateManager, Collections.singletonList(oldtemplate), dataSource);
try (Connection connection1 = getConnection()) {
Connection spyConnection1 = spyConnection(connection1);
when(dataSource.getConnection()).thenReturn(spyConnection1);
Template updatedTemplate = templateManager.updateTemplate(oldTemplateName, ((Template) newTemplate));
Assert.assertEquals(((Template) newTemplate).getTenantId(), updatedTemplate.getTenantId());
Assert.assertEquals(((Template) newTemplate).getTemplateName(), updatedTemplate.getTemplateName());
}
}
}
use of org.wso2.carbon.identity.template.mgt.TemplateManager in project identity-api-server by wso2.
the class ServerIdpManagementService method deleteIDPTemplate.
/**
* Delete a IDP template identified by resource Id.
*
* @param templateId Id of the IDP template
*/
public void deleteIDPTemplate(String templateId) {
try {
TemplateManager templateManager = IdentityProviderServiceHolder.getTemplateManager();
templateManager.deleteTemplateById(templateId);
} catch (TemplateManagementException e) {
throw handleTemplateMgtException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_DELETING_IDP_TEMPLATE, templateId);
}
}
use of org.wso2.carbon.identity.template.mgt.TemplateManager in project identity-api-server by wso2.
the class ServerIdpManagementService method createIDPTemplate.
/**
* Create a new IDP template.
*
* @param identityProviderTemplate identityProviderTemplatePOSTRequest
* @return IdentityProviderTemplateResponse
*/
public String createIDPTemplate(IdentityProviderTemplate identityProviderTemplate) {
try {
TemplateManager templateManager = IdentityProviderServiceHolder.getTemplateManager();
Template idpTemplate = generateIDPTemplate(identityProviderTemplate);
return templateManager.addTemplate(idpTemplate);
} catch (TemplateManagementException e) {
throw handleTemplateMgtException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_ADDING_IDP_TEMPLATE, null);
} catch (JsonProcessingException e) {
throw handleException(Response.Status.BAD_REQUEST, Constants.ErrorMessage.ERROR_CODE_ERROR_ADDING_IDP_TEMPLATE, null);
}
}
Aggregations