How valid is the claim that WWI happened due to fear on the part of the various countries rather than to motives of gain?
This is a very valid claim. Much of the buildup to the war, and much of the sequence that began the war, was caused by countries' fears.
For example, we can argue that Germany worked to strengthen itself before the war because it feared being overwhelmed by enemies on either side. It feared an alliance between France and Russia and worked to make itself strong enough to resist such an alliance.
Paradoxically, this German buildup led to fears on the part of other countries. Britain, for example, felt that Germany might become a real danger. Therefore, Britain started to build up its own military. This, of course, caused more fear on the part of Germany.
These fears, then, pushed various countries to do things that caused WWI to become more likely.