PROTON-2687: restore old gate to original structure, add additional protection to new gates, remove some extraneous leftovers from tests
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportImpl.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportImpl.java
index 6653bd7..da2e9ab 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportImpl.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportImpl.java
@@ -561,18 +561,17 @@
         SessionImpl session = snd.getSession();
         TransportSession tpSession = session.getTransportSession();
 
-        if (tpSession.endSent()) {
+        if (tpSession != null && tpSession.endSent()) {
             // Too late to action this work, clear it.
             return true;
         }
 
-        boolean localChannelSet = tpSession.isLocalChannelSet();
         boolean wasDone = delivery.isDone();
 
         if(!delivery.isDone() &&
            (delivery.getDataLength() > 0 || delivery != snd.current()) &&
            tpSession.hasOutgoingCredit() && tpLink.hasCredit() &&
-           localChannelSet &&
+           tpSession.isLocalChannelSet() &&
            tpLink.getLocalHandle() != null && !_frameWriter.isFull())
         {
             DeliveryImpl inProgress = tpLink.getInProgressDelivery();
@@ -682,7 +681,7 @@
             }
         }
 
-        if(wasDone && delivery.getLocalState() != null && localChannelSet)
+        if(wasDone && delivery.getLocalState() != null && tpSession.isLocalChannelSet())
         {
             TransportDelivery tpDelivery = delivery.getTransportDelivery();
             // Use cached object as holder of data for immediate write to the FrameWriter
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/TransportImplTest.java b/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/TransportImplTest.java
index 56e518b..82ff4c8 100644
--- a/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/TransportImplTest.java
+++ b/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/TransportImplTest.java
@@ -4981,10 +4981,6 @@
 
         // Send the necessary responses to End
         End end = new End();
-        begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
-        begin.setNextOutgoingId(UnsignedInteger.ONE);
-        begin.setIncomingWindow(UnsignedInteger.valueOf(1024));
-        begin.setOutgoingWindow(UnsignedInteger.valueOf(1024));
         transport.handleFrame(new TransportFrame(0, end, null));
 
         assertEndpointState(session, EndpointState.CLOSED, EndpointState.CLOSED);
@@ -5035,7 +5031,7 @@
 
         assertNull("Should not yet have a delivery", sender.current());
 
-        // Send the necessary responses to open/begin/attach as well as a transfer
+        // Send the necessary responses to open/begin
         transport.handleFrame(new TransportFrame(0, new Open(), null));
 
         Begin begin = new Begin();
@@ -5094,10 +5090,6 @@
 
         // Send the necessary responses to End
         End end = new End();
-        begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
-        begin.setNextOutgoingId(UnsignedInteger.ONE);
-        begin.setIncomingWindow(UnsignedInteger.valueOf(1024));
-        begin.setOutgoingWindow(UnsignedInteger.valueOf(1024));
         transport.handleFrame(new TransportFrame(0, end, null));
 
         assertEndpointState(session, EndpointState.CLOSED, EndpointState.CLOSED);