Example usage for org.apache.commons.lang3 StringUtils repeat

List of usage examples for org.apache.commons.lang3 StringUtils repeat

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils repeat.

Prototype

public static String repeat(final char ch, final int repeat) 

Source Link

Document

<p>Returns padding using the specified delimiter repeated to a given length.</p> <pre> StringUtils.repeat('e', 0) = "" StringUtils.repeat('e', 3) = "eee" StringUtils.repeat('e', -2) = "" </pre> <p>Note: this method doesn't not support padding with <a href="http://www.unicode.org/glossary/#supplementary_character">Unicode Supplementary Characters</a> as they require a pair of char s to be represented.

Usage

From source file:org.apache.james.jmap.methods.integration.SetMailboxesMethodTest.java

@Test
public void setMailboxesShouldNotCreateWhenOverLimitName() {
    String overLimitName = StringUtils.repeat("a", MAILBOX_NAME_LENGTH_64K);
    String requestBody = "[" + "  [ \"setMailboxes\"," + "    {" + "      \"create\": {"
            + "        \"create-id01\" : {" + "          \"name\" : \"" + overLimitName + "\"" + "        }"
            + "      }" + "    }," + "    \"#0\"" + "  ]" + "]";

    given().header("Authorization", this.accessToken.serialize()).body(requestBody).when().post("/jmap").then()
            .statusCode(200).body(NAME, equalTo("mailboxesSet"))
            .body(ARGUMENTS + ".notCreated", aMapWithSize(1)).body(ARGUMENTS + ".notCreated",
                    hasEntry(equalTo("create-id01"), Matchers.allOf(
                            hasEntry(equalTo("type"), equalTo("invalidArguments")),
                            hasEntry(equalTo("description"), equalTo("The mailbox name length is too long")))));
}

From source file:org.apache.james.jmap.methods.integration.SetMailboxesMethodTest.java

@Test
public void setMailboxesShouldNotUpdateMailboxWhenOverLimitName() {
    String overLimitName = StringUtils.repeat("a", MAILBOX_NAME_LENGTH_64K);
    jmapServer.getProbe(MailboxProbeImpl.class).createMailbox(MailboxConstants.USER_NAMESPACE, username,
            "myBox");
    Mailbox mailbox = jmapServer.getProbe(MailboxProbeImpl.class).getMailbox(MailboxConstants.USER_NAMESPACE,
            username, "myBox");
    String mailboxId = mailbox.getMailboxId().serialize();
    String requestBody = "[" + "  [ \"setMailboxes\"," + "    {" + "      \"update\": {" + "        \""
            + mailboxId + "\" : {" + "          \"name\" : \"" + overLimitName + "\"" + "        }" + "      }"
            + "    }," + "    \"#0\"" + "  ]" + "]";
    given().header("Authorization", this.accessToken.serialize()).body(requestBody).when().post("/jmap").then()
            .statusCode(200).body(NAME, equalTo("mailboxesSet"))
            .body(ARGUMENTS + ".notUpdated", aMapWithSize(1)).body(ARGUMENTS + ".notUpdated",
                    hasEntry(equalTo(mailboxId), Matchers.allOf(
                            hasEntry(equalTo("type"), equalTo("invalidArguments")),
                            hasEntry(equalTo("description"), equalTo("The mailbox name length is too long")))));
}

From source file:org.apache.james.jmap.methods.integration.SetMailboxesMethodTest.java

@Test
public void setMailboxesShouldCreateWhenOverLimitName() throws Exception {
    String overLimitName = StringUtils.repeat("a", MAILBOX_NAME_LENGTH_64K);
    String requestBody = "[" + "  [ \"setMailboxes\"," + "    {" + "      \"create\": {"
            + "        \"create-id01\" : {" + "          \"name\" : \"" + overLimitName + "\"" + "        }"
            + "      }" + "    }," + "    \"#0\"" + "  ]" + "]";

    given().header("Authorization", this.accessToken.serialize()).body(requestBody).when().post("/jmap").then()
            .statusCode(200).body(NAME, equalTo("mailboxesSet"))
            .body(ARGUMENTS + ".created", hasKey("create-id01"));
}

From source file:org.apache.james.jmap.methods.integration.SetMailboxesMethodTest.java

@Test
public void setMailboxesShouldUpdateMailboxWhenOverLimitName() throws Exception {
    String overLimitName = StringUtils.repeat("a", MAILBOX_NAME_LENGTH_64K);
    jmapServer.getProbe(MailboxProbeImpl.class).createMailbox(MailboxConstants.USER_NAMESPACE, username,
            "myBox");
    Mailbox mailbox = jmapServer.getProbe(MailboxProbeImpl.class).getMailbox(MailboxConstants.USER_NAMESPACE,
            username, "myBox");
    String mailboxId = mailbox.getMailboxId().serialize();
    String requestBody = "[" + "  [ \"setMailboxes\"," + "    {" + "      \"update\": {" + "        \""
            + mailboxId + "\" : {" + "          \"name\" : \"" + overLimitName + "\"" + "        }" + "      }"
            + "    }," + "    \"#0\"" + "  ]" + "]";
    given().header("Authorization", this.accessToken.serialize()).body(requestBody).when().post("/jmap").then()
            .statusCode(200).body(NAME, equalTo("mailboxesSet"))
            .body(ARGUMENTS + ".updated", contains(mailboxId));

    assertThat(jmapServer.getProbe(MailboxProbeImpl.class).listSubscriptions(username))
            .containsOnly(overLimitName);
}

From source file:org.apache.james.jmap.model.KeywordTest.java

@Test
public void keywordShouldThrowWhenFlagNameLengthMoreThanMaxLength() {
    expectedException.expect(IllegalArgumentException.class);
    Keyword.of(StringUtils.repeat("a", FLAG_NAME_MAX_LENTH + 1));
}

From source file:org.apache.james.jmap.model.KeywordTest.java

@Test
public void keywordShouldCreateNewOneWhenFlagNameLengthEqualsMaxLength() {
    String maxLengthFlagName = StringUtils.repeat("a", FLAG_NAME_MAX_LENTH);
    Keyword keyword = Keyword.of(maxLengthFlagName);

    assertThat(keyword.getFlagName()).isEqualTo(maxLengthFlagName);
}

From source file:org.apache.james.mailbox.cassandra.mail.CassandraMailboxMapperTest.java

private MailboxPath tooLongMailboxPath(MailboxPath fromMailboxPath) {
    return new MailboxPath(fromMailboxPath, StringUtils.repeat("b", 65537));
}

From source file:org.apache.kylin.measure.extendedcolumn.ExtendedColumnSerializerTest.java

@Test
public void testNormal() {
    String text = StringUtils.repeat("h", 20);

    ExtendedColumnSerializer serializer = new ExtendedColumnSerializer(DataType.getType("extendedcolumn(20)"));
    MeasureIngester<ByteArray> ingester = measureType.newIngester();
    ByteArray array = ingester.valueOf(new String[] { null, text }, null, null);

    ByteBuffer buffer = ByteBuffer.allocate(serializer.maxLength());
    serializer.serialize(array, buffer);
    buffer.flip();//from w  w w  .j  ava  2s  .  c o  m
    ByteArray des = serializer.deserialize(buffer);
    Assert.assertTrue(new ByteArray(text.getBytes()).equals(des));
}

From source file:org.apache.kylin.measure.extendedcolumn.ExtendedColumnSerializerTest.java

@Test
public void testOverflow() {
    String text = StringUtils.repeat("h", 21);
    ExtendedColumnSerializer serializer = new ExtendedColumnSerializer(DataType.getType("extendedcolumn(20)"));
    MeasureIngester<ByteArray> ingester = measureType.newIngester();
    ByteArray array = ingester.valueOf(new String[] { null, text }, null, null);

    ByteBuffer buffer = ByteBuffer.allocate(serializer.maxLength());
    serializer.serialize(array, buffer);
    buffer.flip();//from   w w w . j av  a  2  s .c  o m
    ByteArray des = serializer.deserialize(buffer);
    Assert.assertTrue(new ByteArray(StringUtils.repeat("h", 20).getBytes()).equals(des));
}

From source file:org.apache.metron.performance.load.monitor.writers.ConsoleWriter.java

@Override
public void accept(Writable writable) {
    List<String> parts = new ArrayList<>();
    Date date = writable.getDate();
    for (Results r : writable.getResults()) {
        Long eps = r.getEps();/*from  ww  w .  j  a  v a2  s . c o  m*/
        if (eps != null) {
            String part = String.format(r.getFormat(), eps);
            if (r.getHistory().isPresent()) {
                part += " (" + getSummary(r.getHistory().get()) + ")";
            }
            parts.add(part);
        }
    }
    if (date != null) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        String header = dateFormat.format(date) + " - ";
        String emptyHeader = StringUtils.repeat(" ", header.length());
        for (int i = 0; i < parts.size(); ++i) {
            String part = parts.get(i);
            if (i == 0) {
                System.out.println(header + (part == null ? "" : part));
            } else {
                System.out.println(emptyHeader + (part == null ? "" : part));
            }
        }
    }
}