27
27
public class ViewIT extends ViewTestBase {
28
28
29
29
public void testCreateView () throws Exception {
30
- final String viewName = "test-view" ;
31
- final String indexPattern = "test-index-*" ;
30
+ final String viewName = randomAlphaOfLength ( 8 ) ;
31
+ final String indexPattern = randomAlphaOfLength ( 8 ) ;
32
32
33
33
logger .info ("Testing createView with valid parameters" );
34
34
final View view = createView (viewName , indexPattern ).getView ();
@@ -37,58 +37,66 @@ public void testCreateView() throws Exception {
37
37
MatcherAssert .assertThat (view .getTargets ().get (0 ).getIndexPattern (), is (indexPattern ));
38
38
39
39
logger .info ("Testing createView with existing view name" );
40
- final Exception ex = assertThrows (ResourceNotFoundException .class , () -> createView (viewName , "new-pattern" ));
41
- MatcherAssert .assertThat (ex .getMessage (), is ("View [test-view ] already exists" ));
40
+ final Exception ex = assertThrows (ResourceNotFoundException .class , () -> createView (viewName , randomAlphaOfLength ( 8 ) ));
41
+ MatcherAssert .assertThat (ex .getMessage (), is ("View [" + viewName + " ] already exists" ));
42
42
}
43
43
44
44
public void testGetView () throws Exception {
45
- final String viewName = "existing-view" ;
45
+ final String viewName = randomAlphaOfLength (8 );
46
+ createView (viewName , randomAlphaOfLength (8 ));
46
47
47
- logger .info ("Testing getView with existing view" );
48
- createView (viewName , "index-*" );
49
48
final View view = getView (viewName ).getView ();
50
49
MatcherAssert .assertThat (view .getName (), is (viewName ));
51
50
52
51
logger .info ("Testing getView with non-existent view" );
53
- final Exception whenNeverExistedEx = assertThrows (ResourceNotFoundException .class , () -> getView ("non-existent" ));
54
- MatcherAssert .assertThat (whenNeverExistedEx .getMessage (), is ("View [non-existent] does not exist" ));
52
+ final String nonExistentView = "non-existent-" + randomAlphaOfLength (8 );
53
+ final Exception whenNeverExistedEx = assertThrows (ResourceNotFoundException .class , () -> getView (nonExistentView ));
54
+ MatcherAssert .assertThat (whenNeverExistedEx .getMessage (), is ("View [" + nonExistentView + "] does not exist" ));
55
55
}
56
56
57
57
public void testDeleteView () throws Exception {
58
- final String viewName = "deleted-view" ;
59
- createView (viewName , "index-*" );
58
+ final String viewName = randomAlphaOfLength ( 8 ) ;
59
+ createView (viewName , randomAlphaOfLength ( 8 ) );
60
60
61
61
logger .info ("Testing deleteView with existing view" );
62
62
deleteView (viewName );
63
63
final Exception whenDeletedEx = assertThrows (ResourceNotFoundException .class , () -> getView (viewName ));
64
- MatcherAssert .assertThat (whenDeletedEx .getMessage (), is ("View [deleted-view ] does not exist" ));
64
+ MatcherAssert .assertThat (whenDeletedEx .getMessage (), is ("View [" + viewName + " ] does not exist" ));
65
65
66
66
logger .info ("Testing deleteView with non-existent view" );
67
- final Exception whenNeverExistedEx = assertThrows (ResourceNotFoundException .class , () -> deleteView ("non-existent" ));
68
- MatcherAssert .assertThat (whenNeverExistedEx .getMessage (), is ("View [non-existent] does not exist" ));
67
+ final String nonExistentView = "non-existent-" + randomAlphaOfLength (8 );
68
+ final Exception whenNeverExistedEx = assertThrows (ResourceNotFoundException .class , () -> deleteView (nonExistentView ));
69
+ MatcherAssert .assertThat (whenNeverExistedEx .getMessage (), is ("View [" + nonExistentView + "] does not exist" ));
69
70
}
70
71
71
72
public void testUpdateView () throws Exception {
72
- final String viewName = "updatable-view" ;
73
- final View originalView = createView (viewName , "index-old-*" ).getView ();
73
+ final String viewName = randomAlphaOfLength (8 );
74
+ final String originalIndexPattern = randomAlphaOfLength (8 );
75
+ final View originalView = createView (viewName , originalIndexPattern ).getView ();
74
76
75
77
logger .info ("Testing updateView with existing view" );
76
- final View updatedView = updateView (viewName , "new description" , "index-new-*" ).getView ();
78
+ final String newDescription = randomAlphaOfLength (20 );
79
+ final String newIndexPattern = "newPattern-" + originalIndexPattern ;
80
+ final View updatedView = updateView (viewName , newDescription , newIndexPattern ).getView ();
77
81
78
82
MatcherAssert .assertThat (updatedView , not (is (originalView )));
79
- MatcherAssert .assertThat (updatedView .getDescription (), is ("new description" ));
83
+ MatcherAssert .assertThat (updatedView .getDescription (), is (newDescription ));
80
84
MatcherAssert .assertThat (updatedView .getTargets (), hasSize (1 ));
81
- MatcherAssert .assertThat (updatedView .getTargets ().get (0 ).getIndexPattern (), is ("index-new-*" ));
85
+ MatcherAssert .assertThat (updatedView .getTargets ().get (0 ).getIndexPattern (), is (newIndexPattern ));
82
86
83
87
logger .info ("Testing updateView with non-existent view" );
88
+ final String nonExistentView = "non-existent-" + randomAlphaOfLength (8 );
84
89
final Exception whenNeverExistedEx = assertThrows (
85
90
ResourceNotFoundException .class ,
86
- () -> updateView ("non-existent" , null , "index-*" )
91
+ () -> updateView (nonExistentView , null , "index-*" )
87
92
);
88
- MatcherAssert .assertThat (whenNeverExistedEx .getMessage (), is ("View [non-existent ] does not exist" ));
93
+ MatcherAssert .assertThat (whenNeverExistedEx .getMessage (), is ("View [" + nonExistentView + " ] does not exist" ));
89
94
}
90
95
91
96
public void testListViewNames () throws Exception {
97
+ logger .info ("Testing listViewNames when no views have been created" );
98
+ MatcherAssert .assertThat (listViewNames (), is (List .of ()));
99
+
92
100
final String view1 = "view1" ;
93
101
final String view2 = "view2" ;
94
102
createView (view1 , "index-1-*" );
@@ -128,8 +136,8 @@ public void testSearchOperations() throws Exception {
128
136
assertHitCount (searchView ("both-indices" ), indexInView1DocCount + indexInView2DocCount );
129
137
130
138
logger .info ("Testing searchView with non-existent view" );
131
- final Exception whenNeverExistedEx = assertThrows ( ResourceNotFoundException . class , () -> searchView ( "non-existent" ) );
132
- MatcherAssert . assertThat ( whenNeverExistedEx . getMessage (), is ( "View [non-existent] does not exist" ));
133
-
139
+ final String nonExistentView = "non-existent-" + randomAlphaOfLength ( 8 );
140
+ final Exception whenNeverExistedEx = assertThrows ( ResourceNotFoundException . class , () -> searchView ( nonExistentView ));
141
+ MatcherAssert . assertThat ( whenNeverExistedEx . getMessage (), is ( "View [" + nonExistentView + "] does not exist" ));
134
142
}
135
143
}
0 commit comments