(The Baal shem tov said, that joy leads one to the greatest heights, it is a foundation for all Mitzvot.)
A person will always be happy if he realizes and is aware that everything is Hashgocho Protis, meaning, that everything that happens comes as a direct result of G-d's Will. Everything that happens to us, even difficulties and undesirable events, are controlled by Hashem. And we must trust that there is a good reason for everything in our life.
When we are sad or depressed, our energy is drained, we are weak and it is possible that the evil inclination will overpower us.(chsv)
Experiences that appear negative, undesirable, are really disguised good and it is only a test for us.
G-d is testing us to see how committed we are to the Torah and Mitzvos.
Chassidus gives a deeper explanation for the purpose of these tests and challenges.
It explains that the word, "test" - Nisayon, comes from the word "l'nasos", which means - "to test", and it also means "to raise high".
The tests and challenges we face are intended to enable us to reach a higher spiritual level.
G-d chose to allow us to reach a higher spiritual level thru tests and challenges.
When we realize that there is G-dliness contained in these challenging experiences it helps us become aware that they are in essence hidden good.
When we realize and believe that everything is really good then that will cause us to be truly happy.