#
#  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.
#

# Paths on which ACLs will be set
create path /acltest/A/B

# Path on which node properties will be set
create path /proptest/X/Y(nt:unstructured)

# Service users and ACLs for our integration tests
create service user fredWilmaService
create service user anotherService

# ACLs for those service users
set ACL for fredWilmaService
  allow jcr:all on /acltest
  deny jcr:write on /acltest/A
end

set ACL for fredWilmaService
  allow jcr:write on /acltest/A/B
end

set ACL on /acltest
  allow jcr:all for anotherService
end

set ACL on /acltest/A/B
  deny jcr:write for anotherService
end

register nodetypes
<<===
<< <slingtest='http://sling.apache.org/ns/test/repoinit-it/v1.0'>
<< [slingtest:unstructured] > nt:unstructured
===>>

# SLING-8757 home() functions
create user alice
create user bob

set ACL on home(fredWilmaService)
  allow jcr:all for alice
  deny jcr:all for bob
end

create group grpA
add fredWilmaService,alice to group grpA

create group grpB
add anotherService,bob,grpA to group grpB
remove bob,grpA from group grpB

create group grpC
add grpA, bob, grpB to group grpC

set properties on /proptest/X/Y
  set pathArray to /d/e/f/*, m/n/*
  default someInteger{Long} to 42
  set someFlag{Boolean} to true
  default someDate{Date} to "2020-03-19T11:39:33.437+05:30"
  set customSingleValueStringProp to test
  set customSingleValueQuotedStringProp to "hello, you!"
  set stringArray to test1, test2
  default someInteger{Long} to 65
  set quotedA to "Here's a \"double quoted string\" with suffix"
  set quotedMix to "quoted", non-quoted, "the last \" one"
end

# SLING-10192 set properties on user or group profile
set properties on authorizable(alice),authorizable(grpA)
  set pathArray to /d/e/f/*, m/n/*
  default someInteger{Long} to 42
  set someFlag{Boolean} to true
  default someDate{Date} to "2020-03-19T11:39:33.437+05:30"
  set customSingleValueStringProp to test
  set customSingleValueQuotedStringProp to "hello, you!"
  set stringArray to test1, test2
  default someInteger{Long} to 65
  set quotedA to "Here's a \"double quoted string\" with suffix"
  set quotedMix to "quoted", non-quoted, "the last \" one"
  set nested/someInteger{Long} to 42
end

# SLING-10192 set properties on a subtree of the user or group profile
set properties on authorizable(bob)/nested,authorizable(grpB)/nested
  set pathArray to /d/e/f/*, m/n/*
  default someInteger{Long} to 42
  set someFlag{Boolean} to true
  default someDate{Date} to "2020-03-19T11:39:33.437+05:30"
  set customSingleValueStringProp to test
  set customSingleValueQuotedStringProp to "hello, you!"
  set stringArray to test1, test2
  default someInteger{Long} to 65
  set quotedA to "Here's a \"double quoted string\" with suffix"
  set quotedMix to "quoted", non-quoted, "the last \" one"
  set nested/someInteger{Long} to 42
end

ensure nodes (nt:unstructured) /forcedMultiValue with properties
  set multiValue{String[]} to "item1","item2"
  set singleMultiValue{String[]} to "single"
  set emptyMultiValue{String[]} to
  set longMultiValue{Long[]} to 1243,5678
  set singleLongMultiValue{Long[]} to 1243
  set emptyLongMultiValue{Long[]} to
end
