Package: CucCredentials
CucCredentials
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CucCredentials() |
|
|
|
|
|
||||||||||||||||||||
getExpirationDate() |
|
|
|
|
|
||||||||||||||||||||
getName() |
|
|
|
|
|
||||||||||||||||||||
getPassword() |
|
|
|
|
|
||||||||||||||||||||
getStatus() |
|
|
|
|
|
||||||||||||||||||||
isEnabled() |
|
|
|
|
|
||||||||||||||||||||
setEnabled(boolean) |
|
|
|
|
|
||||||||||||||||||||
setExpirationDate(String) |
|
|
|
|
|
||||||||||||||||||||
setName(String) |
|
|
|
|
|
||||||||||||||||||||
setPassword(String) |
|
|
|
|
|
Coverage
1: /*******************************************************************************
2: * Copyright (c) 2016, 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
12: *******************************************************************************/
13: package org.eclipse.kapua.qa.common.cucumber;
14:
15: import org.eclipse.kapua.service.authentication.credential.CredentialStatus;
16:
17: import java.text.DateFormat;
18: import java.text.ParseException;
19: import java.text.SimpleDateFormat;
20: import java.time.Duration;
21: import java.time.Instant;
22: import java.util.Date;
23:
24: /**
25: * Data object used in Gherkin to transfer Credentials data.
26: */
27: public class CucCredentials {
28:
29: private String name;
30:
31: private String password;
32:
33: private boolean enabled;
34:
35: private String expirationDate;
36:
37: public String getName() {
38: return name;
39: }
40:
41: public void setName(String name) {
42: this.name = name;
43: }
44:
45: public String getPassword() {
46: return password;
47: }
48:
49: public void setPassword(String password) {
50: this.password = password;
51: }
52:
53: public boolean isEnabled() {
54: return enabled;
55: }
56:
57: public void setEnabled(boolean enabled) {
58: this.enabled = enabled;
59: }
60:
61: public CredentialStatus getStatus() {
62:• if (isEnabled()) {
63: return CredentialStatus.ENABLED;
64: } else {
65: return CredentialStatus.DISABLED;
66: }
67: }
68:
69: public Date getExpirationDate() {
70: DateFormat df = new SimpleDateFormat("dd/mm/yyyy");
71: Date expDate = null;
72: Instant now = Instant.now();
73:
74:• if (expirationDate == null) {
75: return null;
76: }
77: // Special keywords for date
78:• switch (expirationDate) {
79: case "yesterday":
80: expDate = Date.from(now.minus(Duration.ofDays(1)));
81: break;
82: case "today":
83: expDate = Date.from(now);
84: break;
85: case "tomorrow":
86: expDate = Date.from(now.plus(Duration.ofDays(1)));
87: break;
88: }
89: // Just parse date
90: try {
91: expDate = df.parse(expirationDate);
92: } catch (ParseException | NullPointerException e) {
93: // skip, leave date null
94: }
95:
96: return expDate;
97: }
98:
99: public void setExpirationDate(String expirationDate) {
100: this.expirationDate = expirationDate;
101: }
102: }