Search in sources :

Example 26 with Label

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

the class LabelDAOImplIT method testGetLabelById.

@Test
public void testGetLabelById() throws Exception {
    LabelDAO labelDAO = DAOFactory.getLabelDAO();
    Label label = SampleTestObjectCreator.createLabel("public", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
    Label labelAdded = LabelDAOImpl.addLabel(label);
    Label labelFromDb = labelDAO.getLabelByID(labelAdded.getId());
    Assert.assertNotNull(labelFromDb);
    Assert.assertEquals(label.getName(), labelFromDb.getName());
    Assert.assertEquals(label.getType(), labelFromDb.getType());
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) Test(org.testng.annotations.Test)

Example 27 with Label

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

the class LabelDAOImplIT method testGetLabelNamesByIDs.

@Test
public void testGetLabelNamesByIDs() throws Exception {
    LabelDAO labelDAO = DAOFactory.getLabelDAO();
    Label label1 = SampleTestObjectCreator.createLabel("public", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
    Label label2 = SampleTestObjectCreator.createLabel("private", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
    List<Label> labelList = new ArrayList<>();
    labelList.add(label1);
    labelList.add(label2);
    labelDAO.addLabels(labelList);
    List<String> labelIds = new ArrayList<>();
    labelIds.add("10000000003");
    labelIds.add(label2.getId());
    List<Label> labelFromDb = new ArrayList<>();
    for (String id : labelIds) {
        labelFromDb.add(labelDAO.getLabelByID(id));
    }
    Assert.assertNotNull(labelFromDb);
    Assert.assertEquals(labelFromDb.size(), 2);
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) Test(org.testng.annotations.Test)

Example 28 with Label

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

the class LabelDAOImplIT method testGetLabelsByIDForIncorrectLabelID.

@Test
public void testGetLabelsByIDForIncorrectLabelID() throws Exception {
    LabelDAO labelDAO = DAOFactory.getLabelDAO();
    Label labelFromDb = labelDAO.getLabelByID("100000000002");
    Assert.assertNull(labelFromDb);
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) Test(org.testng.annotations.Test)

Example 29 with Label

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

the class LabelDAOImplIT method testAddGetLabels.

@Test
public void testAddGetLabels() throws Exception {
    LabelDAO labelDAO = DAOFactory.getLabelDAO();
    List<String> accessUrls = new ArrayList<>();
    accessUrls.add("https://test.public");
    accessUrls.add("http://test.public");
    Label label1 = SampleTestObjectCreator.createLabel("public", SampleTestObjectCreator.LABEL_TYPE_GATEWAY).accessUrls(accessUrls).build();
    LabelDAOImpl.addLabel(label1);
    Label label2 = SampleTestObjectCreator.createLabel("private", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
    List<Label> labelList = new ArrayList<>();
    LabelDAOImpl.addLabel(label2);
    List<Label> labelsFromDb = labelDAO.getLabels();
    Assert.assertNotNull(labelsFromDb);
    Assert.assertEquals(labelsFromDb.size(), 4);
}
Also used : ArrayList(java.util.ArrayList) Label(org.wso2.carbon.apimgt.core.models.Label) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) Test(org.testng.annotations.Test)

Example 30 with Label

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

the class APIStoreImplTestCase method testGetLabelInfoException.

@Test(description = "Exception when retrieving labels", expectedExceptions = LabelException.class)
public void testGetLabelInfoException() throws APIManagementException {
    LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
    APIStore apiStore = getApiStoreImpl(labelDAO);
    List<String> labels = new ArrayList<>();
    labels.add("label");
    Mockito.when(labelDAO.getLabelsByName(labels)).thenThrow(new APIMgtDAOException("Error occurred while retrieving label information", new SQLException()));
    apiStore.getLabelInfo(labels, USER_NAME);
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) 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