Search in sources :

Example 31 with Label

use of org.wso2.carbon.apimgt.core.models.Label 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)

Example 32 with Label

use of org.wso2.carbon.apimgt.core.models.Label in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method getLabelsByType.

@Test(description = "get  labels by STORE type")
public void getLabelsByType() throws Exception {
    LabelDAO labelDao = Mockito.mock(LabelDAO.class);
    APIStore apiStore = getApiStoreImpl(labelDao);
    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);
    List<Label> returnedLabels = apiStore.getLabelsByType("STORE");
    Assert.assertNotNull(returnedLabels);
    Mockito.verify(labelDao, Mockito.atLeastOnce()).getLabelsByType("STORE");
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 33 with Label

use of org.wso2.carbon.apimgt.core.models.Label in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testGetAPIWSDLArchive.

@Test(description = "Retrieve a WSDL archive of an API")
public void testGetAPIWSDLArchive() throws APIManagementException, IOException {
    final String labelName = "SampleLabel";
    Label label = SampleTestObjectCreator.createLabel(labelName, SampleTestObjectCreator.LABEL_TYPE_STORE).build();
    List<String> labels = new ArrayList<>();
    labels.add(label.getName());
    API api = SampleTestObjectCreator.createDefaultAPI().labels(labels).build();
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
    APIStore apiStore = getApiStoreImpl(apiDAO, labelDAO);
    Mockito.when(apiDAO.getAPI(api.getId())).thenReturn(api);
    Mockito.when(labelDAO.getLabelByName(labelName)).thenReturn(label);
    Mockito.when(apiDAO.getWSDLArchive(api.getId())).thenReturn(SampleTestObjectCreator.createDefaultWSDL11ArchiveInputStream());
    String expectedEndpoint = SampleTestObjectCreator.ACCESS_URL + labelName + (api.getContext().startsWith("/") ? api.getContext() : "/" + api.getContext());
    WSDLArchiveInfo archiveInfo = apiStore.getAPIWSDLArchive(api.getId(), label.getName());
    Assert.assertNotNull(archiveInfo);
    Assert.assertNotNull(archiveInfo.getWsdlInfo());
    Assert.assertNotNull(archiveInfo.getWsdlInfo().getEndpoints());
    Map<String, String> endpoints = archiveInfo.getWsdlInfo().getEndpoints();
    Assert.assertTrue(endpoints.containsValue(expectedEndpoint));
    Assert.assertFalse(endpoints.containsValue(SampleTestObjectCreator.ORIGINAL_ENDPOINT_STOCK_QUOTE));
    Assert.assertFalse(endpoints.containsValue(SampleTestObjectCreator.ORIGINAL_ENDPOINT_WEATHER));
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) WSDLArchiveInfo(org.wso2.carbon.apimgt.core.models.WSDLArchiveInfo) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 34 with Label

use of org.wso2.carbon.apimgt.core.models.Label in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method getAllLabelsException.

@Test(description = "get all labels Exception", expectedExceptions = Exception.class)
public void getAllLabelsException() 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.getLabels()).thenReturn(labels);
    Mockito.doThrow(new LabelException("Error occurred while retrieving labels ")).when(labelDao).getLabels();
    apiStore.getAllLabels();
}
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)

Example 35 with Label

use of org.wso2.carbon.apimgt.core.models.Label in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testGetLabelInfo.

@Test(description = "Retrieve labels")
public void testGetLabelInfo() throws APIManagementException {
    LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
    APIStore apiStore = getApiStoreImpl(labelDAO);
    List<Label> labelList = new ArrayList<>();
    List<String> labelNames = new ArrayList<>();
    Label label = SampleTestObjectCreator.createLabel("Public", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
    labelList.add(label);
    labelNames.add(label.getName());
    Mockito.when(labelDAO.getLabelsByName(labelNames)).thenReturn(labelList);
    List<Label> returnedLabels = apiStore.getLabelInfo(labelNames, USER_NAME);
    Assert.assertEquals(returnedLabels, labelList);
    Mockito.verify(labelDAO, Mockito.times(1)).getLabelsByName(labelNames);
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

Label (org.wso2.carbon.apimgt.core.models.Label)65 ArrayList (java.util.ArrayList)52 Test (org.testng.annotations.Test)45 LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)32 API (org.wso2.carbon.apimgt.core.models.API)29 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)28 SQLException (java.sql.SQLException)21 PreparedStatement (java.sql.PreparedStatement)20 HashMap (java.util.HashMap)16 Connection (java.sql.Connection)15 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)14 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)13 Test (org.junit.Test)12 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)11 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)11 Map (java.util.Map)10 BeforeTest (org.testng.annotations.BeforeTest)9 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)8 Response (javax.ws.rs.core.Response)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8