@Test
  public void appendString() {
    Appendable builder1 = new StringBuilder();
    this.classUnderTest().appendString(builder1);
    Assert.assertEquals(
        FastList.newList(this.classUnderTest()).toString(), '[' + builder1.toString() + ']');

    Appendable builder2 = new StringBuilder();
    this.classUnderTest().appendString(builder2, ", ");
    Assert.assertEquals(
        FastList.newList(this.classUnderTest()).toString(), '[' + builder2.toString() + ']');

    Appendable builder3 = new StringBuilder();
    this.classUnderTest().appendString(builder3, "[", ", ", "]");
    Assert.assertEquals(FastList.newList(this.classUnderTest()).toString(), builder3.toString());
  }
 @Override
 @Test
 public void appendString() {
   Appendable builder = new StringBuilder();
   this.newWith(1, 2, 3).appendString(builder);
   Assert.assertEquals("1, 2, 3", builder.toString());
 }
 /** Verify injecting multiple components using a single Integration Object. */
 @UnAdaptableTest
 public void testInjectingMultipleComponents() throws Exception {
   DefDescriptor<ComponentDef> cmp1 =
       addSourceAutoCleanup(ComponentDef.class, String.format(baseComponentTag, "", ""));
   DefDescriptor<ComponentDef> cmp2 =
       addSourceAutoCleanup(ComponentDef.class, String.format(baseComponentTag, "", ""));
   Map<String, Object> attributes = Maps.newHashMap();
   Appendable out = new StringBuffer();
   Integration integration = service.createIntegration("", Mode.UTEST, true, null);
   try {
     integration.injectComponent(cmp1.getDescriptorName(), attributes, "", "", out);
     integration.injectComponent(cmp2.getDescriptorName(), attributes, "", "", out);
   } catch (Exception unexpected) {
     fail("Failed to inject multiple component. Exception:" + unexpected.getMessage());
   }
   // Verify that the boot strap was written only once
   assertNotNull(out);
   Pattern frameworkJS =
       Pattern.compile(
           "<script src=\"/auraFW/javascript/[^/]+/aura_.{4}.js\\?aura.fwuid=[-0-9A-Za-z_]*\" ></script>");
   Matcher m = frameworkJS.matcher(out.toString());
   int counter = 0;
   while (m.find()) {
     counter++;
   }
   assertEquals("Bootstrap template should be written out only once.", 1, counter);
 }
 @Override
 @Test
 public void appendString() {
   MutableCollection<Object> collection = this.newWith(1, 2, 3);
   Appendable builder = new StringBuilder();
   collection.appendString(builder);
   Assert.assertEquals(collection.toString(), '[' + builder.toString() + ']');
 }
 @Test
 public void forEach() {
   InternalIterable<Boolean> select = this.newPrimitiveWith(true, false, true, false, true);
   Appendable builder = new StringBuilder();
   Procedure<Boolean> appendProcedure = Procedures.append(builder);
   select.forEach(appendProcedure);
   Assert.assertEquals("truefalsetruefalsetrue", builder.toString());
 }
  @Test
  public void appendString_with_start_separator_end() {
    ImmutableBag<String> bag = this.newBag();

    Appendable builder = new StringBuilder();
    bag.appendString(builder, "[", ", ", "]");
    Assert.assertEquals(bag.toString(), builder.toString());
  }
  @Test
  public void appendString_with_separator() {
    ImmutableBag<String> bag = this.newBag();

    Appendable builder = new StringBuilder();
    bag.appendString(builder, ", ");
    Assert.assertEquals(bag.toString(), '[' + builder.toString() + ']');
  }
  @Test
  public void appendString() {
    ImmutableBag<String> bag = this.newBag();

    Appendable builder = new StringBuilder();
    bag.appendString(builder);
    Assert.assertEquals(FastList.newList(bag).makeString(), builder.toString());
  }
Beispiel #9
0
 @Test
 public void writeFile() {
   MetaRepository m3 = MetaRepository.createFM3();
   Appendable stream = new StringBuilder();
   m3.accept(new MSEPrinter(stream));
   String mse = stream.toString();
   assertTrue(mse.length() != 0);
   // out(mse);
 }
Beispiel #10
0
  public void functionHandler(FunctionDescr functionDescr) {
    // for now all functions are in MAIN
    // setModuleName( functionDescr );
    functionDescr.setNamespace("MAIN");
    Appendable builder = new StringBuilderAppendable();

    // strip lead/trailing quotes
    String name = functionDescr.getName().trim();
    if (name.charAt(0) == '"') {
      name = name.substring(1);
    }

    if (name.charAt(name.length() - 1) == '"') {
      name = name.substring(0, name.length() - 1);
    }
    builder.append("function " + name + "(");

    for (int i = 0, length = functionDescr.getParameterNames().size(); i < length; i++) {
      builder.append(functionDescr.getParameterNames().get(i));
      if (i < length - 1) {
        builder.append(", ");
      }
    }

    builder.append(") {\n");
    // TODO: fix this
    //        List list = (List) functionDescr.getBody();
    //        for ( Iterator it = list.iterator(); it.hasNext(); ) {
    //            FunctionHandlers.dump( (LispForm) it.next(),
    //                                   builder,
    //                                   true );
    //        }
    builder.append("}");

    System.out.println("mvel expr:" + builder.toString());

    functionDescr.setText(builder.toString());
    functionDescr.setDialect("clips");

    PackageDescr pkgDescr = createPackageDescr(functionDescr.getNamespace());
    pkgDescr.addFunction(functionDescr);

    this.packageBuilder.addPackage(pkgDescr);
  }
  @Override
  @Test(expected = UnsupportedOperationException.class)
  public void appendString_with_collection_containing_self() {
    super.appendString_with_collection_containing_self();

    MutableCollection<Object> collection = this.newWith(1, 2, 3);
    collection.add(collection);
    Appendable builder = new StringBuilder();
    collection.appendString(builder);
    Assert.assertEquals(collection.toString(), '[' + builder.toString() + ']');
  }
Beispiel #12
0
  public static void buildHyperlinkUrl(
      Appendable externalWriter,
      String target,
      String targetType,
      Map<String, String> parameterMap,
      String prefix,
      boolean fullPath,
      boolean secure,
      boolean encode,
      HttpServletRequest request,
      HttpServletResponse response,
      Map<String, Object> context)
      throws IOException {

    // We may get an encoded request like:
    // &#47;projectmgr&#47;control&#47;EditTaskContents&#63;workEffortId&#61;10003
    // Try to reducing a possibly encoded string down to its simplest form:
    // /projectmgr/control/EditTaskContents?workEffortId=10003
    // This step make sure the following appending externalLoginKey operation to work correctly
    String localRequestName = StringEscapeUtils.unescapeHtml(target);

    localRequestName = UtilHttp.encodeAmpersands(localRequestName);
    Appendable localWriter = new StringWriter();

    if ("intra-app".equals(targetType)) {
      if (request != null && response != null) {
        ServletContext servletContext = request.getSession().getServletContext();
        RequestHandler rh = (RequestHandler) servletContext.getAttribute("_REQUEST_HANDLER_");
        externalWriter.append(
            rh.makeLink(request, response, "/" + localRequestName, fullPath, secure, encode));
      } else if (prefix != null) {
        externalWriter.append(prefix);
        externalWriter.append(localRequestName);
      } else {
        externalWriter.append(localRequestName);
      }
    } else if ("inter-app".equals(targetType)) {
      String fullTarget = localRequestName;
      localWriter.append(fullTarget);
      String externalLoginKey = (String) request.getAttribute("externalLoginKey");
      if (UtilValidate.isNotEmpty(externalLoginKey)) {
        if (fullTarget.indexOf('?') == -1) {
          localWriter.append('?');
        } else {
          localWriter.append("&amp;");
        }
        localWriter.append("externalLoginKey=");
        localWriter.append(externalLoginKey);
      }
    } else if ("content".equals(targetType)) {
      appendContentUrl(localWriter, localRequestName, request);
    } else if ("plain".equals(targetType)) {
      localWriter.append(localRequestName);
    } else {
      localWriter.append(localRequestName);
    }

    if (UtilValidate.isNotEmpty(parameterMap)) {
      String localUrl = localWriter.toString();
      externalWriter.append(localUrl);
      boolean needsAmp = true;
      if (localUrl.indexOf('?') == -1) {
        externalWriter.append('?');
        needsAmp = false;
      }

      for (Map.Entry<String, String> parameter : parameterMap.entrySet()) {
        String parameterValue = null;
        if (parameter.getValue() instanceof String) {
          parameterValue = parameter.getValue();
        } else {
          Object parameterObject = parameter.getValue();

          // skip null values
          if (parameterObject == null) continue;

          if (parameterObject instanceof String[]) {
            // it's probably a String[], just get the first value
            String[] parameterArray = (String[]) parameterObject;
            parameterValue = parameterArray[0];
            Debug.logInfo(
                "Found String array value for parameter ["
                    + parameter.getKey()
                    + "], using first value: "
                    + parameterValue,
                module);
          } else {
            // not a String, and not a String[], just use toString
            parameterValue = parameterObject.toString();
          }
        }

        if (needsAmp) {
          externalWriter.append("&amp;");
        } else {
          needsAmp = true;
        }
        externalWriter.append(parameter.getKey());
        externalWriter.append('=');
        StringUtil.SimpleEncoder simpleEncoder =
            (StringUtil.SimpleEncoder) context.get("simpleEncoder");
        if (simpleEncoder != null && parameterValue != null) {
          externalWriter.append(
              simpleEncoder.encode(
                  URLEncoder.encode(parameterValue, Charset.forName("UTF-8").displayName())));
        } else {
          externalWriter.append(parameterValue);
        }
      }
    } else {
      externalWriter.append(localWriter.toString());
    }
  }
Beispiel #13
0
 public String toJson(JsonElement jsonElement) {
   Appendable stringWriter = new StringWriter();
   toJson(jsonElement, stringWriter);
   return stringWriter.toString();
 }
Beispiel #14
0
 public String toJson(Object obj, Type type) {
   Appendable stringWriter = new StringWriter();
   toJson(obj, type, stringWriter);
   return stringWriter.toString();
 }
  @Test
  public void appendString() {
    Appendable appendable = new StringBuilder();
    this.getEmptyMap().appendString(appendable);
    Assert.assertEquals("", appendable.toString());

    Appendable appendable0 = new StringBuilder();
    this.newWithKeysValues(0, true).appendString(appendable0);
    Assert.assertEquals("0=true", appendable0.toString());

    Appendable appendable1 = new StringBuilder();
    this.newWithKeysValues(1, false).appendString(appendable1);
    Assert.assertEquals("1=false", appendable1.toString());

    Appendable appendable2 = new StringBuilder();
    this.newWithKeysValues(null, false).appendString(appendable2);
    Assert.assertEquals("null=false", appendable2.toString());

    Appendable appendable3 = new StringBuilder();
    MutableObjectBooleanMap<Integer> map1 = this.newWithKeysValues(0, true, 1, false);
    map1.appendString(appendable3);
    Assert.assertTrue(
        appendable3.toString(),
        "0=true, 1=false".equals(appendable3.toString())
            || "1=false, 0=true".equals(appendable3.toString()));

    Appendable appendable4 = new StringBuilder();
    map1.appendString(appendable4, "/");
    Assert.assertTrue(
        appendable4.toString(),
        "0=true/1=false".equals(appendable4.toString())
            || "1=false/0=true".equals(appendable4.toString()));

    Appendable appendable5 = new StringBuilder();
    map1.appendString(appendable5, "[", "/", "]");
    Assert.assertTrue(
        appendable5.toString(),
        "[0=true/1=false]".equals(appendable5.toString())
            || "[1=false/0=true]".equals(appendable5.toString()));
  }
Beispiel #16
0
    /** Run the job */
    @Override
    public void run() {

      int status = Integer.MIN_VALUE;

      try {

        // Execute the program and capture the output

        try {

          ProcessBuilder pb = new ProcessBuilder(getArguments());
          pb.redirectErrorStream(true);
          Process p = pb.start();

          if (bufferedThreadOutput) {
            BufferedReader es = new BufferedReader(new InputStreamReader(p.getErrorStream()));

            while (true) {
              String l = es.readLine();
              if (l == null) break;
              l += "\n";
              output.append(l);

              Iterator<JobOutputListener> I = outputListeners.iterator();
              while (I.hasNext()) {
                JobOutputListener x = I.next();
                if (!x.jobOutput(l)) I.remove();
              }

              if (newOutputListener != null) {
                String s = output.toString();
                if (s.length() > newOutputCharsSent) {
                  newOutputListener.jobOutput(s.substring(newOutputCharsSent));
                }
                outputListeners.add(newOutputListener);
                newOutputListener = null;
              }
            }

            es.close();
          } else {
            InputStreamReader es = new InputStreamReader(p.getInputStream());

            while (true) {
              int r = es.read();
              if (r < 0) break;
              output.append((char) r);

              Iterator<JobOutputListener> I = outputListeners.iterator();
              while (I.hasNext()) {
                JobOutputListener x = I.next();
                if (!x.jobOutput("" + (char) r)) I.remove();
              }

              if (newOutputListener != null) {
                String s = output.toString();
                if (s.length() > newOutputCharsSent) {
                  newOutputListener.jobOutput(s.substring(newOutputCharsSent));
                }
                outputListeners.add(newOutputListener);
                newOutputListener = null;
              }
            }

            es.close();
          }

          if (newOutputListener != null) {
            newOutputListener.jobOutput(output.toString());
            outputListeners.add(newOutputListener);
            newOutputListener = null;
          }

          status = p.waitFor();
        } catch (RuntimeException e) {
          throw e;
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
      } finally {

        // Extract the log file name from the output

        String s = output.toString();
        int p_start = s.indexOf("Tinkubator Graph Database Benchmark");
        int p_key = p_start < 0 ? -1 : s.indexOf("Log File", p_start);
        int p = p_key < 0 ? -1 : s.indexOf(':', p_key);
        if (p > 0) {
          p += 2;
          int p_end = s.indexOf('\n', p);
          logFile = new File(s.substring(p, p_end));
        }

        // Finish

        Job.this.status = status;
        Job.this.executionCount++;

        last = this;
        current = null; // This must be the very last statement
      }
    }
Beispiel #17
0
 @Override
 public final String toString() {
   return buf.toString();
 }
 public String makeString(String start, String separator, String end) {
   Appendable stringBuilder = new StringBuilder();
   this.appendString(stringBuilder, start, separator, end);
   return stringBuilder.toString();
 }
Beispiel #19
0
 /** Returns the description as a string. */
 public String toString() {
   return out.toString();
 }