Example #1
0
 @Test
 public void testExistingFilePlainOutputToFileWithoutReadAndRwPermissions() throws Exception {
   final File file = temporaryFolder.newFile("file.output");
   // That works fine on Linux/Unix, but ....
   // It's not possible to make a file unreadable in Windows NTFS for owner.
   // http://stackoverflow.com/a/4354686
   // https://github.com/google/google-oauth-java-client/issues/55#issuecomment-69403681
   // assertTrue(file.setReadable(false, false));
   assertTrue(file.setWritable(false, false));
   exit.expectSystemExitWithStatus(-1);
   exit.checkAssertionAfterwards(
       new Assertion() {
         @Override
         public void checkAssertion() throws IOException {
           assertEquals(
               "Permission denied : '" + file.getCanonicalPath() + "'." + System.lineSeparator(),
               systemOut.getLog());
           assertEquals("", systemErr.getLog());
         }
       });
   Main.main(
       "-c",
       getPath("config-classname.xml"),
       "-f",
       "plain",
       "-o",
       file.getCanonicalPath(),
       getPath("InputMain.java"));
 }
Example #2
0
 @Test
 public void testExistingTargetFilePlainOutputToFileWithoutRwPermissions() throws Exception {
   final File file = temporaryFolder.newFile("file.output");
   assertTrue(file.setReadable(true, true));
   assertTrue(file.setWritable(false, false));
   exit.expectSystemExitWithStatus(-1);
   exit.checkAssertionAfterwards(
       new Assertion() {
         @Override
         public void checkAssertion() throws IOException {
           assertEquals(
               "Permission denied : '" + file.getCanonicalPath() + "'." + System.lineSeparator(),
               systemOut.getLog());
           assertEquals("", systemErr.getLog());
         }
       });
   Main.main(
       "-c",
       getPath("config-classname.xml"),
       "-f",
       "plain",
       "-o",
       file.getCanonicalPath(),
       getPath("InputMain.java"));
 }
Example #3
0
  @Test(enabled = true)
  public void sendToDifiTest() throws URISyntaxException {

    OperationalMode modeOfOperation = globalConfiguration.getModeOfOperation();
    assertEquals(modeOfOperation, OperationalMode.TEST, "This test may only be run in TEST mode");

    URL resource = MainIT.class.getClassLoader().getResource("BII04_T10_EHF-v2.0_invoice.xml");
    URI uri = resource.toURI();
    File testFile = new File(uri);
    assertTrue(testFile.canRead(), "Can not locate " + testFile);

    String[] args = {
      "-f", testFile.toString(),
      "-r", WellKnownParticipant.DIFI_TEST.toString(),
      "-s", WellKnownParticipant.U4_TEST.toString(),
      "-t", "true",
      "-e", "/tmp" // current directory
    };

    // Executes the outbound message sender
    try {
      Main.main(args);
    } catch (Exception e) {
      fail("Failed " + e.getMessage(), e);
    }
  }
Example #4
0
  @Test(enabled = false)
  public void sendToEspapTest() throws URISyntaxException {

    OperationalMode modeOfOperation = globalConfiguration.getModeOfOperation();
    assertEquals(modeOfOperation, OperationalMode.TEST, "This test may only be run in TEST mode");

    URL resource = MainIT.class.getClassLoader().getResource("BII04_T10_EHF-v2.0_invoice.xml");
    URI uri = resource.toURI();
    File testFile = new File(uri);
    assertTrue(testFile.canRead(), "Can not locate " + testFile);

    String[] args = {
      "-f", testFile.toString(),
      "-r", "9946:ESPAP",
      "-s", WellKnownParticipant.DIFI_TEST.toString(),
      "-t", "true",
      "-u", "https://ap1.espap.pt/oxalis/as2",
      "-m", "AS2",
      "-i", "APP_1000000222"
    };

    // Executes the outbound message sender
    try {
      Main.main(args);
    } catch (Exception e) {
      fail("Failed " + e.getMessage());
    }
  }
Example #5
0
  @Test
  public void testWrongArgument() throws Exception {
    exit.expectSystemExitWithStatus(-1);
    exit.checkAssertionAfterwards(
        new Assertion() {
          @Override
          public void checkAssertion() {
            final String usage =
                String.format(
                    Locale.ROOT,
                    "Unrecognized option: -w%n"
                        + "usage: java com.puppycrawl.tools.checkstyle.Main [options] -c <config.xml>%n"
                        + "            file...%n"
                        + " -c <arg>   Sets the check configuration file to use.%n"
                        + " -f <arg>   Sets the output format. (plain|xml). Defaults to plain%n"
                        + " -o <arg>   Sets the output file. Defaults to stdout%n"
                        + " -p <arg>   Loads the properties file%n"
                        + " -t         Print Abstract Syntax Tree(AST) of the file%n"
                        + " -v         Print product version and exit%n");

            assertEquals(usage, systemOut.getLog());
            assertEquals("", systemErr.getLog());
          }
        });
    Main.main("-w");
  }
Example #6
0
  @Test
  public void testFileReferenceDuringException() throws Exception {
    exit.expectSystemExitWithStatus(-2);
    exit.checkAssertionAfterwards(
        new Assertion() {
          @Override
          public void checkAssertion() {
            final String expectedExceptionMessage =
                String.format(
                    Locale.ROOT, "Starting audit...%n" + "Checkstyle ends with 1 errors.%n");
            assertEquals(expectedExceptionMessage, systemOut.getLog());

            final String exceptionFirstLine =
                String.format(
                    Locale.ROOT,
                    "com.puppycrawl.tools.checkstyle.api."
                        + "CheckstyleException: Exception was thrown while processing "
                        + new File(getNonCompilablePath("InputIncorrectClass.java")).getPath()
                        + "%n");
            assertTrue(systemErr.getLog().startsWith(exceptionFirstLine));
          }
        });

    // We put xml as source to cause parse excepion
    Main.main(
        "-c", getPath("config-classname.xml"), getNonCompilablePath("InputIncorrectClass.java"));
  }
  /*
   * osa 6
   */
  @Points("77.6")
  @Test
  public void manyCards() {
    Main.main(new String[0]);
    String[] rivit = io.getSysOut().split("\n");
    assertTrue("Et tulosta mitään", rivit.length > 0);
    for (String rivi : rivit) {
      assertTrue(
          "Print card info and owner name of card at the same line."
              + "Remove possible extra code from main()",
          rivi.toLowerCase().contains("pek") || rivi.toLowerCase().contains("bri"));
      assertFalse(
          "Print only one card info per line. Now you print line " + rivi,
          rivi.toLowerCase().contains("pek") && rivi.toLowerCase().contains("bri"));
    }
    ArrayList<String> pekka = new ArrayList<String>();
    ArrayList<String> matti = new ArrayList<String>();
    for (String rivi : rivit) {
      if (rivi.toLowerCase().contains("bri")) {
        matti.add(rivi);
      } else if (rivi.toLowerCase().contains("pek")) {
        pekka.add(rivi);
      }
    }

    tarkastaMatinRivit(matti);
    tarkastaPekanRivit(pekka);
  }
  public static void main(String[] args) throws Exception {
    System.out.println("Ready for native bridge tests.");

    System.loadLibrary(args[0]);

    Main.main(null);
  }
Example #9
0
  @Test
  public void testExistingTargetFileXmlOutput() throws Exception {

    exit.checkAssertionAfterwards(
        new Assertion() {
          @Override
          public void checkAssertion() throws IOException {
            final String expectedPath = getFilePath("InputMain.java");
            final ResourceBundle compilationProperties =
                ResourceBundle.getBundle("checkstylecompilation");
            final String version = compilationProperties.getString("checkstyle.compile.version");
            assertEquals(
                String.format(
                    Locale.ROOT,
                    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>%n"
                        + "<checkstyle version=\"%s\">%n"
                        + "<file name=\"%s\">%n"
                        + "</file>%n"
                        + "</checkstyle>%n",
                    version,
                    expectedPath),
                systemOut.getLog());
            assertEquals("", systemErr.getLog());
          }
        });
    Main.main("-c", getPath("config-classname.xml"), "-f", "xml", getPath("InputMain.java"));
  }
Example #10
0
 @Test
 public void testExistingTargetFileWithError() throws Exception {
   exit.expectSystemExitWithStatus(2);
   exit.checkAssertionAfterwards(
       new Assertion() {
         @Override
         public void checkAssertion() throws IOException {
           final String expectedPath = getFilePath("InputMain.java");
           assertEquals(
               String.format(
                   Locale.ROOT,
                   "Starting audit...%n"
                       + "[ERROR] %1$s:3:14: "
                       + "Name 'InputMain' must match pattern '^[a-z0-9]*$'. [TypeName]%n"
                       + "[ERROR] %1$s:5:7: "
                       + "Name 'InputMainInner' must match pattern '^[a-z0-9]*$'. [TypeName]%n"
                       + "Audit done.%n"
                       + "Checkstyle ends with 2 errors.%n",
                   expectedPath),
               systemOut.getLog());
           assertEquals("", systemErr.getLog());
         }
       });
   Main.main("-c", getPath("config-classname2-error.xml"), getPath("InputMain.java"));
 }
  public static void main(String args[]) throws IOException {

    String[] params = new String[1];

    params[0] = args[0] + ".sho";

    Main.main(params);
  }
Example #12
0
  public static void main(String[] args) throws Throwable {
    ShellArg arg = new ShellArg(args);
    if (arg.hasKey("-name") == false) {
      arg.put("-name", "catalina");
    }

    Main.main(arg.toStringArray());
  }
  @Test
  public void testMain() throws Exception {
    String inputDir = testFilesFolder + fileSep + "trityper";
    String inputExprs = testFilesFolder + fileSep + "Geuvadis_CEU_YRI_Expr.txt.gz";
    String inputExprsAnnot = testFilesFolder + fileSep + "Geuvadis_CEU_YRI_Annot.txt";
    String inputGte = testFilesFolder + fileSep + "Geuvadis_CEU_gte.txt";

    System.out.println(inputDir);

    Main.main(
        "--mode",
        "metaqtl",
        "--in",
        inputDir,
        "--out",
        tmpOutputFolder.getAbsolutePath(),
        "--cis",
        "--perm",
        "10",
        "--inexp",
        inputExprs,
        "--inexpannot",
        inputExprsAnnot,
        "--inexpplatform",
        "Ensembl_v.71",
        "--gte",
        inputGte,
        "--skipqqplot",
        "--skipdotplot",
        "--rseed",
        "0");

    QTLTextFile eExp =
        new QTLTextFile(
            testFilesFolder + fileSep + "TestOutput" + fileSep + "Cis-CEU-eQTLsFDR0.05.txt",
            QTLTextFile.R);

    QTLFileSorter r = new QTLFileSorter();
    r.run(
        tmpOutputFolder.getAbsolutePath() + fileSep + "eQTLsFDR0.05.txt",
        tmpOutputFolder.getAbsolutePath() + fileSep + "eQTLsFDR0.05_S.txt");

    QTLTextFile eActual =
        new QTLTextFile(
            tmpOutputFolder.getAbsolutePath() + fileSep + "eQTLsFDR0.05_S.txt", QTLTextFile.R);
    Iterator<EQTL> eExpIterator = eExp.getEQtlIterator();
    Iterator<EQTL> eActualIterator = eActual.getEQtlIterator();

    while (eExpIterator.hasNext() && eActualIterator.hasNext()) {
      assertTrue(eActualIterator.next().sameQTL(eExpIterator.next()), "eQTL not identical");
    }

    assertFalse(eExpIterator.hasNext(), "not all expected eQTL are found");
    assertFalse(eActualIterator.hasNext(), "found more eQTL than expected");
  }
 @Test
 public void mainTest() throws IOException {
   long startTime = System.currentTimeMillis();
   URL url = Thread.currentThread().getContextClassLoader().getResource("data001.in");
   String[] input = {url.getPath()};
   Main.main(input);
   long endTime = System.currentTimeMillis();
   long intervalMilliseconds = endTime - startTime;
   long intervalSeconds = intervalMilliseconds / 1000;
   System.out.println("duration = " + intervalSeconds);
 }
Example #15
0
  @Test
  public void testVersionPrint() throws Exception {

    exit.checkAssertionAfterwards(
        new Assertion() {
          @Override
          public void checkAssertion() {
            assertEquals("Checkstyle version: null" + System.lineSeparator(), systemOut.getLog());
            assertEquals("", systemErr.getLog());
          }
        });
    Main.main("-v");
  }
Example #16
0
 @Test
 public void testNoConfigSpecified() throws Exception {
   exit.expectSystemExitWithStatus(-1);
   exit.checkAssertionAfterwards(
       new Assertion() {
         @Override
         public void checkAssertion() {
           assertEquals(
               "Must specify a config XML file." + System.lineSeparator(), systemOut.getLog());
           assertEquals("", systemErr.getLog());
         }
       });
   Main.main(getPath("InputMain.java"));
 }
  @Test
  public void testHtml() throws IOException {
    Path src = Paths.get("base/spec/spec.txt");
    Path dest = Files.createTempFile("test", ".tmp");

    try {
      Main.main(new String[] {src.toAbsolutePath().toString(), dest.toAbsolutePath().toString()});

      Path result = Paths.get("base/result/spec.html");
      assertEquals(Files.readAllLines(result), Files.readAllLines(dest));
    } finally {
      Files.delete(dest);
    }
  }
Example #18
0
 @Test
 public void testNonExistingTargetFile() throws Exception {
   exit.expectSystemExitWithStatus(-1);
   exit.checkAssertionAfterwards(
       new Assertion() {
         @Override
         public void checkAssertion() {
           assertEquals(
               "Files to process must be specified, found 0." + System.lineSeparator(),
               systemOut.getLog());
           assertEquals("", systemErr.getLog());
         }
       });
   Main.main("-c", "/google_checks.xml", "NonExistingFile.java");
 }
Example #19
0
  @Test
  public void testExistingTargetFilePlainOutput() throws Exception {

    exit.checkAssertionAfterwards(
        new Assertion() {
          @Override
          public void checkAssertion() {
            assertEquals(
                String.format(Locale.ROOT, "Starting audit...%n" + "Audit done.%n"),
                systemOut.getLog());
            assertEquals("", systemErr.getLog());
          }
        });
    Main.main("-c", getPath("config-classname.xml"), "-f", "plain", getPath("InputMain.java"));
  }
Example #20
0
  @Test
  public void testExistingDirectoryWithViolations() throws Exception {

    // we just reference there all violations
    final String[][] outputValues = {
      {"InputComplexityOverflow", "1", "172"},
    };

    final int allowedLength = 170;
    final String msgKey = "maxLen.file";
    final String bundle = "com.puppycrawl.tools.checkstyle.checks.sizes.messages";

    exit.checkAssertionAfterwards(
        new Assertion() {
          @Override
          public void checkAssertion() throws IOException {
            final String expectedPath = getFilePath("checks/metrics") + File.separator;
            final StringBuilder sb = new StringBuilder();
            sb.append("Starting audit...").append(System.getProperty("line.separator"));
            final String format = "[WARN] %s.java:%s: %s [FileLength]";
            for (String[] outputValue : outputValues) {
              final String localizedMessage =
                  new LocalizedMessage(
                          0,
                          bundle,
                          msgKey,
                          new Integer[] {Integer.valueOf(outputValue[2]), allowedLength},
                          null,
                          getClass(),
                          null)
                      .getMessage();
              final String line =
                  String.format(
                      Locale.ROOT,
                      format,
                      expectedPath + outputValue[0],
                      outputValue[1],
                      localizedMessage);
              sb.append(line).append(System.getProperty("line.separator"));
            }
            sb.append("Audit done.").append(System.getProperty("line.separator"));
            assertEquals(sb.toString(), systemOut.getLog());
            assertEquals("", systemErr.getLog());
          }
        });

    Main.main("-c", getPath("config-filelength.xml"), getPath("checks/metrics"));
  }
Example #21
0
 @Test
 public void testNonExistingOutputFormat() throws Exception {
   exit.expectSystemExitWithStatus(-1);
   exit.checkAssertionAfterwards(
       new Assertion() {
         @Override
         public void checkAssertion() {
           assertEquals(
               String.format(
                   Locale.ROOT,
                   "Invalid output format. " + "Found 'xmlp' but expected 'plain' or 'xml'.%n"),
               systemOut.getLog());
           assertEquals("", systemErr.getLog());
         }
       });
   Main.main("-c", "/google_checks.xml", "-f", "xmlp", getPath("InputMain.java"));
 }
Example #22
0
  public static void addPaczka(Poczta poczta) {

    try {
      PreparedStatement addPaczkaStmt =
          polaczenie.prepareStatement(
              "INSERT INTO Paczka (id_paczka, odbiorca_id, nadawca_id, informacje) VALUES (?, ?, ?, ?)");
      addPaczkaStmt.setLong(1, poczta.getId_paczka());
      addPaczkaStmt.setLong(2, poczta.getOdbiorca_id());
      addPaczkaStmt.setLong(3, poczta.getNadawca_id());
      addPaczkaStmt.setString(4, poczta.getInformacje());
      addPaczkaStmt.executeUpdate();
    } catch (SQLException e) {
      e.printStackTrace();
    }
    System.out.println("The package has been successfully added!");
    Main.main(null);
  }
Example #23
0
  @Test
  public void testConflictingOptionsTvsF() throws Exception {

    exit.expectSystemExitWithStatus(-1);
    exit.checkAssertionAfterwards(
        new Assertion() {
          @Override
          public void checkAssertion() {
            assertEquals(
                "Option '-t' cannot be used with other options." + System.lineSeparator(),
                systemOut.getLog());
            assertEquals("", systemErr.getLog());
          }
        });

    Main.main("-f", "plain", "-t", getPath("checks/metrics"));
  }
Example #24
0
  @Test
  public void testPrintTreeOnMoreThanOneFile() throws Exception {

    exit.expectSystemExitWithStatus(-1);
    exit.checkAssertionAfterwards(
        new Assertion() {
          @Override
          public void checkAssertion() {
            assertEquals(
                "Printing AST is allowed for only one file." + System.lineSeparator(),
                systemOut.getLog());
            assertEquals("", systemErr.getLog());
          }
        });

    Main.main("-t", getPath("checks/metrics"));
  }
Example #25
0
 @Test
 public void testExistingIncorrectConfigFile() throws Exception {
   exit.expectSystemExitWithStatus(-2);
   exit.checkAssertionAfterwards(
       new Assertion() {
         @Override
         public void checkAssertion() {
           final String output = String.format(Locale.ROOT, "Checkstyle ends with 1 errors.%n");
           assertEquals(output, systemOut.getLog());
           final String errorOuput =
               "com.puppycrawl.tools.checkstyle.api."
                   + "CheckstyleException: unable to parse configuration stream - ";
           assertTrue(systemErr.getLog().startsWith(errorOuput));
         }
       });
   Main.main("-c", getPath("config-Incorrect.xml"), getPath("InputMain.java"));
 }
 @VisibleForTesting
 static int runInternal(Main method) {
   try {
     method.main();
     return 0;
   } catch (SoyCompilationException compilationException) {
     System.err.println(compilationException.getMessage());
     return 1;
   } catch (Exception e) {
     System.err.println(
         "INTERNAL SOY ERROR.\n"
             + "Please open an issue at "
             + "https://github.com/google/closure-templates/issues"
             + " with this stack trace and repro steps");
     e.printStackTrace(System.err);
     return 1;
   }
 }
Example #27
0
  @Test
  public void testConflictingOptionsTvsO() throws Exception {
    final File file = temporaryFolder.newFile("file.output");

    exit.expectSystemExitWithStatus(-1);
    exit.checkAssertionAfterwards(
        new Assertion() {
          @Override
          public void checkAssertion() {
            assertEquals(
                "Option '-t' cannot be used with other options." + System.lineSeparator(),
                systemOut.getLog());
            assertEquals("", systemErr.getLog());
          }
        });

    Main.main("-o", file.getCanonicalPath(), "-t", getPath("checks/metrics"));
  }
Example #28
0
 @Test
 public void testNonExistingConfigFile() throws Exception {
   exit.expectSystemExitWithStatus(-1);
   exit.checkAssertionAfterwards(
       new Assertion() {
         @Override
         public void checkAssertion() {
           assertEquals(
               String.format(
                   Locale.ROOT,
                   "Could not find config XML file "
                       + "'src/main/resources/non_existing_config.xml'.%n"),
               systemOut.getLog());
           assertEquals("", systemErr.getLog());
         }
       });
   Main.main("-c", "src/main/resources/non_existing_config.xml", getPath("InputMain.java"));
 }
Example #29
0
 @Test
 public void testExistingTargetFilePlainOutputProperties() throws Exception {
   // exit.expectSystemExitWithStatus(0);
   exit.checkAssertionAfterwards(
       new Assertion() {
         @Override
         public void checkAssertion() {
           assertEquals(
               String.format(Locale.ROOT, "Starting audit...%n" + "Audit done.%n"),
               systemOut.getLog());
           assertEquals("", systemErr.getLog());
         }
       });
   Main.main(
       "-c",
       getPath("config-classname-prop.xml"),
       "-p",
       getPath("mycheckstyle.properties"),
       getPath("InputMain.java"));
 }
Example #30
0
 @Test
 public void testExistingTargetFilePlainOutputNonexistingProperties() throws Exception {
   exit.expectSystemExitWithStatus(-1);
   exit.checkAssertionAfterwards(
       new Assertion() {
         @Override
         public void checkAssertion() {
           assertEquals(
               "Could not find file 'nonexisting.properties'." + System.lineSeparator(),
               systemOut.getLog());
           assertEquals("", systemErr.getLog());
         }
       });
   Main.main(
       "-c",
       getPath("config-classname-prop.xml"),
       "-p",
       "nonexisting.properties",
       getPath("InputMain.java"));
 }