'Test that the Netstat flow works.'

def testNetstat(self):

    class ClientMock(object, ):
        def Netstat(self, _):
            'Returns    fake    connections.'
            conn1 = rdf_client.NetworkConnection(state=rdf_client.NetworkConnection.State.LISTEN, type=rdf_client.NetworkConnection.Type.SOCK_STREAM, local_address=rdf_client.NetworkEndpoint(ip='0.0.0.0', port=22), remote_address=rdf_client.NetworkEndpoint(ip='0.0.0.0', port=0), pid=2136, ctime=0)
            conn2 = rdf_client.NetworkConnection(state=rdf_client.NetworkConnection.State.LISTEN, type=rdf_client.NetworkConnection.Type.SOCK_STREAM, local_address=rdf_client.NetworkEndpoint(ip='192.168.1.1', port=31337), remote_address=rdf_client.NetworkEndpoint(ip='1.2.3.4', port=6667), pid=1, ctime=0)
            return [conn1, conn2]
    fd = aff4.FACTORY.Create(self.client_id, aff4_grr.VFSGRRClient, token=self.token)
    fd.Set(fd.Schema.SYSTEM('Windows'))
    fd.Close()
    for s in flow_test_lib.TestFlowHelper(network.Netstat.__name__, ClientMock(), client_id=self.client_id, token=self.token):
        session_id = s
    fd = flow.GRRFlow.ResultCollectionForFID(session_id, token=self.token)
    conns = list(fd)
    self.assertEqual(len(conns), 2)
    self.assertEqual(conns[0].local_address.ip, '0.0.0.0')
    self.assertEqual(conns[0].local_address.port, 22)
    self.assertEqual(conns[1].local_address.ip, '192.168.1.1')
    self.assertEqual(conns[1].pid, 1)
    self.assertEqual(conns[1].remote_address.port, 6667)
