Example #1
0
  public void proceed() throws Exception {
    Util.deleteDir(Const.WORKING_DIR);
    Util.deleteFile(Const.DB_FILE_NAME);
    Util.deleteFile(Const.ERROR_FILE_NAME);

    if (!(new File(Const.WORKING_DIR)).mkdir()) {
      throw new Exception("Error!  Cannot create working directory for xml, wbxml and zip files");
    }

    fillArrLines();
    validateArrLines();
    createXmlMessages();
    Util.writeRecordsToFiles();
    Util.sortAllRecordsIntoArray();
    genenerateOperatorsNamesTable();
    Arrays.sort(arraySortedRecords); // re-sort again including newlly generated names offset
    // Util.printRecords(); // for debugging !!!!!!!!!!!!!
    genenerateApplicationsSettingsTable();
    genenerateCarrierIndexTable();
    genenerateHeaderTable();
    Validator.postValidate();
    writeTablesToFile();

    // clean working directory
    if (REMOVE_WORKING_DIR) {
      Util.deleteDir(Const.WORKING_DIR);
    }

    /// ------------- test --------------
    // Util.printRecords();
  }
Example #2
0
 public void testServletBridgeLibraryIsMissing() {
   IWARProduct product = createBasicProduct();
   Validator validator = new Validator(product);
   Validation validation = validator.validate();
   assertFalse(validation.isValid());
   ValidationError[] errors = validation.getErrors();
   boolean foundServletBridgeMissing = false;
   for (int i = 0; i < errors.length; i++) {
     ValidationError error = errors[i];
     String message = error.getMessage();
     if (error.getType() == ValidationError.LIBRARY_MISSING
         && message.indexOf(SERVLETBRIDGE) != -1) {
       foundServletBridgeMissing = true;
     }
   }
   assertTrue(foundServletBridgeMissing);
 }
 public static void main(String[] args) throws IOException, ClassNotFoundException {
   Validator[] validators = {new ValidatorImpl()};
   CorrectnessTest.check(validators);
   String[][] data = {
     readData("dataset1.dat"), readData("dataset2.dat"), readData("dataset3.dat")
   };
   for (Validator val : validators) {
     System.out.println(val.getClass().getSimpleName());
     System.out.println(val.getClass().getSimpleName().replaceAll(".", "="));
     System.out.println(
         "Dataset1 Count\tDataset1 Time\tDataset2 Count"
             + "\tDataset2 Time\tDataset3 Count\tDataset3 Time");
     for (int i = 0; i < DATA_POINTS; i++) {
       test(val, data);
     }
   }
 }
Example #4
0
 public void testContainsServletBridgeLibrary() throws Exception {
   IWARProduct product = createBasicProduct();
   IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
   IProject project = wsRoot.getProject("warProduct");
   if (!project.exists()) {
     project.create(null);
     project.open(null);
   }
   IFile jar = project.getFile(SERVLETBRIDGE + ".jar");
   if (!jar.exists()) {
     File bridge = File.createTempFile(SERVLETBRIDGE, ".jar");
     FileInputStream stream = new FileInputStream(bridge);
     jar.create(stream, true, null);
   }
   product.addLibrary(jar.getFullPath(), false);
   Validator validator = new Validator(product);
   Validation validation = validator.validate();
   assertTrue(validation.isValid());
 }
Example #5
0
 private void checkForMissingRequiredBundle(final String id) throws IOException {
   IWARProduct product = createPlainProducttWithLibraries();
   Validator validator = new Validator(product);
   Validation validation = validator.validate();
   assertFalse(validation.isValid());
   ValidationError[] errors = validation.getErrors();
   boolean foundMissingBundle = false;
   for (int i = 0; i < errors.length && !foundMissingBundle; i++) {
     ValidationError error = errors[i];
     if (error.getType() == ValidationError.BUNDLE_MISSING) {
       IProductPlugin missingBundle = (IProductPlugin) error.getCausingObject();
       String message = error.getMessage();
       if (missingBundle.getId().equals(id) && message.indexOf(id) != -1) {
         foundMissingBundle = true;
       }
     }
   }
   assertTrue(foundMissingBundle);
 }
Example #6
0
  public void createXmlMessages() throws Exception {
    Browser.createXmlMessages();
    MMS.createXmlMessages();
    JavaApp.createXmlMessages();

    // IM should be last to generate id_name for all other applications!!!
    // set flag to avoid duplicationNAP names before calling createXmlMessages()
    // The method setNAPFlagForIMAndValidate() should be changed for new  applications
    Validator.setNAPFlagForIMAndValidate();
    IM.createXmlMessages();
  }
Example #7
0
  // set offset for Applications Settings for each record and generate Applications Setting Table
  public void genenerateApplicationsSettingsTable() throws Exception {
    int totalDataLength = 0;
    String err = ""; // collected all errors for setBlockApplicationsForOneRecord();

    // set offset and binary data for Applications Settings for each record
    for (int i = 0; i < arraySortedRecords.length; i++) {
      try {
        arraySortedRecords[i].application_settings_offset = totalDataLength;
        int currDataLength = setBlockApplicationsForOneRecord(arraySortedRecords[i]);
        totalDataLength += currDataLength;
      } catch (Exception ex) {
        err += ex.getMessage() + "\n";
      }
    }
    if (err.length() > 0) {
      throw new Exception(err);
    }

    // create appl settings table
    byte[] b;
    applicationsSettingsTable = new BlockTable(totalDataLength);
    for (int i = 0; i < arraySortedRecords.length; i++) {
      b = arraySortedRecords[i].application_settings;
      applicationsSettingsTable.appendData(b);
      arraySortedRecords[i].application_settings = null; // release memory !!!!

      //////////////// -- test --///////////////////
      /* int iii = ( ( ( (int) b[0]) & 0xff) << 16) +
          ( ( ( (int) b[1]) & 0xff) << 8) + ( ( (int) b[2]) & 0xff);
      System.out.println(arraySortedRecords[i].key.replaceAll(":", "_") +
                         " :  " + b.length + "  iii= " + (iii >>> 1) +
                         "  flag: " + (iii & 1));*/
      ///////////////////// -- end test-- ///////////////////

    }

    Validator.validateMaxAppsSettingsLength(applicationsSettingsTable.length);
    int lastOffset = arraySortedRecords[arraySortedRecords.length - 1].application_settings_offset;
    Validator.validateMaxAppsSettingsOffset(lastOffset);
  }
Example #8
0
 public void testLibrariesDoesntExist() {
   IWARProduct product = createBasicProduct();
   String projectPath = File.separator + "test";
   Path path = new Path(projectPath + File.separator + "test.jar");
   product.addLibrary(path, false);
   Path servletBridgePath = new Path(projectPath + File.separator + SERVLETBRIDGE_JAR);
   product.addLibrary(servletBridgePath, false);
   Validator validator = new Validator(product);
   Validation validation = validator.validate();
   assertFalse(validation.isValid());
   ValidationError[] errors = validation.getErrors();
   boolean testJarIsMissing = false;
   for (int i = 0; i < errors.length; i++) {
     ValidationError error = errors[i];
     String message = error.getMessage();
     if (error.getType() == ValidationError.LIBRARY_DOESNT_EXIST
         && message.indexOf("test.jar") != -1) {
       testJarIsMissing = true;
     }
   }
   assertTrue(testJarIsMissing);
 }
Example #9
0
 private void checkForBannedBundle(final String id) throws Exception {
   IWARProduct product = createBasicProductWithLibraries();
   IProductPlugin plugin = new ProductPlugin(product.getModel());
   plugin.setId(id);
   IProductPlugin[] plugins = new IProductPlugin[] {plugin};
   product.addPlugins(plugins);
   Validator validator = new Validator(product);
   Validation validation = validator.validate();
   assertFalse(validation.isValid());
   ValidationError[] errors = validation.getErrors();
   boolean foundBannedBundle = false;
   for (int i = 0; i < errors.length && !foundBannedBundle; i++) {
     ValidationError error = errors[i];
     if (error.getType() == ValidationError.BUNDLE_BANNED) {
       IProductPlugin bannedPlugin = (IProductPlugin) error.getCausingObject();
       String message = error.getMessage();
       if (bannedPlugin.getId().equals(id) && message.indexOf(id) != -1) {
         foundBannedBundle = true;
       }
     }
   }
   assertTrue(foundBannedBundle);
 }
Example #10
0
  // generate operators names table with name length. assign offset for each record
  public static void genenerateOperatorsNamesTable() throws Exception {
    // operatorsNamesBytes
    HashMap hashNames = new HashMap();
    String name;

    for (int i = 0; i < arraySortedRecords.length; i++) {
      name = arraySortedRecords[i].operator_name;

      if (hashNames.containsKey(name)) {
        Integer offset = (Integer) hashNames.get(name);
        arraySortedRecords[i].operator_name_offset = offset.intValue();
      } else {

        byte[] nameByteArr = name.getBytes();
        // since operatorsNamesBytes.length are always even...
        int half_offset = operatorsNamesBytes.length() / 2;
        Validator.validateOperatorNameOffset(half_offset); // validate half_offset
        arraySortedRecords[i].operator_name_offset = half_offset;

        int nameLength =
            nameByteArr.length + 1; // length of name  + one byte to present this length.
        operatorsNamesBytes.addByte((byte) nameLength);
        operatorsNamesBytes.addBytes(nameByteArr);
        if ((operatorsNamesBytes.length() % 2) > 0) {
          // add one dummy byte to make it even
          operatorsNamesBytes.addByte((byte) 0);
        }
        hashNames.put(name, new Integer(half_offset));
      }
    }

    // create operators Names Table
    operatorsNamesTable = new BlockTable(operatorsNamesBytes.length());
    operatorsNamesTable.appendData(operatorsNamesBytes.getBytes());

    Validator.validateOperatorNamesTableSize(operatorsNamesTable.length);
  }
Example #11
0
  public static String getPath(String fullFileName) {
    int pos = fullFileName.lastIndexOf("/");

    if (pos == -1) {
      pos = fullFileName.lastIndexOf("\\");
    }

    String shortFileName = fullFileName.substring(0, pos);

    if (Validator.isNull(shortFileName)) {
      return "/";
    }

    return shortFileName;
  }
  private static void test(Validator val, String[] dataset)
      throws IOException, ClassNotFoundException {
    Benchmark mbm = new Benchmark();
    mbm.start();

    int truecount = 0;
    for (int i = 0; i < REPEATS; i++) {
      truecount = 0;
      for (String s : dataset) {
        if (val.checkInteger(s)) truecount++;
      }
    }

    mbm.stop();
    System.out.printf("%d\t%s", truecount, mbm);
  }
Example #13
0
  // Choose between wbxml or zip (the smallest one) to be used;
  // adds 3 additional bytes with metadata and set binary data for the record
  // returns length for the application settings + 3 bytes
  public int setBlockApplicationsForOneRecord(Record record) throws Exception {
    String key = record.key;
    // String generalPath = Const.WORKING_DIR + Const.PATH_SEP +
    //    key.replaceAll(":", "_");
    String generalPath = Const.WORKING_DIR + Const.PATH_SEP + Util.generateFileNameFromKey(key);

    File w = new File(generalPath + ".wbxml");
    if (!w.exists()) {
      throw new Exception("Error: The file " + generalPath + ".wbxml doesn't exist!");
    }

    FileInputStream in;
    boolean usedZip;
    // Choose between wbxml or zip (the smallest one) to be used in case if USE_ZIP
    // has not been set to false in function main().
    if (USE_ZIP) { // zip wbxml files
      File z = new File(generalPath + ".zip");
      if (!z.exists()) {
        throw new Exception("Error: The file " + generalPath + ".zip doesn't exist!");
      }
      FileInputStream inw = new FileInputStream(w);
      FileInputStream inz = new FileInputStream(z);
      usedZip = inz.available() < inw.available();
      in = (usedZip) ? inz : inw;
    } else { // do not zip wbxml files
      usedZip = false;
      in = new FileInputStream(w);
    }

    byte[] appWbxmlSettings = new byte[in.available()];
    in.read(appWbxmlSettings);
    in.close();

    // get 3 bytes that provide info: for data length (23 bits) and compressed flag (1 bit)
    // and write it into metaInfo
    BlockTable metaInfo =
        new BlockTable((Const.APP_BLOCK_LENGTH + Const.APP_COMPRESSWD_FLAG) / 8); // 3 bytes
    int appBlockSettingsLength = metaInfo.data.length + appWbxmlSettings.length;
    int compressFlag = (usedZip) ? 1 : 0;
    Util.addBitsToTable(metaInfo, appBlockSettingsLength, Const.APP_BLOCK_LENGTH);
    Util.addBitsToTable(metaInfo, compressFlag, Const.APP_COMPRESSWD_FLAG);
    record.setBlockApplicationSettings(metaInfo.data, appWbxmlSettings);

    Validator.validateAppBlockSettingsLength(appBlockSettingsLength, generalPath);

    return appBlockSettingsLength;
  }
Example #14
0
 public int run(PbTest[] tests, int timelimit, int memlimit) throws ServerException {
   allStdout = new ArrayList<String>();
   allStderr = new ArrayList<String>();
   int correct = 0;
   for (int i = 0; i < tests.length; ++i) {
     try {
       exec(runCmd, tests[i].in, timelimit, memlimit);
       allStdout.add(stdout);
       allStderr.add(stderr);
       if (!stderr.isEmpty()) {
         log.fine("NOK, stderr: " + stderr);
         continue;
       }
       if (!validator.ok(stdout, tests[i].out)) continue;
       log.fine("OK");
       ++correct;
     } catch (Exception e) {
       // Assume incorrect. Do NOT propagate anyhing from the exception to
       // the client, just put it in the log.
       log.finer("exc: " + UtilSrv.describe(e));
     }
   }
   return correct;
 }
Example #15
0
 public void testLibrariesExist() throws Exception {
   IWARProduct product = createBasicProductWithLibraries();
   Validator validator = new Validator(product);
   Validation validation = validator.validate();
   assertTrue(validation.isValid());
 }
Example #16
0
 public void validate() throws ValidationException {
   Validator validator = new Validator();
   validator.validate(this);
 }