Ejemplo n.º 1
0
  @Test
  public void testCallPloidyThree() throws Exception {
    Files.write(Resources.toByteArray(getClass().getResource("testfile2.bam")), bamFile);
    Files.write(Resources.toByteArray(getClass().getResource("hla-a.bed")), bedFile);

    new FilterConsensus(bamFile, bedFile, outputFile, gene, cdna, removeGaps, minimumBreadth, 3)
        .call();
    assertEquals(6, countLines(outputFile));
  }
Ejemplo n.º 2
0
  @Test
  public void testCallKirExons() throws Exception {
    Files.write(
        Resources.toByteArray(getClass().getResource("2DL1_0020101.bwa.sorted.bam")), bamFile);
    Files.write(Resources.toByteArray(getClass().getResource("kir-2dl1.exons.bed")), bedFile);

    cdna = false;
    removeGaps = false;
    new FilterConsensus(
            bamFile, bedFile, outputFile, gene, cdna, removeGaps, minimumBreadth, expectedPloidy)
        .call();
    assertEquals(16, countLines(outputFile));
  }
Ejemplo n.º 3
0
  @Test
  public void packingALargeFileShouldGenerateTheSameOutputWhenOverwritingAsWhenAppending()
      throws IOException {
    File reference = File.createTempFile("reference", ".zip");
    String packageName = getClass().getPackage().getName().replace(".", "/");
    URL sample = Resources.getResource(packageName + "/macbeth.properties");
    byte[] input = Resources.toByteArray(sample);

    try (CustomZipOutputStream out = ZipOutputStreams.newOutputStream(output, OVERWRITE_EXISTING);
        ZipOutputStream ref = new ZipOutputStream(new FileOutputStream(reference))) {
      CustomZipEntry entry = new CustomZipEntry("macbeth.properties");
      entry.setTime(System.currentTimeMillis());
      out.putNextEntry(entry);
      ref.putNextEntry(entry);
      out.write(input);
      ref.write(input);
    }

    byte[] seen = Files.readAllBytes(output);
    byte[] expected = Files.readAllBytes(reference.toPath());

    // Make sure the output is valid.
    try (ZipInputStream in = new ZipInputStream(Files.newInputStream(output))) {
      ZipEntry entry = in.getNextEntry();
      assertEquals("macbeth.properties", entry.getName());
      assertNull(in.getNextEntry());
    }

    assertArrayEquals(expected, seen);
  }
Ejemplo n.º 4
0
  /** @return true if already exists/wrote to file, false if writing to file failed */
  protected boolean copyDefaultConfig() {
    File dataFolder = getDataFolder();

    // make data folder if it isn't there
    if (!dataFolder.exists() && !dataFolder.mkdir()) {
      // data folder creation failed
      return false;
    }

    File configFile = new File(getDataFolder(), "config.yml");

    // config file already exists
    if (configFile.exists()) return true;

    // write the defaults
    URL defaultConfig = Resources.getResource(this.getClass(), "/default.yml");
    try {
      // write /default.yml to the config.yml file
      Files.write(Resources.toByteArray(defaultConfig), configFile);
    } catch (IOException e) {
      e.printStackTrace();
      // something failed during writing
      return false;
    }

    // config wrote successfully
    return true;
  }
Ejemplo n.º 5
0
  @Test
  public void testMixinIcon() throws Exception {
    byte[] data = Resources.toByteArray(getClass().getResource("mixinicon.png"));
    final Icon icon = Icon.from(data, "image/png", Instant.now());

    Mixin mixin =
        Mixin.create()
            .name("myapplication:postal_code")
            .displayName("My content type")
            .icon(icon)
            .addFormItem(
                Input.create()
                    .name("postal_code")
                    .label("Postal code")
                    .inputType(InputTypeName.TEXT_LINE)
                    .build())
            .build();
    setupMixin(mixin);

    // exercise
    final Response response = this.resource.getIcon("myapplication:postal_code", 20, null);
    final BufferedImage mixinIcon = (BufferedImage) response.getEntity();

    // verify
    assertImage(mixinIcon, 20);
  }
 public HttpResponse prepareResponse(int responseStatus, String fileName) throws IOException {
   HttpResponse response =
       new BasicHttpResponse(
           new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), responseStatus, ""));
   response.setStatusCode(responseStatus);
   byte[] bytes = Resources.toByteArray(Resources.getResource(fileName));
   response.setEntity(new ByteArrayEntity(bytes));
   return response;
 }
 @Test
 public void apkBytes() throws IOException {
   byte[] apk = Resources.toByteArray(Resources.getResource("one.apk"));
   List<String> methods = DexMethods.list(apk);
   assertThat(methods)
       .containsExactly(
           "Params <init>()",
           "Params test(String, String, String, String)",
           "java.lang.Object <init>()");
 }
 @Test
 public void dexBytes() throws IOException {
   byte[] dex = Resources.toByteArray(Resources.getResource("params_joined.dex"));
   List<String> methods = DexMethods.list(dex);
   assertThat(methods)
       .containsExactly(
           "Params <init>()",
           "Params test(String, String, String, String)",
           "java.lang.Object <init>()");
 }
 private void initializeIfNecessary() {
   if (wordprocessingMLPackage == null) {
     try {
       final byte[] bytes =
           Resources.toByteArray(
               Resources.getResource(this.getClass(), "SimpleObjectsExport.docx"));
       wordprocessingMLPackage = docxService.loadPackage(new ByteArrayInputStream(bytes));
     } catch (IOException | LoadTemplateException e) {
       throw new RuntimeException(e);
     }
   }
 }
Ejemplo n.º 10
0
 private FullHttpResponse handleStaticResource(String path, HttpRequest request)
     throws IOException {
   URL url = getSecureUrlForPath(RESOURCE_BASE + path);
   if (url == null) {
     // log at debug only since this is typically just exploit bot spam
     logger.debug("unexpected path: {}", path);
     return new DefaultFullHttpResponse(HTTP_1_1, NOT_FOUND);
   }
   Date expires = getExpiresForPath(path);
   if (request.headers().contains(HttpHeaderNames.IF_MODIFIED_SINCE) && expires == null) {
     // all static resources without explicit expires are versioned and can be safely
     // cached forever
     return new DefaultFullHttpResponse(HTTP_1_1, NOT_MODIFIED);
   }
   ByteBuf content = Unpooled.copiedBuffer(Resources.toByteArray(url));
   FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, content);
   if (expires != null) {
     response.headers().add(HttpHeaderNames.EXPIRES, expires);
   } else {
     response.headers().add(HttpHeaderNames.LAST_MODIFIED, new Date(0));
     response
         .headers()
         .add(HttpHeaderNames.EXPIRES, new Date(System.currentTimeMillis() + TEN_YEARS));
   }
   int extensionStartIndex = path.lastIndexOf('.');
   checkState(
       extensionStartIndex != -1,
       "found path under %s with no extension: %s",
       RESOURCE_BASE,
       path);
   String extension = path.substring(extensionStartIndex + 1);
   MediaType mediaType = mediaTypes.get(extension);
   checkNotNull(
       mediaType, "found extension under %s with no media type: %s", RESOURCE_BASE, extension);
   response.headers().add(HttpHeaderNames.CONTENT_TYPE, mediaType);
   response.headers().add(HttpHeaderNames.CONTENT_LENGTH, Resources.toByteArray(url).length);
   return response;
 }
Ejemplo n.º 11
0
  @Test
  public void compressionCanBeSetOnAPerFileBasisAndIsHonoured() throws IOException {
    // Create some input that can be compressed.
    String packageName = getClass().getPackage().getName().replace(".", "/");
    URL sample = Resources.getResource(packageName + "/sample-bytes.properties");
    byte[] input = Resources.toByteArray(sample);

    try (CustomZipOutputStream out = ZipOutputStreams.newOutputStream(output)) {
      CustomZipEntry entry = new CustomZipEntry("default");
      // Don't set the compression level. Should be the default.
      out.putNextEntry(entry);
      out.write(input);

      entry = new CustomZipEntry("stored");
      entry.setCompressionLevel(NO_COMPRESSION);
      byte[] bytes = "stored".getBytes();
      entry.setSize(bytes.length);
      entry.setCrc(Hashing.crc32().hashBytes(bytes).padToLong());
      out.putNextEntry(entry);

      out.write(bytes);

      entry = new CustomZipEntry("best");
      entry.setCompressionLevel(BEST_COMPRESSION);
      out.putNextEntry(entry);
      out.write(input);
    }

    try (ZipInputStream in = new ZipInputStream(Files.newInputStream(output))) {
      ZipEntry entry = in.getNextEntry();
      assertEquals("default", entry.getName());
      ByteStreams.copy(in, ByteStreams.nullOutputStream());
      long defaultCompressedSize = entry.getCompressedSize();
      assertNotEquals(entry.getCompressedSize(), entry.getSize());

      entry = in.getNextEntry();
      ByteStreams.copy(in, ByteStreams.nullOutputStream());
      assertEquals("stored", entry.getName());
      assertEquals(entry.getCompressedSize(), entry.getSize());

      entry = in.getNextEntry();
      ByteStreams.copy(in, ByteStreams.nullOutputStream());
      assertEquals("best", entry.getName());
      ByteStreams.copy(in, ByteStreams.nullOutputStream());
      assertThat(entry.getCompressedSize(), lessThan(defaultCompressedSize));
    }
  }
Ejemplo n.º 12
0
  @Test
  public void testCompressResponse() throws Exception {
    request.setMethod("GET");
    request.setURI("/banner");
    request.setHeader(HttpHeaders.ACCEPT_ENCODING, "gzip");

    HttpTester.Response response =
        HttpTester.parseResponse(servletTester.getResponses(request.generate()));
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.get(HttpHeader.CONTENT_ENCODING)).isEqualTo("gzip");
    assertThat(response.get(HttpHeader.VARY)).isEqualTo(HttpHeaders.ACCEPT_ENCODING);
    assertThat(response.get(HttpHeader.CONTENT_TYPE)).isEqualToIgnoringCase(PLAIN_TEXT_UTF_8);
    try (GZIPInputStream is =
        new GZIPInputStream(new ByteArrayInputStream(response.getContentBytes()))) {
      assertThat(ByteStreams.toByteArray(is))
          .isEqualTo(Resources.toByteArray(Resources.getResource("assets/banner.txt")));
    }
  }
  @Test
  public void testRelationshipTypeIcon() throws Exception {
    byte[] data = Resources.toByteArray(getClass().getResource("relationshipicon.png"));
    final Icon icon = Icon.from(data, "image/png", Instant.now());

    RelationshipType relationshipType =
        RelationshipType.create()
            .name("myapplication:like")
            .fromSemantic("likes")
            .toSemantic("liked by")
            .addAllowedFromType(ContentTypeName.from("myapplication:person"))
            .addAllowedToType(ContentTypeName.from("myapplication:person"))
            .icon(icon)
            .build();
    setupRelationshipType(relationshipType);

    // exercise
    final Response response = this.resource.getIcon("myapplication:like", 20, null);
    final BufferedImage mixinIcon = (BufferedImage) response.getEntity();

    // verify
    assertImage(mixinIcon, 20);
  }
  @Override
  protected void execute(final ExecutionContext ec) {

    // defaults
    final String resourceName = checkParam("resourceName", ec, String.class);

    // validate
    final URL resource = Resources.getResource(getClass(), resourceName);
    byte[] bytes;
    try {
      bytes = Resources.toByteArray(resource);
    } catch (IOException e) {
      throw new IllegalArgumentException("Could not read from resource: " + resourceName);
    }

    // execute
    final Blob blob = new Blob(resourceName, ExcelService.XSLX_MIME_TYPE, bytes);
    final List<T> objects = excelService.fromExcel(blob, cls);

    for (final T obj : objects) {
      doPersist(obj);
      this.objects.add(obj);
    }
  }
Ejemplo n.º 15
0
 public boolean testStart(
     String profile, String testHandle, String jira, String patch, boolean clearLibraryCache)
     throws Exception {
   patch = Strings.nullToEmpty(patch).trim();
   if (!patch.isEmpty()) {
     byte[] bytes = Resources.toByteArray(new URL(patch));
     if (bytes.length == 0) {
       throw new IllegalArgumentException("Patch " + patch + " was zero bytes");
     }
   }
   TestStartRequest startRequest =
       new TestStartRequest(profile, testHandle, jira, patch, clearLibraryCache);
   post(startRequest, false);
   boolean result = false;
   try {
     result = testTailLog(testHandle);
     if (testOutputDir != null) {
       downloadTestResults(testHandle, testOutputDir);
     }
   } finally {
     System.out.println("\n\nLogs are located: " + mLogsEndpoint + testHandle + "\n\n");
   }
   return result;
 }
  public PTest(
      final TestConfiguration configuration,
      final ExecutionContext executionContext,
      final String buildTag,
      final File logDir,
      final LocalCommandFactory localCommandFactory,
      final SSHCommandExecutor sshCommandExecutor,
      final RSyncCommandExecutor rsyncCommandExecutor,
      final Logger logger)
      throws Exception {
    mConfiguration = configuration;
    mLogger = logger;
    mBuildTag = buildTag;
    mExecutedTests = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
    mFailedTests = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
    mExecutionContext = executionContext;
    mSshCommandExecutor = sshCommandExecutor;
    mRsyncCommandExecutor = rsyncCommandExecutor;
    mExecutor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
    final File failedLogDir = Dirs.create(new File(logDir, "failed"));
    final File succeededLogDir = Dirs.create(new File(logDir, "succeeded"));
    final File scratchDir =
        Dirs.createEmpty(new File(mExecutionContext.getLocalWorkingDirectory(), "scratch"));
    File patchDir = Dirs.createEmpty(new File(logDir, "patches"));
    File patchFile = null;
    if (!configuration.getPatch().isEmpty()) {
      patchFile = new File(patchDir, buildTag + ".patch");
      Files.write(Resources.toByteArray(new URL(configuration.getPatch())), patchFile);
    }
    ImmutableMap.Builder<String, String> templateDefaultsBuilder = ImmutableMap.builder();
    templateDefaultsBuilder
        .put("repository", configuration.getRepository())
        .put("repositoryName", configuration.getRepositoryName())
        .put("repositoryType", configuration.getRepositoryType())
        .put("buildTool", configuration.getBuildTool())
        .put("branch", configuration.getBranch())
        .put("clearLibraryCache", String.valueOf(configuration.isClearLibraryCache()))
        .put("workingDir", mExecutionContext.getLocalWorkingDirectory())
        .put("buildTag", buildTag)
        .put("logDir", logDir.getAbsolutePath())
        .put("javaHome", configuration.getJavaHome())
        .put("javaHomeForTests", configuration.getJavaHomeForTests())
        .put("antEnvOpts", configuration.getAntEnvOpts())
        .put("antArgs", configuration.getAntArgs())
        .put("antTestArgs", configuration.getAntTestArgs())
        .put("antTestTarget", configuration.getAntTestTarget())
        .put("mavenEnvOpts", configuration.getMavenEnvOpts())
        .put("mavenArgs", configuration.getMavenArgs())
        .put("mavenBuildArgs", configuration.getMavenBuildArgs())
        .put("mavenTestArgs", configuration.getMavenTestArgs());
    final ImmutableMap<String, String> templateDefaults = templateDefaultsBuilder.build();
    TestParser testParser =
        new TestParser(
            configuration.getContext(),
            configuration.getTestCasePropertyName(),
            new File(
                mExecutionContext.getLocalWorkingDirectory(),
                configuration.getRepositoryName() + "-source"),
            logger);

    HostExecutorBuilder hostExecutorBuilder =
        new HostExecutorBuilder() {
          @Override
          public HostExecutor build(Host host) {
            return new HostExecutor(
                host,
                executionContext.getPrivateKey(),
                mExecutor,
                sshCommandExecutor,
                rsyncCommandExecutor,
                templateDefaults,
                scratchDir,
                succeededLogDir,
                failedLogDir,
                10,
                logger);
          }
        };
    List<HostExecutor> hostExecutors = new ArrayList<HostExecutor>();
    for (Host host : mExecutionContext.getHosts()) {
      hostExecutors.add(hostExecutorBuilder.build(host));
    }
    mHostExecutors = new CopyOnWriteArrayList<HostExecutor>(hostExecutors);
    mPhases = Lists.newArrayList();
    mPhases.add(
        new PrepPhase(
            mHostExecutors, localCommandFactory, templateDefaults, scratchDir, patchFile, logger));
    mPhases.add(
        new ExecutionPhase(
            mHostExecutors,
            mExecutionContext,
            hostExecutorBuilder,
            localCommandFactory,
            templateDefaults,
            succeededLogDir,
            failedLogDir,
            testParser.parse(),
            mExecutedTests,
            mFailedTests,
            logger));
    mPhases.add(new ReportingPhase(mHostExecutors, localCommandFactory, templateDefaults, logger));
  }
Ejemplo n.º 17
0
 private static File createFile(final String name) throws IOException {
   File file = File.createTempFile("gtrReaderTest", ".xml");
   Files.write(Resources.toByteArray(GtrReaderTest.class.getResource(name)), file);
   file.deleteOnExit();
   return file;
 }
Ejemplo n.º 18
0
 private static void copyResource(final String name, final File file) throws Exception {
   Files.write(Resources.toByteArray(FilterConsensusTest.class.getResource(name)), file);
 }
 private static void copyResource(final String name, final File file) throws Exception {
   Files.write(Resources.toByteArray(InterleaveFastqTest.class.getResource(name)), file);
 }