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

WFCatAssetInfoCollectorTest.lua

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

ADOBE CONFIDENTIAL
------------------
Copyright 2016 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.

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

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

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

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

local WFCatAssetInfoCollectorTest = {}

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

function WFCatAssetInfoCollectorTest.rxTestBasic( rxTest )

	local collector = WFCatAssetInfoCollector.makeCollector()
	


	-- test accumulation:
	
	collector:accumulateValues( "asset1", "shared_keywords", "partial_keywords", { "keyword_c", "keyword_d", "keyword_b", "keyword_a" }, true )
	collector:accumulateValues( "asset2", "shared_keywords", "partial_keywords", { "keyword_e", "keyword_d", "keyword_a", "keyword_f" }, true )
	collector:accumulateValues( "asset3", "shared_keywords", "partial_keywords", { "keyword_f", "keyword_d", "keyword_h", "keyword_a" }, true )
	
	local result = collector:getCollectedValues( 3 )
	
	rxTest:expectEqual( result.shared_keywords, { "keyword_a", "keyword_d" } )
	rxTest:expectEqual( result.partial_keywords, { "keyword_b", "keyword_c", "keyword_e", "keyword_f", "keyword_h" } )

	-- remove "keyword_d" and "keyword_b" from asset1...

	collector:accumulateValues( "asset1", "shared_keywords", "partial_keywords", { "keyword_a", "keyword_c" }, true )

	result = collector:getCollectedValues( 3 )

	rxTest:expectEqual( result.shared_keywords, { "keyword_a" } )
	rxTest:expectEqual( result.partial_keywords, { "keyword_c", "keyword_d", "keyword_e", "keyword_f", "keyword_h", } )


	-- test consolidation:
	
	collector:consolidateValue( "asset1", "value1", 1 )
	collector:consolidateValue( "asset2", "value1", 1 )
	collector:consolidateValue( "asset3", "value1", 1 )

	collector:consolidateValue( "asset1", "value2", 1 )
	collector:consolidateValue( "asset2", "value2", 2 )
	collector:consolidateValue( "asset3", "value2", 3 )

	result = collector:getCollectedValues( 3 )

	rxTest:expectEqual( result.value1, 1 )
	rxTest:expectEqual( result.value2, nil )

	collector:consolidateValue( "asset1", "value2", 4 )
	collector:consolidateValue( "asset2", "value2", 4 )
	collector:consolidateValue( "asset3", "value2", 4 )

	result = collector:getCollectedValues( 3 )

	rxTest:expectEqual( result.value2, 4 )

	collector:consolidateValue( "asset1", "value2", 3 )

	result = collector:getCollectedValues( 3 )

	rxTest:expectEqual( result.value2, nil )
		
	collector:consolidateValue( "asset1", "value2", nil, 0 )

	result = collector:getCollectedValues( 3 )

	rxTest:expectEqual( result.value2, 0 )
	
	collector:consolidateValue( "asset2", "value2", nil, 0 )
	collector:consolidateValue( "asset3", "value2", nil, 0 )

	result = collector:getCollectedValues( 3 )

	rxTest:expectEqual( result.value2, 0 )

end

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

return WFRxTestCase.wrapSuite( 'WFCatAssetInfoCollectorTest', WFCatAssetInfoCollectorTest )
