1 package com.atlassian.webdriver.confluence.page;
2
3 import com.atlassian.webdriver.utils.by.ByJquery;
4 import org.openqa.selenium.WebElement;
5 import org.openqa.selenium.support.FindBy;
6
7 import java.text.ParseException;
8 import java.text.SimpleDateFormat;
9 import java.util.Date;
10 import java.util.regex.Matcher;
11 import java.util.regex.Pattern;
12
13
14
15
16
17 public class LicenseDetailsPage extends ConfluenceAbstractPage
18 {
19
20 private static String URI = "/admin/license.action";
21
22 @FindBy (className = "confluenceTable")
23 WebElement licenseTable;
24
25 @FindBy (name = "licenseString")
26 WebElement updateLicenseTextArea;
27
28 @FindBy (name = "update")
29 WebElement submitLicenseButton;
30
31
32 public String getUrl()
33 {
34 return URI;
35 }
36
37 public String getOrganisation()
38 {
39 return licenseTable.findElement(ByJquery.$("td:contains(Organisation) ~ td")).getText();
40 }
41
42 public Date getDatePurchased()
43 {
44 SimpleDateFormat format = new SimpleDateFormat("MMM dd, yyyy");
45
46 String datePurchased = licenseTable.findElement(ByJquery.$("td:contains(Date Purchased) ~ td")).getText();
47
48 Date date;
49 try
50 {
51 date = format.parse(datePurchased);
52 }
53 catch (ParseException e)
54 {
55 throw new RuntimeException(e);
56 }
57
58 return date;
59 }
60
61
62 public boolean isEvaluation() {
63 throw new UnsupportedOperationException("isEvaluation hasn't been implemented yet");
64 }
65
66 public String getLicenseType()
67 {
68 return licenseTable.findElement(ByJquery.$("td:contains(License Type) ~ td")).getText();
69 }
70
71 public String getSupportEntitlementNumber()
72 {
73 return licenseTable.findElement(ByJquery.$("td:contains(Support Entitlement Number) ~ td")).getText();
74 }
75
76 public String getServerID()
77 {
78 return licenseTable.findElement(ByJquery.$("td:contains(Server ID) ~ td strong")).getText();
79 }
80
81 public int getUserLimit()
82 {
83 return Integer.valueOf(licenseTable.findElement(ByJquery.$("td:contains(Licensed Users) ~ td > strong")).getText());
84 }
85
86 public int getActiveUsers()
87 {
88 String userLimit = licenseTable.findElement(ByJquery.$("td:contains(Licensed Users) ~ td")).getText();
89
90 Pattern re = Pattern.compile("[(]([0-9]+) signed up currently[)]");
91 Matcher m = re.matcher(userLimit);
92
93 if (m.find())
94 {
95 String activeUSers = m.group(1);
96 return Integer.valueOf(activeUSers);
97 }
98
99 return -1;
100 }
101
102 public LicenseDetailsPage updateLicense(String license)
103 {
104
105 updateLicenseTextArea.sendKeys(license);
106 submitLicenseButton.click();
107
108 return pageBinder.bind(LicenseDetailsPage.class);
109 }
110
111 }