public BarResource getBarResource(final String path, final String name, Class<?> clazz) throws IOException { final InputStream stream = clazz.getResourceAsStream(path); assertThat(stream).isNotNull(); try { final byte[] byteArray = IOUtils.toByteArray(stream); return new BarResource(name, byteArray); } finally { stream.close(); } }
protected void addBarResourceInPath(final BarResource resource, final String path) { final String resourcePath = path + resource.getName(); final byte[] resourceContent = resource.getContent(); if (resourceContent == null || resourceContent.length == 0) { throw new IllegalArgumentException("You are trying to add file " + resourcePath + " with empty content into the BusinessArchive (bar file)." + " Either add content to this file, or remove it from the resources."); } entity.addResource(resourcePath, resourceContent); }
public static BarResource getContentAndBuildBarResource(final String name, final Class<? extends Connector> clazz) throws IOException { final InputStream stream = clazz.getResourceAsStream(name); assertNotNull(stream); final byte[] byteArray = IOUtils.toByteArray(stream); stream.close(); return new BarResource(name, byteArray); }
protected void addBarResourceInPath(final BarResource resource, final String path) { final String resourcePath = path + resource.getName(); final byte[] resourceContent = resource.getContent(); if (resourceContent == null || resourceContent.length == 0) { throw new IllegalArgumentException("You are trying to add file " + resourcePath + " with empty content into the BusinessArchive (bar file)." + " Either add content to this file, or remove it from the resources."); } entity.addResource(resourcePath, resourceContent); }
public static BarResource generateConnectorImplementation(String definitionId, String definitionVersion, Class<? extends Connector> connectorClass) throws UnsupportedEncodingException { return new BarResource( connectorClass.getSimpleName() + ".impl", BuildTestUtil.buildConnectorImplementationFile(definitionId, definitionVersion, definitionId + "-impl", "generated", connectorClass.getName())); } /*
public static BarResource generateJarAndBuildBarResource(final Class<?> clazz, final String name) throws IOException { final byte[] data = IOUtil.generateJar(clazz); return new BarResource(name, data); }
void addToBusinessArchive(BusinessArchiveBuilder businessArchiveBuilder, List<SBARResource> resources) { for (SBARResource resource : resources) { businessArchiveBuilder.addConnectorImplementation(new BarResource(resource.getName(), resource.getContent())); } }
void addToBusinessArchive(BusinessArchiveBuilder businessArchiveBuilder, List<SBARResource> resources) { for (SBARResource resource : resources) { businessArchiveBuilder.addConnectorImplementation(new BarResource(resource.getName(), resource.getContent())); } }
abstract void addToBusinessArchive(BusinessArchiveBuilder businessArchiveBuilder, BarResource resource); }
abstract void addToBusinessArchive(BusinessArchiveBuilder businessArchiveBuilder, BarResource resource); }
@Override public void exportToBusinessArchive(long processDefinitionId, BusinessArchiveBuilder businessArchiveBuilder) throws SBonitaException { final ArrayList<FilterOption> filters = new ArrayList<>(); filters.add(new FilterOption(SDependencyMapping.class, "artifactId", processDefinitionId)); filters.add(new FilterOption(SDependencyMapping.class, "artifactType", ScopeType.PROCESS.name())); final List<SDependencyMapping> dependencyMappings = dependencyService .getDependencyMappings(new QueryOptions(0, Integer.MAX_VALUE, null, filters, null)); for (SDependencyMapping dependencyMapping : dependencyMappings) { final SDependency dependency = dependencyService.getDependency(dependencyMapping.getDependencyId()); businessArchiveBuilder.addClasspathResource(new BarResource(dependency.getFileName(), dependency.getValue())); } }
@Override public void exportToBusinessArchive(long processDefinitionId, BusinessArchiveBuilder businessArchiveBuilder) throws SBonitaException { final ArrayList<FilterOption> filters = new ArrayList<>(); filters.add(new FilterOption(SDependencyMapping.class, "artifactId", processDefinitionId)); filters.add(new FilterOption(SDependencyMapping.class, "artifactType", ScopeType.PROCESS.name())); final List<SDependencyMapping> dependencyMappings = dependencyService .getDependencyMappings(new QueryOptions(0, Integer.MAX_VALUE, null, filters, null)); for (SDependencyMapping dependencyMapping : dependencyMappings) { final SDependency dependency = dependencyService.getDependency(dependencyMapping.getDependencyId()); businessArchiveBuilder.addClasspathResource(new BarResource(dependency.getFileName(), dependency.getValue())); } }
@Test public void manageBusinessArchiveResources() throws Exception { final ProcessDefinitionBuilder processDefinitionBuilder = new ProcessDefinitionBuilder().createNewInstance("MyProcess", "1.0"); final BusinessArchive businessArchive = new BusinessArchiveBuilder().createNewBusinessArchive().setProcessDefinition(processDefinitionBuilder.done()) .addExternalResource(new BarResource("dummy.txt", new byte[] { 'a', 'b', 'c', 'd' })).done(); // Add a resource to the biz archive: BusinessArchiveFactory.writeBusinessArchiveToFile(businessArchive, barFile); // read from the file final BusinessArchive readBusinessArchive = BusinessArchiveFactory.readBusinessArchive(barFile); assertTrue("Added resource not found in BusinessArchive", readBusinessArchive.getResources().containsKey("resources/dummy.txt")); }
@Test public void addingEmptyDocument_to_BusinessArchive_should_throw_exception() throws Exception { final BusinessArchiveBuilder builder = new BusinessArchiveBuilder().createNewBusinessArchive() .setProcessDefinition(new ProcessDefinitionBuilder().createNewInstance("EmptyDoc", "7.3").done()); expectedEx.expect(IllegalArgumentException.class); expectedEx.expectMessage("You are trying to add file documents/resume.pdf with empty content into the BusinessArchive (bar file)." + " Either add content to this file, or remove it from the resources."); builder.addDocumentResource(new BarResource("resume.pdf", new byte[] {})); }
@Test public void addingEmptyResource_to_BusinessArchive_should_throw_exception() throws Exception { final BusinessArchiveBuilder builder = new BusinessArchiveBuilder().createNewBusinessArchive() .setProcessDefinition(new ProcessDefinitionBuilder().createNewInstance("Dummy", "11.01").done()); expectedEx.expect(IllegalArgumentException.class); expectedEx.expectMessage("You are trying to add file resources/dummy.txt with empty content into the BusinessArchive (bar file)." + " Either add content to this file, or remove it from the resources."); builder.addExternalResource(new BarResource("dummy.txt", new byte[] {})); }
@Test public void addingNullResource_to_BusinessArchive_should_throw_exception() throws Exception { final BusinessArchiveBuilder builder = new BusinessArchiveBuilder().createNewBusinessArchive() .setProcessDefinition(new ProcessDefinitionBuilder().createNewInstance("Dummy", "11.02").done()); expectedEx.expect(IllegalArgumentException.class); expectedEx.expectMessage("You are trying to add file resources/dummy.txt with empty content into the BusinessArchive (bar file)." + " Either add content to this file, or remove it from the resources."); builder.addExternalResource(new BarResource("dummy.txt", null)); }
@Test(expected = InvalidBusinessArchiveFormatException.class) public void createProcessWithAInBarDocumentMissingFile() throws InvalidProcessDefinitionException, InvalidBusinessArchiveFormatException { final ProcessDefinitionBuilder builder = new ProcessDefinitionBuilder().createNewInstance("MyProcessWithExternalDocuments", "1.0"); builder.addDocumentDefinition("myDoc").addContentFileName("testFile.txt").addDescription("a cool pdf document").addMimeType("application/pdf") .addFile("myPdf.pdf"); final DesignProcessDefinition processDefinition = builder.done(); new BusinessArchiveBuilder().createNewBusinessArchive().setProcessDefinition(processDefinition) .addDocumentResource(new BarResource("testFile.txt", new byte[] { 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 })).done(); }
.addDocumentResource(new BarResource("testFile.txt", new byte[] { 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 })).done(); BusinessArchiveFactory.writeBusinessArchiveToFile(businessArchive, barFile);