Skip to content

Commit 05cebbb

Browse files
author
Denisa Dan
committed
Modified PR after the request changes and added tests
Signed-off-by: Denisa Dan <[email protected]>
1 parent 67e7ccb commit 05cebbb

File tree

6 files changed

+290
-164
lines changed

6 files changed

+290
-164
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
# (c) Copyright 2017 Hewlett-Packard Enterprise Development Company, L.P.
2-
# All rights reserved. This program and the accompanying materials
3-
# are made available under the terms of the Apache License v2.0 which accompany this distribution.
4-
#
5-
# The Apache License is available at
6-
# http://www.apache.org/licenses/LICENSE-2.0
7-
#
8-
########################################################################################################################
9-
#!!
10-
#! @description: Decision that checks the state of a System Property file.
11-
#!
12-
#! @result CONTAINS: System Property is set at default value.
13-
#! @result DOES_NOT_CONTAIN: System Property is not set at default value.
14-
#!!#
15-
########################################################################################################################
16-
17-
namespace: io.cloudslang.base.examples.yoda
18-
19-
decision:
20-
name: contains
21-
22-
results:
23-
- CONTAINS: ${get_sp('io.cloudslang.base.examples.properties.default_quote', 'false') == 'true'}
24-
- DOES_NOT_CONTAIN
1+
# (c) Copyright 2017 Hewlett-Packard Enterprise Development Company, L.P.
2+
# All rights reserved. This program and the accompanying materials
3+
# are made available under the terms of the Apache License v2.0 which accompany this distribution.
4+
#
5+
# The Apache License is available at
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
########################################################################################################################
9+
# System property file for base.examples.yoda operations.
10+
#
11+
# io.cloudslang.base.examples.properties.default_quote: value of default quote
12+
#
13+
########################################################################################################################
14+
15+
namespace: io.cloudslang.base.examples.yoda
16+
17+
properties:
18+
- default_quote: 'false'
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
# (c) Copyright 2017 Hewlett-Packard Enterprise Development Company, L.P.
2-
# All rights reserved. This program and the accompanying materials
3-
# are made available under the terms of the Apache License v2.0 which accompany this distribution.
4-
#
5-
# The Apache License is available at
6-
# http://www.apache.org/licenses/LICENSE-2.0
7-
#
8-
########################################################################################################################
9-
# System property file for base.examples.yoda operations.
10-
#
11-
# io.cloudslang.base.examples.properties.default_quote: value of default quote
12-
#
13-
########################################################################################################################
14-
15-
namespace: io.cloudslang.base.examples.properties
16-
17-
properties:
18-
- default_quote: 'true'
1+
# (c) Copyright 2017 Hewlett-Packard Enterprise Development Company, L.P.
2+
# All rights reserved. This program and the accompanying materials
3+
# are made available under the terms of the Apache License v2.0 which accompany this distribution.
4+
#
5+
# The Apache License is available at
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
########################################################################################################################
9+
# System property file for base.examples.yoda operations.
10+
#
11+
# io.cloudslang.base.examples.properties.default_quote: value of default quote
12+
#
13+
########################################################################################################################
14+
15+
namespace: io.cloudslang.base.examples.yoda
16+
17+
properties:
18+
- default_quote: 'true'
Lines changed: 72 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,72 @@
1-
# (c) Copyright 2017 Hewlett-Packard Enterprise Development Company, L.P.
2-
# All rights reserved. This program and the accompanying materials
3-
# are made available under the terms of the Apache License v2.0 which accompany this distribution.
4-
#
5-
# The Apache License is available at
6-
# http://www.apache.org/licenses/LICENSE-2.0
7-
########################################################################################################################
8-
#!!
9-
#! @description: The flow displays a Yoda quote based on a random number generator.
10-
#!
11-
#! @input file_path: The path for the file that contains the quotes.
12-
#!
13-
#! @result SUCCESS: The quote was displayed successfully.
14-
#! @result FAILURE: Failure occurred during execution.
15-
#!!#
16-
########################################################################################################################
17-
18-
namespace: io.cloudslang.base.examples.yoda
19-
20-
imports:
21-
math: io.cloudslang.base.math
22-
base: io.cloudslang.base.print
23-
fs: io.cloudslang.base.filesystem
24-
25-
flow:
26-
name: generate_random_quote
27-
28-
inputs:
29-
- file_path
30-
31-
workflow:
32-
- read_quotes:
33-
do:
34-
fs.read_from_file:
35-
- file_path: ${file_path}
36-
publish:
37-
- read_text
38-
navigate:
39-
- SUCCESS: generate_random_number
40-
- FAILURE: FAILURE
41-
42-
- generate_random_number:
43-
do:
44-
math.random_number_generator:
45-
- min: '0'
46-
- max: ${str(len(read_text.strip().split(';')) - 2)}
47-
publish:
48-
- random_number
49-
navigate:
50-
- SUCCESS: print_quote
51-
- FAILURE: FAILURE
52-
53-
- print_quote:
54-
do:
55-
base.print_text:
56-
- text: ${str(read_text.split(';')[int(random_number)])}
57-
navigate:
58-
- SUCCESS: SUCCESS
59-
results:
60-
- SUCCESS
61-
- FAILURE
1+
# (c) Copyright 2017 Hewlett-Packard Enterprise Development Company, L.P.
2+
# All rights reserved. This program and the accompanying materials
3+
# are made available under the terms of the Apache License v2.0 which accompany this distribution.
4+
#
5+
# The Apache License is available at
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
########################################################################################################################
8+
#!!
9+
#! @description: The flow displays a Yoda quote based on a random number generator.
10+
#!
11+
#! @input file_path: The path for the file that contains the quotes.
12+
#!
13+
#! @output quotes: A list with all the quotes from the file.
14+
#! @output random_quote: The quote randomly selected.
15+
#!
16+
#! @result SUCCESS: The quote was displayed successfully.
17+
#! @result FAILURE: Failure occurred during execution.
18+
#!!#
19+
########################################################################################################################
20+
21+
namespace: io.cloudslang.base.examples.yoda
22+
23+
imports:
24+
math: io.cloudslang.base.math
25+
base: io.cloudslang.base.print
26+
fs: io.cloudslang.base.filesystem
27+
28+
flow:
29+
name: generate_random_quote
30+
31+
inputs:
32+
- file_path
33+
34+
workflow:
35+
- read_quotes:
36+
do:
37+
fs.read_from_file:
38+
- file_path: ${file_path}
39+
publish:
40+
- read_text
41+
- quotes : ${str(read_text)}
42+
navigate:
43+
- SUCCESS: generate_random_number
44+
- FAILURE: FAILURE
45+
46+
- generate_random_number:
47+
do:
48+
math.random_number_generator:
49+
- min: '0'
50+
- max: ${str(len(quotes.strip().split(';')) - 2)}
51+
- quotes
52+
publish:
53+
- random_number
54+
- random_quote: ${str(quotes.split(';')[int(random_number)])}
55+
navigate:
56+
- SUCCESS: print_quote
57+
- FAILURE: FAILURE
58+
59+
- print_quote:
60+
do:
61+
base.print_text:
62+
- text: ${str(random_quote)}
63+
navigate:
64+
- SUCCESS: SUCCESS
65+
66+
outputs:
67+
- quotes
68+
- random_quote
69+
70+
results:
71+
- SUCCESS
72+
- FAILURE
Lines changed: 63 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,64 @@
1-
# (c) Copyright 2017 Hewlett-Packard Enterprise Development Company, L.P.
2-
# All rights reserved. This program and the accompanying materials
3-
# are made available under the terms of the Apache License v2.0 which accompany this distribution.
4-
#
5-
# The Apache License is available at
6-
# http://www.apache.org/licenses/LICENSE-2.0
7-
#
8-
########################################################################################################################
9-
#!!
10-
#! @description: The flow is based on a System Property file
11-
#! If it is set on true it displays the default quote, otherwise generates a random quote.
12-
#!
13-
#! @input default_quote : quote with a default value.
14-
#! @input file_path: The path for the file that contains the quotes.
15-
#!
16-
#! @result SUCCESS: Flow completed successfully.
17-
#! @result FAILURE: Failure occurred during execution.
18-
#!!#
19-
########################################################################################################################
20-
21-
namespace: io.cloudslang.base.examples.yoda
22-
23-
imports:
24-
base: io.cloudslang.base.print
25-
fs: io.cloudslang.base.filesystem
26-
math: io.cloudslang.base.math
27-
quote_generator: io.cloudslang.base.examples.yoda
28-
29-
flow:
30-
name: quote_check
31-
32-
inputs:
33-
- default_quote:
34-
default: "Do or do not, there is no try!"
35-
private: true
36-
- file_path
37-
38-
workflow:
39-
- print_quote:
40-
do:
41-
quote_generator.contains: []
42-
navigate:
43-
- CONTAINS: print_default_quote
44-
- DOES_NOT_CONTAIN: print_random_quote
45-
46-
- print_random_quote:
47-
do:
48-
quote_generator.generate_random_quote:
49-
- file_path
50-
navigate:
51-
- SUCCESS: SUCCESS
52-
- FAILURE: FAILURE
53-
54-
- print_default_quote:
55-
do:
56-
base.print_text:
57-
- text: ${default_quote}
58-
navigate:
59-
- SUCCESS: SUCCESS
60-
results:
61-
- SUCCESS
1+
# (c) Copyright 2017 Hewlett-Packard Enterprise Development Company, L.P.
2+
# All rights reserved. This program and the accompanying materials
3+
# are made available under the terms of the Apache License v2.0 which accompany this distribution.
4+
#
5+
# The Apache License is available at
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
########################################################################################################################
9+
#!!
10+
#! @description: The flow is based on a System Property file.
11+
#! If it is set on true it displays the default quote, otherwise generates a random quote.
12+
#!
13+
#! @input default_quote : quote with a default value.
14+
#! @input file_path: The path for the file that contains the quotes.
15+
#!
16+
#! @result SUCCESS: Flow completed successfully.
17+
#! @result FAILURE: Failure occurred during execution.
18+
#!!#
19+
########################################################################################################################
20+
21+
namespace: io.cloudslang.base.examples.yoda
22+
23+
imports:
24+
base: io.cloudslang.base.print
25+
fs: io.cloudslang.base.filesystem
26+
math: io.cloudslang.base.math
27+
quote_generator: io.cloudslang.base.examples.yoda
28+
utils: io.cloudslang.base.utils
29+
30+
flow:
31+
name: quote_check
32+
33+
inputs:
34+
- default_quote:
35+
default: "Do or do not, there is no try!"
36+
private: true
37+
- file_path
38+
39+
workflow:
40+
- print_quote:
41+
do:
42+
utils.is_true:
43+
- bool_value: ${str(get_sp('io.cloudslang.base.examples.yoda.default_quote', 'false'))}
44+
navigate:
45+
- 'TRUE': print_default_quote
46+
- 'FALSE': print_random_quote
47+
48+
- print_random_quote:
49+
do:
50+
quote_generator.generate_random_quote:
51+
- file_path
52+
navigate:
53+
- SUCCESS: SUCCESS
54+
- FAILURE: FAILURE
55+
56+
- print_default_quote:
57+
do:
58+
base.print_text:
59+
- text: ${default_quote}
60+
navigate:
61+
- SUCCESS: SUCCESS
62+
results:
63+
- SUCCESS
6264
- FAILURE
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# (c) Copyright 2014-2017 Hewlett-Packard Enterprise Development Company, L.P.
2+
# All rights reserved. This program and the accompanying materials
3+
# are made available under the terms of the Apache License v2.0 which accompany this distribution.
4+
#
5+
# The Apache License is available at
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
########################################################################################################################
9+
test_quote_check_sp_true:
10+
description: Tests that quote_check finishes with SUCCESS for the default case
11+
testSuites: [yoda]
12+
testFlowPath: test.io.cloudslang.base.examples.test_quote_check
13+
systemPropertiesFile: ${project_path}/configuration/properties/io/cloudslang/base/examples/yoda/samples_true.prop.sl
14+
inputs:
15+
- file_path: ${project_path}/resources/base/examples/yoda/yoda_quotes.txt
16+
result: SUCCESS_PRINTING_DEFAULT
17+
18+
test_quote_check_sp_false:
19+
description: Tests that quote_check returns a random quote when the properties file is set on false
20+
testSuites: [yoda]
21+
testFlowPath: test.io.cloudslang.base.examples.test_quote_check
22+
systemPropertiesFile: ${project_path}/configuration/properties/io/cloudslang/base/examples/yoda/samples_false.prop.sl
23+
inputs:
24+
- file_path: ${project_path}/resources/base/examples/yoda/yoda_quotes.txt
25+
result: QUOTE_EXISTS
26+
27+
test_quote_check_sp_not_specified:
28+
description: Tests that quote_check returns a random quote when the properties file is not specified
29+
testSuites: [yoda]
30+
testFlowPath: test.io.cloudslang.base.examples.test_quote_check
31+
inputs:
32+
- file_path: ${project_path}/resources/base/examples/yoda/yoda_quotes.txt
33+
result: QUOTE_EXISTS

0 commit comments

Comments
 (0)