If you have right of way or any other political alliance, probably wont attack you if it's a two sided agreement. You wont be able to do that with an AI though. Also if you are allied with a country that is later taken over by AI due to lack of player participation; then the AI will likely cancel that alliance.
In regards to TNT's feedback, the AI in my experience attacks regardless of the fact that you have stationed troops at the border. But sometimes the do go to war without doing anything either.