com.boundary.sdk.metric.MeasureRouteBuilderTest.java Source code

Java tutorial

Introduction

Here is the source code for com.boundary.sdk.metric.MeasureRouteBuilderTest.java

Source

// Copyright 2014-2015 Boundary, Inc.
//
// Licensed 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 com.boundary.sdk.metric;

import static org.junit.Assert.*;

import java.util.concurrent.TimeUnit;

import org.apache.camel.EndpointInject;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.http.AuthMethod;
import org.apache.camel.component.http.HttpComponent;
import org.apache.camel.component.http.HttpConfiguration;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MeasureRouteBuilderTest extends CamelSpringTestSupport {

    private static Logger LOG = LoggerFactory.getLogger(MeasureRouteBuilderTest.class);

    @Produce(uri = "direct:measure-in")
    private ProducerTemplate in;

    @EndpointInject(uri = "mock:measure-out")
    private MockEndpoint out;

    public void setUp() throws Exception {
        super.setUp();
    }

    public void tearDown() throws Exception {
        super.tearDown();
    }

    @Test
    public void testSendMetric() throws InterruptedException {
        Measurement measurement = new Measurement();
        measurement.setSource("26");
        measurement.setMetric("API_RESPONSE_TIME");
        measurement.setMeasure(100);
        out.setExpectedMessageCount(1);
        in.sendBody(measurement);

        out.await(20, TimeUnit.SECONDS);

        out.assertIsSatisfied();
    }

    @Override
    protected AbstractApplicationContext createApplicationContext() {
        return new ClassPathXmlApplicationContext("META-INF/spring/measure-route-test.xml");
    }
}