12
12
13
13
import org .apache .http .impl .client .CloseableHttpClient ;
14
14
import org .junit .AfterClass ;
15
+ import org .junit .Before ;
15
16
import org .junit .BeforeClass ;
16
17
import org .junit .Test ;
17
18
import org .mockserver .client .MockServerClient ;
18
19
import org .mockserver .integration .ClientAndServer ;
19
- import org .openqa .selenium .JavascriptExecutor ;
20
20
import org .openqa .selenium .support .ui .WebDriverWait ;
21
21
import org .springframework .boot .test .mock .mockito .MockBean ;
22
22
23
23
import com .ericsson .ei .config .SeleniumConfig ;
24
- import com .ericsson .ei .frontend .pageobjects .IndexPage ;
25
24
import com .ericsson .ei .frontend .pageobjects .TestRulesPage ;
26
25
27
26
public class TestRulesFunctionality extends SeleniumBaseClass {
@@ -30,113 +29,123 @@ public class TestRulesFunctionality extends SeleniumBaseClass {
30
29
private static ClientAndServer mockServer ;
31
30
private static final String BASE_URL = "localhost" ;
32
31
33
- private static final String DOWNLOADED_RULES_TEMPLATE_FILE_PATH = String .join (
34
- File . separator , SeleniumConfig . getTempDownloadDirectory (). getPath (), "rulesTemplate.json" );
35
- private static final String RULES_TEMPLATE_FILE_PATH = String .join (
36
- File . separator , "src" , "functionaltest" , "resources" , "responses" , "RulesTemplateObject.json" );
37
- private static final String DOWNLOADED_RULES_FILE_PATH = String .join (
38
- File . separator , SeleniumConfig . getTempDownloadDirectory (). getPath (), "rules.json" );
39
- private static final String DOWNLOADED_EVENTS_TEMPLATE_FILE_PATH = String .join (
40
- File . separator , SeleniumConfig .getTempDownloadDirectory ().getPath (), "eventsTemplate.json" );
41
- private static final String EVENTS_TEMPLATE_FILE_PATH = String .join (
42
- File . separator , "src" , "functionaltest" , "resources" , "responses" , "EventsTemplateObject.json" );
43
- private static final String AGGREGATED_OBJECT_FILE_PATH = String .join (
44
- File . separator , "src" , "functionaltest" , "resources" , "responses" , "AggregatedObjectResponse.json" );
32
+ private static final String DOWNLOADED_RULES_TEMPLATE_FILE_PATH = String .join (File . separator , SeleniumConfig . getTempDownloadDirectory (). getPath (),
33
+ "rulesTemplate.json" );
34
+ private static final String RULES_TEMPLATE_FILE_PATH = String .join (File . separator , "src" , "functionaltest" , "resources" , "responses" ,
35
+ "RulesTemplateObject.json" );
36
+ private static final String DOWNLOADED_RULES_FILE_PATH = String .join (File . separator , SeleniumConfig . getTempDownloadDirectory (). getPath (),
37
+ "rules.json" );
38
+ private static final String DOWNLOADED_EVENTS_TEMPLATE_FILE_PATH = String .join (File . separator ,
39
+ SeleniumConfig .getTempDownloadDirectory ().getPath (), "eventsTemplate.json" );
40
+ private static final String EVENTS_TEMPLATE_FILE_PATH = String .join (File . separator , "src" , "functionaltest" , "resources" , "responses" ,
41
+ "EventsTemplateObject.json" );
42
+ private static final String AGGREGATED_OBJECT_FILE_PATH = String .join (File . separator , "src" , "functionaltest" , "resources" , "responses" ,
43
+ "AggregatedObjectResponse.json" );
45
44
46
45
@ MockBean
47
46
protected CloseableHttpClient mockedHttpClient ;
48
47
49
- @ Test
50
- public void testJourneyToFindAggregatedObjectButton () throws Exception {
51
- // Set up
52
- int portServer = mockServer .getLocalPort ();
53
- backEndInstancesUtils .setDefaultBackEndInstanceToNull ();
54
- backEndInstancesUtils .setDefaultBackEndInstance ("new_instance_default" , "localhost" , portServer , "" , true );
55
- JavascriptExecutor js = driver ;
48
+ private TestRulesPage testRulesPage ;
49
+ private String downloadedRulesTemplate = "" ;
50
+ private String downloadedEventsTemplate = "" ;
56
51
57
- // Open indexpage and verify that it is opened
58
- IndexPage indexPageObject = new IndexPage (null , driver , baseUrl );
59
- indexPageObject .loadPage ();
60
-
61
- // Verify that we can navigate to test rules page
62
- TestRulesPage testRulesPage = indexPageObject .clickTestRulesPage ();
63
- assert (new WebDriverWait (driver , 10 ).until ((webdriver ) -> testRulesPage .presenceOfTestRulesHeader ()));
64
-
65
- //Enable buttons
66
- js .executeScript ("$('button.btn').prop(\" disabled\" , false);" );
52
+ @ Before
53
+ public void before () throws IOException {
54
+ int serverPort = mockServer .getLocalPort ();
55
+ backEndInstancesUtils .setDefaultBackEndInstanceToNull ();
56
+ backEndInstancesUtils .setDefaultBackEndInstance ("new_instance_default" , "localhost" , serverPort , "" , true );
57
+ testRulesPage = new TestRulesPage (null , driver , baseUrl );
58
+ testRulesPage .loadPage ();
59
+ }
67
60
68
- // Verify that "download rules template" button works
69
- String downloadedRulesTemplate = "" ;
70
- String mockedResponse = getJSONStringFromFile (RULES_TEMPLATE_FILE_PATH );
71
- mockClient .when (request ().withMethod ("GET" ).withPath ("/download/rulesTemplate" ))
72
- .respond (response ().withStatusCode (200 ).withBody (mockedResponse ));
61
+ @ Test
62
+ public void testJourneyToFindAggregatedObjectButton () throws Exception {
63
+ enableTestRulesButtons ();
64
+ verifyDownloadRulesTemplateButton ();
65
+ verifyUploadRulesFile ();
66
+ verifyDownloadRulesButton ();
67
+ verifyAddAndRemoveRuleButton ();
68
+ verifyDownloadEventsTemplateButton ();
69
+ verifyUploadEventsFile ();
70
+ verifyAddAndRemoveEventButton ();
71
+ verifyAggregatedObjectButton ();
72
+ }
73
73
74
- testRulesPage .clickDownloadRulesTemplate ();
75
- new WebDriverWait (driver , 10 ).until ((webdriver ) -> Files .exists (Paths .get (DOWNLOADED_RULES_TEMPLATE_FILE_PATH )));
76
- downloadedRulesTemplate = getJSONStringFromFile (DOWNLOADED_RULES_TEMPLATE_FILE_PATH );
74
+ @ BeforeClass
75
+ public static void setUpMocks () throws IOException {
76
+ mockServer = startClientAndServer ();
77
+ mockClient = new MockServerClient (BASE_URL , mockServer .getLocalPort ());
78
+ }
77
79
78
- assertEquals (mockedResponse , downloadedRulesTemplate );
80
+ @ AfterClass
81
+ public static void tearDownMocks () throws IOException {
82
+ mockClient .stop ();
83
+ }
79
84
80
- // Verify that uploading the downloaded template file works.
81
- testRulesPage . uploadRulesTemplate ( DOWNLOADED_RULES_TEMPLATE_FILE_PATH );
82
- String firstRule = testRulesPage . getFirstRuleText ();
83
- assertEquals ( true , downloadedRulesTemplate . contains ( firstRule ));
85
+ private void verifyAggregatedObjectButton () throws IOException {
86
+ String findAggregatedObjectResponse = getJSONStringFromFile ( AGGREGATED_OBJECT_FILE_PATH );
87
+ mockClient . when ( request (). withMethod ( "POST" ). withPath ( "/rules/rule-check/aggregation" ))
88
+ . respond ( response (). withStatusCode ( 200 ). withBody ( findAggregatedObjectResponse ));
84
89
85
- // Verify that it is possible to download rules
86
- mockClient .when (request ().withMethod ("GET" ).withPath ("/download/rules" ))
87
- .respond (response ().withStatusCode (200 ).withBody (downloadedRulesTemplate ));
88
- testRulesPage .clickDownloadRulesButton ();
89
- new WebDriverWait (driver , 10 ).until ((webdriver ) -> Files .exists (Paths .get (DOWNLOADED_RULES_FILE_PATH )));
90
- String downloadedRules = getJSONStringFromFile (DOWNLOADED_RULES_FILE_PATH );
91
- assertEquals (downloadedRulesTemplate , downloadedRules );
90
+ testRulesPage .clickFindAggregatedObject ();
91
+ assertEquals (findAggregatedObjectResponse , testRulesPage .getAggregatedResultData ());
92
+ }
92
93
93
- // Verify that add rule button works
94
- testRulesPage .clickAddRuleButton ();
94
+ private void verifyAddAndRemoveEventButton () {
95
+ testRulesPage .clickAddEventButton ();
96
+ testRulesPage .clickRemoveEventNumber (3 );
97
+ assert (new WebDriverWait (driver , 10 ).until ((webdriver ) -> !testRulesPage .presenceOfEventNumber (3 )));
98
+ }
95
99
96
- // Verify that removing a rule works
97
- testRulesPage .clickRemoveRuleNumber (3 );
98
- assert (new WebDriverWait (driver , 10 ).until ((webdriver ) -> !testRulesPage .presenceOfRuleNumber (3 )));
100
+ private void verifyUploadEventsFile () {
101
+ testRulesPage .uploadEventsTemplate (DOWNLOADED_EVENTS_TEMPLATE_FILE_PATH );
102
+ String firstEvent = testRulesPage .getFirstEventText ();
103
+ assertEquals (true , downloadedEventsTemplate .contains (firstEvent ));
104
+ }
99
105
100
- // Verify that "download events template" button works
106
+ private void verifyDownloadEventsTemplateButton () throws IOException {
101
107
String downloadEventsTemplateMockedResponse = getJSONStringFromFile (EVENTS_TEMPLATE_FILE_PATH );
102
108
mockClient .when (request ().withMethod ("GET" ).withPath ("/download/eventsTemplate" ))
103
109
.respond (response ().withStatusCode (200 ).withBody (downloadEventsTemplateMockedResponse ));
104
110
105
111
testRulesPage .clickDownloadEventsTemplate ();
106
112
new WebDriverWait (driver , 10 ).until ((webdriver ) -> Files .exists (Paths .get (DOWNLOADED_EVENTS_TEMPLATE_FILE_PATH )));
107
- String downloadedEventsTemplate = getJSONStringFromFile (DOWNLOADED_EVENTS_TEMPLATE_FILE_PATH );
113
+ downloadedEventsTemplate = getJSONStringFromFile (DOWNLOADED_EVENTS_TEMPLATE_FILE_PATH );
108
114
assertEquals (downloadEventsTemplateMockedResponse , downloadedEventsTemplate );
115
+ }
109
116
110
- // Verify that uploading the downloaded template file works.
111
- testRulesPage .uploadEventsTemplate (DOWNLOADED_EVENTS_TEMPLATE_FILE_PATH );
112
- String firstEvent = testRulesPage .getFirstEventText ();
113
- assertEquals (true , downloadedEventsTemplate .contains (firstEvent ));
114
-
115
- // Verify that add rule button works
116
- testRulesPage .clickAddEventButton ();
117
-
118
- // Verify that removing a rule works
119
- testRulesPage .clickRemoveEventNumber (3 );
120
- assert (new WebDriverWait (driver , 10 ).until ((webdriver ) -> !testRulesPage .presenceOfEventNumber (3 )));
121
-
122
- // Verify that find aggregated object button works
123
- String findAggregatedObjectResponse = getJSONStringFromFile (AGGREGATED_OBJECT_FILE_PATH );
124
- mockClient .when (request ().withMethod ("POST" ).withPath ("/rules/rule-check/aggregation" ))
125
- .respond (response ().withStatusCode (200 ).withBody (findAggregatedObjectResponse ));
117
+ private void verifyAddAndRemoveRuleButton () {
118
+ testRulesPage .clickAddRuleButton ();
119
+ testRulesPage .clickRemoveRuleNumber (3 );
120
+ assert (new WebDriverWait (driver , 10 ).until ((webdriver ) -> !testRulesPage .presenceOfRuleNumber (3 )));
121
+ }
126
122
127
- testRulesPage .clickFindAggregatedObject ();
128
- assertEquals (findAggregatedObjectResponse , testRulesPage .getAggregatedResultData ());
123
+ private void verifyDownloadRulesButton () throws IOException {
124
+ mockClient .when (request ().withMethod ("GET" ).withPath ("/download/rules" ))
125
+ .respond (response ().withStatusCode (200 ).withBody (downloadedRulesTemplate ));
126
+ testRulesPage .clickDownloadRulesButton ();
127
+ new WebDriverWait (driver , 10 ).until ((webdriver ) -> Files .exists (Paths .get (DOWNLOADED_RULES_FILE_PATH )));
128
+ String downloadedRules = getJSONStringFromFile (DOWNLOADED_RULES_FILE_PATH );
129
+ assertEquals (downloadedRulesTemplate , downloadedRules );
129
130
}
130
131
131
- @ BeforeClass
132
- public static void setUpMocks () throws IOException {
133
- mockServer = startClientAndServer ();
134
- mockClient = new MockServerClient ( BASE_URL , mockServer . getLocalPort ( ));
132
+ private void verifyUploadRulesFile () {
133
+ testRulesPage . uploadRulesTemplate ( DOWNLOADED_RULES_TEMPLATE_FILE_PATH );
134
+ String firstRule = testRulesPage . getFirstRuleText ();
135
+ assertEquals ( true , downloadedRulesTemplate . contains ( firstRule ));
135
136
}
136
137
137
- @ AfterClass
138
- public static void tearDownMocks () throws IOException {
139
- mockClient .stop ();
138
+ private void verifyDownloadRulesTemplateButton () throws IOException {
139
+ String mockedResponse = getJSONStringFromFile (RULES_TEMPLATE_FILE_PATH );
140
+ mockClient .when (request ().withMethod ("GET" ).withPath ("/download/rulesTemplate" ))
141
+ .respond (response ().withStatusCode (200 ).withBody (mockedResponse ));
142
+ testRulesPage .clickDownloadRulesTemplate ();
143
+ new WebDriverWait (driver , 10 ).until ((webdriver ) -> Files .exists (Paths .get (DOWNLOADED_RULES_TEMPLATE_FILE_PATH )));
144
+ downloadedRulesTemplate = getJSONStringFromFile (DOWNLOADED_RULES_TEMPLATE_FILE_PATH );
145
+ assertEquals (mockedResponse , downloadedRulesTemplate );
140
146
}
141
147
148
+ private void enableTestRulesButtons () {
149
+ driver .executeScript ("$('button.btn').prop(\" disabled\" , false);" );
150
+ }
142
151
}
0 commit comments