<commit_before>/**
 * Licensed to the Rhiot under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.rhiot.cloudplatform.camel.vertxproton;

import com.google.common.truth.Truth;
import org.apache.activemq.broker.BrokerService;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;

import static java.util.UUID.randomUUID;
import static org.apache.camel.component.amqp.AMQPComponent.amqp10Component;
import static org.apache.camel.test.AvailablePortFinder.getNextAvailable;

public class ProtonjComponentTest extends CamelTestSupport {

    @EndpointInject(uri = "mock:peer2peer")
    MockEndpoint mockEndpoint;

    @EndpointInject(uri = "mock:mytopic")
    MockEndpoint topicMockEndpoint;

    int peerConsumerPort = getNextAvailable();

    @BeforeClass
    public static void beforeClass() throws Exception {
        BrokerService broker = new BrokerService();
        broker.setPersistent(false);
        broker.addConnector("amqp://0.0.0.0:9999");
        broker.start();
    }

    String destination = UUID.randomUUID().toString();

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        context.addComponent("amqp", amqp10Component("amqp://guest:guest@localhost:9999"));
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("protonj:amqp://~0.0.0.0:" + peerConsumerPort).to("mock:peer2peer");

                from("amqp:topic:mytopic").to("mock:mytopic");

                from("protonj:amqp://0.0.0.0:9999/inout").setBody().constant("bar").process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                        System.out.println("OOOOO");
                    }
                });
            }
        };
    }

    // Messages fixtures

    String message = randomUUID().toString();

    // Peer2peer tests

    @Test
    public void shouldReceivePeer2PeerMessage() throws InterruptedException {
        mockEndpoint.expectedBodiesReceived(message);
        template.sendBody("protonj:amqp://0.0.0.0:" + peerConsumerPort, message);
        mockEndpoint.assertIsSatisfied();<commit_msg>Removed obsolete logging.<commit_after>/**
 * Licensed to the Rhiot under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.rhiot.cloudplatform.camel.vertxproton;

import com.google.common.truth.Truth;
import org.apache.activemq.broker.BrokerService;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;

import static java.util.UUID.randomUUID;
import static org.apache.camel.component.amqp.AMQPComponent.amqp10Component;
import static org.apache.camel.test.AvailablePortFinder.getNextAvailable;

public class ProtonjComponentTest extends CamelTestSupport {

    @EndpointInject(uri = "mock:peer2peer")
    MockEndpoint mockEndpoint;

    @EndpointInject(uri = "mock:mytopic")
    MockEndpoint topicMockEndpoint;

    int peerConsumerPort = getNextAvailable();

    @BeforeClass
    public static void beforeClass() throws Exception {
        BrokerService broker = new BrokerService();
        broker.setPersistent(false);
        broker.addConnector("amqp://0.0.0.0:9999");
        broker.start();
    }

    String destination = UUID.randomUUID().toString();

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        context.addComponent("amqp", amqp10Component("amqp://guest:guest@localhost:9999"));
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("protonj:amqp://~0.0.0.0:" + peerConsumerPort).to("mock:peer2peer");

                from("amqp:topic:mytopic").to("mock:mytopic");

                from("protonj:amqp://0.0.0.0:9999/inout").setBody().constant("bar");
            }
        };
    }

    // Messages fixtures

    String message = randomUUID().toString();

    // Peer2peer tests

    @Test
    public void shouldReceivePeer2PeerMessage() throws InterruptedException {
        mockEndpoint.expectedBodiesReceived(message);
        template.sendBody("protonj:amqp://0.0.0.0:" + peerConsumerPort, message);
        mockEndpoint.assertIsSatisfied();
{'fraction_non_alphanumeric': 0.10220376876397318, 'fraction_numerical': 0.013094857872884063, 'mean_word_length': 3.4863896848137537, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 8, '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': '5223013', 'n_tokens_mistral': 1752, 'n_tokens_neox': 1708, 'n_words': 446}