@Test public void testPerformMigration() { String entityType = "student"; String collectionName = "student"; Entity entity = new MongoEntity("student", new HashMap<String, Object>()); ValidationWithoutNaturalKeys repo = mock(ValidationWithoutNaturalKeys.class); when(repo.updateWithoutValidatingNaturalKeys(anyString(), any(Entity.class))).thenReturn(true); initMockMigration(); sliSchemaVersionValidator.performMigration(entityType, entity, repo, collectionName, false); Mockito.verify(repo, never()).updateWithoutValidatingNaturalKeys(anyString(), any(Entity.class)); sliSchemaVersionValidator.performMigration(entityType, entity, repo, collectionName, true); Mockito.verify(repo, Mockito.times(1)).updateWithoutValidatingNaturalKeys(anyString(), any(Entity.class)); }
protected Entity performMigration(String entityType, Entity entity, ValidationWithoutNaturalKeys repo, String collectionName, boolean doUpdate) { int newVersionNumber = this.entityTypesBeingMigrated.get(entityType); int entityVersionNumber = this.getEntityVersionNumber(entity); Entity localEntity = entity; for (MigrationStrategy migrationStrategy : this.getMigrationStrategies(entityType, entityVersionNumber, newVersionNumber)) { localEntity = (Entity) migrationStrategy.migrate(localEntity); } localEntity.getMetaData().put(VERSION_NUMBER_FIELD, newVersionNumber); if (doUpdate) { repo.updateWithoutValidatingNaturalKeys(collectionName, localEntity); } return localEntity; }
SliSchemaVersionValidator { protected Entity performMigration(String entityType, Entity entity, ValidationWithoutNaturalKeys repo, String collectionName, boolean doUpdate) { int newVersionNumber = this.entityTypesBeingMigrated.get(entityType); int entityVersionNumber = this.getEntityVersionNumber(entity); Entity localEntity = entity; for (MigrationStrategy migrationStrategy : this.getMigrationStrategies(entityType, entityVersionNumber, newVersionNumber)) { localEntity = (Entity) migrationStrategy.migrate(localEntity); } localEntity.getMetaData().put(VERSION_NUMBER_FIELD, newVersionNumber); if (doUpdate) { repo.updateWithoutValidatingNaturalKeys(collectionName, localEntity); } return localEntity; } }
SliSchemaVersionValidator { protected Entity performMigration(String entityType, Entity entity, ValidationWithoutNaturalKeys repo, String collectionName, boolean doUpdate) { int newVersionNumber = this.entityTypesBeingMigrated.get(entityType); int entityVersionNumber = this.getEntityVersionNumber(entity); Entity localEntity = entity; for (MigrationStrategy migrationStrategy : this.getMigrationStrategies(entityType, entityVersionNumber, newVersionNumber)) { localEntity = (Entity) migrationStrategy.migrate(localEntity); } localEntity.getMetaData().put(VERSION_NUMBER_FIELD, newVersionNumber); if (doUpdate) { repo.updateWithoutValidatingNaturalKeys(collectionName, localEntity); } return localEntity; }  }
SliSchemaVersionValidator { protected Entity performMigration(String entityType, Entity entity, ValidationWithoutNaturalKeys repo, String collectionName, boolean doUpdate) { int newVersionNumber = this.entityTypesBeingMigrated.get(entityType); int entityVersionNumber = this.getEntityVersionNumber(entity); Entity localEntity = entity; for (MigrationStrategy migrationStrategy : this.getMigrationStrategies(entityType, entityVersionNumber, newVersionNumber)) { localEntity = (Entity) migrationStrategy.migrate(localEntity); } localEntity.getMetaData().put(VERSION_NUMBER_FIELD, newVersionNumber); if (doUpdate) { repo.updateWithoutValidatingNaturalKeys(collectionName, localEntity); } return localEntity; }  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 Entity performMigration(String entityType, Entity entity, ValidationWithoutNaturalKeys repo, String collectionName, boolean doUpdate) { int newVersionNumber = this.entityTypesBeingMigrated.get(entityType); int entityVersionNumber = this.getEntityVersionNumber(entity); Entity localEntity = entity; for (MigrationStrategy migrationStrategy : this.getMigrationStrategies(entityType, entityVersionNumber, newVersionNumber)) { localEntity = (Entity) migrationStrategy.migrate(localEntity); } localEntity.getMetaData().put(VERSION_NUMBER_FIELD, newVersionNumber); if (doUpdate) { repo.updateWithoutValidatingNaturalKeys(collectionName, localEntity); } return localEntity; }  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; }