Exemple #1
1
 @Override
 public String getHeaderField(final String field) {
   final List<String> values = headers.get(field);
   final StringBuilder sb = new StringBuilder();
   for (final String v : values) sb.append(v).append(';');
   return sb.substring(0, sb.length() - 1);
 }
  @Test
  public void testGetLookupParameters() throws Exception {
    protocolFundingSourceService = new ProtocolFundingSourceServiceImpl();
    StringBuilder builder = new StringBuilder();

    Entry<String, String> entry =
        protocolFundingSourceService.getLookupParameters(FundingSourceType.SPONSOR);
    Assert.assertNotNull(entry);
    builder.append("sponsorCode:" + PROTOCOL_FUNDING_SOURCE_NUMBER + Constants.COMMA);
    builder.append("sponsorName:" + PROTOCOL_FUNDING_SOURCE_NAME);
    Assert.assertThat(entry.getValue(), JUnitMatchers.containsString(builder.toString()));
    builder.delete(0, builder.length());

    entry = protocolFundingSourceService.getLookupParameters(FundingSourceType.UNIT);
    Assert.assertNotNull(entry);
    builder.append("unitNumber:" + PROTOCOL_FUNDING_SOURCE_NUMBER + Constants.COMMA);
    builder.append("unitName:" + PROTOCOL_FUNDING_SOURCE_NAME);
    Assert.assertThat(entry.getValue(), JUnitMatchers.containsString(builder.toString()));
    builder.delete(0, builder.length());

    entry =
        protocolFundingSourceService.getLookupParameters(FundingSourceType.PROPOSAL_DEVELOPMENT);
    Assert.assertNotNull(entry);
    builder.append("proposalNumber:" + PROTOCOL_FUNDING_SOURCE_NUMBER + Constants.COMMA);
    builder.append("sponsor.sponsorName:" + PROTOCOL_FUNDING_SOURCE_NAME + Constants.COMMA);
    builder.append("title:" + PROTOCOL_FUNDING_SOURCE_TITLE);
    Assert.assertThat(entry.getValue(), JUnitMatchers.containsString(builder.toString()));
    builder.delete(0, builder.length());

    entry =
        protocolFundingSourceService.getLookupParameters(FundingSourceType.INSTITUTIONAL_PROPOSAL);
    Assert.assertNotNull(entry);
    builder.append("proposalId:" + PROTOCOL_FUNDING_SOURCE + Constants.COMMA);
    builder.append("proposalNumber:" + PROTOCOL_FUNDING_SOURCE_NUMBER + Constants.COMMA);
    builder.append("sponsor.sponsorName:" + PROTOCOL_FUNDING_SOURCE_NAME + Constants.COMMA);
    builder.append("title:" + PROTOCOL_FUNDING_SOURCE_TITLE);
    Assert.assertThat(entry.getValue(), JUnitMatchers.containsString(builder.toString()));
    builder.delete(0, builder.length());

    entry = protocolFundingSourceService.getLookupParameters(FundingSourceType.AWARD);
    Assert.assertNotNull(entry);
    builder.append("awardId:" + PROTOCOL_FUNDING_SOURCE + Constants.COMMA);
    builder.append("awardNumber:" + PROTOCOL_FUNDING_SOURCE_NUMBER + Constants.COMMA);
    builder.append("sponsor.sponsorName:" + PROTOCOL_FUNDING_SOURCE_NAME + Constants.COMMA);
    builder.append("title:" + PROTOCOL_FUNDING_SOURCE_TITLE);
    Assert.assertThat(entry.getValue(), JUnitMatchers.containsString(builder.toString()));

    try {
      entry = protocolFundingSourceService.getLookupParameters(FundingSourceType.OTHER);
      fail("IllegalArgumentException was not thrown for invalid test case using OTHER");
    } catch (IllegalArgumentException e) {
      // yup
    }
  }
Exemple #3
0
  public String bestmod(String s, int k) {
    String ret = s;
    StringBuilder sub = new StringBuilder(s);

    for (int i = 1, size = s.length(); i < size; ++i) {
      sub =
          new StringBuilder(
              sub.toString().substring(size - 1) + sub.toString().substring(0, size - 1));

      StringBuilder sub2 = new StringBuilder(sub);
      int count = k;

      for (int j = 1; j <= sub2.length() && count > 0; ++j) {
        if (sub2.charAt(j - 1) != 'a') {
          sub2.setCharAt(j - 1, 'a');
          --count;
        }
      }

      if (sub2.toString().compareTo(ret) < 0) {
        ret = sub2.toString();
      }
    }

    return ret;
  }
 @Test
 public void testClearStringBuilder() {
   StringBuilder s = new StringBuilder();
   s.append("Testing clear");
   MiscUtils.clearStringBuilder(s);
   assertEquals(0, s.length());
   assertEquals("", s.toString());
 }
 /** Test of getSlaves method, of class HadoopCluster. */
 @Test
 public void testGetSlaves() {
   out.println("getSlaves");
   List<ClusterInstance> result = cluster.getSlaves();
   out.println("found " + result.size() + " slaves for group " + TEST_GROUP);
   assertNotNull(result);
   StringBuilder sb = new StringBuilder("\t");
   for (ClusterInstance slave : result) {
     assertEquals(cluster.getGroupName(), slave.getSecurityGroups().get(0));
     Instance slaveInstance = slave.getInstance();
     if (sb.length() > 1) sb.delete(1, sb.length());
     sb.append(slaveInstance.getInstanceId());
     sb.append(" ");
     sb.append(slaveInstance.getInstanceType());
     sb.append(" ");
     sb.append(slaveInstance.getLaunchTime().toString());
     sb.append(" ");
     sb.append(slaveInstance.getImageId());
     out.println(sb.toString());
   }
 }
 protected static String pwdOutputFor(Object... entities) {
   StringBuilder builder = new StringBuilder();
   for (Object entity : entities) {
     builder.append((builder.length() == 0 ? "" : "-->"));
     if (entity instanceof Node) {
       builder.append("(").append(((Node) entity).getId()).append(")");
     } else {
       builder.append("<").append(((Relationship) entity).getId()).append(">");
     }
   }
   return Pattern.quote(builder.toString());
 }
  @Test
  public void testParseUTF_SB1() throws Exception {
    VanillaBytes bytes = Bytes.allocateElasticDirect();
    byte[] bytes2 = new byte[128];
    Arrays.fill(bytes2, (byte) '?');
    bytes.write(bytes2);

    StringBuilder sb = new StringBuilder();

    BytesInternal.parseUtf8(bytes, sb, 128);
    assertEquals(128, sb.length());
    assertEquals(new String(bytes2, 0), sb.toString());
  }
Exemple #8
0
  /** Tests the internal parser (Option {@link MainOptions#INTPARSE}). */
  @Test
  public void intParse() {
    set(MainOptions.CHOP, false);

    final StringBuilder sb = new StringBuilder();

    final String[] docs = {
      "<x/>",
      " <x/> ",
      "<x></x>",
      "<x>A</x>",
      "<x><x>",
      "<x/><x/>",
      "<x></x><x/>",
      "<x>",
      "</x>",
      "<x></x></x>",
      "x<x>",
      "<x>x",
      "<x><![CDATA[ ]]></x>",
    };
    for (final String doc : docs) {
      // parse document with default parser (expected to yield correct result)
      set(MainOptions.INTPARSE, false);
      boolean def = true;
      try {
        new CreateDB(NAME, doc).execute(context);
      } catch (final BaseXException ex) {
        def = false;
      }

      // parse document with internal parser
      set(MainOptions.INTPARSE, true);
      boolean cust = true;
      try {
        new CreateDB(NAME, doc).execute(context);
      } catch (final BaseXException ex) {
        cust = false;
      }

      // compare results
      if (def != cust) {
        sb.append('\n').append(def ? "- not accepted: " : "- not rejected: ").append(doc);
      }
    }

    // list all errors
    if (sb.length() != 0) fail(sb.toString());

    set(MainOptions.MAINMEM, false);
  }
 private String getAllProblems() {
   StringBuilder builder = new StringBuilder();
   for (Problem problem : problems) {
     if (builder.length() > 0) {
       builder.append(", ");
     }
     builder.append(problem.getLine());
     builder.append('.');
     builder.append(problem.getCharacter());
     builder.append(':');
     builder.append(problem.getMessage());
   }
   return builder.toString();
 }
  /*
     This is a copy of buildDeterministicValue() from core:com.yahoo.ycsb.workloads.CoreWorkload.java.
     That method is neither public nor static so we need a copy.
  */
  private String buildDeterministicValue(String key, String fieldkey) {
    int size = FIELD_LENGTH;
    StringBuilder sb = new StringBuilder(size);
    sb.append(key);
    sb.append(':');
    sb.append(fieldkey);
    while (sb.length() < size) {
      sb.append(':');
      sb.append(sb.toString().hashCode());
    }
    sb.setLength(size);

    return sb.toString();
  }
  private void runPlan(String expectedSQL) throws Exception {
    DumpGroupLoadablePlan loadablePlan = new DumpGroupLoadablePlan();
    DirectObjectPlan plan = loadablePlan.plan();

    Schema schema = new Schema(ais());
    StoreAdapter adapter = newStoreAdapter(schema);
    QueryContext queryContext =
        new SimpleQueryContext(adapter) {
          @Override
          public String getCurrentSchema() {
            return SCHEMA_NAME;
          }
        };
    QueryBindings queryBindings = queryContext.createBindings();
    queryBindings.setValue(0, new Value(MString.varcharFor(SCHEMA_NAME), SCHEMA_NAME));
    queryBindings.setValue(1, new Value(MString.varcharFor(groupName), groupName));
    if (multiple) queryBindings.setValue(2, new Value(MNumeric.INT.instance(false), 10));
    if (commitFreq > 0)
      queryBindings.setValue(3, new Value(MNumeric.INT.instance(false), commitFreq));

    DirectObjectCursor cursor = plan.cursor(queryContext, queryBindings);

    StringBuilder actual = new StringBuilder();

    cursor.open();
    while (true) {
      List<?> columns = cursor.next();
      if (columns == null) {
        break;
      } else if (!columns.isEmpty()) {
        assertTrue(columns.size() == 1);
        if (actual.length() > 0) actual.append("\n");
        actual.append(columns.get(0));
      }
    }
    cursor.close();

    assertEquals(expectedSQL, actual.toString());
  }