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

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

Introduction

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

Prototype

public static boolean contains(final CharSequence seq, final CharSequence searchSeq) 

Source Link

Document

Checks if CharSequence contains a search CharSequence, handling null .

Usage

From source file:org.onlab.packet.ndp.RouterAdvertisementTest.java

/**
 * Tests toString.//from   w  w  w .j  a  va2  s  .c o m
 */
@Test
public void testToStringRA() throws Exception {
    RouterAdvertisement ra = deserializer.deserialize(bytePacket, 0, bytePacket.length);
    String str = ra.toString();

    assertTrue(StringUtils.contains(str, "currentHopLimit=" + (byte) 3));
    assertTrue(StringUtils.contains(str, "mFlag=" + (byte) 1));
    assertTrue(StringUtils.contains(str, "oFlag=" + (byte) 1));
    assertTrue(StringUtils.contains(str, "routerLifetime=" + (short) 0x258));
    assertTrue(StringUtils.contains(str, "reachableTime=" + 0x3e8));
    assertTrue(StringUtils.contains(str, "retransmitTimer=" + 0x1f4));

    // TODO: need to handle options
}

From source file:org.onlab.packet.TCPTest.java

/**
 * Tests toString.//  w w w. j ava2s  . c o m
 */
@Test
public void testToStringTcp() throws Exception {
    TCP tcp = deserializer.deserialize(bytePacketTCP4, 0, bytePacketTCP4.length);
    String str = tcp.toString();

    assertTrue(StringUtils.contains(str, "sourcePort=" + 0x50));
    assertTrue(StringUtils.contains(str, "destinationPort=" + 0x60));
    assertTrue(StringUtils.contains(str, "sequence=" + 0x10));
    assertTrue(StringUtils.contains(str, "acknowledge=" + 0x20));
    assertTrue(StringUtils.contains(str, "dataOffset=" + (byte) 0x5));
    assertTrue(StringUtils.contains(str, "flags=" + (short) 0x2));
    assertTrue(StringUtils.contains(str, "windowSize=" + (short) 0x1000));
    assertTrue(StringUtils.contains(str, "checksum=" + (short) 0x1bae));
    assertTrue(StringUtils.contains(str, "urgentPointer=" + (short) 0x1));
}

From source file:org.onlab.packet.UDPTest.java

/**
 * Tests toString.// w  w w  . ja v  a 2 s . c o m
 */
@Test
public void testToStringUdp() throws Exception {
    UDP udp = deserializer.deserialize(bytePacketUDP4, 0, bytePacketUDP4.length);
    String str = udp.toString();

    assertTrue(StringUtils.contains(str, "sourcePort=" + 0x50));
    assertTrue(StringUtils.contains(str, "destinationPort=" + 0x60));
    assertTrue(StringUtils.contains(str, "length=" + (short) 8));
    assertTrue(StringUtils.contains(str, "checksum=" + (short) 0x7bda));
}

From source file:org.onlab.packet.VXLANTest.java

/**
 * Tests toString./*  ww  w.j  a  v  a  2s  .  co  m*/
 */
@Test
public void testToStringVXLAN() throws Exception {
    VXLAN vxlan = deserializer.deserialize(BYTE_PACKET_VXLAN, 0, BYTE_PACKET_VXLAN.length);
    String str = vxlan.toString();

    assertTrue(StringUtils.contains(str, "flags=" + TEST_FLAGS));
    assertTrue(StringUtils.contains(str, "vni=" + TEST_VNI1));
}

From source file:org.openbase.bco.ontology.lib.utility.StringModifier.java

/**
 * Method extracts the service type name of the input state method name (e.g. getPowerState to powerStateService).
 *
 * @param stateMethodName is the state method name, which includes the needed service type name.
 * @return the service type name in camel case (first char lower case, e.g. powerStateService)
 * @throws NotAvailableException is thrown in case the input is null or no valid state (name).
 *///w w w .j  ava  2 s . c om
static String getServiceTypeNameFromStateMethodName(final String stateMethodName) throws NotAvailableException {
    Preconditions.checkNotNull(stateMethodName, "Couldn't get service type name, cause input string is null.");
    String serviceTypeName = stateMethodName;

    if (StringUtils.containsIgnoreCase(serviceTypeName, MethodRegEx.GET.getName())) {
        final int indexOfGet = StringUtils.indexOfIgnoreCase(serviceTypeName, MethodRegEx.GET.getName());
        final int lengthOfGet = MethodRegEx.GET.getName().length();

        serviceTypeName = serviceTypeName.substring(indexOfGet + lengthOfGet);
        serviceTypeName = firstCharToLowerCase(serviceTypeName);

        if (StringUtils.contains(serviceTypeName, MethodRegEx.STATE.getName())) {
            final int indexOfState = serviceTypeName.indexOf(MethodRegEx.STATE.getName());
            final int lengthOfState = MethodRegEx.STATE.getName().length();

            serviceTypeName = serviceTypeName.substring(0, indexOfState + lengthOfState);
            serviceTypeName += MethodRegEx.SERVICE.getName();
        }
    }

    if (OntConfig.SERVICE_NAME_MAP.keySet().contains(serviceTypeName)) {
        return serviceTypeName;
    } else {
        throw new NotAvailableException("Input string is no state (method) name! " + serviceTypeName);
    }
}

From source file:org.opendaylight.controller.cluster.datastore.DatastoreContextIntrospector.java

private static String convertToCamelCase(String inString) {
    String str = inString.trim();
    if (StringUtils.contains(str, '-') || StringUtils.contains(str, ' ')) {
        str = inString.replace('-', ' ');
        str = WordUtils.capitalizeFully(str);
        str = StringUtils.deleteWhitespace(str);
    }/*from   w ww . j  a  v a 2s  .c  om*/

    return StringUtils.uncapitalize(str);
}

From source file:org.opendaylight.controller.config.yang.logback.config.LogbackModuleFactory.java

private List<org.slf4j.Logger> removeUnusableLoggers(final List<Logger> loggerList, final Logger rootLogger) {
    Collections.sort(loggerList, new LoggerComparator());
    Map<String, org.slf4j.Logger> loggersToReturn = new HashMap<>();

    for (org.slf4j.Logger log : loggerList) {
        boolean shouldAdd = true;
        for (Entry<String, org.slf4j.Logger> entry : loggersToReturn.entrySet()) {
            if (StringUtils.contains(log.getName(), entry.getKey())) {
                if (((Logger) log).getLevel() != null
                        && ((Logger) log).getLevel().equals(((Logger) entry.getValue()).getLevel())
                        && !((Logger) log).iteratorForAppenders().hasNext()) {
                    shouldAdd = false;/*www  . jav  a 2 s. co m*/
                    break;
                }
                if (((Logger) log).getLevel() == null
                        && ((Logger) log).getEffectiveLevel()
                                .equals(((Logger) entry.getValue()).getEffectiveLevel())
                        && !((Logger) log).iteratorForAppenders().hasNext()) {
                    shouldAdd = false;
                    break;
                }
            }
            if (((Logger) log).getLevel() != null && ((Logger) log).getLevel().equals(rootLogger.getLevel())
                    && !((Logger) log).iteratorForAppenders().hasNext()) {
                shouldAdd = false;
                break;
            }
            if (((Logger) log).getLevel() == null
                    && ((Logger) log).getEffectiveLevel().equals(rootLogger.getEffectiveLevel())
                    && !((Logger) log).iteratorForAppenders().hasNext()) {
                shouldAdd = false;
                break;
            }
        }
        if (shouldAdd) {
            loggersToReturn.put(log.getName(), log);
        }
    }
    return Lists.newArrayList(loggersToReturn.values());
}

From source file:org.openmrs.layout.AddressSupportTest.java

/**
 * As described in TRUNK-3849, when AddressSupport was copied from package
 * org.openmrs.layout.web.address to org.openmrs.layout.address, and the AddressTemplate in the
 * database was updated, the web AddressSupport class stopped working with ClassCastExceptions.
 * A fix was made for backward-compatibility; this test ensures that the fix is working.
 *///from  w  w w.j a  v a 2  s .  c  o m
@Test
@Verifies(value = "should succeed even if db AddressTemplate class has changed", method = "getAddressTemplate()")
public void getAddressTemplate_shouldSucceedEvenIfDBAddressTemplateClassHasChanged() throws Exception {

    executeDataSet(PERSON_ADDRESS_VALIDATOR_DATASET_PACKAGE_PATH);

    //first make sure the test setup is correct even if the dataset changes -- the AddressTemplate class used by this AddressSupport class
    //(in the 'web' package differs from the updated classname in the DB
    String newAddressTemplateClass = "org.openmrs.layout.address.AddressTemplate";
    String xml = Context.getAdministrationService()
            .getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_ADDRESS_TEMPLATE);
    Assert.assertTrue(StringUtils.contains(xml, newAddressTemplateClass));
    Assert.assertEquals(newAddressTemplateClass, AddressTemplate.class.getName());

    AddressSupport addressSupport = AddressSupport.getInstance();
    List<AddressTemplate> addressTemplates = addressSupport.getAddressTemplate();
    Assert.assertNotNull(addressTemplates.get(0));
}

From source file:org.openmrs.layout.web.address.AddressSupportTest.java

/**
 * As described in TRUNK-3849, when AddressSupport was copied from package
 * org.openmrs.layout.web.address to org.openmrs.layout.address, and the AddressTemplate in the
 * database was updated, the web AddressSupport class stopped working with ClassCastExceptions.
 * A fix was made for backward-compatibility; this test ensures that the fix is working.
 *///  ww w  .  j a  va 2 s.c om
@Test
@Verifies(value = "should succeed even if db AddressTemplate class has changed", method = "getAddressTemplate()")
public void getAddressTemplate_shouldSucceedEvenIfDBAddressTemplateClassHasChanged() throws Exception {

    executeDataSet(PERSON_ADDRESS_VALIDATOR_DATASET_PACKAGE_PATH);

    //first make sure the test setup is correct even if the dataset changes -- the AddressTemplate class used by this AddressSupport class
    //(in the 'web' package differs from the updated classname in the DB
    String newAddressTemplateClass = "org.openmrs.layout.address.AddressTemplate";
    String xml = Context.getAdministrationService()
            .getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_ADDRESS_TEMPLATE);
    Assert.assertTrue(StringUtils.contains(xml, newAddressTemplateClass));
    Assert.assertNotEquals(newAddressTemplateClass, AddressTemplate.class.getName());

    AddressSupport addressSupport = AddressSupport.getInstance();
    List<AddressTemplate> addressTemplates = addressSupport.getAddressTemplate();
    Assert.assertNotNull(addressTemplates.get(0));
}

From source file:org.opens.tanaguru.rules.accessiweb22.Aw22Rule13021Test.java

@Override
protected void setProcess() {
    //----------------------------------------------------------------------
    //------------------------------3NMI-01---------------------------------
    //----------------------------------------------------------------------
    ProcessResult processResult = processPageTest("AW22.Test.13.2.1-3NMI-01");
    // check number of elements in the page
    assertEquals(0, processResult.getElementCounter());
    // check test result
    assertEquals(TestSolution.NEED_MORE_INFO, processResult.getValue());
    // check number of remarks and their value
    assertEquals(1, processResult.getRemarkSet().size());
    ProcessRemark processRemark = processResult.getRemarkSet().iterator().next();
    assertEquals(TestSolution.NEED_MORE_INFO, processRemark.getIssue());
    assertEquals(RemarkMessageStore.CHECK_JS_PROMPT_A_NEW_WINDOW_MSG, processRemark.getMessageCode());

    //----------------------------------------------------------------------
    //------------------------------3NMI-02---------------------------------
    //----------------------------------------------------------------------
    processResult = processPageTest("AW22.Test.13.2.1-3NMI-02");
    // check number of elements in the page
    assertEquals(0, processResult.getElementCounter());
    // check test result
    assertEquals(TestSolution.NEED_MORE_INFO, processResult.getValue());
    // check number of remarks and their value
    assertEquals(1, processResult.getRemarkSet().size());
    processRemark = processResult.getRemarkSet().iterator().next();
    assertEquals(TestSolution.NEED_MORE_INFO, processRemark.getIssue());
    assertEquals(RemarkMessageStore.CHECK_JS_PROMPT_A_NEW_WINDOW_MSG, processRemark.getMessageCode());

    //----------------------------------------------------------------------
    //------------------------------3NMI-03---------------------------------
    //----------------------------------------------------------------------
    processResult = processPageTest("AW22.Test.13.2.1-3NMI-03");
    // check number of elements in the page
    assertEquals(0, processResult.getElementCounter());
    // check test result
    assertEquals(TestSolution.NEED_MORE_INFO, processResult.getValue());
    // check number of remarks and their value
    assertEquals(1, processResult.getRemarkSet().size());
    processRemark = processResult.getRemarkSet().iterator().next();
    assertEquals(TestSolution.NEED_MORE_INFO, processRemark.getIssue());
    assertEquals(RemarkMessageStore.CHECK_JS_PROMPT_A_NEW_WINDOW_MSG, processRemark.getMessageCode());

    //----------------------------------------------------------------------
    //------------------------------3NMI-04---------------------------------
    //----------------------------------------------------------------------
    processResult = processPageTest("AW22.Test.13.2.1-3NMI-04");
    // check number of elements in the page
    assertEquals(1, processResult.getElementCounter());
    // check test result
    assertEquals(TestSolution.NEED_MORE_INFO, processResult.getValue());
    // check number of remarks and their value
    assertEquals(1, processResult.getRemarkSet().size());
    SourceCodeRemark sourceCodeRemark = ((SourceCodeRemark) ((LinkedHashSet) processResult.getRemarkSet())
            .iterator().next());/*  w  ww. jav a 2s .co  m*/
    assertEquals(TestSolution.NEED_MORE_INFO, sourceCodeRemark.getIssue());
    assertEquals(RemarkMessageStore.CHECK_USER_IS_WARNED_WHEN_NEW_WINDOW_OPEN_MSG,
            sourceCodeRemark.getMessageCode());
    assertEquals(HtmlElementStore.A_ELEMENT, sourceCodeRemark.getTarget());
    // check number of evidence elements and their value
    assertEquals(2, sourceCodeRemark.getElementList().size());

    //----------------------------------------------------------------------
    //------------------------------3NMI-05---------------------------------
    //----------------------------------------------------------------------
    processResult = processPageTest("AW22.Test.13.2.1-3NMI-05");
    // check number of elements in the page
    assertEquals(4, processResult.getElementCounter());
    // check test result
    assertEquals(TestSolution.NEED_MORE_INFO, processResult.getValue());
    // check number of remarks and their value
    assertEquals(4, processResult.getRemarkSet().size());
    Iterator<ProcessRemark> iter = processResult.getRemarkSet().iterator();
    sourceCodeRemark = (SourceCodeRemark) iter.next();
    assertEquals(TestSolution.NEED_MORE_INFO, sourceCodeRemark.getIssue());
    assertEquals(RemarkMessageStore.CHECK_USER_IS_WARNED_WHEN_NEW_WINDOW_OPEN_MSG,
            sourceCodeRemark.getMessageCode());
    assertEquals(HtmlElementStore.A_ELEMENT, sourceCodeRemark.getTarget());
    // check number of evidence elements and their value
    assertEquals(2, sourceCodeRemark.getElementList().size());
    Iterator<EvidenceElement> eIter = sourceCodeRemark.getElementList().iterator();
    EvidenceElement ee = eIter.next();
    assertTrue(StringUtils.contains(ee.getValue(), "My link 1"));
    assertEquals(HtmlElementStore.TEXT_ELEMENT2, ee.getEvidence().getCode());
    ee = eIter.next();
    assertEquals("attribute-absent", ee.getValue());
    assertEquals(AttributeStore.TITLE_ATTR, ee.getEvidence().getCode());

    sourceCodeRemark = (SourceCodeRemark) iter.next();
    assertEquals(TestSolution.NEED_MORE_INFO, sourceCodeRemark.getIssue());
    assertEquals(RemarkMessageStore.CHECK_USER_IS_WARNED_WHEN_NEW_WINDOW_OPEN_MSG,
            sourceCodeRemark.getMessageCode());
    assertEquals(HtmlElementStore.A_ELEMENT, sourceCodeRemark.getTarget());
    // check number of evidence elements and their value
    assertEquals(2, sourceCodeRemark.getElementList().size());
    eIter = sourceCodeRemark.getElementList().iterator();
    ee = eIter.next();
    assertTrue(StringUtils.contains(ee.getValue(), "My link 2"));
    assertEquals(HtmlElementStore.TEXT_ELEMENT2, ee.getEvidence().getCode());
    ee = eIter.next();
    assertEquals("attribute-absent", ee.getValue());
    assertEquals(AttributeStore.TITLE_ATTR, ee.getEvidence().getCode());

    sourceCodeRemark = (SourceCodeRemark) iter.next();
    assertEquals(TestSolution.NEED_MORE_INFO, sourceCodeRemark.getIssue());
    assertEquals(RemarkMessageStore.CHECK_USER_IS_WARNED_WHEN_NEW_WINDOW_OPEN_MSG,
            sourceCodeRemark.getMessageCode());
    assertEquals(HtmlElementStore.A_ELEMENT, sourceCodeRemark.getTarget());
    // check number of evidence elements and their value
    assertEquals(2, sourceCodeRemark.getElementList().size());
    eIter = sourceCodeRemark.getElementList().iterator();
    ee = eIter.next();
    System.out.println(ee.getValue());
    assertTrue(StringUtils.contains(ee.getValue(), "My link 3"));
    assertEquals(HtmlElementStore.TEXT_ELEMENT2, ee.getEvidence().getCode());
    ee = eIter.next();
    assertEquals("Link 3 title", ee.getValue());
    assertEquals(AttributeStore.TITLE_ATTR, ee.getEvidence().getCode());

    sourceCodeRemark = (SourceCodeRemark) iter.next();
    assertEquals(TestSolution.NEED_MORE_INFO, sourceCodeRemark.getIssue());
    assertEquals(RemarkMessageStore.CHECK_USER_IS_WARNED_WHEN_NEW_WINDOW_OPEN_MSG,
            sourceCodeRemark.getMessageCode());
    assertEquals(HtmlElementStore.A_ELEMENT, sourceCodeRemark.getTarget());
    // check number of evidence elements and their value
    assertEquals(2, sourceCodeRemark.getElementList().size());
    eIter = sourceCodeRemark.getElementList().iterator();
    ee = eIter.next();
    System.out.println(ee.getValue());
    assertTrue(StringUtils.contains(ee.getValue(), "My link 4"));
    assertEquals(HtmlElementStore.TEXT_ELEMENT2, ee.getEvidence().getCode());
    ee = eIter.next();
    assertEquals("attribute-absent", ee.getValue());
    assertEquals(AttributeStore.TITLE_ATTR, ee.getEvidence().getCode());

    //----------------------------------------------------------------------
    //------------------------------3NMI-06---------------------------------
    //----------------------------------------------------------------------
    processResult = processPageTest("AW22.Test.13.2.1-3NMI-06");
    // check number of elements in the page
    assertEquals(0, processResult.getElementCounter());
    // check test result
    assertEquals(TestSolution.NEED_MORE_INFO, processResult.getValue());
    // check number of remarks and their value
    assertEquals(1, processResult.getRemarkSet().size());
    processRemark = processResult.getRemarkSet().iterator().next();
    assertEquals(TestSolution.NEED_MORE_INFO, processRemark.getIssue());
    assertEquals(RemarkMessageStore.CHECK_JS_PROMPT_A_NEW_WINDOW_MSG, processRemark.getMessageCode());

}