<commit_before>package com.adaptris.core.jms;

import com.adaptris.core.BaseCase;
import com.adaptris.core.MetadataCollection;
import com.adaptris.core.MetadataElement;
import com.adaptris.core.jms.activemq.EmbeddedActiveMq;
import com.adaptris.core.metadata.NoOpMetadataFilter;
import com.adaptris.core.metadata.RegexMetadataFilter;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

/**
 * @author mwarman
 */
public abstract class MetadataConverterCase extends BaseCase {

  static final String HEADER = "header";

  MetadataConverterCase(String name) {
    super(name);
  }

  public void testMetadataFilter() throws Exception {
    MetadataConverter mc = createConverter();
    assertTrue(mc.getMetadataFilter() instanceof NoOpMetadataFilter);
    mc.setMetadataFilter(new RegexMetadataFilter());
    assertTrue(mc.getMetadataFilter() instanceof RegexMetadataFilter);
  }

  public void testSetProperty() throws Exception {
    EmbeddedActiveMq broker = new EmbeddedActiveMq();
    MetadataConverter mc = createConverter();
    try {
      broker.start();
      Session session = broker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
      MetadataCollection metadataCollection = new MetadataCollection();
      metadataCollection.add(new MetadataElement(HEADER, getStringValue()));
      Message jmsMsg = session.createMessage();
      mc.moveMetadata(metadataCollection, jmsMsg);
      assertEquals(getStringValue(), jmsMsg.getStringProperty(HEADER));
      assertValue(jmsMsg);
    } finally {
      broker.destroy();
    }
  }

  public void testSetPropertyWithReserved() throws Exception {
    EmbeddedActiveMq broker = new EmbeddedActiveMq();
    MetadataConverter mc = createConverter();
    try {
      broker.start();
      Session session = broker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
      MetadataCollection metadataCollection = new MetadataCollection();
      metadataCollection.add(new MetadataElement(HEADER, getStringValue()));
      metadataCollection.add(new MetadataElement("JMSCorrelationID", "1234"));
      Message jmsMsg = session.createMessage();
      mc.moveMetadata(metadataCollection, jmsMsg);
      assertEquals(getStringValue(), jmsMsg.getStringProperty(HEADER));
      assertValue(jmsMsg);
    } finally {
      broker.destroy();
    }
  }

  abstract MetadataConverter createConverter();

  abstract String getStringValue();

  abstract void assertValue(Message jmsMsg) throws JMSException;

}
<commit_msg>MetadataConverterCase reserved tests asserts<commit_after>package com.adaptris.core.jms;

import com.adaptris.core.BaseCase;
import com.adaptris.core.MetadataCollection;
import com.adaptris.core.MetadataElement;
import com.adaptris.core.jms.activemq.EmbeddedActiveMq;
import com.adaptris.core.metadata.NoOpMetadataFilter;
import com.adaptris.core.metadata.RegexMetadataFilter;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

/**
 * @author mwarman
 */
public abstract class MetadataConverterCase extends BaseCase {

  static final String HEADER = "header";

  MetadataConverterCase(String name) {
    super(name);
  }

  public void testMetadataFilter() throws Exception {
    MetadataConverter mc = createConverter();
    assertTrue(mc.getMetadataFilter() instanceof NoOpMetadataFilter);
    mc.setMetadataFilter(new RegexMetadataFilter());
    assertTrue(mc.getMetadataFilter() instanceof RegexMetadataFilter);
  }

  public void testSetProperty() throws Exception {
    EmbeddedActiveMq broker = new EmbeddedActiveMq();
    MetadataConverter mc = createConverter();
    try {
      broker.start();
      Session session = broker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
      MetadataCollection metadataCollection = new MetadataCollection();
      metadataCollection.add(new MetadataElement(HEADER, getStringValue()));
      Message jmsMsg = session.createMessage();
      mc.moveMetadata(metadataCollection, jmsMsg);
      assertEquals(getStringValue(), jmsMsg.getStringProperty(HEADER));
      assertValue(jmsMsg);
    } finally {
      broker.destroy();
    }
  }

  public void testSetPropertyWithReserved() throws Exception {
    EmbeddedActiveMq broker = new EmbeddedActiveMq();
    MetadataConverter mc = createConverter();
    try {
      broker.start();
      Session session = broker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
      MetadataCollection metadataCollection = new MetadataCollection();
      metadataCollection.add(new MetadataElement(HEADER, getStringValue()));
      metadataCollection.add(new MetadataElement("JMSCorrelationID", "1234"));
      Message jmsMsg = session.createMessage();
      mc.moveMetadata(metadataCollection, jmsMsg);
      assertEquals(getStringValue(), jmsMsg.getStringProperty(HEADER));
      assertNull(jmsMsg.getStringProperty("JMSCorrelationID"));
      assertValue(jmsMsg);
    } finally {
      broker.destroy();
    }
  }

  abstract MetadataConverter createConverter();

  abstract String getStringValue();

  abstract void assertValue(Message jmsMsg) throws JMSException;

}

{'fraction_non_alphanumeric': 0.09502262443438914, 'fraction_numerical': 0.0015082956259426848, 'mean_word_length': 4.135527589545014, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7151770', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1384, 'n_words': 278}