Skip to content

Package: BasicSteps

BasicSteps

nameinstructionbranchcomplexitylinemethod
BasicSteps(StepData)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
anAssertionErrorWasThrown()
M: 38 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
checkAsyncCountResult(Long)
M: 15 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
checkBoolResult(String)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
checkCountResult(Long)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
checkIntResult(int)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
checkStringResult(String)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
checkWaitMultipier()
M: 10 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
doNothing()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
exceptionCaught()
M: 38 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
iExpectTheAssertErrorWithTheText(String, String)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
iExpectTheException(String)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
noAssertionErrorWasThrown()
M: 18 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
noExceptionCaught()
M: 18 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
secondsPassed(int)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setCustomDate(String)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
setCustomText(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setExpectedExceptionDetails(String, String)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
setHostPort(String, String)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setNullScope()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setNullUser()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setRootScope()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setRootUserId()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setSpecificScopeId(Integer)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setSpecificUserId(Integer)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setSystemProperty(String, String)
M: 13 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
waitSeconds(int)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
waitingMilliseconds(int)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017, 2020 Red Hat Inc and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License v1.0
6: * which accompanies this distribution, and is available at
7: * http://www.eclipse.org/legal/epl-v10.html
8: *
9: * Contributors:
10: * Red Hat Inc - initial API and implementation
11: *******************************************************************************/
12: package org.eclipse.kapua.qa.common;
13:
14: import cucumber.api.java.Before;
15: import cucumber.api.java.en.And;
16: import cucumber.api.java.en.Given;
17: import cucumber.api.java.en.Then;
18: import cucumber.api.java.en.When;
19: import cucumber.runtime.java.guice.ScenarioScoped;
20: import org.eclipse.kapua.commons.util.KapuaDateUtils;
21: import org.slf4j.Logger;
22: import org.slf4j.LoggerFactory;
23:
24: import javax.inject.Inject;
25: import java.time.Duration;
26: import java.util.Date;
27:
28: @ScenarioScoped
29: public class BasicSteps extends TestBase {
30:
31: private static final Logger logger = LoggerFactory.getLogger(BasicSteps.class);
32:
33: private static final double WAIT_MULTIPLIER = Double.parseDouble(System.getProperty("org.eclipse.kapua.qa.waitMultiplier", "1.0"));
34:
35: private static final String LAST_ACCOUNT_ID = "LastAccountId";
36: private static final String LAST_USER_ID = "LastUserId";
37: private static final String EXCEPTION_NAME = "ExceptionName";
38: private static final String EXCEPTION_CAUGHT = "ExceptionCaught";
39: private static final String ASSERT_ERROR_NAME = "AssertErrorName";
40: private static final String ASSERT_ERROR_CAUGHT = "AssertErrorCaught";
41:
42: /**
43: * Scenario scoped step data.
44: */
45: private StepData stepData;
46:
47: @Inject
48: public BasicSteps(StepData stepData) {
49: this.stepData = stepData;
50: }
51:
52: @Before
53: public void checkWaitMultipier() {
54:• if (WAIT_MULTIPLIER != 1.0d) {
55: logger.info("Wait multiplier active: {}", WAIT_MULTIPLIER);
56: }
57: }
58:
59: @Given("A placeholder step")
60: public void doNothing() {
61:
62: // An empty placeholder step. Just a breakpoint anchor point. Used to pause
63: // test execution by placing a breakpoint into.
64: Integer a = 10;
65: }
66:
67: @Given("^Scope with ID (\\d+)$")
68: public void setSpecificScopeId(Integer id) {
69:
70: stepData.put(LAST_ACCOUNT_ID, getKapuaId(id));
71: }
72:
73: @Given("^The KAPUA-SYS scope$")
74: public void setRootScope() {
75:
76: stepData.put(LAST_ACCOUNT_ID, SYS_SCOPE_ID);
77: }
78:
79: @Given("^A null scope$")
80: public void setNullScope() {
81:
82: stepData.put(LAST_ACCOUNT_ID, null);
83: }
84:
85: @Given("^The User ID (\\d+)$")
86: public void setSpecificUserId(Integer id) {
87:
88: stepData.put(LAST_USER_ID, getKapuaId(id));
89: }
90:
91: @Given("^The KAPUA-SYS user$")
92: public void setRootUserId() {
93:
94: stepData.put(LAST_USER_ID, SYS_USER_ID);
95: }
96:
97: @Given("^A null user")
98: public void setNullUser() {
99:
100: stepData.put(LAST_USER_ID, null);
101: }
102:
103: @Given("^Server with host \"(.+)\" on port \"(.+)\"$")
104: public void setHostPort(String host, String port) {
105: stepData.put("host", host);
106: stepData.put("port", port);
107: }
108:
109: @Given("^I expect the exception \"(.+)\" with the text \"(.+)\"$")
110: public void setExpectedExceptionDetails(String name, String text) {
111: stepData.put("ExceptionExpected", true);
112: stepData.put(EXCEPTION_NAME, name);
113: stepData.put("ExceptionMessage", text);
114: }
115:
116: @When("^I wait (\\d+) seconds?$")
117: public void waitSeconds(int seconds) throws InterruptedException {
118: double effectiveSeconds = ((double) seconds) * WAIT_MULTIPLIER;
119: Thread.sleep(Duration.ofSeconds((long) Math.ceil(effectiveSeconds)).toMillis());
120: }
121:
122: @When("(\\d+) seconds?.* passed")
123: public void secondsPassed(int seconds) throws InterruptedException {
124: waitSeconds(seconds);
125: }
126:
127: @Then("^An exception was thrown$")
128: public void exceptionCaught() {
129:• String exName = stepData.contains(EXCEPTION_NAME) ? (String)stepData.get(EXCEPTION_NAME) : "Unknown";
130:• boolean exCaught = stepData.contains(EXCEPTION_CAUGHT) ? (boolean) stepData.get(EXCEPTION_CAUGHT) : false;
131: assertTrue(String.format("Exception %s was expected but was not raised.", exName), exCaught);
132: }
133:
134: @Then("^No exception was thrown$")
135: public void noExceptionCaught() {
136:• boolean exCaught = stepData.contains(EXCEPTION_CAUGHT) ? (boolean) stepData.get(EXCEPTION_CAUGHT) : false;
137: assertFalse("An unexpected exception was raised!", exCaught);
138: }
139:
140: @Then("^I count (\\d+)$")
141: public void checkCountResult(Long num) {
142: assertEquals(num, stepData.get("Count"));
143: }
144:
145: @Then("^I count (\\d+) or more$")
146: public void checkAsyncCountResult(Long num) {
147:• assertTrue((Long) stepData.get("Count") >= num);
148: }
149:
150: @Then("^I get the integer (\\d+)$")
151: public void checkIntResult(int num) {
152: assertEquals(num, (int) stepData.get("IntValue"));
153: }
154:
155: @Then("^I get the boolean \"(.+)\"$")
156: public void checkBoolResult(String val) {
157: assertEquals(Boolean.valueOf(val), stepData.get("BoolValue"));
158: }
159:
160: @Given("^The text \"(.+)\"$")
161: public void setCustomText(String text) {
162: stepData.put("Text", text);
163: }
164:
165: @Then("^I get the text \"(.+)\"$")
166: public void checkStringResult(String text) {
167: assertEquals(text, stepData.get("Text"));
168: }
169:
170: @Given("^The date \"(.+)\"$")
171: public void setCustomDate(String dateString) throws Exception {
172:
173: primeException();
174: try {
175: Date date = KapuaDateUtils.parseDate(dateString);
176: stepData.put("Date", date);
177: } catch(Exception ex) {
178: verifyException(ex);
179: }
180: }
181:
182: @Given("^System property \"(.*)\" with value \"(.*)\"$")
183: public void setSystemProperty(String key, String value) {
184:• if ("null".equalsIgnoreCase(value)) {
185: System.clearProperty(key);
186: } else {
187: System.setProperty(key, value);
188: }
189: }
190:
191: @And("^I expect the exception \"([^\"]*)\"$")
192: public void iExpectTheException(String name) {
193: stepData.put("ExceptionExpected", true);
194: stepData.put(EXCEPTION_NAME, name);
195: }
196:
197: @Then("^An assertion error was thrown$")
198: public void anAssertionErrorWasThrown() {
199:• String assertErrorName = stepData.contains(ASSERT_ERROR_NAME) ? (String) stepData.get(ASSERT_ERROR_NAME) : "Unknown";
200:• boolean assertErrorCaught = stepData.contains(ASSERT_ERROR_CAUGHT) ? (boolean) stepData.get(ASSERT_ERROR_CAUGHT) : false;
201: assertTrue(String.format("Assert error was expected but was not raised.", assertErrorName), assertErrorCaught);
202: }
203:
204: @And("^I expect the assertion error \"([^\"]*)\" with the text \"([^\"]*)\"$")
205: public void iExpectTheAssertErrorWithTheText(String name, String text) {
206: stepData.put("AssertErrorExpected", true);
207: stepData.put(ASSERT_ERROR_NAME, name);
208: stepData.put("AssertErrorMessage", text);
209: }
210:
211: @And("^No assertion error was thrown$")
212: public void noAssertionErrorWasThrown() {
213:• boolean assertErrorCaught = stepData.contains(ASSERT_ERROR_CAUGHT) ? (boolean) stepData.get(ASSERT_ERROR_CAUGHT) : false;
214: assertFalse("An unexpected assert error was raised!", assertErrorCaught);
215: }
216:
217: @And("^I wait for (\\d+) millisecond(?:|s) for processes to settle down$")
218: public void waitingMilliseconds(int milliseconds) throws InterruptedException {
219: Thread.sleep(milliseconds);
220: }
221: }