use of org.wso2.carbon.humantask.core.engine.commands.Fail in project siddhi by wso2.
the class InMemoryTransportTestCase method inMemoryTestCase7.
@Test
public void inMemoryTestCase7() throws InterruptedException {
log.info("Test inMemory 7");
String streams = "" + "@app:name('TestSiddhiApp')" + "@source(type='testTrpInMemory', topic='Foo', prop1='hi', prop2='test', fail='true', " + " @map(type='passThrough', @attributes(symbol='trp:symbol'," + " volume='volume',price='trp:price'))) " + "define stream FooStream (symbol string, price string, volume long); " + "define stream BarStream (symbol string, price string, volume long); ";
String query = "" + "from FooStream " + "select * " + "insert into BarStream; ";
SiddhiManager siddhiManager = new SiddhiManager();
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("BarStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
wso2Count.incrementAndGet();
for (Event event : events) {
AssertJUnit.assertArrayEquals(event.getData(), new Object[] { "hi", "test", 100L });
}
}
});
siddhiAppRuntime.start();
InMemoryBroker.publish("Foo", new Event(System.currentTimeMillis(), new Object[] { "WSO2", "in", 100L }));
Thread.sleep(100);
// assert event count
AssertJUnit.assertEquals("Number of events", 0, wso2Count.get());
siddhiAppRuntime.shutdown();
}
use of org.wso2.carbon.humantask.core.engine.commands.Fail in project carbon-apimgt by wso2.
the class FileBasedApiImportExportManager method importAndCreateAPIs.
/**
* Imports and creates a set of new APIs to API Manager by reading and decoding the
* input stream. Will fail if the APIs already exists
*
* @param uploadedApiArchiveInputStream InputStream to be read ana decoded to a set of APIs
* @param provider API provider, if needs to be updated
* @return {@link APIListDTO} object comprising of successfully imported APIs
* @throws APIMgtEntityImportExportException if any error occurs while importing or no APIs are imported successfully
*/
public APIListDTO importAndCreateAPIs(InputStream uploadedApiArchiveInputStream, String provider) throws APIMgtEntityImportExportException {
String apiArchiveLocation = path + File.separator + IMPORTED_APIS_DIRECTORY_NAME + ".zip";
String archiveExtractLocation = null;
try {
archiveExtractLocation = APIFileUtils.extractUploadedArchive(uploadedApiArchiveInputStream, IMPORTED_APIS_DIRECTORY_NAME, apiArchiveLocation, path);
} catch (APIMgtDAOException e) {
String errorMsg = "Error in accessing uploaded API archive" + apiArchiveLocation;
log.error(errorMsg, e);
throw new APIMgtEntityImportExportException(errorMsg, e, ExceptionCodes.API_IMPORT_ERROR);
}
// List to contain newly created/updated APIs
Set<APIDetails> apiDetailsSet = decodeApiInformationFromDirectoryStructure(archiveExtractLocation, provider);
List<API> apis = new ArrayList<>();
for (APIDetails apiDetails : apiDetailsSet) {
try {
apis.add(importAndCreateApi(apiDetails));
} catch (APIManagementException e) {
log.error("Error while importing API: " + apiDetails.getApi().getName() + ", version: " + apiDetails.getApi().getVersion());
// skip importing the API
continue;
}
log.info("Successfully imported API: " + apiDetails.getApi().getName() + ", version: " + apiDetails.getApi().getVersion());
}
try {
APIFileUtils.deleteDirectory(path);
} catch (APIMgtDAOException e) {
log.warn("Unable to remove directory " + path);
}
// if no APIs are corrected exported, throw an error
if (apis.isEmpty()) {
String errorMsg = "No APIs imported successfully";
throw new APIMgtEntityImportExportException(errorMsg, ExceptionCodes.API_IMPORT_ERROR);
}
return MappingUtil.toAPIListDTO(apis);
}
use of org.wso2.carbon.humantask.core.engine.commands.Fail in project wso2-synapse by wso2.
the class VFSTransportListenerTest method testVFSTransportListenerBasics.
/**
* Testcase to test basic functionality of {@link VFSTransportListener}
* @throws Exception
*/
public void testVFSTransportListenerBasics() throws Exception {
MockFileHolder.getInstance().clear();
String fileUri = "test1:///foo/bar/test-" + System.currentTimeMillis() + "/DIR/IN/";
String moveAfterFailure = "test1:///foo/bar/test-" + System.currentTimeMillis() + "/DIR/FAIL/";
AxisService axisService = new AxisService("testVFSService");
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_FILE_URI, fileUri));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_CONTENT_TYPE, "text/xml"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_FILE_NAME_PATTERN, ".*\\.txt"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_ACTION_AFTER_PROCESS, VFSTransportListener.MOVE));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_ACTION_AFTER_FAILURE, VFSTransportListener.MOVE));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_MOVE_AFTER_FAILURE, moveAfterFailure));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_MOVE_AFTER_FAILED_MOVE, moveAfterFailure));
axisService.addParameter(new Parameter(VFSConstants.STREAMING, "false"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_LOCKING, VFSConstants.TRANSPORT_FILE_LOCKING_ENABLED));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_INTERVAL, "1000"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_COUNT, "1"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_AUTO_LOCK_RELEASE, "true"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_AUTO_LOCK_RELEASE_INTERVAL, "20000"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_AUTO_LOCK_RELEASE_SAME_NODE, "true"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_DISTRIBUTED_LOCK, "true"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_DISTRIBUTED_LOCK_TIMEOUT, "20000"));
axisService.addParameter(new Parameter(VFSConstants.FILE_SORT_PARAM, VFSConstants.FILE_SORT_VALUE_NAME));
axisService.addParameter(new Parameter(VFSConstants.FILE_SORT_ORDER, "true"));
TransportDescriptionFactory transportDescriptionFactory = new VFSTransportDescriptionFactory();
TransportInDescription transportInDescription = null;
try {
transportInDescription = transportDescriptionFactory.createTransportInDescription();
} catch (Exception e) {
Assert.fail("Error occurred while creating transport in description");
}
VFSTransportListener vfsTransportListener = getListener(transportInDescription);
// initialize listener
vfsTransportListener.init(new ConfigurationContext(new AxisConfiguration()), transportInDescription);
// Initialize VFSTransportListener
vfsTransportListener.doInit();
// Start listener
vfsTransportListener.start();
// Create poll entry
PollTableEntry pollTableEntry = vfsTransportListener.createEndpoint();
Assert.assertTrue("Global file locking not applied to created poll entry", pollTableEntry.isFileLockingEnabled());
// Load configuration of poll entry
pollTableEntry.loadConfiguration(axisService);
populatePollTableEntry(pollTableEntry, axisService, vfsTransportListener);
vfsTransportListener.poll(pollTableEntry);
MockFile targetDir = MockFileHolder.getInstance().getFile(fileUri);
Assert.assertNotNull("Failed target directory creation", targetDir);
Assert.assertEquals("Created target directory is not Folder type", targetDir.getName().getType(), FileType.FOLDER);
MockFile failDir = MockFileHolder.getInstance().getFile(moveAfterFailure);
Assert.assertNotNull("Fail to create expected directory to move files when failure", failDir);
MockFileHolder.getInstance().clear();
}
use of org.wso2.carbon.humantask.core.engine.commands.Fail in project wso2-synapse by wso2.
the class EventFilterTest method testTopicBasedEventFilter.
public void testTopicBasedEventFilter() {
String status = "snow";
try {
MessageContext msgCtx = TestUtils.getAxis2MessageContext("<weatherCondition>" + status + "</weatherCondition>", null).getAxis2MessageContext();
Event<MessageContext> event = new Event<MessageContext>();
event.setMessage(msgCtx);
TopicBasedEventFilter filter = new TopicBasedEventFilter();
filter.setResultValue(status);
filter.setSourceXpath(new SynapseXPath("//weatherCondition"));
assertTrue(filter.match(event));
filter.setResultValue("rain");
assertFalse(filter.match(event));
} catch (Exception e) {
fail("Error while constructing the test message context: " + e.getMessage());
}
}
use of org.wso2.carbon.humantask.core.engine.commands.Fail in project ballerina by ballerina-lang.
the class ParserUtils method getAllPackages.
/**
* Get All Native Packages.
*
* @return {@link Map} Package name, package functions and connectors
*/
public static Map<String, ModelPackage> getAllPackages() {
final Map<String, ModelPackage> modelPackage = new HashMap<>();
// TODO: remove once the packerina api for package listing is available
final String[] packageNames = { "net.http", "net.http.authadaptor", "net.http.endpoints", "net.http.mock", "net.http.swagger", "net.uri", "mime", "net.websub", "net.websub.hub", "net.grpc", "auth", "auth.authz", "auth.authz.permissionstore", "auth.basic", "auth.jwtAuth", "auth.userstore", "auth.utils", "caching", "collections", "config", "data.sql", "file", "internal", "io", "jwt", "jwt.signature", "log", "math", "os", "reflect", "runtime", "security.crypto", "task", "time", "transactions.coordinator", "user", "util" };
try {
List<BLangPackage> builtInPackages = LSPackageLoader.getBuiltinPackages();
for (BLangPackage bLangPackage : builtInPackages) {
loadPackageMap(bLangPackage.packageID.getName().getValue(), bLangPackage, modelPackage);
}
CompilerContext context = CommonUtil.prepareTempCompilerContext();
for (String packageName : packageNames) {
PackageID packageID = new PackageID(new Name("ballerina"), new Name(packageName), new Name("0.0.0"));
BLangPackage bLangPackage = LSPackageLoader.getPackageById(context, packageID);
loadPackageMap(bLangPackage.packageID.getName().getValue(), bLangPackage, modelPackage);
}
} catch (Exception e) {
// Above catch is to fail safe composer front end due to core errors.
logger.warn("Error while loading packages");
}
return modelPackage;
}
Aggregations