2727import com .arcadeanalytics .domain .enumeration .DataSourceType ;
2828import com .arcadeanalytics .repository .DataSourceRepository ;
2929import com .arcadeanalytics .service .dto .SearchQueryDTO ;
30- import com .google .common .collect .Sets ;
3130import org .junit .Before ;
3231import org .junit .BeforeClass ;
3332import org .junit .ClassRule ;
4544import java .util .stream .Collectors ;
4645
4746import static com .arcadeanalytics .index .IndexConstants .ARCADE_ID ;
47+ import static com .google .common .collect .Sets .newHashSet ;
4848import static java .util .Collections .emptySet ;
4949import static org .assertj .core .api .Assertions .assertThat ;
5050
@@ -76,18 +76,19 @@ public static void beforeClass() {
7676 @ Before
7777 public void setUp () throws Exception {
7878 //given
79- dataSource = new DataSource ()
80- .name ("demodb" )
81- .description ("desc" )
82- .remote (false )
83- .type (DataSourceType .ORIENTDB3 )
84- .server (container .getContainerIpAddress ())
85- .port (container .getFirstMappedPort ())
86- .database ("demodb" )
87- .username ("admin" )
88- .password ("admin" );
89-
90- dataSourceRepository .save (dataSource );
79+
80+ dataSource = dataSourceRepository .findByName ("demodb" ).orElseGet (() ->
81+ dataSourceRepository .save (new DataSource ()
82+ .name ("demodb" )
83+ .description ("desc" )
84+ .remote (false )
85+ .type (DataSourceType .ORIENTDB3 )
86+ .server (container .getContainerIpAddress ())
87+ .port (container .getFirstMappedPort ())
88+ .database ("demodb" )
89+ .username ("admin" )
90+ .password ("admin" ))
91+ );
9192
9293 if (!service .hasIndex (dataSource )) {
9394 //when --> ASYNC!!!!!
@@ -102,6 +103,8 @@ public void setUp() throws Exception {
102103 @ Test (expected = RuntimeException .class )
103104 public void shouldDeleteIndex () throws IOException {
104105
106+ assertThat (service .hasIndex (dataSource )).isTrue ();
107+
105108 final boolean deleted = service .deleteIndex (dataSource );
106109
107110 assertThat (deleted ).isTrue ();
@@ -110,6 +113,7 @@ public void shouldDeleteIndex() throws IOException {
110113 SearchQueryDTO queryDTO = new SearchQueryDTO ();
111114 service .search (dataSource , queryDTO );
112115
116+ assertThat (service .hasIndex (dataSource )).isFalse ();
113117
114118 }
115119
@@ -118,9 +122,11 @@ public void shouldFindSameDocumentsWithSimpleSearchAndFilteringOnIds() throws IO
118122 //then simple search for frank and rob
119123 SearchQueryDTO queryDTO = new SearchQueryDTO ();
120124 //explicit OR 'cause default search are in AND
121- queryDTO .setQuery ("roma OR frank" );
125+ queryDTO .setQuery ("Name: roma OR Name: frank" );
122126 List <Sprite > docs = service .search (dataSource , queryDTO );
123- assertThat (docs ).hasSize (10 );
127+ assertThat (docs ).hasSize (9 );
128+
129+ // docs.forEach(sprite -> assertThat(sprite.valueOf("Name")).contains("frank", "roma", "Frank", "Roma"));
124130
125131 String [] ids = docs .stream ()
126132 .map (s -> s .valueOf (ARCADE_ID ))
@@ -132,7 +138,9 @@ public void shouldFindSameDocumentsWithSimpleSearchAndFilteringOnIds() throws IO
132138 queryDTO .setIds (ids );
133139 //now search for all documents and filter by previous ids
134140 docs = service .search (dataSource , queryDTO );
135- assertThat (docs ).hasSize (10 );
141+ assertThat (docs ).hasSize (9 );
142+
143+ // docs.forEach(sprite -> assertThat(sprite.valueOf("Name")).contains("frank", "roma", "Frank", "Roma"));
136144
137145 }
138146
@@ -146,9 +154,10 @@ public void shouldProvideFacetingOverNodesPropertyValues() throws IOException {
146154
147155 List <Sprite > docs = service .search (dataSource , queryDTO );
148156
149- //search limited to 10
157+ //search limited to 50
150158 assertThat (docs ).hasSize (50 );
151159
160+ //maps the ids of retrieved documents
152161 String [] ids = docs .stream ()
153162 .map (s -> s .valueOf (ARCADE_ID ))
154163 .collect (Collectors .toList ())
@@ -161,7 +170,6 @@ public void shouldProvideFacetingOverNodesPropertyValues() throws IOException {
161170
162171 final Map <String , Object > aggregate = service .aggregate (dataSource , queryDTO , emptySet (), emptySet (), 1 , 20 );
163172
164- System .out .println ("aggregate = " + aggregate );
165173 assertThat (aggregate ).containsKeys ("Countries" );
166174
167175 final Map <String , Object > person = (Map <String , Object >) aggregate .get ("Countries" );
@@ -199,7 +207,7 @@ public void shouldProvideFacetingOverNodesPropertyValuesWithClassesAndProperty()
199207 queryDTO .setUseEdges (true );
200208 queryDTO .setIds (ids );
201209
202- final Map <String , Object > aggregate = service .aggregate (dataSource , queryDTO , Sets . newHashSet ("Countries" ), Sets . newHashSet ("Code" ), 1 , 20 );
210+ final Map <String , Object > aggregate = service .aggregate (dataSource , queryDTO , newHashSet ("Countries" ), newHashSet ("Code" ), 1 , 20 );
203211
204212 assertThat (aggregate ).containsKeys ("Countries" );
205213
0 commit comments