<commit_before>package org.torquebox.messaging.deployers;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.net.URL;
import java.util.Set;
import java.io.File;

import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jruby.Ruby;
import org.junit.Before;
import org.junit.Test;
import org.torquebox.interp.deployers.DeployerRuby;
import org.torquebox.messaging.metadata.MessageProcessorMetaData;
import org.torquebox.test.mc.vdf.AbstractDeployerTestCase;
import org.torquebox.test.ruby.TestRubyFactory;

public class MessagingYamlParsingDeployerTest extends AbstractDeployerTestCase {

    private MessagingYamlParsingDeployer deployer;
    private Ruby ruby;

    @Before
    public void setUpDeployer() throws Throwable {
        this.deployer = new MessagingYamlParsingDeployer();
        addDeployer(this.deployer);
        this.ruby = TestRubyFactory.createRuby();
        this.ruby.evalScriptlet("require 'vfs'");
    }

    @Test
    public void testEmptyMessagingConfig() throws Exception {
        File config = new File( System.getProperty( "user.dir" ), "src/test/resources/empty-messaging.yml" );
        String deploymentName = addDeployment(config.toURI().toURL(), "messaging.yml");

        DeploymentUnit unit = getDeploymentUnit(deploymentName);
        unit.addAttachment(DeployerRuby.class, new DeployerRuby(this.ruby));

        processDeployments(true);

        Set<? extends MessageProcessorMetaData> allMetaData = unit.getAllMetaData(MessageProcessorMetaData.class);

        assertTrue(allMetaData.isEmpty());
        undeploy(deploymentName);
    }

    @Test(expected = DeploymentException.class)
    public void testJunkMessagingConfig() throws Exception {
        File config = new File( System.getProperty( "user.dir" ), "src/test/resources/junk-messaging.yml" );
        String deploymentName = addDeployment(config.toURI().toURL(), "messaging.yml");

        DeploymentUnit unit = getDeploymentUnit(deploymentName);
        unit.addAttachment(DeployerRuby.class, new DeployerRuby(this.ruby));

        processDeployments(true);
    }

    @Test
    public void testSingleMessagingConfig() throws Exception {
        File config = new File( System.getProperty( "user.dir" ), "src/test/resources/single-messaging.yml" );
        String deploymentName = addDeployment(config.toURI().toURL(), "messaging.yml");

        DeploymentUnit unit = getDeploymentUnit(deploymentName);
        unit.addAttachment(DeployerRuby.class, new DeployerRuby(this.ruby));

        processDeployments(true);

        Set<? extends MessageProcessorMetaData> allMetaData = unit.getAllMetaData(MessageProcessorMetaData.class);

        assertEquals(1, allMetaData.size());

        MessageProcessorMetaData metaData = allMetaData.iterator().next();

        assertNotNull(metaData);

        assertEquals("MyClass", metaData.getRubyClassName());
        assertEquals("/topics/foo", metaData.getDestinationName());
        assertEquals("myfilter", metaData.getMessageSelector());
        byte[] rubyConfig = metaData.getRubyConfig();
        assertNotNull(rubyConfig);

        undeploy(deploymentName);
    }

}<commit_msg>Look inside the config map.<commit_after>package org.torquebox.messaging.deployers;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.net.URL;
import java.util.Set;
import java.util.Map;
import java.io.File;

import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jruby.Ruby;
import org.jruby.RubyModule;
import org.jruby.RubyString;
import org.jruby.javasupport.JavaEmbedUtils;
import org.junit.Before;
import org.junit.Test;
import org.torquebox.interp.deployers.DeployerRuby;
import org.torquebox.messaging.metadata.MessageProcessorMetaData;
import org.torquebox.test.mc.vdf.AbstractDeployerTestCase;
import org.torquebox.test.ruby.TestRubyFactory;

public class MessagingYamlParsingDeployerTest extends AbstractDeployerTestCase {

    private MessagingYamlParsingDeployer deployer;
    private Ruby ruby;

    @Before
    public void setUpDeployer() throws Throwable {
        this.deployer = new MessagingYamlParsingDeployer();
        addDeployer(this.deployer);
        this.ruby = TestRubyFactory.createRuby();
        this.ruby.evalScriptlet("require 'vfs'");
    }

    @Test
    public void testEmptyMessagingConfig() throws Exception {
        File config = new File( System.getProperty( "user.dir" ), "src/test/resources/empty-messaging.yml" );
        String deploymentName = addDeployment(config.toURI().toURL(), "messaging.yml");

        DeploymentUnit unit = getDeploymentUnit(deploymentName);
        unit.addAttachment(DeployerRuby.class, new DeployerRuby(this.ruby));

        processDeployments(true);

        Set<? extends MessageProcessorMetaData> allMetaData = unit.getAllMetaData(MessageProcessorMetaData.class);

        assertTrue(allMetaData.isEmpty());
        undeploy(deploymentName);
    }

    @Test(expected = DeploymentException.class)
    public void testJunkMessagingConfig() throws Exception {
        File config = new File( System.getProperty( "user.dir" ), "src/test/resources/junk-messaging.yml" );
        String deploymentName = addDeployment(config.toURI().toURL(), "messaging.yml");

        DeploymentUnit unit = getDeploymentUnit(deploymentName);
        unit.addAttachment(DeployerRuby.class, new DeployerRuby(this.ruby));

        processDeployments(true);
    }

    @Test
    public void testSingleMessagingConfig() throws Exception {
        File config = new File( System.getProperty( "user.dir" ), "src/test/resources/single-messaging.yml" );
        String deploymentName = addDeployment(config.toURI().toURL(), "messaging.yml");

        DeploymentUnit unit = getDeploymentUnit(deploymentName);
        unit.addAttachment(DeployerRuby.class, new DeployerRuby(this.ruby));

        processDeployments(true);

        Set<? extends MessageProcessorMetaData> allMetaData = unit.getAllMetaData(MessageProcessorMetaData.class);

        assertEquals(1, allMetaData.size());

        MessageProcessorMetaData metaData = allMetaData.iterator().next();

        assertNotNull(metaData);

        assertEquals("MyClass", metaData.getRubyClassName());
        assertEquals("/topics/foo", metaData.getDestinationName());
        assertEquals("myfilter", metaData.getMessageSelector());
        assertEquals("toast", loadConfig(metaData.getRubyConfig()).get("a"));

        undeploy(deploymentName);
    }

    private Map loadConfig(byte[] bytes) {
        String configStr = RubyString.bytesToString( bytes );
        RubyModule marshal = ruby.getClassFromPath("Marshal");
        return (Map) JavaEmbedUtils.invokeMethod(ruby, marshal, "load", new Object[] { configStr }, Map.class);
    }
        
}
{'fraction_non_alphanumeric': 0.10838212194773668, 'fraction_numerical': 0.000285591889190347, 'mean_word_length': 4.138664710198093, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7065687', 'n_tokens_mistral': 2102, 'n_tokens_neox': 1974, 'n_words': 354}