|
| 1 | +/* |
| 2 | + * Copyright (c) 2022 Eclipse Foundation and/or its affiliates. All rights reserved. |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made available under the |
| 5 | + * terms of the Eclipse Public License v. 2.0, which is available at |
| 6 | + * http://www.eclipse.org/legal/epl-2.0. |
| 7 | + * |
| 8 | + * This Source Code may also be made available under the following Secondary |
| 9 | + * Licenses when the conditions for such availability set forth in the |
| 10 | + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, |
| 11 | + * version 2 with the GNU Classpath Exception, which is available at |
| 12 | + * https://www.gnu.org/software/classpath/license.html. |
| 13 | + * |
| 14 | + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 |
| 15 | + */ |
| 16 | + |
| 17 | +package org.glassfish.grizzly.filterchain; |
| 18 | + |
| 19 | +import java.nio.channels.ServerSocketChannel; |
| 20 | + |
| 21 | +import org.glassfish.grizzly.Buffer; |
| 22 | +import org.glassfish.grizzly.filterchain.FilterChainContext.Operation; |
| 23 | +import org.glassfish.grizzly.memory.Buffers; |
| 24 | +import org.glassfish.grizzly.memory.MemoryManager; |
| 25 | +import org.glassfish.grizzly.nio.transport.TCPNIOConnection; |
| 26 | +import org.glassfish.grizzly.nio.transport.TCPNIOTransport; |
| 27 | +import org.junit.Test; |
| 28 | + |
| 29 | +import static org.junit.Assert.assertEquals; |
| 30 | + |
| 31 | +/** |
| 32 | + * @author David Matejcek |
| 33 | + */ |
| 34 | +public class FilterChainContextTest { |
| 35 | + |
| 36 | + @Test |
| 37 | + public void testToString_null() throws Exception { |
| 38 | + assertEquals("FilterChainContext [connection=null, closeable=null, operation=NONE, message=null, address=null]", |
| 39 | + new FilterChainContext().toString()); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + public void testToString_usual() throws Exception { |
| 44 | + try (ServerSocketChannel channel = ServerSocketChannel.open()) { |
| 45 | + final TCPNIOConnection connection = new TCPNIOConnection(new TCPNIOTransport(), channel); |
| 46 | + final FilterChainContext context = FilterChainContext.create(connection); |
| 47 | + final Buffer buffer = Buffers.wrap(MemoryManager.DEFAULT_MEMORY_MANAGER, "Ororok orebuh"); |
| 48 | + context.setAddress("localhost"); |
| 49 | + context.setMessage(buffer); |
| 50 | + context.setOperation(Operation.CONNECT); |
| 51 | + assertEquals("FilterChainContext [" |
| 52 | + + "connection=TCPNIOConnection{localSocketAddress=null, peerSocketAddress=null}, " |
| 53 | + + "closeable=TCPNIOConnection{localSocketAddress=null, peerSocketAddress=null}, " |
| 54 | + + "operation=CONNECT, " |
| 55 | + + "message=" + buffer + ", " // contains hashcode |
| 56 | + + "address=localhost" |
| 57 | + + "]", |
| 58 | + context.toString()); |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments