RESTServiceUtil { public static void decodeProperties(Set<PropertyCriteria> properties, String encoded) { if (encoded != null && !encoded.trim().isEmpty()) { StringTokenizer st = new StringTokenizer(encoded, ","); while (st.hasMoreTokens()) { String token = st.nextToken(); String[] parts = token.split("[|]"); if (parts.length >= 2) { String name = parts[0].trim(); String value = parts[1].trim(); Operator op = Operator.HAS; if (parts.length > 2) { op = Operator.valueOf(parts[2].trim()); } log.tracef("Extracted property name [%s] value [%s] operator [%s]", name, value, op); properties.add(new PropertyCriteria(name, value, op)); } } } }  static void decodeProperties(Set<PropertyCriteria> properties, String encoded); static void decodeCorrelationIdentifiers(Set<CorrelationIdentifier> correlations, String encoded);  }
@Test public void testDecodePropertiesSingle() { String encoded = "hello|world"; Set<PropertyCriteria> properties = new HashSet<PropertyCriteria>(); RESTServiceUtil.decodeProperties(properties, encoded); assertTrue("Properties should have 1 entry", properties.size() == 1); PropertyCriteria pc = properties.iterator().next(); assertEquals("hello", pc.getName()); assertEquals("world", pc.getValue()); assertEquals(Operator.HAS, pc.getOperator()); }
@Test public void testDecodePropertiesSingleHasNot() { String encoded = "hello|world|HASNOT"; Set<PropertyCriteria> properties = new HashSet<PropertyCriteria>(); RESTServiceUtil.decodeProperties(properties, encoded); assertTrue("Properties should have 1 entry", properties.size() == 1); PropertyCriteria pc = properties.iterator().next(); assertEquals("hello", pc.getName()); assertEquals("world", pc.getValue()); assertEquals(Operator.HASNOT, pc.getOperator()); }
@Test public void testDecodePropertiesSingleWithSpaces() { String encoded = "hello | world "; Set<PropertyCriteria> properties = new HashSet<PropertyCriteria>(); RESTServiceUtil.decodeProperties(properties, encoded); PropertyCriteria pc = properties.iterator().next(); assertEquals("hello", pc.getName()); assertEquals("world", pc.getValue()); assertEquals(Operator.HAS, pc.getOperator()); }
@Test public void testDecodePropertiesSingleWithSpacesHasNot() { String encoded = "hello | world | HASNOT "; Set<PropertyCriteria> properties = new HashSet<PropertyCriteria>(); RESTServiceUtil.decodeProperties(properties, encoded); PropertyCriteria pc = properties.iterator().next(); assertEquals("hello", pc.getName()); assertEquals("world", pc.getValue()); assertEquals(Operator.HASNOT, pc.getOperator()); }
@Test public void testDecodePropertiesMultiple() { String encoded = "hello|world,fred|bloggs"; Set<PropertyCriteria> properties = new HashSet<PropertyCriteria>(); RESTServiceUtil.decodeProperties(properties, encoded); assertTrue("Properties should have 2 entries", properties.size() == 2); Iterator<PropertyCriteria> iter = properties.iterator(); PropertyCriteria pc1 = iter.next(); PropertyCriteria pc2 = iter.next(); if (pc1.getName().equals("hello")) { assertEquals("hello", pc1.getName()); assertEquals("world", pc1.getValue()); assertEquals(Operator.HAS, pc1.getOperator()); assertEquals("fred", pc2.getName()); assertEquals("bloggs", pc2.getValue()); assertEquals(Operator.HAS, pc1.getOperator()); } else { assertEquals("hello", pc2.getName()); assertEquals("world", pc2.getValue()); assertEquals(Operator.HAS, pc2.getOperator()); assertEquals("fred", pc1.getName()); assertEquals("bloggs", pc1.getValue()); assertEquals(Operator.HAS, pc2.getOperator()); } }