package org.wso2.carbon.device.mgt.ios.payload.beans;

import org.testng.Assert;
import org.testng.annotations.Test;
import org.wso2.carbon.device.mgt.ios.payload.dto.PayloadOperationWrapper;
import org.wso2.carbon.device.mgt.ios.payload.exception.PListException;
import org.wso2.carbon.device.mgt.ios.payload.exception.ProfileConfigurationException;
import org.wso2.carbon.device.mgt.ios.payload.operation.ApplicationOperations;

public class AppLockTestSuite {

    @Test(expectedExceptions = ProfileConfigurationException.class)
    public void testAppLockApplication() throws ProfileConfigurationException {

        AppLock appLock = new AppLock();
        appLock.setAppLockApplication(null);

        appLock.validateRequest();

    }

    @Test(expectedExceptions = ProfileConfigurationException.class)
    public void testIdentifier() throws ProfileConfigurationException {

        AppLock appLock = new AppLock();
        AppLockApplication appLockApplication = new AppLockApplication();
        appLockApplication.setIdentifier("");
        appLock.setAppLockApplication(appLockApplication);

        appLock.validateRequest();

    }

    @Test
    public void testAppLockPayload() throws ProfileConfigurationException, PListException {

        AppLock appLock = new AppLock();
        AppLockApplication appLockApplication = new AppLockApplication();
        appLockApplication.setIdentifier("identifier");

        ApplicationOptions applicationOptions = new ApplicationOptions();
        applicationOptions.setDisableTouch(false);
        applicationOptions.setDisableDeviceRotation(false);
        applicationOptions.setDisableVolumeButtons(false);
        applicationOptions.setDisableRingerSwitch(false);
        applicationOptions.setDisableSleepWakeButton(false);
        applicationOptions.setDisableAutoLock(false);
        applicationOptions.setEnableVoiceOver(true);
        applicationOptions.setEnableZoom(true);
        applicationOptions.setEnableInvertColors(true);
        applicationOptions.setEnableAssistiveTouch(true);
        applicationOptions.setEnableSpeakSelection(true);
        applicationOptions.setEnableMonoAudio(true);

        appLockApplication.setOptions(applicationOptions);

        ApplicationUserEnabledOptions applicationUserEnabledOptions = new ApplicationUserEnabledOptions();
        applicationUserEnabledOptions.setVoiceOver(true);
        applicationUserEnabledOptions.setZoom(true);
        applicationUserEnabledOptions.setInvertColors(true);
        applicationUserEnabledOptions.setAssistiveTouch(true);

        appLockApplication.setUserEnabledOptions(applicationUserEnabledOptions);

        appLock.setAppLockApplication(appLockApplication);
        appLock.validateRequest();

        ApplicationOperations applicationOperations = new ApplicationOperations();
        PayloadOperationWrapper payload = applicationOperations.createAppLockPayload(appLock);

        Assert.assertNotNull(payload);

    }
}
