Is it normal that if one applies to programming job, he must do some programming related task for free before the he signs the collective agreement?
Yes, this is a pretty common practise in IT industry. The goal is to check the candidate's ability to complete a task similar to what they'll be required to take up on a day to day basis.
However, the coding task generally isn't very intensive (definition of intensive varies according to the role and the candidate's experience level) or time consuming, and should be doable in a 1-2 hour time frame. Anything beyond that is asking for too much.
Update: As noted in the comments and from some first hand experience, some companies may ask you to perform one or more programming tasks spanning a day or more. However, this practise is generally followed in reputable/large sized corporations or high tech startups, who generally seek specialized and/or exceptional talent.
While this clearly contradicts with what's established previously, this is a common practise. The company wants to make sure they hire a really good fit. In cases like this you get compensated by getting a lucrative and prestigious job which tends to pay pretty well.
Should I ask payment before I do the task or what to do?
Don't explicitly mention it, as such requests don't put you in good light.
However, in a few rare cases, some companies use this practise unethically to get actual work done by the candidate. If you feel that the assignment is pretty lengthy and requires way more time and effort than is typical for an interview, you may not choose not to go ahead with the interview at your own discretion.
In a few cases it is seen that companies offer to pay for the time that you spend completing the task. This happens when it requires one to a few days of effort.
I'm very junior in getting job.
It's safe not to explicitly ask for any compensation, especially considering that you are a junior developer and may not have specialized skills which the company may find valuable beyond their general expectation.
A guideline you can follow is to go for the task only if you really value the opportunity and are eager to work for the organization in question.
P.S.: By demonstrating your skills in an exceptional manner in the assignment puts you in a better position to negotiate your compensation. The assignment is generally reviewed by a senior team member or hiring manager and not by the HR or the recruiter. Thus, impressing the one who designed the test enables you to get compensated indirectly (in a recurring manner on a monthly basis instead of just one time that you may be currently seeking).