Search in sources :

Example 1 with LabelException

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");
}
Also used : LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) LabelException(org.wso2.carbon.apimgt.core.exception.LabelException) Test(org.testng.annotations.Test)

Example 2 with LabelException

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"));
}
Also used : Response(javax.ws.rs.core.Response) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) LabelException(org.wso2.carbon.apimgt.core.exception.LabelException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with LabelException

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"));
}
Also used : Response(javax.ws.rs.core.Response) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) LabelException(org.wso2.carbon.apimgt.core.exception.LabelException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with LabelException

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;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) LabelExtractor(org.wso2.carbon.apimgt.core.api.LabelExtractor) Label(org.wso2.carbon.apimgt.core.models.Label) LabelException(org.wso2.carbon.apimgt.core.exception.LabelException)

Example 5 with LabelException

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");
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) LabelException(org.wso2.carbon.apimgt.core.exception.LabelException) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

LabelException (org.wso2.carbon.apimgt.core.exception.LabelException)10 Label (org.wso2.carbon.apimgt.core.models.Label)5 Test (org.testng.annotations.Test)4 LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)4 Response (javax.ws.rs.core.Response)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)3 ArrayList (java.util.ArrayList)2 BeforeTest (org.testng.annotations.BeforeTest)2 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)2 WSDLProcessor (org.wso2.carbon.apimgt.core.api.WSDLProcessor)2 APIMgtWSDLException (org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)2 APINotFoundException (org.wso2.carbon.apimgt.core.exception.APINotFoundException)2 API (org.wso2.carbon.apimgt.core.models.API)2 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1