/**
   * Test the validate method. 1. The method should succeed with one file specified. 2. The method
   * should succeed and validate 2 files when 2 are specified. 3. The method should output verbose
   * information for valid files when verbose is enabled.
   */
  public void testValidate() {
    String validFile =
        FILE_PROTOCOL
            + PLUGIN_ABSOLUTE_PATH
            + SAMPLES_DIR
            + "Paths/AngleHat^InPath/AngleHatInPathValid.wsdl";
    if (PLUGIN_ABSOLUTE_PATH.startsWith("/")) {
      validFile =
          "file://"
              + PLUGIN_ABSOLUTE_PATH
              + SAMPLES_DIR
              + "Paths/AngleHat^InPath/AngleHatInPathValid.wsdl";
    }
    String validFile2 =
        FILE_PROTOCOL
            + PLUGIN_ABSOLUTE_PATH
            + SAMPLES_DIR
            + "Paths/AngleHatInFilename/AngleHat^InFilenameValid.wsdl";
    if (PLUGIN_ABSOLUTE_PATH.startsWith("/")) {
      validFile2 =
          "file://"
              + PLUGIN_ABSOLUTE_PATH
              + SAMPLES_DIR
              + "Paths/AngleHatInFilename/AngleHat^InFilenameValid.wsdl";
    }
    ILogger currentLogger = LoggerFactory.getInstance().getLogger();
    WSDLValidateTestLogger logger = new WSDLValidateTestLogger();
    LoggerFactory.getInstance().setLogger(logger);

    // 1. The method should succeed with one file specified.
    validate.getWSDLFiles().add(validFile);
    validate.validate();
    assertEquals(
        "Validating a single valid file failed.",
        MessageFormat.format(
            WSDLValidateTextUIMessages._UI_VALIDATION_SUMMARY,
            new Object[] {new Integer(1), new Integer(0)}),
        logger.getInfos().get(0));
    validate.getWSDLFiles().clear();
    logger.getInfos().clear();

    // 2. The method should succeed and validate 2 files when 2 are specified.
    validate.getWSDLFiles().add(validFile);
    validate.getWSDLFiles().add(validFile2);
    validate.validate();
    assertEquals(
        "Validating two valid files failed.",
        MessageFormat.format(
            WSDLValidateTextUIMessages._UI_VALIDATION_SUMMARY,
            new Object[] {new Integer(2), new Integer(0)}),
        logger.getInfos().get(0));
    validate.getWSDLFiles().clear();
    logger.getInfos().clear();

    // 3. The method should output verbose information for valid files when verbose is enabled.
    validate.setVerbose(true);
    validate.getWSDLFiles().add(validFile);
    validate.validate();
    assertEquals(
        "Validating a single valid file failed.",
        MessageFormat.format(WSDLValidateTextUIMessages._UI_FILE_VALID, new Object[] {validFile}),
        logger.getVerboses().get(0));
    assertEquals(
        "Validating a single valid file failed.",
        MessageFormat.format(
            WSDLValidateTextUIMessages._UI_VALIDATION_SUMMARY,
            new Object[] {new Integer(1), new Integer(0)}),
        logger.getInfos().get(0));
    validate.getWSDLFiles().clear();
    validate.setVerbose(false);
    logger.getInfos().clear();
    logger.getVerboses().clear();

    LoggerFactory.getInstance().setLogger(currentLogger);
  }
  /**
   * Test the parseArguments method. 1. -wsdl11v parsing succeeds and registers the validator with
   * the WSDL validator. 2. -extv parsing succeeds and registers the validator with the WSDL
   * validator. 3. Extension validator parsing where a param is omitted succeeds. 4. -logger parsing
   * succeeds and sets the correct logger. 5. -D (property) parsing succeeds sets the property on
   * the configuration. 6. -v, -verbose parsing succeeds and sets verbose correctly. 7. The
   * specified WSDL files are read properly.
   *
   * <p>Not currently tested: -schema -schemaDir -uriresolver
   */
  public void testParseArguments() {
    // 1. -wsdl11v parsing succeeds and registers the validator with the WSDL validator.
    String[] args1 =
        new String[] {
          WSDLValidateWrapper.PARAM_WSDL11VAL,
          "http://wsdl11validator",
          "org.eclipse.wst.wsdl.validation.internal.wsdl11.http.HTTPValidator"
        };
    validate.parseArguments(args1);
    assertTrue(
        "The WSDL 1.1 validator was not registered.",
        org.eclipse.wst.wsdl.validation.internal.wsdl11.ValidatorRegistry.getInstance()
            .hasRegisteredValidator("http://wsdl11validator"));

    // 2. -extv parsing succeeds and registers the validator with the WSDL validator.
    String[] args2 =
        new String[] {WSDLValidateWrapper.PARAM_EXTVAL, "http://extvalidator", "validatorclass"};
    validate.parseArguments(args2);
    assertTrue(
        "The WSDL extension validator was not registered.",
        ValidatorRegistry.getInstance()
            .hasRegisteredValidator("http://extvalidator", ValidatorRegistry.EXT_VALIDATOR));

    // 3. Extension validator parsing where a param is omitted succeeds.
    String[] args3 =
        new String[] {WSDLValidateWrapper.PARAM_EXTVAL, "http://extvalidator2", "-dummyparam"};
    validate.parseArguments(args3);
    assertFalse(
        "The WSDL extension validator was registered without enough information.",
        ValidatorRegistry.getInstance()
            .hasRegisteredValidator("http://extvalidator2", ValidatorRegistry.EXT_VALIDATOR));

    // 4. -logger parsing succeeds and sets the correct logger.
    ILogger currentLogger = LoggerFactory.getInstance().getLogger();
    String[] args4 =
        new String[] {
          WSDLValidateWrapper.PARAM_LOGGER,
          "org.eclipse.wst.wsdl.validation.internal.logging.StandardLogger"
        };
    validate.parseArguments(args4);
    assertTrue(
        "The registered logger is not a StandardLogger",
        LoggerFactory.getInstance().getLogger() instanceof StandardLogger);
    assertFalse(
        "The registered logger is the same as originally registered.",
        currentLogger.equals(LoggerFactory.getInstance().getLogger()));
    LoggerFactory.getInstance().setLogger(currentLogger);

    // 5. -D (property) parsing succeeds sets the property on the configuration.
    String[] args5 = new String[] {WSDLValidateWrapper.PARAM_PROPERTY + "SAMPLENAME=SAMPLEVALUE"};
    validate.parseArguments(args5);
    assertEquals(
        "The parameter was not set correctly.",
        "SAMPLEVALUE",
        validate.getConfiguration().getProperty("SAMPLENAME"));

    // 6. -v, -verbose parsing succeeds and sets verbose correctly.
    String[] args6 = new String[] {WSDLValidateWrapper.PARAM_VERBOSE};
    validate.setVerbose(false);
    validate.parseArguments(args6);
    assertTrue("Verbose is not set to true.", validate.isVerbose());

    String[] args6a = new String[] {WSDLValidateWrapper.PARAM_VERBOSE_SHORT};
    validate.setVerbose(false);
    validate.parseArguments(args6a);
    assertTrue("Verbose is not set to true.", validate.isVerbose());

    // 7. The specified WSDL files are read properly.
    String[] args7 =
        new String[] {"filename1.wsdl", "folder/filename2.wsdl", "folder\filename3.wsdl"};
    validate.parseArguments(args7);
    List wsdlFiles = validate.getWSDLFiles();
    assertEquals("There were not 3 WSDL files listed to validate.", 3, wsdlFiles.size());
    assertTrue(
        "The WSDL file list did not include filename1.wsdl", wsdlFiles.contains("filename1.wsdl"));
    assertTrue(
        "The WSDL file list did not include folder/filename2.wsdl",
        wsdlFiles.contains("folder/filename2.wsdl"));
    assertTrue(
        "The WSDL file list did not include folder\filename3.wsdl",
        wsdlFiles.contains("folder\filename3.wsdl"));
  }