44import com .knowledgepixels .registry .utils .TestUtils ;
55import com .mongodb .client .ClientSession ;
66import com .mongodb .client .model .Sorts ;
7+ import org .bson .Document ;
78import org .junit .jupiter .api .AfterEach ;
89import org .junit .jupiter .api .BeforeEach ;
910import org .junit .jupiter .api .Test ;
1011import org .testcontainers .junit .jupiter .Container ;
1112import org .testcontainers .junit .jupiter .Testcontainers ;
1213import org .testcontainers .mongodb .MongoDBContainer ;
1314
15+ import java .util .ArrayList ;
1416import java .util .HashMap ;
17+ import java .util .List ;
1518
1619import static com .knowledgepixels .registry .RegistryDB .collection ;
1720import static com .knowledgepixels .registry .RegistryDB .getValue ;
@@ -88,7 +91,33 @@ void loadSetting() throws Exception {
8891 assertNotNull (RegistryDB .getValue (mongoSession , Collection .SETTING .toString (), "bootstrap-services" ));
8992
9093 assertEquals (ServerStatus .coreLoading .toString (), getValue (mongoSession , Collection .SERVER_INFO .toString (), "status" ));
91- assertEquals (RegistryDB .collection (Collection .TASKS .toString ()).find (mongoSession ).sort (Sorts .descending ("not-before" )).first ().getString ("action" ), Task .LOAD_FULL .asDocument ().getString ("action" ));
94+ List <Document > retrievedTasks = RegistryDB .collection (Collection .TASKS .toString ())
95+ .find (mongoSession )
96+ .sort (Sorts .descending ("not-before" ))
97+ .into (new ArrayList <>());
98+ assertEquals (retrievedTasks .getFirst ().getString ("action" ), Task .LOAD_FULL .asDocument ().getString ("action" ));
99+ assertEquals (retrievedTasks .get (1 ).getString ("action" ), Task .INIT_COLLECTIONS .asDocument ().getString ("action" ));
100+ }
101+
102+ @ Test
103+ void loadFull () throws Exception {
104+ Task .runTask (Task .INIT_DB , Task .INIT_DB .asDocument ());
105+ Task .runTask (Task .LOAD_CONFIG , Task .LOAD_CONFIG .asDocument ());
106+
107+ TestUtils .copyResourceToDataDir ("setting.trig" );
108+ fakeEnv .addVariable ("REGISTRY_SETTING_FILE" , "./data/setting.trig" ).build ();
109+
110+ Task .runTask (Task .LOAD_SETTING , Task .LOAD_SETTING .asDocument ());
111+ Task .runTask (Task .LOAD_FULL , Task .LOAD_FULL .asDocument ());
112+ ClientSession mongoSession = RegistryDB .getClient ().startSession ();
113+
114+ List <Document > retrievedTasks = RegistryDB .collection (Collection .TASKS .toString ())
115+ .find (mongoSession )
116+ .sort (Sorts .descending ("not-before" ))
117+ .into (new ArrayList <>());
118+
119+ assertEquals (retrievedTasks .getFirst ().getString ("action" ), Task .LOAD_FULL .asDocument ().getString ("action" ));
120+ assertEquals (retrievedTasks .get (1 ).getString ("action" ), Task .LOAD_FULL .asDocument ().getString ("action" ));
92121 }
93122
94123}
0 commit comments