/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF 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 org.apache.qpid.proton4j.engine.impl;

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

import org.apache.qpid.proton4j.engine.Connection;
import org.junit.Test;

/**
 * Test for basic functionality of the ProtonEngine implementation.
 */
public class ProtonEngineTest {

    private Connection connection;

    @Test
    public void testEngineStart() {
        ProtonEngine engine = ProtonEngineFactory.createDefaultEngine();

        // Engine cannot accept input bytes until started.
        assertFalse(engine.isWritable());

        engine.start(result -> {
            assertTrue(result.succeeded());
            connection = result.get();
            assertNotNull(connection);
        });

        // Default engine should start and return a connection immediately
        assertTrue(engine.isWritable());
        assertNotNull(connection);
    }
}

@@ -843,16 +843,61 @@
 .impl;%0A%0A
+import static org.junit.Assert.assertEquals;%0A
 import s
@@ -932,16 +932,16 @@
 tFalse;%0A
-
 import s
@@ -1022,16 +1022,157 @@
 tTrue;%0A%0A
+import java.util.ArrayList;%0A%0Aimport org.apache.qpid.proton4j.amqp.transport.AMQPHeader;%0Aimport org.apache.qpid.proton4j.buffer.ProtonBuffer;%0A
 import o
@@ -1214,16 +1214,65 @@
 ection;%0A
+import org.junit.After;%0Aimport org.junit.Ignore;%0A
 import o
@@ -1430,16 +1430,163 @@
 nection;
+%0A    private ArrayList%3CProtonBuffer%3E engineWrites = new ArrayList%3C%3E();%0A%0A    @After%0A    public void tearDown() %7B%0A        engineWrites.clear();%0A    %7D
 %0A%0A    @T
@@ -2081,24 +2081,24 @@
 ritable());%0A
-
         asse
@@ -2125,11 +2125,972 @@
 );%0A    %7D
+%0A%0A    @Ignore(%22Building out idea of how Engine behaves, when do we emit the header etc%22)%0A    @Test%0A    public void testEngineEmitsAMQPHeaderOnConnectionOpen() %7B%0A        ProtonEngine engine = ProtonEngineFactory.createDefaultEngine();%0A%0A        engine.start(result -%3E %7B%0A            connection = result.get();%0A        %7D);%0A%0A        // Default engine should start and return a connection immediately%0A        assertNotNull(connection);%0A%0A        engine.outputHandler((buffer) -%3E %7B%0A            engineWrites.add(buffer);%0A        %7D);%0A%0A        connection.open();%0A%0A        // Expect the engine to emit the AMQP header%0A        assertEquals(%22Engine did not emit an AMQP Header on Open%22, 1, engineWrites.size());%0A%0A        ProtonBuffer outputBuffer = engineWrites.get(0);%0A        assertEquals(AMQPHeader.HEADER_SIZE_BYTES, outputBuffer.getReadableBytes());%0A        AMQPHeader outputHeader = new AMQPHeader(outputBuffer);%0A%0A        assertFalse(outputHeader.isSaslHeader());%0A    %7D
 %0A%7D%0A

Add basic test for engine and connection start