<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at
  
  http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<project name="Workflow test" basedir="." default="main">
  
  <import file="${webtest.home}/lib/taskdef.xml"/>
  
  <target name="main" depends="sequence, published-footer, overview"/>
  
    
  <target name="sequence">
    <webtest name="Workflow sequence">
      <config host="localhost" port="8888" protocol="http" basepath="default/authoring" />
      <steps>
        <!-- login as lenya -->
        <invoke url="index.html" />
        <setInputField name="username" value="lenya"/>
        <setInputField name="password" value="levi"/>
        <clickButton name="submit"/>
        <verifyElementText type="span" name="workflow-state" text="authoring"/>

        <!-- publish not allowed -->
        <invoke url="index.html?lenya.usecase=workflow.publish"/>
        <verifyText text="The event publish is not executable on document"/>
        <clickButton name="cancel"/>
        <verifyText text="Welcome to the Default Publication from the Lenya community!"/>
        
        <!-- submit -->
        <invoke url="index.html?lenya.usecase=workflow.submit"/>
        <verifyText text="Submit &quot;Welcome to the Lenya default publication&quot; for approval"/>
        <clickButton name="submit"/>
        <verifyElementText type="span" name="workflow-state" text="review"/>
        
        <!-- logout -->
        <invoke url="index.html?lenya.usecase=ac.logout"/>
        <clickButton name="submit"/>
        
        
        <!-- login as alice -->
        <invoke url="index.html" />
        <setInputField name="username" value="alice"/>
        <setInputField name="password" value="levi"/>
        <clickButton name="submit"/>
        <verifyElementText type="span" name="workflow-state" text="review"/>
        
        <!-- reject -->
        <invoke url="index.html?lenya.usecase=workflow.reject"/>
        <verifyText text="Reject document &quot;Welcome to the Lenya default publication&quot;"/>
        <clickButton name="submit"/>
        <verifyElementText type="span" name="workflow-state" text="authoring"/>
        
        <!-- logout -->
        <invoke url="index.html?lenya.usecase=ac.logout"/>
        <clickButton name="submit"/>
        
        <!-- login as lenya -->
        <invoke url="index.html" />
        <setInputField name="username" value="lenya"/>
        <setInputField name="password" value="levi"/>
        <clickButton name="submit"/>
        <verifyElementText type="span" name="workflow-state" text="authoring"/>
        
        <!-- submit -->
        <invoke url="index.html?lenya.usecase=workflow.submit"/>
        <verifyText text="Submit &quot;Welcome to the Lenya default publication&quot; for approval"/>
        <clickButton name="submit"/>
        <verifyElementText type="span" name="workflow-state" text="review"/>
        
        <!-- logout -->
        <invoke url="index.html?lenya.usecase=ac.logout"/>
        <clickButton name="submit"/>
        
        
        <!-- login as alice -->
        <invoke url="index.html" />
        <setInputField name="username" value="alice"/>
        <setInputField name="password" value="levi"/>
        <clickButton name="submit"/>
        <verifyElementText type="span" name="workflow-state" text="review"/>
        
        <!-- publish -->
        
        <invoke url="index.html?lenya.usecase=workflow.publish"/>
        <clickButton name="submit"/>
        <verifyElementText type="span" name="workflow-state" text="live"/>
        
        <!-- deactivate -->
        <invoke url="index.html?lenya.usecase=workflow.deactivate"/>
        <clickButton name="submit"/>
        <verifyElementText type="span" name="workflow-state" text="authoring"/>
        
        <!-- logout -->
        <invoke url="index.html?lenya.usecase=ac.logout"/>
        <clickButton name="submit"/>
        
      </steps>
    </webtest>
  </target>
  
  
  <target name="published-footer">
    <webtest name="Workflow sequence">
      <config host="localhost" port="8888" protocol="http" basepath="default">
        <option name="ThrowExceptionOnFailingStatusCode" value="false"/>
      </config>
      <steps>
        <!-- login as alice -->
        <invoke url="authoring/tutorial.html" />
        <setInputField name="username" value="alice"/>
        <setInputField name="password" value="levi"/>
        <clickButton name="submit"/>
        <verifyElementText type="span" name="workflow-state" text="authoring"/>
        
        <!-- submit -->
        <invoke url="authoring/tutorial.html?lenya.usecase=workflow.submit"/>
        <clickButton name="submit"/>
        <verifyElementText type="span" name="workflow-state" text="review"/>
        
        <!-- live version should not exist -->
        <invoke url="live/tutorial.html"/>
        <storeResponseCode property="status" />
        <verifyProperty name="status" text="404"/>
        
        <!-- publish -->
        <invoke url="authoring/tutorial.html"/>
        <verifyText text="This page has not been published yet."/>
        <invoke url="authoring/tutorial.html?lenya.usecase=workflow.publish"/>
        <clickButton name="submit"/>
        <verifyElementText type="span" name="workflow-state" text="live"/>
        <verifyText text="This page was last published at"/>
        <verifyText text="by Alice."/>
        
        <invoke url="live/tutorial.html"/>
        <verifyText text="This page was last published at"/>
        
        <!-- logout -->
        <invoke url="authoring/tutorial.html?lenya.usecase=ac.logout"/>
        <clickButton name="submit"/>
        
      </steps>
    </webtest>
  </target>
  
  
  <target name="overview">
    <webtest name="myTest">
      <config host="localhost" port="8888" protocol="http" basepath="default/authoring">
        <header name="Accept-Language" value="en"/>
      </config>
      <steps>
        <!-- login as lenya -->
        <invoke url="index.html" />
        <setInputField name="username" value="lenya"/>
        <setInputField name="password" value="levi"/>
        <clickButton name="submit"/>
        <verifyElementText type="span" name="workflow-state" text="authoring"/>
        
        <invoke url="index.html?lenya.usecase=workflow.multiWorkflow"/>
        <verifyElementText type="h1" text="Workflow Overview"/>
      </steps>
    </webtest>
  </target>
  
</project>