Because taking away the rats perception stops the stress because the rat can't perceive the stress but the rat being conscious sees the stress positive thinking wouldn't prevent the stress that is there.No, it is the perception and interpretation of the constraint, not the constraint itself.
If you prevent the rat from perceiving/interpreting the constraint by temporally deactivating its consciousness (anesthetizing it), the ulcers would not have been formed.