Beispiel #1
0
  private LinkedHashMap[] obtenerMapeos(CliGol cliGol, NodeList variables, String[] excluye) {

    LinkedHashMap<String, Object> mapa = new LinkedHashMap<String, Object>();

    LinkedHashMap<String, String> puntos = new LinkedHashMap<String, String>();

    List<String> ex = Arrays.asList(excluye);

    for (int i = 0; i < variables.getLength(); i++) {

      String nom = variables.item(i).getNodeName();

      if (!ex.contains(nom)) {

        String golMapdijo = GolMap.xmlGol(nom);

        String val = null;
        if (golMapdijo != null) {
          val = buscaValEnCli(golMapdijo, cliGol);
          mapa.put(nom, val);

          puntos.put(nom, variables.item(i).getTextContent());
        }
      }
    }

    return new LinkedHashMap[] {mapa, puntos};
  }
Beispiel #2
0
  public static void testCollections() throws Exception {
    CollectionsTest trt = set(CollectionsTest.class, new int[] {1, 2, 3});
    List<String> source = Arrays.asList("1", "2", "3");

    assertTrue(trt.collection() instanceof Collection);
    assertEqualList(source, trt.collection());

    assertTrue(trt.list() instanceof List);
    assertEqualList(source, trt.list());
    assertTrue(trt.set() instanceof Set);
    assertEqualList(source, trt.set());
    assertTrue(trt.queue() instanceof Queue);
    assertEqualList(source, trt.queue());
    // assertTrue( trt.deque() instanceof Deque);
    // assertEqualList( source, trt.deque());
    assertTrue(trt.stack() instanceof Stack);
    assertEqualList(source, trt.stack());
    assertTrue(trt.arrayList() instanceof ArrayList);
    assertEqualList(source, trt.arrayList());
    assertTrue(trt.linkedList() instanceof LinkedList);
    assertEqualList(source, trt.linkedList());
    assertTrue(trt.linkedHashSet() instanceof LinkedHashSet);
    assertEqualList(source, trt.linkedHashSet());
    assertTrue(trt.myList() instanceof MyList);
    assertEqualList(source, trt.myList());
  }
Beispiel #3
0
  private void processGeneList(Session session, Element element, HashMap additionalInformation) {

    String name = getAttribute(element, SessionAttribute.NAME.getText());

    String txt = element.getTextContent();
    String[] genes = txt.trim().split("\\s+");
    GeneList gl = new GeneList(name, Arrays.asList(genes));
    GeneListManager.getInstance().addGeneList(gl);
    session.setCurrentGeneList(gl);

    // Adjust frames
    processFrames(element);
  }
Beispiel #4
0
 @Test
 public void testElementsByTagNameWithoutNamespace() throws Exception {
   String xml =
       "<?xml version=\"1.0\"?><html><head><title>TITLE</title></head><body><p>Good morning</p><p>How are you?</p></body></html>";
   DocumentBuilder builder = builderFactory.newDocumentBuilder();
   Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes("UTF-8")));
   NodeList plist = doc.getElementsByTagName("p");
   List<String> pTexts = new ArrayList<String>();
   for (int i = 0; i < plist.getLength(); i++) {
     pTexts.add(plist.item(i).getFirstChild().getTextContent());
   }
   Assert.assertEquals(pTexts, Arrays.asList("Good morning", "How are you?"));
 }
Beispiel #5
0
  //	@Test
  public void testElementsByTagNameWithNamespace() throws Exception {
    builderFactory = DocumentBuilderFactory.newInstance();
    builderFactory.setNamespaceAware(true);

    String xml =
        "<?xml version=\"1.0\"?>"
            + "<t:root xmlns=\"http://void.com/\" xmlns:t=\"http://t.com/\" id=\"stella\" t:type=\"police\">"
            + "<t:item id=\"a\"/>"
            + "<child id=\"1\"/>"
            + "<t:item id=\"b\"/>"
            + "<child id=\"2\"/>"
            + "</t:root>";

    // TODO: Can I utilize xmlSearchNs or xmlSearchNsByHref? the problem is it searchs a specific
    // node and recurse up.
    // I don't have such a node

    DocumentBuilder builder = builderFactory.newDocumentBuilder();
    Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
    Element root = doc.getDocumentElement();

    List<String> expectedList = Arrays.asList("1", "2");
    List<String> actualList = new ArrayList<String>();
    NodeList nl = root.getElementsByTagNameNS("http://void.com/", "child");
    for (int i = 0; i < nl.getLength(); i++) {
      Element elem = (Element) nl.item(i);
      actualList.add(elem.getAttribute("id"));
    }
    Assert.assertArrayEquals("elementsByTagName", expectedList.toArray(), actualList.toArray());

    expectedList = Arrays.asList("a", "b");
    actualList.clear();
    nl = root.getElementsByTagNameNS("http://t.com/", "item");
    for (int i = 0; i < nl.getLength(); i++) {
      Element elem = (Element) nl.item(i);
      actualList.add(elem.getAttribute("id"));
    }
  }
 private static Collection<String> parseSoapResponseForUrls(byte[] data)
     throws SOAPException, IOException {
   // System.out.println(new String(data));
   final Collection<String> urls = new ArrayList<>();
   MessageFactory factory = MessageFactory.newInstance(WS_DISCOVERY_SOAP_VERSION);
   final MimeHeaders headers = new MimeHeaders();
   headers.addHeader("Content-type", WS_DISCOVERY_CONTENT_TYPE);
   SOAPMessage message = factory.createMessage(headers, new ByteArrayInputStream(data));
   SOAPBody body = message.getSOAPBody();
   for (Node node : getNodeMatching(body, ".*:XAddrs")) {
     if (node.getTextContent().length() > 0) {
       urls.addAll(Arrays.asList(node.getTextContent().split(" ")));
     }
   }
   return urls;
 }
Beispiel #7
0
  private String sustraerInformacionNodo(CliGol cliGol, Node nodo) {

    String[] excluye = {
      "CLI_ID",
      "CLI_SAP",
      "CliApePat",
      "CliApeMat",
      "CliNom",
      "CLI_FEC_NAC",
      "CLI_DOM_CAL",
      "CLI_DOM_NUM_EXT",
      "CLI_DOM_NUM_INT",
      "CLI_DOM_COL",
      "CLI_POS_ID",
      "CliGolP1",
      "CliGolP8",
      "CliGolP10",
      "CliGolP11",
      "CliGolP15",
      "CliGolP17",
      "CliGolP18",
      "CliGolP25",
      "CliGolResAct",
      "CliGolNumTar",
      "CliGolCtaChe",
      "CliGolCrePer",
      "CliGolCreAut",
      "CliGolCreHip",
      "CliGolOtrCre",
      "CliBurMens",
      "PagRnt",
      "CliGolBurCre",
      "CliBurValr",
      "CliGolIng",
      "CliGolImpRen"
    };

    NodeList variables = nodo.getChildNodes();

    LinkedHashMap[] mapas = obtenerMapeos(cliGol, variables, excluye);

    Dao dao = new Dao();
    Object[] descripciones = dao.ObtenLista(mapas[0], Arrays.asList(excluye));

    // <variable,puntos>,descripciones
    return unirMapeos(mapas[1], descripciones);
  }
Beispiel #8
0
  private List<ConfigurationResourceProvider> getConfigurationResourceProviders(
      List<ConfigurationResourceProvider> defaultProviders,
      ConfigurationResourceProviderFactory.ProviderType providerType) {

    ConfigurationResourceProvider[] custom =
        ConfigurationResourceProviderFactory.createProviders(providerType);
    if (custom.length == 0) {
      return defaultProviders;
    } else {
      List<ConfigurationResourceProvider> list = new ArrayList<ConfigurationResourceProvider>();
      list.addAll(defaultProviders);
      // insert the custom providers after the META-INF providers and
      // before those that scan /WEB-INF
      list.addAll((defaultProviders.size() - 1), Arrays.asList(custom));
      return Collections.unmodifiableList(list);
    }
  }
  public boolean runTest(String filename) throws Exception {
    Test test = new Test();
    test.file = new File(filename);
    runTest(test);

    // Print the DOM node
    if (this.resultsWriter != null) {
      this.resultsWriter.write("<html><head>");
      this.resultsWriter.write("<title>" + test.name + "</title>");
      this.resultsWriter.write("<style>");
      this.resultsWriter.write(".ran { background-color: #eeffee; }");
      this.resultsWriter.write(".passed { background-color: #ccffcc; }");
      this.resultsWriter.write(".failed { background-color: #ffcccc; }");
      this.resultsWriter.write(".error { background-color: #ffeeee; }");
      this.resultsWriter.write("</style>");
      this.resultsWriter.write("</head><body>");
      this.resultsWriter.write("<div>\n");
      this.resultsWriter.write(
          "<h3><a name=\"" + test.label + "\">" + test.file.getName() + "</a></h3>\n");
      this.resultsWriter.write("<table border=\"1\">\n");
      this.resultsWriter.write(
          "<tr class=\""
              + (test.result ? "passed" : "failed")
              + "\"><td colspan=\"3\">"
              + test.name
              + "</td></tr>\n");
      for (Command command : test.commands) {
        boolean result = command.result.startsWith("OK");
        this.resultsWriter.write("<tr class=\"" + (result ? "passed" : "failed") + "\"><td>");
        this.resultsWriter.write(command.cmd);
        this.resultsWriter.write("</td><td>");
        if (command.args != null) {
          this.resultsWriter.write(Arrays.asList(command.args).toString());
        }
        this.resultsWriter.write("</td><td>");
        this.resultsWriter.write(command.result);
        this.resultsWriter.write("</td></tr>\n");
        if (command.failure) break;
      }
      this.resultsWriter.write("</table>\n");
      this.resultsWriter.write("</body></html>");
      // outputDocument(this.resultsWriter);
    }
    return test.result;
  }
Beispiel #10
0
  private static Map<String, String> splitQuery(String body) throws UnsupportedEncodingException {
    Map<String, String> query_pairs = new LinkedHashMap<>();
    List<String> pairs = Arrays.asList(body.split("&"));

    for (String pair : pairs) {
      final int idx = pair.indexOf("=");
      final String key = idx > 0 ? URLDecoder.decode(pair.substring(0, idx), "UTF-8") : pair;
      if (!query_pairs.containsKey(key)) {
        query_pairs.put(key, "");
      }
      final String value =
          idx > 0 && pair.length() > idx + 1
              ? URLDecoder.decode(pair.substring(idx + 1), "UTF-8")
              : "";
      query_pairs.put(key, value.trim());
    }
    return query_pairs;
  }
 public Command executeStep(Element stepRow) throws Exception {
   Command command = new Command();
   NodeList stepFields = stepRow.getElementsByTagName("td");
   String cmd = stepFields.item(0).getTextContent().trim();
   command.cmd = cmd;
   ArrayList<String> argList = new ArrayList<String>();
   if (stepFields.getLength() == 1) {
     // skip comments
     command.result = "OK";
     return command;
   }
   for (int i = 1; i < stepFields.getLength(); i++) {
     String content = stepFields.item(i).getTextContent();
     content = content.replaceAll(" +", " ");
     content = content.replace('\u00A0', ' ');
     content = content.trim();
     argList.add(content);
   }
   String args[] = argList.toArray(new String[0]);
   command.args = args;
   if (this.verbose) {
     System.out.println(cmd + " " + Arrays.asList(args));
   }
   try {
     command.result = this.commandProcessor.doCommand(cmd, args);
     command.error = false;
   } catch (Exception e) {
     command.result = e.getMessage();
     command.error = true;
   }
   command.failure = command.error && !cmd.startsWith("verify");
   if (this.verbose) {
     System.out.println(command.result);
   }
   return command;
 }
 ConfigBeanDefinitionParser() {
   skipMap = new HashSet<String>(Arrays.asList(SKIP_ATTRIBUTES));
 }
Beispiel #13
0
  /**
   * return a list of queues for connected groups of pathways place pathways according to the order
   * of the queues and the list
   *
   * @param layouts
   * @param dependOn the index number of pathway this one depends on, -1 if no dependency
   * @return
   */
  public static ArrayList<Queue> pathwayQueues(LayoutInfo[] layouts, int[] dependOn) {
    ArrayList<Queue> queues =
        new ArrayList<Queue>(); // each queue is for a disconnected group of pathways
    int n = layouts.length;
    boolean[] added = new boolean[n]; // whether the pathway is added into a queue
    // boolean[] processed = new boolean[n];//whether all neighbours of this pathway are added into
    // some queue
    Queue<Integer> toProcess = new LinkedList<Integer>();

    // current queue to add pathways into
    // if not null, then exists a queue to add pathways into
    // otherwise need to create a new queue(for disconnected group of pathways)
    Queue currentQueue = null;

    Arrays.sort(layouts, new LayoutBoxSizeComparator());

    /*TODO delete
    LayoutInfo tmp0 = layouts[0];
    LayoutInfo tmp1 = layouts[1];
    LayoutInfo tmp2 = layouts[2];
    LayoutInfo tmp3 = layouts[3];
    LayoutInfo tmp6 = layouts[6];
    layouts[3]=tmp1;
    layouts[2]=tmp6;
    layouts[1]=tmp2;
    layouts[6]=tmp0;
    layouts[0] = tmp3;
    /*
    for(LayoutInfo i:layouts){
        System.out.println(i.getExactLayoutBox().size());
    }
    //*/

    for (int i = n - 1; i >= 0; i--) {
      if (added[i]) {
        continue;
      }

      currentQueue = new LinkedList<Integer>(); // current queue to add connected pathways into
      queues.add(currentQueue);
      toProcess.add(i);
      currentQueue.add(i);
      added[i] = true;
      dependOn[i] = -1;

      while (toProcess.size() != 0) {
        int p = toProcess.remove();
        for (int j = n - 2; j >= 0; j--) { // the first one is already added, so search from n-2
          // find all non-visited neighbour pathways of layout[p]
          if (added[j]) {
            continue;
          }
          if (layouts[p].sharedNodes(layouts[j]).size() > 0 && !added[j]) {
            currentQueue.add(j);
            toProcess.add(j);
            added[j] = true;
            dependOn[j] = p;
          }
        }
        // processed[p]=true;
      }
      currentQueue = null; // finished a connected group of pathways
    }

    return queues;
  }
Beispiel #14
0
  /**
   * Returns a set of column headings and rows for a given metadata request.
   *
   * <p>Leverages mondrian's implementation of the XML/A specification, and is exposed here for use
   * by mondrian's olap4j driver.
   *
   * @param connection Connection
   * @param methodName Metadata method name per XMLA (e.g. "MDSCHEMA_CUBES")
   * @param restrictionMap Restrictions
   * @return Set of rows and column headings
   */
  public static MetadataRowset getMetadataRowset(
      final OlapConnection connection, String methodName, final Map<String, Object> restrictionMap)
      throws OlapException {
    RowsetDefinition rowsetDefinition = RowsetDefinition.valueOf(methodName);

    final XmlaHandler.ConnectionFactory connectionFactory =
        new XmlaHandler.ConnectionFactory() {
          public OlapConnection getConnection(
              String catalog, String schema, String roleName, Properties props)
              throws SQLException {
            return connection;
          }

          public Map<String, Object> getPreConfiguredDiscoverDatasourcesResponse() {
            // This method should not be used by the olap4j xmla
            // servlet. For the mondrian xmla servlet we don't provide
            // the "pre configured discover datasources" feature.
            return null;
          }
        };
    final XmlaRequest request =
        new XmlaRequest() {
          public Method getMethod() {
            return Method.DISCOVER;
          }

          public Map<String, String> getProperties() {
            return Collections.emptyMap();
          }

          public Map<String, Object> getRestrictions() {
            return restrictionMap;
          }

          public String getStatement() {
            return null;
          }

          public String getRoleName() {
            return null;
          }

          public String getRequestType() {
            throw new UnsupportedOperationException();
          }

          public boolean isDrillThrough() {
            throw new UnsupportedOperationException();
          }

          public Format getFormat() {
            throw new UnsupportedOperationException();
          }

          public String getUsername() {
            return null;
          }

          public String getPassword() {
            return null;
          }

          public String getSessionId() {
            return null;
          }
        };
    final Rowset rowset =
        rowsetDefinition.getRowset(
            request,
            new XmlaHandler(connectionFactory, "xmla") {
              @Override
              public OlapConnection getConnection(
                  XmlaRequest request, Map<String, String> propMap) {
                return connection;
              }
            });
    List<Rowset.Row> rowList = new ArrayList<Rowset.Row>();
    rowset.populate(
        new DefaultXmlaResponse(
            new ByteArrayOutputStream(),
            Charset.defaultCharset().name(),
            Enumeration.ResponseMimeType.SOAP),
        connection,
        rowList);
    MetadataRowset result = new MetadataRowset();
    final List<RowsetDefinition.Column> colDefs = new ArrayList<RowsetDefinition.Column>();
    for (RowsetDefinition.Column columnDefinition : rowsetDefinition.columnDefinitions) {
      if (columnDefinition.type == RowsetDefinition.Type.Rowset) {
        // olap4j does not support the extended columns, e.g.
        // Cube.Dimensions
        continue;
      }
      colDefs.add(columnDefinition);
    }
    for (Rowset.Row row : rowList) {
      Object[] values = new Object[colDefs.size()];
      int k = -1;
      for (RowsetDefinition.Column colDef : colDefs) {
        Object o = row.get(colDef.name);
        if (o instanceof List) {
          o = toString((List<String>) o);
        } else if (o instanceof String[]) {
          o = toString(Arrays.asList((String[]) o));
        }
        values[++k] = o;
      }
      result.rowList.add(Arrays.asList(values));
    }
    for (RowsetDefinition.Column colDef : colDefs) {
      String columnName = colDef.name;
      if (LOWERCASE_PATTERN.matcher(columnName).matches()) {
        columnName = Util.camelToUpper(columnName);
      }
      // VALUE is a SQL reserved word
      if (columnName.equals("VALUE")) {
        columnName = "PROPERTY_VALUE";
      }
      result.headerList.add(columnName);
    }
    return result;
  }
Beispiel #15
0
  /**
   * Process a track element. This should return a single track, but could return multiple tracks
   * since the uniqueness of the track id is not enforced.
   *
   * @param session
   * @param element
   * @param additionalInformation
   * @return
   */
  private List<Track> processTrack(
      Session session, Element element, HashMap additionalInformation) {

    String id = getAttribute(element, SessionAttribute.ID.getText());

    // TODo -- put in utility method, extacts attributes from element **Definitely need to do this
    HashMap<String, String> tAttributes = new HashMap();
    HashMap<String, String> drAttributes = null;

    NamedNodeMap tNodeMap = element.getAttributes();
    for (int i = 0; i < tNodeMap.getLength(); i++) {
      Node node = tNodeMap.item(i);
      String value = node.getNodeValue();
      if (value != null && value.length() > 0) {
        tAttributes.put(node.getNodeName(), value);
      }
    }

    if (element.hasChildNodes()) {
      drAttributes = new HashMap();
      Node childNode = element.getFirstChild();
      Node sibNode = childNode.getNextSibling();
      String sibName = sibNode.getNodeName();
      if (sibName.equals(SessionElement.DATA_RANGE.getText())) {
        NamedNodeMap drNodeMap = sibNode.getAttributes();
        for (int i = 0; i < drNodeMap.getLength(); i++) {
          Node node = drNodeMap.item(i);
          String value = node.getNodeValue();
          if (value != null && value.length() > 0) {
            drAttributes.put(node.getNodeName(), value);
          }
        }
      }
    }

    // Get matching tracks.
    List<Track> matchedTracks = trackDictionary.get(id);

    if (matchedTracks == null) {
      log.info("Warning.  No tracks were found with id: " + id + " in session file");
    } else {
      for (final Track track : matchedTracks) {

        // Special case for sequence & gene tracks,  they need to be removed before being placed.
        if (version >= 4 && track == geneTrack || track == seqTrack) {
          igv.removeTracks(Arrays.asList(track));
        }

        track.restorePersistentState(tAttributes);
        if (drAttributes != null) {
          DataRange dr = track.getDataRange();
          dr.restorePersistentState(drAttributes);
          track.setDataRange(dr);
        }
      }
      trackDictionary.remove(id);
    }

    NodeList elements = element.getChildNodes();
    process(session, elements, additionalInformation);

    return matchedTracks;
  }
Beispiel #16
0
 /**
  * Discard cookies along this result<br>
  * For example:
  *
  * <pre>
  * response().discardCookies("theme");
  * </pre>
  *
  * @param names Names of the cookies to discard
  */
 public void discardCookies(String... names) {
   discardedCookies.addAll(Arrays.asList(names));
 }
  public boolean runSuite(String filename) throws Exception {
    if (this.verbose) {
      System.out.println(
          "Running test suite "
              + filename
              + " against "
              + this.host
              + ":"
              + this.port
              + " with "
              + this.browser);
    }
    TestSuite suite = new TestSuite();
    long start = System.currentTimeMillis();
    suite.numTestPasses = 0;
    suite.file = new File(filename);
    File suiteDirectory = suite.file.getParentFile();
    this.document = parseDocument(filename);
    Element table = (Element) this.document.getElementsByTagName("table").item(0);
    NodeList tableRows = table.getElementsByTagName("tr");
    Element tableNameRow = (Element) tableRows.item(0);
    suite.name = tableNameRow.getTextContent();
    suite.result = true;
    suite.tests = new Test[tableRows.getLength() - 1];
    for (int i = 1; i < tableRows.getLength(); i++) {
      Element tableRow = (Element) tableRows.item(i);
      Element cell = (Element) tableRow.getElementsByTagName("td").item(0);
      Element link = (Element) cell.getElementsByTagName("a").item(0);
      Test test = new Test();
      test.label = link.getTextContent();
      test.file = new File(suiteDirectory, link.getAttribute("href"));

      SeleniumHtmlClient subclient = new SeleniumHtmlClient();
      subclient.setHost(this.host);
      subclient.setPort(this.port);
      subclient.setBrowser(this.browser);
      // subclient.setResultsWriter(this.resultsWriter);
      subclient.setBaseUrl(this.baseUrl);
      subclient.setVerbose(this.verbose);
      subclient.runTest(test);
      if (test.result) {
        suite.numTestPasses++;
      }
      suite.result &= test.result;
      suite.tests[i - 1] = test;
    }
    long end = System.currentTimeMillis();

    suite.totalTime = (end - start) / 1000;

    if (this.resultsWriter != null) {
      this.resultsWriter.write("<html><head>\n");
      this.resultsWriter.write("<style type='text/css'>\n");
      this.resultsWriter.write(
          "body, table {font-family: Verdana, Arial, sans-serif;font-size: 12;}\n");
      this.resultsWriter.write("table {border-collapse: collapse;border: 1px solid #ccc;}\n");
      this.resultsWriter.write("th, td {padding-left: 0.3em;padding-right: 0.3em;}\n");
      this.resultsWriter.write("a {text-decoration: none;}\n");
      this.resultsWriter.write(".title {font-style: italic;}");
      this.resultsWriter.write(".selected {background-color: #ffffcc;}\n");
      this.resultsWriter.write(".status_done {background-color: #eeffee;}\n");
      this.resultsWriter.write(".status_passed {background-color: #ccffcc;}\n");
      this.resultsWriter.write(".status_failed {background-color: #ffcccc;}\n");
      this.resultsWriter.write(
          ".breakpoint {background-color: #cccccc;border: 1px solid black;}\n");
      this.resultsWriter.write("</style>\n");
      this.resultsWriter.write("<title>" + suite.name + "</title>\n");
      this.resultsWriter.write("</head><body>\n");
      this.resultsWriter.write("<h1>Test suite results </h1>\n\n");
      this.resultsWriter.write("<table>\n");
      this.resultsWriter.write(
          "<tr>\n<td>result:</td>\n<td>" + (suite.result ? "passed" : "failed") + "</td>\n</tr>\n");
      this.resultsWriter.write(
          "<tr>\n<td>totalTime:</td>\n<td>" + suite.totalTime + "</td>\n</tr>\n");
      this.resultsWriter.write(
          "<tr>\n<td>numTestTotal:</td>\n<td>" + suite.tests.length + "</td>\n</tr>\n");
      this.resultsWriter.write(
          "<tr>\n<td>numTestPasses:</td>\n<td>" + suite.numTestPasses + "</td>\n</tr>\n");
      int numTestFailures = suite.tests.length - suite.numTestPasses;
      this.resultsWriter.write(
          "<tr>\n<td>numTestFailures:</td>\n<td>" + numTestFailures + "</td>\n</tr>\n");
      this.resultsWriter.write("<tr>\n<td>numCommandPasses:</td>\n<td>0</td>\n</tr>\n");
      this.resultsWriter.write("<tr>\n<td>numCommandFailures:</td>\n<td>0</td>\n</tr>\n");
      this.resultsWriter.write("<tr>\n<td>numCommandErrors:</td>\n<td>0</td>\n</tr>\n");
      this.resultsWriter.write("<tr>\n<td>Selenium Version:</td>\n<td>2.24</td>\n</tr>\n");
      this.resultsWriter.write("<tr>\n<td>Selenium Revision:</td>\n<td>.1</td>\n</tr>\n");

      // test suite
      this.resultsWriter.write("<tr>\n<td>\n");
      this.resultsWriter.write(
          "<table id=\"suiteTable\" class=\"selenium\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\"><tbody>\n");
      this.resultsWriter.write(
          "<tr class=\"title "
              + (suite.result ? "status_passed" : "status_failed")
              + "\"><td><b>Test Suite</b></td></tr>\n");

      int i = 0;
      for (Test test : suite.tests) {
        this.resultsWriter.write(
            "<tr class=\""
                + (test.result ? "status_passed" : "status_failed")
                + "\"><td><a href=\"#testresult"
                + i
                + "\">"
                + test.name
                + "</a></td></tr>");
        i++;
      }
      this.resultsWriter.write(
          "</tbody></table>\n</td>\n<td>&nbsp;</td>\n</tr>\n</table>\n<table>");
      int j = 0;
      for (Test test : suite.tests) {
        this.resultsWriter.write(
            "<tr><td><a name=\"testresult" + j + "\">" + test.file + "</a><br/><div>\n");
        this.resultsWriter.write("<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\">\n");
        this.resultsWriter.write(
            "<thead>\n<tr class=\"title "
                + (test.result ? "status_passed" : "status_failed")
                + "\"><td rowspan=\"1\" colspan=\"3\">"
                + test.name
                + "</td></tr>");
        this.resultsWriter.write("</thead><tbody>\n");
        for (Command command : test.commands) {
          boolean result = command.result.startsWith("OK");
          boolean isAssert = command.cmd.startsWith("assert") || command.cmd.startsWith("verify");
          ;
          if (!isAssert) {
            this.resultsWriter.write(
                "<tr class=\"" + (result ? "status_done" : "") + "\">\n<td>\n");
          } else {
            this.resultsWriter.write(
                "<tr class=\"" + (result ? "status_passed" : "status_failed") + "\">\n<td>\n");
          }
          this.resultsWriter.write(command.cmd);
          this.resultsWriter.write("</td>\n");
          if (command.args != null) {
            for (String arg : Arrays.asList(command.args)) {
              this.resultsWriter.write("<td>" + arg + "</td>\n");
            }
          }
        }
        this.resultsWriter.write("</tr>\n");
        this.resultsWriter.write("</tbody></table>\n");
        this.resultsWriter.write("</div></td>\n<td>&nbsp;</td>\n</tr>");

        j++;
      }

      int k = 0;
      for (Test test : suite.tests) {

        k++;
      }

      this.resultsWriter.write("</tbody></table>\n</td><td>&nbsp;</td>\n</tr>\n</table>\n");
      this.resultsWriter.write("</body></html>");
    }
    return suite.result;
  }
Beispiel #18
0
  /**
   * Creates nodes from index entries
   *
   * @param theIndexEntries index entries
   * @param theTargetDocument target document
   * @param theIndexEntryComparator comparator to sort the index entries. if it is null the index
   *     entries will be unsorted
   * @return nodes for the target document
   */
  private Node[] transformToNodes(
      final IndexEntry[] theIndexEntries,
      final Document theTargetDocument,
      final Comparator<IndexEntry> theIndexEntryComparator) {
    if (null != theIndexEntryComparator) {
      Arrays.sort(theIndexEntries, theIndexEntryComparator);
    }

    final List<Element> result = new ArrayList<Element>();
    for (final IndexEntry indexEntry : theIndexEntries) {
      final Element indexEntryNode = createElement(theTargetDocument, "index.entry");

      final Element formattedStringElement = createElement(theTargetDocument, "formatted-value");
      if (indexEntry.getContents() != null) {
        for (final Iterator<Node> i = indexEntry.getContents().iterator(); i.hasNext(); ) {
          final Node child = i.next();
          final Node clone = theTargetDocument.importNode(child, true);
          if (!i.hasNext() && clone.getNodeType() == Node.TEXT_NODE) {
            final Text t = (Text) clone;
            t.setData(t.getData().replaceAll("[\\s\\n]+$", ""));
          }
          formattedStringElement.appendChild(clone);
        }
      } else {
        final Text textNode = theTargetDocument.createTextNode(indexEntry.getFormattedString());
        textNode.normalize();
        formattedStringElement.appendChild(textNode);
      }
      indexEntryNode.appendChild(formattedStringElement);

      final String[] refIDs = indexEntry.getRefIDs();
      for (final String refID : refIDs) {
        final Element referenceIDElement = createElement(theTargetDocument, "refID");
        referenceIDElement.setAttribute("value", refID);
        indexEntryNode.appendChild(referenceIDElement);
      }

      final String val = indexEntry.getValue();
      if (null != val) {
        indexEntryNode.setAttribute("value", val);
      }

      final String sort = indexEntry.getSortString();
      if (null != sort) {
        indexEntryNode.setAttribute("sort-string", sort);
      }

      if (indexEntry.isStartingRange()) {
        indexEntryNode.setAttribute("start-range", "true");
      } else if (indexEntry.isEndingRange()) {
        indexEntryNode.setAttribute("end-range", "true");
      }
      if (indexEntry.isSuppressesThePageNumber()) {
        indexEntryNode.setAttribute("no-page", "true");
      } else if (indexEntry.isRestoresPageNumber()) {
        indexEntryNode.setAttribute("single-page", "true");
      }

      final IndexEntry[] childIndexEntries = indexEntry.getChildIndexEntries();

      final Node[] nodes =
          transformToNodes(childIndexEntries, theTargetDocument, theIndexEntryComparator);

      for (final Node node : nodes) {
        indexEntryNode.appendChild(node);
      }

      final IndexEntry[] seeChildIndexEntries = indexEntry.getSeeChildIndexEntries();
      if (seeChildIndexEntries != null) {
        final Element seeElement = createElement(theTargetDocument, "see-childs");
        final Node[] seeNodes =
            transformToNodes(seeChildIndexEntries, theTargetDocument, theIndexEntryComparator);
        for (final Node node : seeNodes) {
          seeElement.appendChild(node);
        }

        indexEntryNode.appendChild(seeElement);
      }

      final IndexEntry[] seeAlsoChildIndexEntries = indexEntry.getSeeAlsoChildIndexEntries();
      if (seeAlsoChildIndexEntries != null) {
        final Element seeAlsoElement = createElement(theTargetDocument, "see-also-childs");
        final Node[] seeAlsoNodes =
            transformToNodes(seeAlsoChildIndexEntries, theTargetDocument, theIndexEntryComparator);
        for (final Node node : seeAlsoNodes) {
          seeAlsoElement.appendChild(node);
        }

        indexEntryNode.appendChild(seeAlsoElement);
      }

      result.add(indexEntryNode);
    }
    return (Node[]) result.toArray(new Node[result.size()]);
  }
Beispiel #19
0
  /**
   * Test the converter.
   *
   * @throws URISyntaxException
   */
  public static void testConverter() throws URISyntaxException {
    {
      // Test collections as value
      TestReturnTypes trt = set(TestReturnTypes.class, Arrays.asList(55));
      assertTrue(Arrays.equals(new boolean[] {true}, trt.rpaBoolean()));
      assertTrue(Arrays.equals(new byte[] {55}, trt.rpaByte()));
      assertTrue(Arrays.equals(new short[] {55}, trt.rpaShort()));
      assertTrue(Arrays.equals(new int[] {55}, trt.rpaInt()));
      assertTrue(Arrays.equals(new long[] {55}, trt.rpaLong()));
      assertTrue(Arrays.equals(new float[] {55}, trt.rpaFloat()));
      assertTrue(Arrays.equals(new double[] {55}, trt.rpaDouble()));
      assertEquals(Arrays.asList(true), trt.rBooleans());
      assertEquals(Arrays.asList(new Byte((byte) 55)), trt.rBytes());
      assertEquals(Arrays.asList(new Short((short) 55)), trt.rShorts());
      assertEquals(Arrays.asList(Integer.valueOf(55)), trt.rInts());
      assertEquals(Arrays.asList(new Long(55L)), trt.rLongs());
      assertEquals(Arrays.asList(new Float(55F)), trt.rFloats());
      assertEquals(Arrays.asList(new Double(55D)), trt.rDoubles());
      assertEquals(Arrays.asList("55"), trt.rStrings());
      assertEquals(Arrays.asList(new URI("55")), trt.rURIs());

      assertTrue(Arrays.equals(new Boolean[] {true}, trt.raBoolean()));
      assertTrue(Arrays.equals(new Byte[] {55}, trt.raByte()));
      assertTrue(Arrays.equals(new Short[] {55}, trt.raShort()));
      assertTrue(Arrays.equals(new Integer[] {55}, trt.raInt()));
      assertTrue(Arrays.equals(new Long[] {55L}, trt.raLong()));
      assertTrue(Arrays.equals(new Float[] {55F}, trt.raFloat()));
      assertTrue(Arrays.equals(new Double[] {55D}, trt.raDouble()));
      assertTrue(Arrays.equals(new String[] {"55"}, trt.raString()));
      assertTrue(Arrays.equals(new URI[] {new URI("55")}, trt.raURI()));
    }
    {
      // Test primitive arrays as value
      TestReturnTypes trt = set(TestReturnTypes.class, new int[] {55});
      assertTrue(Arrays.equals(new boolean[] {true}, trt.rpaBoolean()));
      assertTrue(Arrays.equals(new byte[] {55}, trt.rpaByte()));
      assertTrue(Arrays.equals(new short[] {55}, trt.rpaShort()));
      assertTrue(Arrays.equals(new int[] {55}, trt.rpaInt()));
      assertTrue(Arrays.equals(new long[] {55}, trt.rpaLong()));
      assertTrue(Arrays.equals(new float[] {55}, trt.rpaFloat()));
      assertTrue(Arrays.equals(new double[] {55}, trt.rpaDouble()));
      assertEquals(Arrays.asList(true), trt.rBooleans());
      assertEquals(Arrays.asList(new Byte((byte) 55)), trt.rBytes());
      assertEquals(Arrays.asList(new Short((short) 55)), trt.rShorts());
      assertEquals(Arrays.asList(Integer.valueOf(55)), trt.rInts());
      assertEquals(Arrays.asList(new Long(55L)), trt.rLongs());
      assertEquals(Arrays.asList(new Float(55F)), trt.rFloats());
      assertEquals(Arrays.asList(new Double(55D)), trt.rDoubles());
      assertEquals(Arrays.asList("55"), trt.rStrings());
      assertEquals(Arrays.asList(new URI("55")), trt.rURIs());

      assertTrue(Arrays.equals(new Boolean[] {true}, trt.raBoolean()));
      assertTrue(Arrays.equals(new Byte[] {55}, trt.raByte()));
      assertTrue(Arrays.equals(new Short[] {55}, trt.raShort()));
      assertTrue(Arrays.equals(new Integer[] {55}, trt.raInt()));
      assertTrue(Arrays.equals(new Long[] {55L}, trt.raLong()));
      assertTrue(Arrays.equals(new Float[] {55F}, trt.raFloat()));
      assertTrue(Arrays.equals(new Double[] {55D}, trt.raDouble()));
      assertTrue(Arrays.equals(new String[] {"55"}, trt.raString()));
      assertTrue(Arrays.equals(new URI[] {new URI("55")}, trt.raURI()));
    }

    {
      // Test single value
      TestReturnTypes trt = set(TestReturnTypes.class, 55);
      assertEquals(true, trt.rpBoolean());
      assertEquals(55, trt.rpByte());
      assertEquals(55, trt.rpShort());
      assertEquals(55, trt.rpInt());
      assertEquals(55L, trt.rpLong());
      assertEquals(55.0D, trt.rpDouble());
      assertEquals(55.0F, trt.rpFloat());
      assertEquals((Boolean) true, trt.rBoolean());
      assertEquals(new Byte((byte) 55), trt.rByte());
      assertEquals(new Short((short) 55), trt.rShort());
      assertEquals(Integer.valueOf(55), trt.rInt());
      assertEquals(new Long(55L), trt.rLong());
      assertEquals(new Float(55F), trt.rFloat());
      assertEquals(new Double(55), trt.rDouble());
      assertEquals("55", trt.rString());
      assertEquals(new URI("55"), trt.rURI());
      assertTrue(Arrays.equals(new boolean[] {true}, trt.rpaBoolean()));
      assertTrue(Arrays.equals(new byte[] {55}, trt.rpaByte()));
      assertTrue(Arrays.equals(new short[] {55}, trt.rpaShort()));
      assertTrue(Arrays.equals(new int[] {55}, trt.rpaInt()));
      assertTrue(Arrays.equals(new long[] {55}, trt.rpaLong()));
      assertTrue(Arrays.equals(new float[] {55}, trt.rpaFloat()));
      assertTrue(Arrays.equals(new double[] {55}, trt.rpaDouble()));
      assertEquals(Arrays.asList(true), trt.rBooleans());
      assertEquals(Arrays.asList(new Byte((byte) 55)), trt.rBytes());
      assertEquals(Arrays.asList(new Short((short) 55)), trt.rShorts());
      assertEquals(Arrays.asList(Integer.valueOf(55)), trt.rInts());
      assertEquals(Arrays.asList(new Long(55L)), trt.rLongs());
      assertEquals(Arrays.asList(new Float(55F)), trt.rFloats());
      assertEquals(Arrays.asList(new Double(55D)), trt.rDoubles());
      assertEquals(Arrays.asList("55"), trt.rStrings());
      assertEquals(Arrays.asList(new URI("55")), trt.rURIs());

      assertTrue(Arrays.equals(new Boolean[] {true}, trt.raBoolean()));
      assertTrue(Arrays.equals(new Byte[] {55}, trt.raByte()));
      assertTrue(Arrays.equals(new Short[] {55}, trt.raShort()));
      assertTrue(Arrays.equals(new Integer[] {55}, trt.raInt()));
      assertTrue(Arrays.equals(new Long[] {55L}, trt.raLong()));
      assertTrue(Arrays.equals(new Float[] {55F}, trt.raFloat()));
      assertTrue(Arrays.equals(new Double[] {55D}, trt.raDouble()));
      assertTrue(Arrays.equals(new String[] {"55"}, trt.raString()));
      assertTrue(Arrays.equals(new URI[] {new URI("55")}, trt.raURI()));
    }
  }