Replace document functionality, test cases for replace document