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;
}
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));
}
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));
}
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);
}
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);
}
Aggregations