use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testRegisterGatewayLabelsWhenOverwriteLabelsTrue.
@Test(description = "Register gateway labels when overwriteLabels value is true")
public void testRegisterGatewayLabelsWhenOverwriteLabelsTrue() throws APIManagementException {
LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
List<Label> labels = new ArrayList<>();
Label label1 = SampleTestObjectCreator.createLabel("testLabel1", 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);
Mockito.when(labelDAO.getLabelsByName(labelNames)).thenReturn(existingLabels);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(labelDAO);
adminService.registerGatewayLabels(labels, "true");
Mockito.verify(labelDAO, Mockito.times(1)).addLabels(labels);
Mockito.verify(labelDAO, Mockito.times(1)).updateLabel(label1);
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetApplicationPolicy.
@Test(description = "Test getting Application policy")
public void testGetApplicationPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
ApplicationPolicy applicationPolicy = SampleTestObjectCreator.createDefaultApplicationPolicy();
Mockito.when(policyDAO.getApplicationPolicy(applicationPolicy.getPolicyName())).thenReturn(applicationPolicy);
adminService.getApplicationPolicy(applicationPolicy.getPolicyName());
Mockito.verify(policyDAO, Mockito.times(1)).getApplicationPolicy(applicationPolicy.getPolicyName());
// Error path
Mockito.when(policyDAO.getApplicationPolicy(applicationPolicy.getPolicyName())).thenThrow(APIMgtDAOException.class);
try {
adminService.getApplicationPolicy(applicationPolicy.getPolicyName());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't retrieve Application policy with name: " + applicationPolicy.getPolicyName());
}
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetApiPolicy.
@Test(description = "Test getting API policy")
public void testGetApiPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
Mockito.when(policyDAO.getApiPolicy(apiPolicy.getPolicyName())).thenReturn(apiPolicy);
adminService.getApiPolicy(apiPolicy.getPolicyName());
Mockito.verify(policyDAO, Mockito.times(1)).getApiPolicy(apiPolicy.getPolicyName());
// Error path
Mockito.when(policyDAO.getApiPolicy(apiPolicy.getPolicyName())).thenThrow(APIMgtDAOException.class);
try {
adminService.getApiPolicy(apiPolicy.getPolicyName());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't retrieve API policy with name: " + apiPolicy.getPolicyName());
}
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetCustomRuleByUUID.
@Test(description = "Test getting custom rule by uuid")
public void testGetCustomRuleByUUID() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
CustomPolicy customPolicy = SampleTestObjectCreator.createDefaultCustomPolicy();
Mockito.when(policyDAO.getCustomPolicyByUuid(customPolicy.getUuid())).thenReturn(customPolicy);
CustomPolicy customPolicyReturned = adminService.getCustomRuleByUUID(customPolicy.getUuid());
Assert.assertEquals(customPolicyReturned, customPolicy);
// Error path
Mockito.when(policyDAO.getCustomPolicyByUuid(customPolicy.getUuid())).thenThrow(APIMgtDAOException.class);
try {
adminService.getCustomRuleByUUID(customPolicy.getUuid());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't get custom policy by UUID: " + customPolicy.getUuid());
}
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetAllEndpoints.
@Test(description = "Test getting all endpoints")
public void testGetAllEndpoints() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(apiDAO);
List<Endpoint> endpointListExpected = new ArrayList<>();
Endpoint endpoint = SampleTestObjectCreator.createMockEndpoint();
endpointListExpected.add(endpoint);
Mockito.when(apiDAO.getEndpoints()).thenReturn(endpointListExpected);
List<Endpoint> endpointListReturned = adminService.getAllEndpoints();
Assert.assertEquals(endpointListReturned, endpointListExpected);
// Error path
Mockito.when(apiDAO.getEndpoints()).thenThrow(APIMgtDAOException.class);
try {
adminService.getAllEndpoints();
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error occurred while getting the Endpoint list");
}
}
Aggregations