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

WFCatAlbumTestUtilsTest.lua

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

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

NOTICE: All information contained herein is, and remain 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 may be covered by U.S. and Foreign
Patents, patents in process, and are protected by trade secret or copyright
law.  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.core.utils
local KSIdGenerator = require 'KSIdGenerator'

	-- WF.oz_client
local WFCatAlbumTestUtils = require 'WFCatAlbumTestUtils'
local WFCatAssetTestUtils = require 'WFCatAssetTestUtils'
local WFCatMockCatalog = require 'WFCatMockCatalog'

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

local WFCatAlbumTestUtilsTest = {}

--------------------------------------------------------------------------------
function WFCatAlbumTestUtilsTest.rxTestCreateEmptyAlbum( rxTest )

	rxTest:setTimeLimit( 5 )

    -- Create asset IDs
	local albumId = KSIdGenerator.uuidInLowercaseHex()
                
    -- Empty album
	local emptyAlbum = {
			_id = albumId,
			name = 'Test album',
			type = "album",
			subtype = "collection_set",
			}
	
	-- Compare empty albums
	local generatedEmptyAlbum = WFCatAlbumTestUtils.createEmptyAlbumDoc(rxTest, albumId)
    rxTest:expectEqual( emptyAlbum, generatedEmptyAlbum )
	
end
--------------------------------------------------------------------------------
function WFCatAlbumTestUtilsTest.rxTestCreateAlbumDocAndAddImages( rxTest )

	rxTest:setTimeLimit( 5 )

	local albumId = KSIdGenerator.uuidInLowercaseHex()
	local albumAssetId1 = KSIdGenerator.uuidInLowercaseHex()
	local albumAssetId2 = KSIdGenerator.uuidInLowercaseHex()
	local albumAssetId3 = KSIdGenerator.uuidInLowercaseHex()
	local assetId1 = KSIdGenerator.uuidInLowercaseHex()
	local assetId2 = KSIdGenerator.uuidInLowercaseHex()
	local assetId3 = KSIdGenerator.uuidInLowercaseHex()
	local wfCatalog = WFCatMockCatalog.createFakeWFCatalog( rxTest )
                
    -- Album
	local album = {
			_id = albumId,
			name = 'Test album',
			type = "album",
			subtype = "collection_set",
			}
	
	--Images
	local image1 = WFCatAssetTestUtils.createAssetDocument( rxTest, wfCatalog, assetId1 )
	local image2 = WFCatAssetTestUtils.createAssetDocument( rxTest, wfCatalog, assetId2 )
	local image3 = WFCatAssetTestUtils.createAssetDocument( rxTest, wfCatalog, assetId3 )
	local albumAsset1 = WFCatAlbumTestUtils.createAlbumAsset( rxTest, albumId, assetId1, albumAssetId1 )
	local albumAsset2 = WFCatAlbumTestUtils.createAlbumAsset( rxTest, albumId, assetId2, albumAssetId2 )
	local albumAsset3 = WFCatAlbumTestUtils.createAlbumAsset( rxTest, albumId, assetId3, albumAssetId3 )
	
	album = {album, image1, albumAsset1, image2, albumAsset2, image3, albumAsset3}
	
	--Generate Album
	local overrides = {
				addDocuments = {image1, image2, image3},
				albumAssetIds = {albumAssetId1, albumAssetId2, albumAssetId3}
			}
	local generatedAlbum = WFCatAlbumTestUtils.createAlbumDocument(rxTest, wfCatalog, albumId, overrides)
	
	--Compare Albums
    rxTest:expectEqual( album, generatedAlbum )
	   
end
--------------------------------------------------------------------------------
function WFCatAlbumTestUtilsTest.rxTestCreateAlbumImagesAndAlbumAssets( rxTest )

	rxTest:setTimeLimit( 5 )

	local albumId = KSIdGenerator.uuidInLowercaseHex()
	local wfCatalog = WFCatMockCatalog.createFakeWFCatalog( rxTest )
                
	--Generate Album
	local overrides = {
				createImages = 3
			}
	local generatedAlbum = WFCatAlbumTestUtils.createAlbumDocument(rxTest, wfCatalog, albumId, overrides)
	
	--Check number of documents
    rxTest:expectEqual( table.getn(generatedAlbum), 7 )
	   
end
--------------------------------------------------------------------------------
function WFCatAlbumTestUtilsTest.rxTestCreateEmptyCollection( rxTest )

	rxTest:setTimeLimit( 5 )

    -- Create collection IDs
	local collectionId = KSIdGenerator.uuidInLowercaseHex()
                
    -- Empty collection
	local emptyAlbumCollection = {
				_id = collectionId,
				name = 'Test collection',
				type = "album",
				subtype = "collection",
			}
	
	-- Compare empty collections
	local generatedEmptyAlbumCollection = WFCatAlbumTestUtils.createEmptyCollection(rxTest, collectionId)
    rxTest:expectEqual( emptyAlbumCollection, generatedEmptyAlbumCollection )
	   
end
--------------------------------------------------------------------------------
function WFCatAlbumTestUtilsTest.rxTestCreateCollectionWithGivenAlbums( rxTest )

	rxTest:setTimeLimit( 5 )

	local collectionId = KSIdGenerator.uuidInLowercaseHex()
	local wfCatalog = WFCatMockCatalog.createFakeWFCatalog( rxTest )
                
    -- CreateAlbumCollection
	local albumOverrides = {
				createImages = 2
			}
	local album1 = {WFCatAlbumTestUtils.createEmptyAlbumDoc(rxTest)}
	local album2 = WFCatAlbumTestUtils.createAlbumDocument(rxTest, wfCatalog, nil, albumOverrides)
	local emptyAlbumCollection = WFCatAlbumTestUtils.createEmptyCollection(rxTest, collectionId)
	
	local collection = {emptyAlbumCollection}
	
	for key, doc in ipairs(album1) do
		table.insert(collection, doc)
	end
	
	for key, doc in ipairs(album2) do
		table.insert(collection, doc)
	end
	
	--Create colletion
	local overrides = {
				addAlbums = {album1, album2}
			}
	local generatedCollection = WFCatAlbumTestUtils.createCollectionSet(rxTest, wfCatalog, collectionId, overrides)
    
	-- Compare empty collections
	rxTest:expectEqual( collection, generatedCollection )
	   
end
--------------------------------------------------------------------------------
function WFCatAlbumTestUtilsTest.rxTestCreateCollectionAndCreateAlbums( rxTest )

	rxTest:setTimeLimit( 5 )

	local collectionId = KSIdGenerator.uuidInLowercaseHex()
	local wfCatalog = WFCatMockCatalog.createFakeWFCatalog( rxTest )
               
	--Create colletion
	local overrides = {
				createAlbums = 2,
				createImagesOnAlbums = 2
			}
	local generatedCollection = WFCatAlbumTestUtils.createCollectionSet(rxTest, wfCatalog, collectionId, overrides)
    
	-- Compare empty collections
	rxTest:expectEqual( 11, table.getn(generatedCollection) )
	   
end
--------------------------------------------------------------------------------

return WFRxTestCase.wrapSuite( 'WFCatAlbumTestUtilsTest', WFCatAlbumTestUtilsTest )