use of org.wso2.carbon.apimgt.core.exception.LabelException in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method getLabelsByTypeException.
@Test(description = "get labels by type Exception", expectedExceptions = Exception.class)
public void getLabelsByTypeException() throws Exception {
LabelDAO labelDao = Mockito.mock(LabelDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(labelDao);
Mockito.when(labelDao.getLabelsByType("GATEWAY")).thenThrow(new LabelException("Error occurred while " + "retrieving labels"));
apiPublisher.getLabelsByType("GATEWAY");
}
use of org.wso2.carbon.apimgt.core.exception.LabelException in project carbon-apimgt by wso2.
the class LabelsApiServiceImplTestCase method testLabelsGetException.
@Test
public void testLabelsGetException() throws Exception {
printTestMethodName();
LabelsApiServiceImpl labelsApiService = new LabelsApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
Mockito.doThrow(new LabelException("Error occurred", ExceptionCodes.LABEL_EXCEPTION)).when(apiPublisher).getAllLabels();
Response response = labelsApiService.labelsGet(null, null, null, null, getRequest());
assertEquals(response.getStatus(), 500);
assertTrue(response.getEntity().toString().contains("Label Error"));
}
use of org.wso2.carbon.apimgt.core.exception.LabelException in project carbon-apimgt by wso2.
the class PoliciesApiServiceImplTestCase method testPoliciesTierLevelTierNameGetException.
@Test
public void testPoliciesTierLevelTierNameGetException() throws Exception {
printTestMethodName();
PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
Mockito.doThrow(new LabelException("Error occurred", ExceptionCodes.POLICY_LEVEL_NOT_SUPPORTED)).when(apiPublisher).getPolicyByName(RestApiUtil.mapRestApiPolicyLevelToPolicyLevelEnum("subscription"), "Gold");
Response response = policiesApiService.policiesTierLevelTierNameGet("Gold", "subscription", null, null, getRequest());
assertEquals(response.getStatus(), 400);
assertTrue(response.getEntity().toString().contains("Throttle Policy level invalid"));
}
use of org.wso2.carbon.apimgt.core.exception.LabelException in project carbon-apimgt by wso2.
the class APIStoreImpl method getLabelInfo.
@Override
public List<Label> getLabelInfo(List<String> labels, String username) throws LabelException {
List<Label> filteredLabels;
String labelExtractorClassName = getConfig().getLabelExtractorImplClass();
try {
List<Label> availableLabels = getLabelDAO().getLabelsByName(labels);
LabelExtractor labelExtractor = (LabelExtractor) Class.forName(labelExtractorClassName).newInstance();
filteredLabels = labelExtractor.filterLabels(username, availableLabels);
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while retrieving label information";
log.error(errorMsg, e);
throw new LabelException(errorMsg, e, ExceptionCodes.LABEL_EXCEPTION);
} catch (ClassNotFoundException e) {
String errorMsg = "Error occurred while loading the class [class name] " + labelExtractorClassName;
log.error(errorMsg, e);
throw new LabelException(errorMsg, e, ExceptionCodes.LABEL_EXCEPTION);
} catch (IllegalAccessException | InstantiationException e) {
String errorMsg = "Error occurred while creating an instance of the class [class name] " + labelExtractorClassName;
log.error(errorMsg, e);
throw new LabelException(errorMsg, e, ExceptionCodes.LABEL_EXCEPTION);
}
return filteredLabels;
}
use of org.wso2.carbon.apimgt.core.exception.LabelException in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method getLabelsByTypeException.
@Test(description = "get labels by type Exception", expectedExceptions = Exception.class)
public void getLabelsByTypeException() throws Exception {
LabelDAO labelDao = Mockito.mock(LabelDAO.class);
APIStore apiStore = getApiStoreImpl();
List<Label> labels = new ArrayList<>();
Label label = new Label.Builder().id("123").name("Default").type("STORE").accessUrls(new ArrayList<>()).build();
labels.add(label);
Mockito.when(labelDao.getLabelsByType("STORE")).thenReturn(labels);
Mockito.doThrow(new LabelException("Error occurred while retrieving labels ")).when(labelDao).getLabelsByType("STORE");
apiStore.getLabelsByType("STORE");
}
Aggregations