--[[----------------------------------------------------------------------------

WFCatExportQueueTest.lua

--------------------------------------------------------------------------------

ADOBE CONFIDENTIAL
------------------
Copyright 2015 Adobe Systems Incorporated
All Rights Reserved.

NOTICE: All information contained herein is, and remains the property of
Adobe Systems Incorporated and its suppliers, if any. The intellectual and
technical concepts contained herein are proprietary to Adobe Systems
Incorporated and its suppliers and are protected by all applicable
intellectual property laws, including trade secret and copyright laws.
Dissemination of this information or reproduction of this material is
strictly forbidden unless prior written permission is obtained from
Adobe Systems Incorporated.

----------------------------------------------------------------------------]]--

	-- RxLua
local Rx = require 'Rx'
local Observable = Rx.Observable

	-- WF.core.self_test
local WFRxTestCase = require 'WFRxTestCase'

	-- WF.oz_client.managed_catalog
local WFCatExportQueue = require 'WFCatExportQueue'


--============================================================================--

local WFCatExportQueueTest = {}

--------------------------------------------------------------------------------

local function queueContentsAsObservable( fq )

	local paths = {}
	local nPaths = 0

	while true do

		local nextPath = fq:nextRequest()
		if not nextPath then break end

		nPaths = nPaths + 1
		paths[ nPaths ] = nextPath

	end

	return Observable.from( paths )

end

--------------------------------------------------------------------------------

function WFCatExportQueueTest.rxTestEmptyQueue( rxTest )

	local rq = WFCatExportQueue()

	local size = rxTest:observe( rq:size() )
	size:expectData( 0 )

	local contents = rxTest:observe( queueContentsAsObservable( rq ) )
	contents:expectCompleted()

	rq:dispose()

end

--------------------------------------------------------------------------------

function WFCatExportQueueTest.rxTestAddOneItem( rxTest )

	local rq = WFCatExportQueue()

	rq:addToQueue( { 'abc' } )

	local size = rxTest:observe( rq:size() )
	size:expectData( 1 )

	local contents = rxTest:observe( queueContentsAsObservable( rq ) )
	contents:expectData( { 'abc' } )
	contents:expectCompleted()

end
--------------------------------------------------------------------------------

function WFCatExportQueueTest.rxTestAddManyItems( rxTest )

	local rq = WFCatExportQueue()

	rq:addToQueue( { 'abc' } )
	rq:addToQueue( { 'defg' } )
	rq:addToQueue( { 'hijkl' } )

	local size = rxTest:observe( rq:size() )
	size:expectData( 3 )

	local contents = rxTest:observe( queueContentsAsObservable( rq ) )
	contents:expectData( { 'abc' } )
	contents:expectData( { 'defg' } )
	contents:expectData( { 'hijkl' } )
	contents:expectCompleted()

	size:expectDataWithinTime( .5, 0 )

end
--------------------------------------------------------------------------------

function WFCatExportQueueTest.rxTestAddAndRemoveItems( rxTest )

	local rq = WFCatExportQueue()

	rq:addToQueue( { 'abc' } )
	rq:addToQueue( { 'defg' } )
	rq:addToQueue( { 'hijkl' } )

	local size = rxTest:observe( rq:size() )
	size:expectData( 3 )
	
	rxTest:expectEqual( rq:nextRequest(), { 'abc' })
	size:expectData( 2 )
	
	rq:addToQueue( { 'mn' } )
	rq:addToQueue( { 'o' } )
	size:expectDataWithinTime( .5, 4 )

	local contents = rxTest:observe( queueContentsAsObservable( rq ) )
	contents:expectData( { 'defg' } )
	contents:expectData( { 'hijkl' } )
	contents:expectData( { 'mn' } )
	contents:expectData( { 'o' } )
	contents:expectCompleted()

	size:expectDataWithinTime( .5, 0 )

end

--------------------------------------------------------------------------------

return WFRxTestCase.wrapSuite( WFCatExportQueueTest )
