Search in sources :

Example 96 with Label

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

the class APIStoreImpl method getAPIWSDL.

@Override
public String getAPIWSDL(String apiId, String labelName) throws APIMgtDAOException, APIMgtWSDLException, APINotFoundException, LabelException {
    API api = getApiDAO().getAPI(apiId);
    if (api == null) {
        throw new APINotFoundException("API with id " + apiId + " not found.", ExceptionCodes.API_NOT_FOUND);
    }
    // api.getLabels() should not be null and the labels should contain labelName
    if ((api.getLabels() == null || !api.getLabels().contains(labelName))) {
        throw new LabelException("API with id " + apiId + " does not contain label " + labelName, ExceptionCodes.LABEL_NOT_FOUND_IN_API);
    }
    String wsdl = getApiDAO().getWSDL(apiId);
    Label label = getLabelDAO().getLabelByName(labelName);
    if (!StringUtils.isEmpty(wsdl)) {
        WSDLProcessor processor;
        try {
            processor = WSDLProcessFactory.getInstance().getWSDLProcessor(wsdl.getBytes(APIMgtConstants.ENCODING_UTF_8));
            return new String(processor.getUpdatedWSDL(api, label), APIMgtConstants.ENCODING_UTF_8);
        } catch (UnsupportedEncodingException e) {
            throw new APIMgtWSDLException("WSDL content is not in utf-8 encoding", e, ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT);
        }
    }
    return null;
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.core.api.WSDLProcessor) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) Label(org.wso2.carbon.apimgt.core.models.Label) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) LabelException(org.wso2.carbon.apimgt.core.exception.LabelException) APINotFoundException(org.wso2.carbon.apimgt.core.exception.APINotFoundException)

Example 97 with Label

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

the class ApiDAOImplIT method testAddGetAPIWithLabels.

@Test
public void testAddGetAPIWithLabels() throws Exception {
    LabelDAO labelDAO = DAOFactory.getLabelDAO();
    Label labelPublic = SampleTestObjectCreator.createLabel("public", SampleTestObjectCreator.LABEL_TYPE_GATEWAY).build();
    Label labelPrivate = SampleTestObjectCreator.createLabel("private", SampleTestObjectCreator.LABEL_TYPE_GATEWAY).build();
    List<Label> labelList = new ArrayList<>();
    labelList.add(labelPublic);
    labelList.add(labelPrivate);
    LabelDAOImpl.addLabel(labelPublic);
    LabelDAOImpl.addLabel(labelPrivate);
    String publicLabelFromDB = labelDAO.getLabelIdByNameAndType("public", SampleTestObjectCreator.LABEL_TYPE_GATEWAY);
    String privateLabelFromDB = labelDAO.getLabelIdByNameAndType("private", SampleTestObjectCreator.LABEL_TYPE_GATEWAY);
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    List<String> labelIds = new ArrayList<>();
    labelIds.add(publicLabelFromDB);
    labelIds.add(privateLabelFromDB);
    Collections.sort(labelIds);
    API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
    API apiWithBothLabels = builder.labels(labelIds).build();
    testAddGetEndpoint();
    apiDAO.addAPI(apiWithBothLabels);
    List<String> publicLabelOnly = new ArrayList<>();
    publicLabelOnly.add(publicLabelFromDB);
    API.APIBuilder builder2 = SampleTestObjectCreator.createAlternativeAPI();
    API apiWithPublicLabel = builder2.labels(publicLabelOnly).build();
    apiDAO.addAPI(apiWithPublicLabel);
    API apiFromDB = apiDAO.getAPI(apiWithBothLabels.getId());
    Assert.assertNotNull(apiFromDB);
    Assert.assertEquals(apiFromDB.getLabels().size(), 2);
    Assert.assertTrue(apiWithBothLabels.getLabels().equals(apiFromDB.getLabels()), TestUtil.printDiff(apiWithBothLabels.getLabels(), apiFromDB.getLabels()));
    List<API> apiListPublicPrivate = apiDAO.getAPIsByGatewayLabel(Arrays.asList(labelPublic.getName(), labelPrivate.getName()));
    Assert.assertEquals(apiListPublicPrivate.size(), 2);
    Assert.assertTrue(TestUtil.testAPIEqualsLazy(apiListPublicPrivate.get(0), apiWithBothLabels) || TestUtil.testAPIEqualsLazy(apiListPublicPrivate.get(1), apiWithBothLabels));
    Assert.assertTrue(TestUtil.testAPIEqualsLazy(apiListPublicPrivate.get(0), apiWithPublicLabel) || TestUtil.testAPIEqualsLazy(apiListPublicPrivate.get(1), apiWithPublicLabel));
    List<API> apiListPrivate = apiDAO.getAPIsByGatewayLabel(Collections.singletonList(labelPrivate.getName()));
    Assert.assertEquals(apiListPrivate.size(), 1);
    Assert.assertTrue(TestUtil.testAPIEqualsLazy(apiListPrivate.get(0), apiWithBothLabels));
    Assert.assertFalse(TestUtil.testAPIEqualsLazy(apiListPrivate.get(0), apiWithPublicLabel));
}
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) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 98 with Label

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

the class LabelDAOImplIT method testUpdateLabel.

@Test
public void testUpdateLabel() throws Exception {
    LabelDAO labelDAO = DAOFactory.getLabelDAO();
    Label label = SampleTestObjectCreator.createLabel("public", SampleTestObjectCreator.LABEL_TYPE_GATEWAY).build();
    Label labelAddedtoDB = LabelDAOImpl.addLabel(label);
    List<String> accessUrls = new ArrayList<>();
    accessUrls.add("https://updated.public");
    Label updatedLabel = SampleTestObjectCreator.createLabel("public", SampleTestObjectCreator.LABEL_TYPE_GATEWAY).id(labelAddedtoDB.getId()).accessUrls(accessUrls).build();
    labelDAO.updateLabel(updatedLabel);
    List<Label> labelsFromDb = labelDAO.getLabelsByType(SampleTestObjectCreator.LABEL_TYPE_GATEWAY);
    Assert.assertNotNull(labelsFromDb);
    Assert.assertEquals(labelsFromDb.size(), 2);
    Assert.assertTrue(labelsFromDb.contains(updatedLabel));
}
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 99 with Label

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

the class LabelDAOImplIT method testGetLabelsByNameForIncorrectLabelNames.

@Test
public void testGetLabelsByNameForIncorrectLabelNames() 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();
    LabelDAOImpl.addLabel(label1);
    LabelDAOImpl.addLabel(label2);
    List<String> labelNames = new ArrayList<>();
    labelNames.add("test");
    labelNames.add(label1.getName());
    List<Label> labelFromDb = labelDAO.getLabelsByName(labelNames);
    Assert.assertNotNull(labelFromDb);
    Assert.assertEquals(labelFromDb.size(), 1);
}
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 100 with Label

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

the class LabelDAOImplIT method testGetLabelsByID.

@Test
public void testGetLabelsByID() 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<>();
    LabelDAOImpl.addLabel(label1);
    LabelDAOImpl.addLabel(label2);
    List<String> labelNames = new ArrayList<>();
    labelNames.add(label1.getName());
    labelNames.add(label2.getName());
    List<String> labelIds = new ArrayList<>();
    labelIds.add(label1.getId());
    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)

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