Search in sources :

Example 1 with TemplateManager

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);
        }
    }
}
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) TemplateManagementClientException(org.wso2.carbon.identity.template.mgt.exception.TemplateManagementClientException) 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 TemplateManager

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

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

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);
    }
}
Also used : TemplateManagementException(org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException) TemplateManager(org.wso2.carbon.identity.template.mgt.TemplateManager)

Example 5 with TemplateManager

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);
    }
}
Also used : TemplateManagementException(org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException) TemplateManager(org.wso2.carbon.identity.template.mgt.TemplateManager) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IdentityProviderTemplate(org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplate) Template(org.wso2.carbon.identity.template.mgt.model.Template)

Aggregations

Template (org.wso2.carbon.identity.template.mgt.model.Template)9 Connection (java.sql.Connection)8 DataSource (javax.sql.DataSource)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 Test (org.testng.annotations.Test)8 TestUtils.getConnection (org.wso2.carbon.identity.template.mgt.util.TestUtils.getConnection)8 TestUtils.mockDataSource (org.wso2.carbon.identity.template.mgt.util.TestUtils.mockDataSource)8 TestUtils.spyConnection (org.wso2.carbon.identity.template.mgt.util.TestUtils.spyConnection)8 TemplateManager (org.wso2.carbon.identity.template.mgt.TemplateManager)3 TemplateManagementException (org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException)3 IdentityProviderTemplate (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplate)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TemplateManagementClientException (org.wso2.carbon.identity.template.mgt.exception.TemplateManagementClientException)1 TemplateInfo (org.wso2.carbon.identity.template.mgt.model.TemplateInfo)1