RESTServiceUtil { public static void decodeCorrelationIdentifiers(Set<CorrelationIdentifier> correlations, 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 scope = parts[0].trim(); String value = parts[1].trim(); log.tracef("Extracted correlation identifier scope [%s] value [%s]", scope, value); CorrelationIdentifier cid = new CorrelationIdentifier(); cid.setScope(Scope.valueOf(scope)); cid.setValue(value); correlations.add(cid); } } } }  static void decodeProperties(Set<PropertyCriteria> properties, String encoded); static void decodeCorrelationIdentifiers(Set<CorrelationIdentifier> correlations, String encoded);  }
@Test public void testDecodeCorrelationIdsSingle() { String encoded = "Interaction|world"; Set<CorrelationIdentifier> correlations = new HashSet<CorrelationIdentifier>(); RESTServiceUtil.decodeCorrelationIdentifiers(correlations, encoded); assertTrue("Correlation identifiers should have 1 entry", correlations.size() == 1); CorrelationIdentifier cid = new CorrelationIdentifier(); cid.setScope(Scope.Interaction); cid.setValue("world"); assertTrue(correlations.contains(cid)); }
@Test public void testDecodeCorrelationIdsSingleWithSpaces() { String encoded = " Interaction | world "; Set<CorrelationIdentifier> correlations = new HashSet<CorrelationIdentifier>(); RESTServiceUtil.decodeCorrelationIdentifiers(correlations, encoded); assertTrue("Correlation identifiers should have 1 entry", correlations.size() == 1); CorrelationIdentifier cid = new CorrelationIdentifier(); cid.setScope(Scope.Interaction); cid.setValue("world"); assertTrue(correlations.contains(cid)); }
@Test public void testDecodeCorrelationIdsMultiple() { String encoded = "Interaction|world,ControlFlow|hello"; Set<CorrelationIdentifier> correlations = new HashSet<CorrelationIdentifier>(); RESTServiceUtil.decodeCorrelationIdentifiers(correlations, encoded); assertTrue("Correlation identifiers should have 2 entry", correlations.size() == 2); CorrelationIdentifier cid1 = new CorrelationIdentifier(); cid1.setScope(Scope.Interaction); cid1.setValue("world"); CorrelationIdentifier cid2 = new CorrelationIdentifier(); cid2.setScope(Scope.ControlFlow); cid2.setValue("hello"); assertTrue(correlations.contains(cid1)); assertTrue(correlations.contains(cid2)); }