how can I test if a sample was created from a specific Discrete Distribution How can I test if a sample was created from a specific discrete distribution.
For example, if I have the following distribution 
1- 0.2  
2- 0.5 
3- 0.3

and I get the following sample,
[2,2,2,1,1,3,2,2,1] ( the order is not important ) 
How can I test if the sample was created from the distribution?
Or how can reject the hypothesis that sample came from the  distribution.
Thanks.
EDIT
What do you think about the following python code?
In the code I create 100000 samples 
each sample is with size 9 and is from the discrete probability that I wrote above, for example
Sample1 = [1,2,2,1,3,1,1,1,2]
Sample2 = [2,1,2,2,3,2,1,1,2]
Sample3 = [1,2,2,1,2,1,2,1,1]
...
Now I count how many repetition I have from each sample 
( The order does not count. 
[1,1,1,1,1,1,2,2,2] == [2,2,1,1,1,1,1,2,1])
I will get the probability for each sample. after I have the probability of each sample I sum all the probabilities that are lower then the probability of my sample ( The original sample in the question ) .. this is my p value?  ( I got the idea from this link http://en.wikipedia.org/wiki/Multinomial_test ) 
from collections import Counter
import scipy


NumberOfRuns = 100000.0
z = [tuple(sorted(random.choice(3,9,p=[0.2,0.5,0.3])+1)) for i in arange(NumberOfRuns)]  # Create the sample

zz = Counter(z) # Count how many there are from each option.
Psig = 0


# Following the direction in this link  http://en.wikipedia.org/wiki/Multinomial_test
for i in sort(zz.values()):  #Check the sum of all probabilities that are below my sample probability 
    if i>z.count((1,1,1,2,2,2,2,2,3)):
        print 'The sample is more common then ', Psig/NumberOfRuns, ' of all other samples, If this is above 5% you can not reject the hypothesis '
        break
    Psig+=i

 A: A test won't tell you that a sample did come from a given distribution, but one might lead you to conclude that it did not. You might, however, conclude that a sample is consistent with having come from a given distribution.
If your outcomes {1,2,3} are simply category labels, so that under random sampling your sample could be regarded as multinomial, the most common test for this would be the chi-square goodness of fit test. 
An alternative (that's perhaps not recommended as often as it should be) is the G-test.
In either case, you'll typically need substantially larger samples if you hope to have much power.
In cases where the category labels are interval or ratio (particularly in situations when there are many categories rather than just 3), you may have more interest in smooth alternatives (e.g. location-shift, scale-shift, etc alternatives), in which case more powerful tests are available. If you're primarily interested in a location-shift-like alternatives with 3 categories, you might consider this (but otherwise I'd just stick with one of the above tests, as there's little to gain).
An alternative might be an adapted version of a Kolmogorov-Smirnov or an Anderson-Darling test (they must be adapted because of the discreteness of the distribution -- the usual tests don't have the tabulated distribution). Simulation would be a reasonable way to get the p-value for a test of this particular discrete null.
A: The exact multinomial test can be done when there are so few samples. With N=9 there are only 55 possible outcomes. You can compute each probability for the 55 cases. 
from math import factorial
from collections import Counter

# https://en.wikipedia.org/wiki/Multinomial_test
def p(probs, counts): 
    result = factorial(sum(counts))
    for prob, count in zip(probs, counts):
        result *= prob ** count / factorial(count)
    return result

z = [b for a, b in sorted(Counter([2,2,2,1,1,3,2,2,1]).items())]
possibles = [(i, j, k) for i in range(10) for j in range(10) for k in range(10) if i + j + k == 9]
assert tuple(z) in possibles

P0 = p((0.2, 0.5, 0.3), z)
Psig = 0
for possible in possibles:
    P = p((0.2, 0.5, 0.3), possible)
    print("{}: {}".format(possible, P))
    if P <= P0:
        Psig += P

