Skip to content

Package: EndpointServiceSteps

EndpointServiceSteps

nameinstructionbranchcomplexitylinemethod
EndpointServiceSteps(StepData, DBHelper)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
afterScenario()
M: 26 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
beforeScenario(Scenario)
M: 43 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
editEndpointSchema(String)
M: 28 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
foundEndpointBySchema(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%
foundEndpointBySchemaDomainPort(String, String, int)
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%
foundEndpointBySchemaDomainPortSection(String, String, int, String)
M: 113 C: 0
0%
M: 18 C: 0
0%
M: 10 C: 0
0%
M: 29 C: 0
0%
M: 1 C: 0
0%
iCreateCORSFilter(String, String, int)
M: 31 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
iCreateEndpointWithDnsAndPort(String, int)
M: 33 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
iCreateEndpointWithDomainWithoutSchemaAndPort(String)
M: 30 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
iCreateEndpointWithNullParameters()
M: 36 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
iCreateEndpointWithPortWithoutSchemaAndDomain(int)
M: 30 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
iCreateEndpointWithSchemaAndDomainWithoutPort(String, String)
M: 33 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
iCreateEndpointWithSchemaAndPortWithoutDomain(String, int)
M: 36 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
iCreateEndpointWithSchemaDnsAndPort(String, String, int)
M: 40 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
iCreateEndpointWithSchemaDomainPortAndSecureField(String, String, int, String)
M: 47 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
iCreateEndpointWithSchemaOnly(String)
M: 30 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
iCreateMultipleCORSFilter(DataTable)
M: 28 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
iDeleteAllCORSFilters()
M: 39 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
iDeleteEndpointWithSchema(String)
M: 35 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
iDeleteEndpointWithSchema(String, String, int)
M: 49 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
iDeleteEndpointWithSchemaDomainAndPort(String, String, int)
M: 56 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
iDeleteEndpointsWithSchema(String)
M: 45 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
iDeleteTheLastCreatedEndpoint()
M: 18 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
iEditEndpointSchema(String)
M: 26 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
iEditLastCreatedEndpointDomainNameTo(String)
M: 26 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
iEditLastCreatedEndpointPort(int)
M: 20 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
iEditLastCreatedEndpointPortInEndpoint(int, String, String, int)
M: 50 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
iEditLastCreatedEndpointSecureField(String)
M: 28 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
iFindEndpoint(int)
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
iFoundEndpoint(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%
iFoundEndpointWithSchemaDomainAndPort(String, String, int)
M: 21 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
iHaveCORSFilter(int)
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
iSearchForAllEndpoints()
M: 27 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
iTryToCreateInvalidEndpoint()
M: 61 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%
notFoundEndpointWithSchema(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%
static {...}
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2019, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.service.endpoint.steps;
14:
15: import cucumber.api.DataTable;
16: import cucumber.api.Scenario;
17: import cucumber.api.java.After;
18: import cucumber.api.java.Before;
19: import cucumber.api.java.en.And;
20: import cucumber.api.java.en.Then;
21: import cucumber.api.java.en.When;
22: import cucumber.runtime.java.guice.ScenarioScoped;
23: import org.apache.shiro.SecurityUtils;
24: import org.eclipse.kapua.KapuaException;
25: import org.eclipse.kapua.KapuaIllegalNullArgumentException;
26: import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
27: import org.eclipse.kapua.commons.security.KapuaSession;
28: import org.eclipse.kapua.commons.util.xml.XmlUtil;
29: import org.eclipse.kapua.locator.KapuaLocator;
30: import org.eclipse.kapua.model.query.predicate.AndPredicate;
31: import org.eclipse.kapua.model.query.predicate.AttributePredicate;
32: import org.eclipse.kapua.qa.common.DBHelper;
33: import org.eclipse.kapua.qa.common.StepData;
34: import org.eclipse.kapua.qa.common.TestBase;
35: import org.eclipse.kapua.qa.common.TestJAXBContextProvider;
36: import org.eclipse.kapua.service.endpoint.EndpointInfo;
37: import org.eclipse.kapua.service.endpoint.EndpointInfoAttributes;
38: import org.eclipse.kapua.service.endpoint.EndpointInfoCreator;
39: import org.eclipse.kapua.service.endpoint.EndpointInfoFactory;
40: import org.eclipse.kapua.service.endpoint.EndpointInfoListResult;
41: import org.eclipse.kapua.service.endpoint.EndpointInfoQuery;
42: import org.eclipse.kapua.service.endpoint.EndpointInfoService;
43: import org.slf4j.Logger;
44: import org.slf4j.LoggerFactory;
45:
46: import javax.inject.Inject;
47: import java.util.List;
48: import java.util.concurrent.Callable;
49:
50:
51: @ScenarioScoped
52: public class EndpointServiceSteps extends TestBase {
53:
54: private EndpointInfoService endpointInfoService;
55: private EndpointInfoFactory endpointInfoFactory;
56:
57: // ****************************************************************************************
58: // * Implementation of Gherkin steps used in JobService.feature scenarios. *
59: // * *
60: // * MockedLocator is used for Location Service. Mockito is used to mock other *
61: // * services that the Account services dependent on. Dependent services are: *
62: // * - Authorization Service *
63: // ****************************************************************************************
64:
65: private static final String ENDPOINT_INFO = "EndpointInfo";
66:
67: private static final Logger LOGGER = LoggerFactory.getLogger(EndpointServiceSteps.class);
68:
69: // Default constructor
70: @Inject
71: public EndpointServiceSteps(StepData stepData, DBHelper dbHelper) {
72:
73: this.stepData = stepData;
74: this.database = dbHelper;
75: }
76:
77: // ************************************************************************************
78: // ************************************************************************************
79: // * Definition of Cucumber scenario steps *
80: // ************************************************************************************
81: // ************************************************************************************
82:
83: // ************************************************************************************
84: // * Setup and tear-down steps *
85: // ************************************************************************************
86:
87: @Before
88: public void beforeScenario(Scenario scenario) {
89:
90: this.scenario = scenario;
91: database.setup();
92: stepData.clear();
93:
94: locator = KapuaLocator.getInstance();
95: endpointInfoService = locator.getService(EndpointInfoService.class);
96: endpointInfoFactory = locator.getFactory(EndpointInfoFactory.class);
97:
98:• if (isUnitTest()) {
99: // Create KapuaSession using KapuaSecurtiyUtils and kapua-sys user as logged in user.
100: // All operations on database are performed using system user.
101: // Only for unit tests. Integration tests assume that a real logon is performed.
102: KapuaSession kapuaSession = new KapuaSession(null, SYS_SCOPE_ID, SYS_USER_ID);
103: KapuaSecurityUtils.setSession(kapuaSession);
104: }
105:
106: // Setup JAXB context
107: XmlUtil.setContextProvider(new TestJAXBContextProvider());
108: }
109:
110: @After
111: public void afterScenario() {
112:
113: // ************************************************************************************
114: // * Clean up the database *
115: // ************************************************************************************
116: try {
117: LOGGER.info("Logging out in cleanup");
118:• if (isIntegrationTest()) {
119: database.deleteAll();
120: SecurityUtils.getSubject().logout();
121: } else {
122: database.dropAll();
123: database.close();
124: }
125: KapuaSecurityUtils.clearSession();
126: } catch (Exception e) {
127: LOGGER.error("Failed to log out in @After", e);
128: }
129: }
130:
131: // ************************************************************************************
132: // * The Cucumber test steps *
133: // ************************************************************************************
134:
135: @And("^I create endpoint with schema \"([^\"]*)\", domain \"([^\"]*)\" and port (\\d+)$")
136: public void iCreateEndpointWithSchemaDnsAndPort(String schema, String dns, int port) throws Exception {
137: EndpointInfoCreator endpointInfoCreator = endpointInfoFactory.newCreator(getCurrentScopeId());
138: endpointInfoCreator.setSchema(schema);
139: endpointInfoCreator.setDns(dns);
140: endpointInfoCreator.setPort(port);
141: endpointInfoCreator.setEndpointType(EndpointInfo.ENDPOINT_TYPE_RESOURCE);
142: try {
143: stepData.remove(ENDPOINT_INFO);
144: EndpointInfo endpointInfo = endpointInfoService.create(endpointInfoCreator);
145: stepData.put(ENDPOINT_INFO, endpointInfo);
146: } catch (KapuaException ex) {
147: verifyException(ex);
148: }
149: }
150:
151: @And("^I try to create endpoint with invalid symbols in schema$")
152: public void iTryToCreateInvalidEndpoint() throws Exception {
153: String invalidSymbols = "!\"#$%&'()=Ȃ" +
154: ">:;<-.,⁄@‹›€" +
155: "*ı–°·‚_±Œ„‰" +
156: "?“‘”’ÉØ∏{}|Æ" +
157: "æÒ\uF8FFÔÓÌÏÎÍÅ«" +
158: "◊ш¯Èˇ¿";
159:• for (int i = 0; i < invalidSymbols.length(); i++) {
160: EndpointInfoCreator endpointInfoCreator = endpointInfoFactory.newCreator(getCurrentScopeId());
161: String schema = invalidSymbols + invalidSymbols.charAt(i);
162: endpointInfoCreator.setSchema(schema);
163: endpointInfoCreator.setDns("dns.com");
164: endpointInfoCreator.setPort(2222);
165: endpointInfoCreator.setEndpointType(EndpointInfo.ENDPOINT_TYPE_RESOURCE);
166: try {
167: stepData.remove("EndpointInfo");
168: EndpointInfo endpointInfo = endpointInfoService.create(endpointInfoCreator);
169: stepData.put("EndpointInfo", endpointInfo);
170: } catch (KapuaException ex) {
171: verifyException(ex);
172: }
173: }
174: }
175:
176: @And("^I create endpoint with domain name \"([^\"]*)\" and port (\\d+) without schema$")
177: public void iCreateEndpointWithDnsAndPort(String dns, int port) throws Exception {
178: EndpointInfoCreator endpointInfoCreator = endpointInfoFactory.newCreator(getCurrentScopeId());
179: endpointInfoCreator.setDns(dns);
180: endpointInfoCreator.setPort(port);
181: endpointInfoCreator.setEndpointType(EndpointInfo.ENDPOINT_TYPE_RESOURCE);
182: try {
183: EndpointInfo endpointInfo = endpointInfoService.create(endpointInfoCreator);
184: stepData.put("EndpointInfo", endpointInfo);
185: } catch (KapuaIllegalNullArgumentException ex) {
186: verifyException(ex);
187: }
188: }
189:
190: @And("^I create endpoint with schema \"([^\"]*)\" without domain name and port$")
191: public void iCreateEndpointWithSchemaOnly(String schema) throws Exception {
192: EndpointInfoCreator endpointInfoCreator = endpointInfoFactory.newCreator(getCurrentScopeId());
193: endpointInfoCreator.setSchema(schema);
194: endpointInfoCreator.setEndpointType(EndpointInfo.ENDPOINT_TYPE_RESOURCE);
195: try {
196: EndpointInfo endpointInfo = endpointInfoService.create(endpointInfoCreator);
197: stepData.put("EndpointInfo", endpointInfo);
198: } catch (KapuaIllegalNullArgumentException ex) {
199: verifyException(ex);
200: }
201: }
202:
203: @And("^I create endpoint with NULL parameters$")
204: public void iCreateEndpointWithNullParameters() throws Exception {
205: EndpointInfoCreator endpointInfoCreator = endpointInfoFactory.newCreator(getCurrentScopeId());
206: endpointInfoCreator.setSchema(null);
207: endpointInfoCreator.setDns(null);
208: endpointInfoCreator.setPort(0);
209: endpointInfoCreator.setEndpointType(EndpointInfo.ENDPOINT_TYPE_RESOURCE);
210: try {
211: EndpointInfo endpointInfo = endpointInfoService.create(endpointInfoCreator);
212: stepData.put("EndpointInfo", endpointInfo);
213: } catch (KapuaIllegalNullArgumentException ex) {
214: verifyException(ex);
215: }
216: }
217:
218: @When("^I delete the endpoint with schema \"([^\"]*)\", domain \"([^\"]*)\" and port (\\d+)$")
219: public void iDeleteEndpointWithSchema(String schema, String domain, int port) throws Throwable {
220: primeException();
221: try {
222: EndpointInfoQuery endpointInfoQuery = endpointInfoFactory.newQuery(getCurrentScopeId());
223: endpointInfoQuery.setPredicate(endpointInfoQuery.attributePredicate(EndpointInfoAttributes.SCHEMA, schema, AttributePredicate.Operator.EQUAL));
224: EndpointInfo endpointInfo = endpointInfoService.query(endpointInfoQuery).getFirstItem();
225: assertEquals(schema, endpointInfo.getSchema());
226: assertEquals(domain, endpointInfo.getDns());
227: assertEquals(port, endpointInfo.getPort());
228:
229: endpointInfoService.delete(SYS_SCOPE_ID, endpointInfo.getId());
230: } catch (KapuaException ex) {
231: verifyException(ex);
232: }
233: }
234:
235: @And("^I try to find endpoint with schema \"([^\"]*)\", domain \"([^\"]*)\" and port (\\d+)$")
236: public void foundEndpointBySchemaDomainPort(String schema, String domain, int port) throws Exception {
237: foundEndpointBySchemaDomainPortSection(schema, domain, port, EndpointInfo.ENDPOINT_TYPE_RESOURCE);
238: }
239:
240: @And("^I try to find endpoint with schema \"([^\"]*)\"$")
241: public void foundEndpointBySchema(String schema) throws Exception {
242: foundEndpointBySchemaDomainPortSection(schema, null, -1, EndpointInfo.ENDPOINT_TYPE_RESOURCE);
243: }
244:
245: @And("^I try to find endpoint with schema \"([^\"]*)\", domain \"([^\"]*)\" and port (\\d+)$ and section \"([^\"]*)\"$")
246: public void foundEndpointBySchemaDomainPortSection(String schema, String domain, int port, String section) throws Exception {
247: primeException();
248: try {
249: EndpointInfoQuery endpointInfoQuery = endpointInfoFactory.newQuery(getCurrentScopeId());
250: AndPredicate andPredicate = endpointInfoQuery.andPredicate();
251:
252:• if (section.equals("cors")) {
253: section = EndpointInfo.ENDPOINT_TYPE_CORS;
254: } //to simplify argument passing
255:
256:• if (schema != null) {
257: andPredicate.and(endpointInfoQuery.attributePredicate(EndpointInfoAttributes.SCHEMA, schema, AttributePredicate.Operator.EQUAL));
258: }
259:• if (section != null) {
260: andPredicate.and(endpointInfoQuery.attributePredicate(EndpointInfoAttributes.ENDPOINT_TYPE, section));
261: }
262:• if (domain != null) {
263: andPredicate.and(endpointInfoQuery.attributePredicate(EndpointInfoAttributes.DNS, domain, AttributePredicate.Operator.EQUAL));
264: }
265:• if (port != -1) {
266: andPredicate.and(endpointInfoQuery.attributePredicate(EndpointInfoAttributes.PORT, port, AttributePredicate.Operator.EQUAL));
267: }
268:
269: endpointInfoQuery.setPredicate(andPredicate);
270: EndpointInfo endpointInfo = endpointInfoService.query(endpointInfoQuery).getFirstItem();
271:
272:• if (schema != null) {
273: assertEquals(schema, endpointInfo.getSchema());
274: }
275:• if (section != null) {
276: assertEquals(section, endpointInfo.getEndpointType());
277: }
278:• if (domain != null) {
279: assertEquals(domain, endpointInfo.getDns());
280: }
281:• if (port != -1) {
282: assertEquals(port, endpointInfo.getPort());
283: }
284:
285: stepData.put(ENDPOINT_INFO, endpointInfo);
286: stepData.put("EndpointInfoId", endpointInfo.getId());
287: } catch (Exception ex) {
288: verifyException(ex);
289: }
290: }
291:
292: @And("^I try to edit endpoint schema to \"([^\"]*)\"$")
293: public void editEndpointSchema(String schema) throws Exception {
294: EndpointInfo endpointInfo = (EndpointInfo) stepData.get(ENDPOINT_INFO);
295: endpointInfo.setSchema(schema);
296: primeException();
297: try {
298: EndpointInfo newEndpoint = endpointInfoService.update(endpointInfo);
299: stepData.put(ENDPOINT_INFO, newEndpoint);
300: } catch (KapuaException ex) {
301: verifyException(ex);
302: }
303: }
304:
305: @And("^I delete endpoint with schema \"([^\"]*)\"$")
306: public void iDeleteEndpointWithSchema(String schema) throws Exception {
307: primeException();
308: try {
309: EndpointInfoQuery endpointInfoQuery = endpointInfoFactory.newQuery(getCurrentScopeId());
310: endpointInfoQuery.setPredicate(endpointInfoQuery.attributePredicate(EndpointInfoAttributes.SCHEMA, schema, AttributePredicate.Operator.EQUAL));
311: EndpointInfo endpointInfo = endpointInfoService.query(endpointInfoQuery).getFirstItem();
312: endpointInfoService.delete(SYS_SCOPE_ID, endpointInfo.getId());
313: } catch (KapuaException ex) {
314: verifyException(ex);
315: }
316: }
317:
318: @And("^I delete the last created endpoint$")
319: public void iDeleteTheLastCreatedEndpoint() throws Exception {
320: try {
321: EndpointInfo endpointInfo = (EndpointInfo) stepData.get(ENDPOINT_INFO);
322: endpointInfoService.delete(SYS_SCOPE_ID, endpointInfo.getId());
323: } catch (Exception e) {
324: verifyException(e);
325: }
326: }
327:
328: @And("^I delete endpoint with schema \"([^\"]*)\", domain \"([^\"]*)\" and port (\\d+)$")
329: public void iDeleteEndpointWithSchemaDomainAndPort(String schema, String domainName, int port) throws Exception {
330: primeException();
331: try {
332: EndpointInfoQuery endpointInfoQuery = endpointInfoFactory.newQuery(getCurrentScopeId());
333: endpointInfoQuery.setPredicate(endpointInfoQuery.attributePredicate(EndpointInfoAttributes.SCHEMA, schema, AttributePredicate.Operator.EQUAL));
334: endpointInfoQuery.setPredicate(endpointInfoQuery.attributePredicate(EndpointInfoAttributes.DNS, domainName, AttributePredicate.Operator.EQUAL));
335: endpointInfoQuery.setPredicate(endpointInfoQuery.attributePredicate(EndpointInfoAttributes.PORT, port, AttributePredicate.Operator.EQUAL));
336: EndpointInfo endpointInfo = endpointInfoService.query(endpointInfoQuery).getFirstItem();
337: endpointInfoService.delete(getCurrentScopeId(), endpointInfo.getId());
338: stepData.put("DeletedEndpointInfo", endpointInfo);
339: } catch (Exception ex) {
340: verifyException(ex);
341: }
342: }
343:
344: @And("^I search for all endpoints in current scopeId")
345: public void iSearchForAllEndpoints() throws Exception {
346: primeException();
347: try {
348: EndpointInfoQuery endpointInfoQuery = endpointInfoFactory.newQuery(getCurrentScopeId());
349: EndpointInfoListResult endpointInfo = endpointInfoService.query(endpointInfoQuery);
350: stepData.put("NumberOfEndpoints", endpointInfo.getSize());
351: } catch (Exception ex) {
352: verifyException(ex);
353: }
354: }
355:
356: @Then("^I find (\\d+) endpoints")
357: public void iFindEndpoint(int numberOfEndpoints) {
358: int foundEndpoints = (int) stepData.get("NumberOfEndpoints");
359: assertEquals(foundEndpoints, numberOfEndpoints);
360: }
361:
362: @Then("^I found endpoint with schema \"([^\"]*)\"$")
363: public void iFoundEndpoint(String endpointSchema) {
364: EndpointInfo endpointInfo = (EndpointInfo) stepData.get("EndpointInfo");
365:
366: assertEquals(endpointSchema, endpointInfo.getSchema());
367: }
368:
369: @Then("^I found endpoint with schema \"([^\"]*)\", domain \"([^\"]*)\" and port (\\d+)$")
370: public void iFoundEndpointWithSchemaDomainAndPort(String endpointSchema, String domainName, int port) {
371: EndpointInfo endpointInfo = (EndpointInfo) stepData.get("EndpointInfo");
372:
373: assertEquals(endpointSchema, endpointInfo.getSchema());
374: assertEquals(domainName, endpointInfo.getDns());
375: assertEquals(port, endpointInfo.getPort());
376: }
377:
378: @Then("^I did not find endpoint with schema \"([^\"]*)\"$")
379: public void notFoundEndpointWithSchema(String endpointSchema) {
380: EndpointInfo endpointInfo = (EndpointInfo) stepData.get("EndpointInfo");
381:
382: assertNotEquals(endpointSchema, endpointInfo.getSchema());
383: }
384:
385: @When("^I delete all endpoints with schema \"([^\"]*)\"$")
386: public void iDeleteEndpointsWithSchema(String schema) throws Throwable {
387: primeException();
388: try {
389: EndpointInfoQuery endpointInfoQuery = endpointInfoFactory.newQuery(getCurrentScopeId());
390: endpointInfoQuery.setPredicate(endpointInfoQuery.attributePredicate(EndpointInfoAttributes.SCHEMA, schema, AttributePredicate.Operator.EQUAL));
391: EndpointInfoListResult endpointsToDelete = endpointInfoService.query(endpointInfoQuery);
392:• for (int i = 0; i < endpointsToDelete.getSize(); i++) {
393: endpointInfoService.delete(getCurrentScopeId(), endpointsToDelete.getItem(i).getId());
394: }
395: } catch (KapuaException ex) {
396: verifyException(ex);
397: }
398: }
399:
400: @Then("^I edit last created endpoint Schema to \"([^\"]*)\"$")
401: public void iEditEndpointSchema(String schema) throws Throwable {
402: EndpointInfo endpointInfo = (EndpointInfo) stepData.get("EndpointInfo");
403:• if (schema.equals("NULL")) {
404: schema = null;
405: }
406: try {
407: endpointInfo.setSchema(schema);
408: endpointInfoService.update(endpointInfo);
409: } catch (Exception e) {
410: verifyException(e);
411: }
412: }
413:
414: @Then("^I edit last created endpoint Domain Name to \"([^\"]*)\"$")
415: public void iEditLastCreatedEndpointDomainNameTo(String domainName) throws Throwable {
416: EndpointInfo endpointInfo = (EndpointInfo) stepData.get("EndpointInfo");
417:• if (domainName.equals("NULL")) {
418: domainName = null;
419: }
420: try {
421: endpointInfo.setDns(domainName);
422: endpointInfoService.update(endpointInfo);
423: } catch (Exception e) {
424: verifyException(e);
425: }
426: }
427:
428: @Then("^I edit last created endpoint Port to (\\d+)$")
429: public void iEditLastCreatedEndpointPort(int port) throws Throwable {
430: EndpointInfo endpointInfo = (EndpointInfo) stepData.get("EndpointInfo");
431: try {
432: endpointInfo.setPort(port);
433: endpointInfoService.update(endpointInfo);
434: } catch (Exception e) {
435: verifyException(e);
436: }
437: }
438:
439: @Then("^I edit port number to (\\d+) in endpoint with schema \"([^\"]*)\", domain \"([^\"]*)\" and port (\\d+)$")
440: public void iEditLastCreatedEndpointPortInEndpoint(int newPort, String schema, String domainName, int port) throws Throwable {
441: try {
442: EndpointInfoQuery endpointInfoQuery = endpointInfoFactory.newQuery(getCurrentScopeId());
443: endpointInfoQuery.setPredicate(endpointInfoQuery.attributePredicate(EndpointInfoAttributes.SCHEMA, schema, AttributePredicate.Operator.EQUAL));
444: endpointInfoQuery.setPredicate(endpointInfoQuery.attributePredicate(EndpointInfoAttributes.DNS, domainName, AttributePredicate.Operator.EQUAL));
445: endpointInfoQuery.setPredicate(endpointInfoQuery.attributePredicate(EndpointInfoAttributes.PORT, port, AttributePredicate.Operator.EQUAL));
446: EndpointInfo endpointInfo = endpointInfoService.query(endpointInfoQuery).getFirstItem();
447: endpointInfo.setPort(newPort);
448: endpointInfoService.update(endpointInfo);
449: } catch (Exception e) {
450: verifyException(e);
451: }
452: }
453:
454: @And("^I create endpoint with schema \"([^\"]*)\" and port (\\d+) without domain name$")
455: public void iCreateEndpointWithSchemaAndPortWithoutDomain(String schema, int port) throws Throwable {
456: EndpointInfoCreator endpointInfoCreator = endpointInfoFactory.newCreator(getCurrentScopeId());
457: endpointInfoCreator.setSchema(schema);
458: endpointInfoCreator.setPort(port);
459: endpointInfoCreator.setDns(null);
460: endpointInfoCreator.setEndpointType(EndpointInfo.ENDPOINT_TYPE_RESOURCE);
461: try {
462: EndpointInfo endpointInfo = endpointInfoService.create(endpointInfoCreator);
463: stepData.put("EndpointInfo", endpointInfo);
464: } catch (KapuaIllegalNullArgumentException ex) {
465: verifyException(ex);
466: }
467: }
468:
469: @And("^I create endpoint with domain name \"([^\"]*)\" without schema and port$")
470: public void iCreateEndpointWithDomainWithoutSchemaAndPort(String domainName) throws Throwable {
471: EndpointInfoCreator endpointInfoCreator = endpointInfoFactory.newCreator(getCurrentScopeId());
472: endpointInfoCreator.setDns(domainName);
473: endpointInfoCreator.setEndpointType(EndpointInfo.ENDPOINT_TYPE_RESOURCE);
474: try {
475: EndpointInfo endpointInfo = endpointInfoService.create(endpointInfoCreator);
476: stepData.put("EndpointInfo", endpointInfo);
477: } catch (KapuaIllegalNullArgumentException ex) {
478: verifyException(ex);
479: }
480: }
481:
482: @And("^I create endpoint with schema \"([^\"]*)\" and domain \"([^\"]*)\" without port$")
483: public void iCreateEndpointWithSchemaAndDomainWithoutPort(String schema, String domainName) throws Throwable {
484: EndpointInfoCreator endpointInfoCreator = endpointInfoFactory.newCreator(getCurrentScopeId());
485: endpointInfoCreator.setDns(domainName);
486: endpointInfoCreator.setSchema(schema);
487: endpointInfoCreator.setEndpointType(EndpointInfo.ENDPOINT_TYPE_RESOURCE);
488: try {
489: EndpointInfo endpointInfo = endpointInfoService.create(endpointInfoCreator);
490: stepData.put("EndpointInfo", endpointInfo);
491: } catch (Exception ex) {
492: verifyException(ex);
493: }
494: }
495:
496: @And("^I create endpoint with port (\\d+) without schema and domain name$")
497: public void iCreateEndpointWithPortWithoutSchemaAndDomain(int port) throws Throwable {
498: EndpointInfoCreator endpointInfoCreator = endpointInfoFactory.newCreator(getCurrentScopeId());
499: endpointInfoCreator.setPort(port);
500: endpointInfoCreator.setEndpointType(EndpointInfo.ENDPOINT_TYPE_RESOURCE);
501: try {
502: EndpointInfo endpointInfo = endpointInfoService.create(endpointInfoCreator);
503: stepData.put("EndpointInfo", endpointInfo);
504: } catch (KapuaIllegalNullArgumentException ex) {
505: verifyException(ex);
506: }
507: }
508:
509: @And("^I create endpoint with schema \"([^\"]*)\", domain \"([^\"]*)\", port (\\d+) and \"([^\"]*)\" secure field$")
510: public void iCreateEndpointWithSchemaDomainPortAndSecureField(String schema, String domainName, int port, String secureField) throws Throwable {
511: EndpointInfoCreator endpointInfoCreator = endpointInfoFactory.newCreator(getCurrentScopeId());
512: endpointInfoCreator.setSchema(schema);
513: endpointInfoCreator.setDns(domainName);
514: endpointInfoCreator.setPort(port);
515: endpointInfoCreator.setEndpointType(EndpointInfo.ENDPOINT_TYPE_RESOURCE);
516:• if (secureField.equals("ENABLED")) {
517: endpointInfoCreator.setSecure(true);
518: } else {
519: endpointInfoCreator.setSecure(false);
520: }
521: try {
522: EndpointInfo endpointInfo = endpointInfoService.create(endpointInfoCreator);
523: stepData.put("EndpointInfo", endpointInfo);
524: } catch (KapuaIllegalNullArgumentException ex) {
525: verifyException(ex);
526: }
527: }
528:
529: @Then("^I edit last created endpoint Secure field to \"([^\"]*)\"$")
530: public void iEditLastCreatedEndpointSecureField(String secureField) throws Throwable {
531: EndpointInfo endpointInfo = (EndpointInfo) stepData.get("EndpointInfo");
532: try {
533:• if (secureField.equals("ENABLED")) {
534: endpointInfo.setSecure(true);
535: } else {
536: endpointInfo.setSecure(false);
537: }
538: endpointInfoService.update(endpointInfo);
539: } catch (Exception e) {
540: verifyException(e);
541: }
542: }
543:
544: @When("^I create a CORS filter with schema \"([^\"]*)\", domain \"([^\"]*)\" and port (\\d+)$")
545: public void iCreateCORSFilter(String schema, String domain, int port) throws Exception {
546: EndpointInfoCreator endpointInfoCreator = endpointInfoFactory.newCreator(getCurrentScopeId());
547: endpointInfoCreator.setSchema(schema);
548: endpointInfoCreator.setDns(domain);
549: endpointInfoCreator.setPort(port);
550: endpointInfoCreator.setEndpointType(EndpointInfo.ENDPOINT_TYPE_CORS);
551:
552: try {
553: EndpointInfo endpointInfo = endpointInfoService.create(endpointInfoCreator);
554: } catch (KapuaException ex) {
555: verifyException(ex);
556: }
557: }
558:
559: @And("^I create the following CORS filters$")
560: public void iCreateMultipleCORSFilter(DataTable corsFilters) throws Throwable {
561:• for (List<String> config : corsFilters.raw()) {
562: iCreateCORSFilter(config.get(0), config.get(1), Integer.parseInt(config.get(2)));
563: }
564: }
565:
566: @Then("I have (\\d+) CORS filters?$")
567: public void iHaveCORSFilter(int expectedNum) throws KapuaException {
568: int corsFilter = KapuaSecurityUtils.doPrivileged(new Callable<Integer>() {
569: @Override
570: public Integer call() throws Exception {
571: EndpointInfoQuery endpointInfoQuery = endpointInfoFactory.newQuery(getCurrentScopeId());
572: EndpointInfoListResult corsFilters = endpointInfoService.query(endpointInfoQuery, EndpointInfo.ENDPOINT_TYPE_CORS);
573: return corsFilters.getSize();
574: }
575: });
576: assertEquals(expectedNum, corsFilter);
577: }
578:
579: @And("^I delete all CORS filters")
580: public void iDeleteAllCORSFilters() throws Exception {
581: primeException();
582:
583: try {
584: EndpointInfoQuery endpointInfoQuery = endpointInfoFactory.newQuery(getCurrentScopeId());
585: EndpointInfoListResult endpointsToDelete = endpointInfoService.query(endpointInfoQuery, EndpointInfo.ENDPOINT_TYPE_CORS);
586:
587:• for (int i = 0; i < endpointsToDelete.getSize(); i++) {
588: endpointInfoService.delete(getCurrentScopeId(), endpointsToDelete.getItem(i).getId());
589: }
590:
591: } catch (KapuaException ex) {
592: verifyException(ex);
593: }
594: }
595: }