@Test public void testGetMigrationStrategies() { initMockMigration(); Entity entity = new MongoEntity("staff", new HashMap<String, Object>()); List<MigrationStrategy> strategies = sliSchemaVersionValidator.getMigrationStrategies("staff", 0, 2); assertEquals("Should match", 1, strategies.size()); assertTrue("Should be true", strategies.get(0) instanceof AddStrategy); assertTrue("Should be true", checkEntity((Entity) strategies.get(0).migrate(entity), "somefield", "somevalue")); entity = new MongoEntity("staff", new HashMap<String, Object>()); strategies = sliSchemaVersionValidator.getMigrationStrategies("staff", 0, 3); assertEquals("Should match", 2, strategies.size()); assertTrue("Should be true", strategies.get(0) instanceof AddStrategy); assertTrue("Should be true", checkEntity((Entity) strategies.get(0).migrate(entity), "somefield", "somevalue")); assertTrue("Should be true", strategies.get(1) instanceof AddStrategy); assertTrue("Should be true", checkEntity((Entity) strategies.get(1).migrate(entity), "favoriteColor", "yellow")); entity = new MongoEntity("staff", new HashMap<String, Object>()); strategies = sliSchemaVersionValidator.getMigrationStrategies("staff", 0, 4); assertEquals("Should match", 3, strategies.size()); assertTrue("Should be true", strategies.get(0) instanceof AddStrategy); assertTrue("Should be true", checkEntity((Entity) strategies.get(0).migrate(entity), "somefield", "somevalue")); assertTrue("Should be true", strategies.get(1) instanceof AddStrategy); assertTrue("Should be true", checkEntity((Entity) strategies.get(1).migrate(entity), "favoriteColor", "yellow")); assertTrue("Should be true", strategies.get(2) instanceof AddStrategy); assertTrue("Should be true", checkEntity((Entity) strategies.get(2).migrate(entity), "mascot", "red")); entity = new MongoEntity("staff", new HashMap<String, Object>()); strategies = sliSchemaVersionValidator.getMigrationStrategies("staff", 3, 4); assertEquals("Should match", 1, strategies.size()); assertTrue("Should be true", strategies.get(0) instanceof AddStrategy); assertTrue("Should be true", checkEntity((Entity) strategies.get(0).migrate(entity), "mascot", "red")); strategies = sliSchemaVersionValidator.getMigrationStrategies("staff", 0, 1); assertEquals("Should match", 0, strategies.size()); entity = new MongoEntity("staff", new HashMap<String, Object>()); strategies = sliSchemaVersionValidator.getMigrationStrategies("staff", 2, 4); assertEquals("Should match", 2, strategies.size()); assertTrue("Should be true", strategies.get(0) instanceof AddStrategy); assertTrue("Should be true", checkEntity((Entity) strategies.get(0).migrate(entity), "favoriteColor", "yellow")); assertTrue("Should be true", strategies.get(1) instanceof AddStrategy); assertTrue("Should be true", checkEntity((Entity) strategies.get(1).migrate(entity), "mascot", "red")); strategies = sliSchemaVersionValidator.getMigrationStrategies("staff", 3, 1); assertEquals("Should match", 0, strategies.size()); }
protected List<MigrationStrategy> getMigrationStrategies(String entityType, int entityVersionNumber, int newVersionNumber) { Map<String, List<MigrationStrategy>> entityMigrations = migrationStrategyMap.get(entityType); List<MigrationStrategy> allStrategies = new LinkedList<MigrationStrategy>(); if (entityMigrations != null) { for (Integer version = entityVersionNumber+1; version <= newVersionNumber; version++) { List<MigrationStrategy> strategies = entityMigrations.get(version.toString()); if (strategies != null) { allStrategies.addAll(strategies); } } if (!allStrategies.isEmpty()) { return allStrategies; } } return NO_STRATEGIES_DEFINED; }
SliSchemaVersionValidator { protected List<MigrationStrategy> getMigrationStrategies(String entityType, int entityVersionNumber, int newVersionNumber) { Map<String, List<MigrationStrategy>> entityMigrations = migrationStrategyMap.get(entityType); List<MigrationStrategy> allStrategies = new LinkedList<MigrationStrategy>(); if (entityMigrations != null) { for (Integer version = entityVersionNumber+1; version <= newVersionNumber; version++) { List<MigrationStrategy> strategies = entityMigrations.get(version.toString()); if (strategies != null) { allStrategies.addAll(strategies); } } if (!allStrategies.isEmpty()) { return allStrategies; } } return NO_STRATEGIES_DEFINED; } }
SliSchemaVersionValidator { protected List<MigrationStrategy> getMigrationStrategies(String entityType, int entityVersionNumber, int newVersionNumber) { Map<String, List<MigrationStrategy>> entityMigrations = migrationStrategyMap.get(entityType); List<MigrationStrategy> allStrategies = new LinkedList<MigrationStrategy>(); if (entityMigrations != null) { for (Integer version = entityVersionNumber+1; version <= newVersionNumber; version++) { List<MigrationStrategy> strategies = entityMigrations.get(version.toString()); if (strategies != null) { allStrategies.addAll(strategies); } } if (!allStrategies.isEmpty()) { return allStrategies; } } return NO_STRATEGIES_DEFINED; }  }
SliSchemaVersionValidator { protected List<MigrationStrategy> getMigrationStrategies(String entityType, int entityVersionNumber, int newVersionNumber) { Map<String, List<MigrationStrategy>> entityMigrations = migrationStrategyMap.get(entityType); List<MigrationStrategy> allStrategies = new LinkedList<MigrationStrategy>(); if (entityMigrations != null) { for (Integer version = entityVersionNumber+1; version <= newVersionNumber; version++) { List<MigrationStrategy> strategies = entityMigrations.get(version.toString()); if (strategies != null) { allStrategies.addAll(strategies); } } if (!allStrategies.isEmpty()) { return allStrategies; } } return NO_STRATEGIES_DEFINED; }  void insertVersionInformation(Entity entity); @PostConstruct void initMigration(); Entity migrate(String collectionName, Entity entity, ValidationWithoutNaturalKeys repo); Iterable<Entity> migrate(String collectionName, Iterable<Entity> entities, ValidationWithoutNaturalKeys repo); MongoTemplate getMongoTemplate(); void setMongoTemplate(MongoTemplate mongoTemplate); }
SliSchemaVersionValidator { protected List<MigrationStrategy> getMigrationStrategies(String entityType, int entityVersionNumber, int newVersionNumber) { Map<String, List<MigrationStrategy>> entityMigrations = migrationStrategyMap.get(entityType); List<MigrationStrategy> allStrategies = new LinkedList<MigrationStrategy>(); if (entityMigrations != null) { for (Integer version = entityVersionNumber+1; version <= newVersionNumber; version++) { List<MigrationStrategy> strategies = entityMigrations.get(version.toString()); if (strategies != null) { allStrategies.addAll(strategies); } } if (!allStrategies.isEmpty()) { return allStrategies; } } return NO_STRATEGIES_DEFINED; }  void insertVersionInformation(Entity entity); @PostConstruct void initMigration(); Entity migrate(String collectionName, Entity entity, ValidationWithoutNaturalKeys repo); Iterable<Entity> migrate(String collectionName, Iterable<Entity> entities, ValidationWithoutNaturalKeys repo); MongoTemplate getMongoTemplate(); void setMongoTemplate(MongoTemplate mongoTemplate); static final String SARJE; static final String DAL_SV; static final String ID; static final String MONGO_SV; static final String METADATA_COLLECTION; }