Search in sources :

Example 1 with Validator

use of com.mozilla.bagheera.validation.Validator in project bagheera by mozilla-metrics.

the class AccessFilterTest method setup.

@Before
public void setup() throws IOException {
    String[] namespaces = new String[] { "foo_*", "bar" };
    WildcardProperties props = new WildcardProperties();
    String propsFileStr = "foo_*.allow.delete.access=false\n" + "foo_*.id.validation=true\n" + "bar.allow.delete.access=true\n" + "bar.id.validation=false";
    InputStream is = new ByteArrayInputStream(propsFileStr.getBytes("UTF-8"));
    props.load(is);
    filter = new AccessFilter(new Validator(namespaces), props);
    remoteAddr = InetSocketAddress.createUnresolved("192.168.1.1", 51723);
    Channel channel = createMock(Channel.class);
    expect(channel.getCloseFuture()).andReturn(new DefaultChannelFuture(channel, false));
    expect(channel.getRemoteAddress()).andReturn(remoteAddr);
    OrderedMemoryAwareThreadPoolExecutor executor = new OrderedMemoryAwareThreadPoolExecutor(10, 0L, 0L);
    final ExecutionHandler handler = new ExecutionHandler(executor, true, true);
    ctx = new FakeChannelHandlerContext(channel, handler);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultChannelFuture(org.jboss.netty.channel.DefaultChannelFuture) WildcardProperties(com.mozilla.bagheera.util.WildcardProperties) Channel(org.jboss.netty.channel.Channel) ExecutionHandler(org.jboss.netty.handler.execution.ExecutionHandler) OrderedMemoryAwareThreadPoolExecutor(org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor) Validator(com.mozilla.bagheera.validation.Validator) FakeChannelHandlerContext(org.jboss.netty.channel.FakeChannelHandlerContext) Before(org.junit.Before)

Example 2 with Validator

use of com.mozilla.bagheera.validation.Validator in project bagheera by mozilla-metrics.

the class DummyProducer method setup.

@Before
public void setup() {
    validator = Mockito.mock(Validator.class);
    producer = new DummyProducer();
    channelGroup = Mockito.mock(ChannelGroup.class);
    manager = Mockito.mock(MetricsManager.class);
    HttpMetric metric = Mockito.mock(HttpMetric.class);
    Mockito.when(manager.getGlobalHttpMetric()).thenReturn(metric);
    Mockito.when(manager.getHttpMetricForNamespace(Mockito.anyString())).thenReturn(metric);
    mockChannelBuffer = Mockito.mock(ChannelBuffer.class);
    Mockito.when(mockChannelBuffer.readable()).thenReturn(true);
    Mockito.when(mockChannelBuffer.readableBytes()).thenReturn(1);
    Mockito.when(mockChannelBuffer.toByteBuffer()).thenReturn(ByteBuffer.allocate(1));
    mockChannel = Mockito.mock(Channel.class);
    mockFuture = Mockito.mock(ChannelFuture.class);
    Mockito.when(mockChannel.getRemoteAddress()).thenReturn(new InetSocketAddress("localhost", 8080));
    Mockito.when(mockChannel.write(Mockito.any())).thenReturn(mockFuture);
    // We get a NoClassDefFoundError without this.
    if (!new File("./target/classes/com/mozilla/bagheera/BagheeraProto.class").exists()) {
        fail("You must run 'mvn compile' before the tests will run properly from Eclipse");
    }
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) MetricsManager(com.mozilla.bagheera.metrics.MetricsManager) InetSocketAddress(java.net.InetSocketAddress) Channel(org.jboss.netty.channel.Channel) File(java.io.File) Validator(com.mozilla.bagheera.validation.Validator) ChannelGroup(org.jboss.netty.channel.group.ChannelGroup) HttpMetric(com.mozilla.bagheera.metrics.HttpMetric) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Before(org.junit.Before)

Aggregations

Validator (com.mozilla.bagheera.validation.Validator)2 Channel (org.jboss.netty.channel.Channel)2 Before (org.junit.Before)2 HttpMetric (com.mozilla.bagheera.metrics.HttpMetric)1 MetricsManager (com.mozilla.bagheera.metrics.MetricsManager)1 WildcardProperties (com.mozilla.bagheera.util.WildcardProperties)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)1 ChannelFuture (org.jboss.netty.channel.ChannelFuture)1 DefaultChannelFuture (org.jboss.netty.channel.DefaultChannelFuture)1 FakeChannelHandlerContext (org.jboss.netty.channel.FakeChannelHandlerContext)1 ChannelGroup (org.jboss.netty.channel.group.ChannelGroup)1 ExecutionHandler (org.jboss.netty.handler.execution.ExecutionHandler)1 OrderedMemoryAwareThreadPoolExecutor (org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor)1