use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testAddThreatProtectionPolicy.
@Test(description = "Test adding threat protection policy")
public void testAddThreatProtectionPolicy() throws APIManagementException {
ThreatProtectionDAO threatProtectionDAO = Mockito.mock(ThreatProtectionDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(threatProtectionDAO);
ThreatProtectionPolicy policy = SampleTestObjectCreator.createUniqueThreatProtectionPolicy();
Mockito.doThrow(APIMgtDAOException.class).when(threatProtectionDAO).updatePolicy(policy);
Mockito.doThrow(APIMgtDAOException.class).when(threatProtectionDAO).addPolicy(policy);
// Error path
try {
adminService.addThreatProtectionPolicy(policy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error adding threat protection policy");
}
try {
policy.setUuid("");
adminService.addThreatProtectionPolicy(policy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error adding threat protection policy");
}
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testUpdateApplicationPolicy.
@Test(description = "Test update application policy")
public void testUpdateApplicationPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
ApplicationPolicy applicationPolicy = SampleTestObjectCreator.createDefaultApplicationPolicy();
adminService.updateApplicationPolicy(applicationPolicy);
Mockito.verify(policyDAO, Mockito.times(1)).updateApplicationPolicy(applicationPolicy);
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).updateApplicationPolicy(applicationPolicy);
try {
adminService.updateApplicationPolicy(applicationPolicy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't update Application policy for uuid: " + applicationPolicy.getUuid());
}
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testUpdateCustomRule.
@Test(description = "Test updating a custom rule")
public void testUpdateCustomRule() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
CustomPolicy customPolicy = SampleTestObjectCreator.createDefaultCustomPolicy();
adminService.updateCustomRule(customPolicy);
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).updateCustomPolicy(customPolicy);
try {
adminService.updateCustomRule(customPolicy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't update custom policy with UUID: " + customPolicy.getUuid());
}
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testRegisterGatewayLabels.
@Test(description = "Register gateway labels")
public void testRegisterGatewayLabels() throws APIManagementException {
LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
List<Label> labels = new ArrayList<>();
Label label1 = SampleTestObjectCreator.createLabel("testLabel1", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
Label label2 = SampleTestObjectCreator.createLabel("testLabel2", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
labels.add(label1);
List<String> labelNames = new ArrayList<>();
labelNames.add(label1.getName());
List<Label> existingLabels = new ArrayList<>();
existingLabels.add(label1);
existingLabels.add(label2);
Mockito.when(labelDAO.getLabelsByName(labelNames)).thenReturn(existingLabels);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(labelDAO);
adminService.registerGatewayLabels(labels, "false");
Mockito.verify(labelDAO, Mockito.times(1)).addLabels(labels);
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testAddPolicy.
@Test(description = "Add policy")
public void testAddPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
APIPolicy policy = SampleTestObjectCreator.createDefaultAPIPolicy();
adminService.addApiPolicy(policy);
Mockito.verify(policyDAO, Mockito.times(1)).addApiPolicy(policy);
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).addApiPolicy(policy);
try {
adminService.addApiPolicy(policy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't add API policy for uuid: " + policy.getUuid());
}
}
Aggregations