@@ -105,6 +105,9 @@ public class DAOTestIT {
105105 @ Value ("${elasticsearch.filter.index:test_saveandrestore_filter}" )
106106 private String ES_FILTER_INDEX ;
107107
108+ @ Value ("${elasticsearch.composite_snapshot_node.index:test_saveandrestore_composite_snapshot}" )
109+ private String ES_COMPOSITE_SNAPSHOT_INDEX ;
110+
108111 private static Alarm alarm ;
109112 private static Time time ;
110113 private static Display display ;
@@ -115,7 +118,6 @@ public void init() {
115118 alarm = Alarm .of (AlarmSeverity .NONE , AlarmStatus .NONE , "name" );
116119 display = Display .none ();
117120 clearAllData ();
118- System .out .println ();
119121 }
120122
121123 @ AfterEach
@@ -1826,7 +1828,7 @@ public void testGetAllNodes() {
18261828 */
18271829 private void clearAllData () {
18281830 List <Node > childNodes = nodeDAO .getChildNodes (Node .ROOT_FOLDER_UNIQUE_ID );
1829- childNodes .forEach (node -> nodeDAO .deleteNode ( node .getUniqueId ()));
1831+ childNodes .forEach (node -> nodeDAO .deleteNodes ( List . of ( node .getUniqueId () )));
18301832 nodeDAO .deleteAllFilters ();
18311833 }
18321834
@@ -1854,6 +1856,17 @@ public void dropIndices() {
18541856 } catch (IOException e ) {
18551857 e .printStackTrace ();
18561858 }
1859+
1860+ try {
1861+ BooleanResponse exists = client .indices ().exists (ExistsRequest .of (e -> e .index (ES_COMPOSITE_SNAPSHOT_INDEX )));
1862+ if (exists .value ()) {
1863+ client .indices ().delete (
1864+ DeleteIndexRequest .of (
1865+ c -> c .index (ES_COMPOSITE_SNAPSHOT_INDEX )));
1866+ }
1867+ } catch (IOException e ) {
1868+ e .printStackTrace ();
1869+ }
18571870 }
18581871
18591872 @ Test
@@ -2253,4 +2266,122 @@ public void testSearchForPvs() {
22532266 // No pvs specified -> find all nodes.
22542267 assertEquals (4 , searchResult .getHitCount ());
22552268 }
2269+
2270+ @ Test
2271+ public void testSnapshotContainedInCompositeSnapshot () throws Exception {
2272+ Node rootNode = nodeDAO .getRootNode ();
2273+ Node folderNode =
2274+ Node .builder ().name ("folder" ).build ();
2275+ folderNode = nodeDAO .createNode (rootNode .getUniqueId (), folderNode );
2276+
2277+ //************ Create snapshot1 ************/
2278+ Node config = Node .builder ().nodeType (NodeType .CONFIGURATION ).name ("My config 1" ).build ();
2279+ Configuration configuration = new Configuration ();
2280+ configuration .setConfigurationNode (config );
2281+ ConfigurationData configurationData = new ConfigurationData ();
2282+ configurationData .setPvList (Arrays .asList (ConfigPv .builder ().pvName ("pv1" ).build (),
2283+ ConfigPv .builder ().pvName ("pv2" ).build ()));
2284+ configuration .setConfigurationData (configurationData );
2285+
2286+ configuration = nodeDAO .createConfiguration (folderNode .getUniqueId (), configuration );
2287+
2288+ SnapshotItem item1 = SnapshotItem .builder ().configPv (configuration .getConfigurationData ().getPvList ().get (0 ))
2289+ .value (VDouble .of (7.7 , alarm , time , display )).build ();
2290+ SnapshotItem item2 = SnapshotItem .builder ().configPv (configuration .getConfigurationData ().getPvList ().get (1 ))
2291+ .value (VDouble .of (7.7 , alarm , time , display )).build ();
2292+
2293+ Snapshot snapshot = new Snapshot ();
2294+ snapshot .setSnapshotNode (Node .builder ().nodeType (NodeType .SNAPSHOT ).name ("snapshot name" )
2295+ .description ("comment" )
2296+ .userName ("user" ).build ());
2297+ SnapshotData snapshotData = new SnapshotData ();
2298+ snapshotData .setSnapshotItems (Arrays .asList (item1 , item2 ));
2299+ snapshot .setSnapshotData (snapshotData );
2300+ Node newSnapshot1 = nodeDAO .createSnapshot (configuration .getConfigurationNode ().getUniqueId (), snapshot ).getSnapshotNode ();
2301+ //************ End create snapshot1 ************/
2302+
2303+ //************ Create snapshot2 ************/
2304+ Node config2 = Node .builder ().nodeType (NodeType .CONFIGURATION ).name ("My config 2" ).build ();
2305+ Configuration configuration2 = new Configuration ();
2306+ configuration2 .setConfigurationNode (config2 );
2307+ ConfigurationData configurationData2 = new ConfigurationData ();
2308+ configurationData2 .setPvList (Arrays .asList (ConfigPv .builder ().pvName ("pv12" ).build (),
2309+ ConfigPv .builder ().pvName ("pv22" ).build ()));
2310+ configuration2 .setConfigurationData (configurationData2 );
2311+
2312+ configuration2 = nodeDAO .createConfiguration (folderNode .getUniqueId (), configuration2 );
2313+
2314+ SnapshotItem item12 = SnapshotItem .builder ().configPv (configuration2 .getConfigurationData ().getPvList ().get (0 ))
2315+ .value (VDouble .of (7.7 , alarm , time , display )).build ();
2316+ SnapshotItem item22 = SnapshotItem .builder ().configPv (configuration2 .getConfigurationData ().getPvList ().get (1 ))
2317+ .value (VDouble .of (7.7 , alarm , time , display )).build ();
2318+
2319+ Snapshot snapshot2 = new Snapshot ();
2320+ snapshot2 .setSnapshotNode (Node .builder ().nodeType (NodeType .SNAPSHOT ).name ("snapshot name 2" )
2321+ .description ("comment" )
2322+ .userName ("user" ).build ());
2323+ SnapshotData snapshotData2 = new SnapshotData ();
2324+ snapshotData2 .setSnapshotItems (Arrays .asList (item12 , item22 ));
2325+ snapshot2 .setSnapshotData (snapshotData2 );
2326+ Node newSnapshot2 = nodeDAO .createSnapshot (configuration2 .getConfigurationNode ().getUniqueId (), snapshot2 ).getSnapshotNode ();
2327+ //************ End create snapshot2 ************/
2328+
2329+ //************ Create composite snapshot ************/
2330+ Node compositeSnapshotNode = Node .builder ().name ("My composite snapshot" ).nodeType (NodeType .COMPOSITE_SNAPSHOT ).build ();
2331+
2332+ CompositeSnapshot compositeSnapshot = new CompositeSnapshot ();
2333+ compositeSnapshot .setCompositeSnapshotNode (compositeSnapshotNode );
2334+
2335+ CompositeSnapshotData compositeSnapshotData = new CompositeSnapshotData ();
2336+ compositeSnapshotData .setUniqueId (compositeSnapshotNode .getUniqueId ());
2337+
2338+ compositeSnapshotData .setReferencedSnapshotNodes (Arrays .asList (snapshot .getSnapshotNode ().getUniqueId (),
2339+ snapshot2 .getSnapshotNode ().getUniqueId ()));
2340+ compositeSnapshot .setCompositeSnapshotData (compositeSnapshotData );
2341+
2342+ compositeSnapshot = nodeDAO .createCompositeSnapshot (folderNode .getUniqueId (), compositeSnapshot );
2343+ //************ End create composite snapshot ************/
2344+
2345+ MultiValueMap <String , String > searchParameters = new LinkedMultiValueMap <>();
2346+ searchParameters .put ("containedin" , List .of (newSnapshot1 .getUniqueId ()));
2347+ searchParameters .put ("from" , List .of ("0" ));
2348+ searchParameters .put ("size" , List .of ("100" ));
2349+
2350+ List <Node > nodes = nodeDAO .containedInCompositeSnapshot (searchParameters );
2351+
2352+ assertEquals (nodes .size (), 1 );
2353+
2354+ //************ Create another composite snapshot ************/
2355+ Node compositeSnapshotNode2 = Node .builder ().name ("My composite snapshot 2" ).nodeType (NodeType .COMPOSITE_SNAPSHOT ).build ();
2356+
2357+ CompositeSnapshot compositeSnapshot2 = new CompositeSnapshot ();
2358+ compositeSnapshot2 .setCompositeSnapshotNode (compositeSnapshotNode2 );
2359+
2360+ CompositeSnapshotData compositeSnapshotData2 = new CompositeSnapshotData ();
2361+ compositeSnapshotData2 .setUniqueId (compositeSnapshotNode2 .getUniqueId ());
2362+
2363+ compositeSnapshotData2 .setReferencedSnapshotNodes (Arrays .asList (snapshot .getSnapshotNode ().getUniqueId (),
2364+ snapshot2 .getSnapshotNode ().getUniqueId ()));
2365+ compositeSnapshot2 .setCompositeSnapshotData (compositeSnapshotData2 );
2366+
2367+ nodeDAO .createCompositeSnapshot (folderNode .getUniqueId (), compositeSnapshot2 );
2368+ //************ End create another composite snapshot ************/
2369+
2370+ nodes = nodeDAO .containedInCompositeSnapshot (searchParameters );
2371+
2372+ assertEquals (nodes .size (), 2 );
2373+
2374+ searchParameters .put ("containedin" , List .of ("non-existing" ));
2375+
2376+ nodes = nodeDAO .containedInCompositeSnapshot (searchParameters );
2377+
2378+ assertEquals (nodes .size (), 0 );
2379+
2380+ searchParameters .put ("containedin" , Collections .emptyList ());
2381+
2382+ assertThrows (IllegalArgumentException .class , () -> nodeDAO .containedInCompositeSnapshot (searchParameters ));
2383+
2384+ nodeDAO .deleteNode (compositeSnapshotNode .getUniqueId ());
2385+ nodeDAO .deleteNode (compositeSnapshotNode2 .getUniqueId ());
2386+ }
22562387}
0 commit comments