use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class IsolatedClassLoaderFactory method getLibraryPackages.
private JarInfo getLibraryPackages(List<URL> libraries) {
Set<String> packages = new HashSet<>();
Set<String> resources = new HashSet<>();
final JarExplorer jarExplorer = new FileJarExplorer();
for (URL library : libraries) {
try {
JarInfo jarInfo = jarExplorer.explore(library.toURI());
packages.addAll(jarInfo.getPackages());
resources.addAll(jarInfo.getResources());
} catch (URISyntaxException e) {
throw new MuleRuntimeException(e);
}
}
return new JarInfo(packages, resources);
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class ZipUtils method compress.
/**
* Compress a set of resource files into a ZIP file
*
* @param targetFile file that will contain the zipped files
* @param resources resources to compress
* @throws UncheckedIOException in case of any error processing the files
*/
public static void compress(File targetFile, ZipResource[] resources) {
try (ZipOutputStream out = new ZipOutputStream(new FileOutputStream(targetFile))) {
for (ZipResource zipResource : resources) {
URL resourceUrl = ClassUtils.getResource(zipResource.file, ZipUtils.class);
if (resourceUrl == null) {
resourceUrl = new File(zipResource.file).toURI().toURL();
}
try (FileInputStream in = new FileInputStream(new File(resourceUrl.toURI()))) {
out.putNextEntry(new ZipEntry(zipResource.alias == null ? zipResource.file : zipResource.alias));
byte[] buffer = new byte[1024];
int count;
while ((count = in.read(buffer)) > 0) {
out.write(buffer, 0, count);
}
} catch (URISyntaxException e) {
throw new MuleRuntimeException(e);
}
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class MuleContextUtils method mockContextWithServices.
/**
* Creates and configures a mock {@link MuleContext} to return testing services implementations.
*
* @return the created {@code muleContext}.
*/
public static MuleContextWithRegistries mockContextWithServices() {
final MuleContextWithRegistries muleContext = mockMuleContext();
SchedulerService schedulerService = spy(new SimpleUnitTestSupportSchedulerService());
when(muleContext.getSchedulerService()).thenReturn(schedulerService);
ErrorTypeRepository errorTypeRepository = mock(ErrorTypeRepository.class);
when(muleContext.getErrorTypeRepository()).thenReturn(errorTypeRepository);
when(errorTypeRepository.getErrorType(any(ComponentIdentifier.class))).thenReturn(of(mock(ErrorType.class)));
final MuleRegistry registry = muleContext.getRegistry();
NotificationListenerRegistry notificationListenerRegistry = mock(NotificationListenerRegistry.class);
ConfigurationProperties configProps = mock(ConfigurationProperties.class);
when(configProps.resolveBooleanProperty(any())).thenReturn(empty());
ConfigurationComponentLocator configurationComponentLocator = mock(ConfigurationComponentLocator.class);
when(configurationComponentLocator.find(any(Location.class))).thenReturn(empty());
when(configurationComponentLocator.find(any(ComponentIdentifier.class))).thenReturn(emptyList());
try {
when(registry.lookupObject(NotificationListenerRegistry.class)).thenReturn(notificationListenerRegistry);
Map<Class, Object> injectableObjects = new HashMap<>();
injectableObjects.put(MuleContext.class, muleContext);
injectableObjects.put(SchedulerService.class, schedulerService);
injectableObjects.put(ErrorTypeRepository.class, errorTypeRepository);
injectableObjects.put(ExtendedExpressionManager.class, muleContext.getExpressionManager());
injectableObjects.put(StreamingManager.class, muleContext.getRegistry().lookupObject(StreamingManager.class));
injectableObjects.put(ObjectStoreManager.class, muleContext.getRegistry().lookupObject(OBJECT_STORE_MANAGER));
injectableObjects.put(NotificationDispatcher.class, muleContext.getRegistry().lookupObject(NotificationDispatcher.class));
injectableObjects.put(NotificationListenerRegistry.class, notificationListenerRegistry);
injectableObjects.put(ConfigurationComponentLocator.class, configurationComponentLocator);
injectableObjects.put(ConfigurationProperties.class, configProps);
// Ensure injection of consistent mock objects
when(muleContext.getInjector()).thenReturn(new MocksInjector(injectableObjects));
} catch (RegistrationException e1) {
throw new MuleRuntimeException(e1);
}
return muleContext;
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class MVELExpressionLanguageTestCase method createEvent.
protected PrivilegedEvent createEvent(String payload, DataType dataType, Object attributes, DataType attributesDataType) {
InternalMessage message = mock(InternalMessage.class);
when(message.getPayload()).thenReturn(new TypedValue<>(payload, dataType));
when(message.getAttributes()).thenReturn(new TypedValue<>(attributes, attributesDataType));
try {
return this.<PrivilegedEvent.Builder>getEventBuilder().message(message).build();
} catch (MuleException e) {
throw new MuleRuntimeException(e);
}
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class SingleResourceTransactionFactoryManager method getTransactionFactoryFor.
public TransactionFactory getTransactionFactoryFor(Class type) {
TransactionFactory transactionFactory = transactionFactoriesCache.get(type);
if (transactionFactory == null) {
for (Class transactionResourceType : transactionFactories.keySet()) {
if (transactionResourceType.isAssignableFrom(type)) {
transactionFactory = transactionFactories.get(transactionResourceType);
this.transactionFactoriesCache.put(type, transactionFactory);
break;
}
}
}
if (transactionFactory == null) {
throw new MuleRuntimeException(CoreMessages.createStaticMessage(String.format("No %s for transactional resource %s", TransactionFactory.class.getName(), type.getName())));
}
return transactionFactory;
}
Aggregations