use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testDeleteLabel.
@Test(description = "Delete a label")
public void testDeleteLabel() throws APIManagementException {
LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(labelDAO);
Label label = SampleTestObjectCreator.createLabel("Public", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
String labelId = label.getId();
adminService.deleteLabel(labelId);
Mockito.verify(labelDAO, Mockito.times(1)).deleteLabel(labelId);
}
use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testRegisterGatewayLabelsWhenOverwriteLabelsNull.
@Test(description = "Register gateway labels when overwriteLabels value is null")
public void testRegisterGatewayLabelsWhenOverwriteLabelsNull() 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);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(labelDAO);
adminService.registerGatewayLabels(labels, null);
Mockito.verify(labelDAO, Mockito.times(1)).addLabels(labels);
}
use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testDeleteLabelException.
@Test(description = "Exception when deleting a label", expectedExceptions = APIManagementException.class)
public void testDeleteLabelException() throws APIManagementException {
LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(labelDAO);
Label label = SampleTestObjectCreator.createLabel("Public", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
String labelId = label.getId();
Mockito.doThrow(new APIMgtDAOException("Error occurred while deleting label [labelId] " + labelId)).when(labelDAO).deleteLabel(labelId);
adminService.deleteLabel(labelId);
Mockito.verify(labelDAO, Mockito.times(1)).deleteLabel(labelId);
}
use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class KubernetesGatewayImplTestCase method testRemoveContainerBasedGateway.
@Test
public void testRemoveContainerBasedGateway() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
KubernetesGatewayImpl kubernetesGateway = getKubernetesGatewayImpl(openShiftClient);
NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
BaseOperation baseOperation = Mockito.mock(BaseOperation.class);
Mockito.when(openShiftClient.services().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.withLabel(Mockito.anyString(), Mockito.anyString())).thenReturn(baseOperation);
Mockito.when(baseOperation.delete()).thenReturn(true);
Mockito.when(openShiftClient.extensions().deployments().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
Mockito.when(openShiftClient.extensions().ingresses().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
API api = SampleTestObjectCreator.createDefaultAPI().build();
kubernetesGateway.removeContainerBasedGateway("label", api);
Mockito.verify(openShiftClient, Mockito.times(2)).services();
Mockito.verify(openShiftClient, Mockito.times(4)).extensions();
}
use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class GatewaysApiServiceImpl method gatewaysRegisterPost.
/**
* Register gateway
*
* @param body RegistrationDTO
* @param contentType Content-Type header value
* @return Registration summary details
* @throws NotFoundException If failed to register gateway
*/
@Override
public Response gatewaysRegisterPost(RegistrationDTO body, String contentType, Request request) throws NotFoundException {
try {
LabelInfoDTO labelInfoDTO = body.getLabelInfo();
if (labelInfoDTO != null) {
APIMgtAdminService adminService = RestApiUtil.getAPIMgtAdminService();
String overwriteLabels = labelInfoDTO.getOverwriteLabels();
List<Label> labels = MappingUtil.convertToLabels(labelInfoDTO.getLabelList());
adminService.registerGatewayLabels(labels, overwriteLabels);
RegistrationSummary registrationSummary = adminService.getRegistrationSummary();
return Response.ok().entity(MappingUtil.toRegistrationSummaryDTO(registrationSummary)).build();
} else {
String errorMessage = "Label information cannot be null";
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.LABEL_INFORMATION_CANNOT_BE_NULL);
HashMap<String, String> paramList = new HashMap<String, String>();
org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
} catch (APIManagementException e) {
String errorMessage = "Error while registering the gateway";
HashMap<String, String> paramList = new HashMap<String, String>();
org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations