use of org.wso2.carbon.apimgt.api.APIDefinition in project carbon-apimgt by wso2.
the class APIStoreImpl method addCompositeApiFromDefinition.
/**
* {@inheritDoc}
*/
@Override
public String addCompositeApiFromDefinition(InputStream apiDefinition) throws APIManagementException {
try {
String apiDefinitionString = IOUtils.toString(apiDefinition);
CompositeAPI.Builder apiBuilder = apiDefinitionFromSwagger20.generateCompositeApiFromSwaggerResource(getUsername(), apiDefinitionString);
apiBuilder.apiDefinition(apiDefinitionString);
addCompositeApi(apiBuilder);
return apiBuilder.getId();
} catch (IOException e) {
throw new APIManagementException("Couldn't Generate ApiDefinition from file", ExceptionCodes.API_DEFINITION_MALFORMED);
}
}
use of org.wso2.carbon.apimgt.api.APIDefinition in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testSingleWSDLForAPI.
@Test
public void testSingleWSDLForAPI() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
// there can't be any WSDLs added at first
boolean isWSDLExists = apiDAO.isWSDLExists(api.getId());
Assert.assertFalse(isWSDLExists);
boolean isWSDLArchiveExists = apiDAO.isWSDLArchiveExists(api.getId());
Assert.assertFalse(isWSDLArchiveExists);
// add a WSDL
byte[] wsdlContentBytes = SampleTestObjectCreator.createDefaultWSDL11Content();
apiDAO.addOrUpdateWSDL(api.getId(), wsdlContentBytes, ADMIN);
// retrieves and check whether they are same
String receivedFromDB = apiDAO.getWSDL(api.getId());
Assert.assertEquals(new String(wsdlContentBytes), receivedFromDB);
// now there should be a single WSDL for API exists but no WSDL archives
isWSDLExists = apiDAO.isWSDLExists(api.getId());
Assert.assertTrue(isWSDLExists);
isWSDLArchiveExists = apiDAO.isWSDLArchiveExists(api.getId());
Assert.assertFalse(isWSDLArchiveExists);
// update the WSDL file
wsdlContentBytes = SampleTestObjectCreator.createAlternativeWSDL11Content();
apiDAO.addOrUpdateWSDL(api.getId(), wsdlContentBytes, ADMIN);
// retrieves and check whether updated successfully
receivedFromDB = apiDAO.getWSDL(api.getId());
Assert.assertEquals(new String(wsdlContentBytes), receivedFromDB);
// update with a WSDL archive
InputStream wsdl11ArchiveInputStream = SampleTestObjectCreator.createDefaultWSDL11ArchiveInputStream();
byte[] wsdlArchiveBytesDefault = IOUtils.toByteArray(SampleTestObjectCreator.createDefaultWSDL11ArchiveInputStream());
apiDAO.addOrUpdateWSDLArchive(api.getId(), wsdl11ArchiveInputStream, ADMIN);
// retrieves and check whether successfully updated
InputStream wsdlArchiveInputStreamFromDB = apiDAO.getWSDLArchive(api.getId());
byte[] streamFromDBBytes = IOUtils.toByteArray(wsdlArchiveInputStreamFromDB);
Assert.assertEquals(wsdlArchiveBytesDefault.length, streamFromDBBytes.length);
// removes and validate
apiDAO.removeWSDLArchiveOfAPI(api.getId());
isWSDLExists = apiDAO.isWSDLExists(api.getId());
Assert.assertFalse(isWSDLExists);
isWSDLArchiveExists = apiDAO.isWSDLArchiveExists(api.getId());
Assert.assertFalse(isWSDLArchiveExists);
}
use of org.wso2.carbon.apimgt.api.APIDefinition in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testUpdateGetDedicatedGatewayWhenLabelsAreEmpty.
@Test
public void testUpdateGetDedicatedGatewayWhenLabelsAreEmpty() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
DedicatedGateway dedicatedGateway = new DedicatedGateway();
dedicatedGateway.setEnabled(true);
dedicatedGateway.setUpdatedBy(api.getCreatedBy());
dedicatedGateway.setApiId(api.getId());
List<String> labels = new ArrayList<>();
apiDAO.updateDedicatedGateway(dedicatedGateway, labels);
DedicatedGateway result = apiDAO.getDedicatedGateway(api.getId());
Assert.assertEquals(result.isEnabled(), dedicatedGateway.isEnabled());
}
use of org.wso2.carbon.apimgt.api.APIDefinition in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testWSDLArchiveForAPI.
@Test
public void testWSDLArchiveForAPI() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
// there can't be any WSDLs added at first
boolean isWSDLExists = apiDAO.isWSDLExists(api.getId());
Assert.assertFalse(isWSDLExists);
boolean isWSDLArchiveExists = apiDAO.isWSDLArchiveExists(api.getId());
Assert.assertFalse(isWSDLArchiveExists);
// add a WSDL
InputStream wsdl11ArchiveInputStream = SampleTestObjectCreator.createDefaultWSDL11ArchiveInputStream();
byte[] wsdlArchiveBytesDefault = IOUtils.toByteArray(SampleTestObjectCreator.createDefaultWSDL11ArchiveInputStream());
apiDAO.addOrUpdateWSDLArchive(api.getId(), wsdl11ArchiveInputStream, ADMIN);
// retrieves and check whether they are same
InputStream wsdlArchiveInputStreamFromDB = apiDAO.getWSDLArchive(api.getId());
byte[] streamFromDBBytes = IOUtils.toByteArray(wsdlArchiveInputStreamFromDB);
Assert.assertEquals(wsdlArchiveBytesDefault.length, streamFromDBBytes.length);
// now there should be a single WSDL for API exists but no WSDL archives
isWSDLExists = apiDAO.isWSDLExists(api.getId());
Assert.assertTrue(isWSDLExists);
isWSDLArchiveExists = apiDAO.isWSDLArchiveExists(api.getId());
Assert.assertTrue(isWSDLArchiveExists);
// update the WSDL archive
InputStream alternativeWSDL11ArchiveInputStream = SampleTestObjectCreator.createAlternativeWSDL11ArchiveInputStream();
apiDAO.addOrUpdateWSDLArchive(api.getId(), alternativeWSDL11ArchiveInputStream, ADMIN);
// retrieves and check whether updated successfully
byte[] wsdlArchiveBytesAlternative = IOUtils.toByteArray(SampleTestObjectCreator.createAlternativeWSDL11ArchiveInputStream());
wsdlArchiveInputStreamFromDB = apiDAO.getWSDLArchive(api.getId());
streamFromDBBytes = IOUtils.toByteArray(wsdlArchiveInputStreamFromDB);
Assert.assertEquals(streamFromDBBytes.length, wsdlArchiveBytesAlternative.length);
// update the WSDL with a file
byte[] wsdlContentBytes = SampleTestObjectCreator.createAlternativeWSDL11Content();
apiDAO.addOrUpdateWSDL(api.getId(), wsdlContentBytes, ADMIN);
// retrieves and check whether updated successfully
String receivedFromDB = apiDAO.getWSDL(api.getId());
Assert.assertEquals(new String(wsdlContentBytes), receivedFromDB);
// removes and validate
apiDAO.removeWSDL(api.getId());
isWSDLExists = apiDAO.isWSDLExists(api.getId());
Assert.assertFalse(isWSDLExists);
isWSDLArchiveExists = apiDAO.isWSDLArchiveExists(api.getId());
Assert.assertFalse(isWSDLArchiveExists);
}
use of org.wso2.carbon.apimgt.api.APIDefinition in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testDocumentAdd.
@Test
public void testDocumentAdd() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultFileDocumentationInfo();
Assert.assertFalse(apiDAO.isDocumentExist(api.getId(), documentInfo));
apiDAO.addDocumentInfo(api.getId(), documentInfo);
apiDAO.addDocumentFileContent(documentInfo.getId(), IOUtils.toInputStream(SampleTestObjectCreator.createDefaultInlineDocumentationContent()), "inline1.txt", documentInfo.getCreatedBy());
Assert.assertTrue(apiDAO.isDocumentExist(api.getId(), documentInfo));
List<DocumentInfo> documentInfoList = apiDAO.getDocumentsInfoList(api.getId());
Assert.assertEquals(documentInfoList.get(0), documentInfo);
apiDAO.deleteDocument(documentInfo.getId());
Assert.assertFalse(apiDAO.isDocumentExist(api.getId(), documentInfo));
}
Aggregations